Edit: godver ik maak er een zooitje van. Hoe dan ook. Hier heb je wat functies, hoop dat je er wat mee kan, zoek de logica zelf maar uit.
function getBoundaries(dObj, dayFirst, dayLast)
{
var bounds = new Array();
bounds[0] = new Date(dObj.getFullYear(), dObj.getMonth(), (dObj.getDate() + dayFirst));
bounds[1] = new Date(dObj.getFullYear(), dObj.getMonth(), (dObj.getDate() + dayLast));
return bounds;
}
function getWeekBoundaries(today)
{
var day = today.getDay();
var startday = 1; // 0 = Sunday 1 = Monday
var bounds;
switch (day)
{
case 0:
bounds = (startday) ? getBoundaries(today, 7, 0) : getBoundaries(today, 0, 6);
break;
case 1:
bounds = (startday) ? getBoundaries(today, 0, 6) : getBoundaries(today, -1, 5);
break;
case 2:
bounds = (startday) ? getBoundaries(today, -1, 5) : getBoundaries(today, -2, 4);
break;
case 3:
bounds = (startday) ? getBoundaries(today, -2, 4) : getBoundaries(today, -3, 3);
break;
case 4:
bounds = (startday) ? getBoundaries(today, -3, 3) : getBoundaries(today, -4, 2);
break;
case 5:
bounds = (startday) ? getBoundaries(today, -4, 2) : getBoundaries(today, -5, 1);
break;
case 6:
bounds = (startday) ? getBoundaries(today, -5, 1) : getBoundaries(today, 7, 0);
break;
}
return bounds;
}
Date.prototype.getWeek = function()
{
var thisDate = this;
var year = thisDate.getFullYear();
var month = thisDate.getMonth();
var day = thisDate.getDate();
month += 1;
var a = Math.floor((14-(month))/12);
var y = year+4800-a;
var m = (month)+(12*a)-3;
var jd = day + Math.floor(((153*m)+2)/5) +
(365*y) + Math.floor(y/4) - Math.floor(y/100) +
Math.floor(y/400) - 32045;
var d4 = (jd+31741-(jd%7))%146097%36524%1461;
var L = Math.floor(d4/1460);
var d1 = ((d4-L)%365)+L;
NumberOfWeek = Math.floor(d1/7) + 1;
return NumberOfWeek;
}