timezone offset error in getWeekOfYear v0.3.1
There's an issue with the current implementation that fails when the first week of the year and the current
week of the year aren't in the same timezone (which happens often due to daylight savings time).
Found this in v 0.3.1 but checked and v.4.x isn't different.
This is how we fixed it. Hope it helps.
dojo.date.getWeekOfYear = function (dateObject, firstDay) {
if (arguments.length == 1) { firstDay = 0; } // Sunday
// work out the first day of the year corresponding to the week
var firstDayOfYear = new Date(dateObject.getFullYear(), 0, 1);
var day = firstDayOfYear.getDay();
// XXX fix for timezone differences
var dateOffset = dateObject.getTimezoneOffset();
var fdateOffset = firstDayOfYear.getTimezoneOffset();
//dojo.debug("-- input tz offset: "+dateOffset+" vs firstday tz offset: "+fdateOffset);
var diffOffset = fdateOffset - dateOffset;
dateObject.setMinutes( dateObject.getMinutes() + diffOffset );
// XXX fixing an order of operations bug
firstDayOfYear.setDate(firstDayOfYear.getDate() - (day + firstDay - (day > firstDay ? 7 : 0)));
return Math.floor( (dateObject.getTime() - firstDayOfYear.getTime()) / 604800000 );
}
yikes, formatting not preserved. sorry about that, not as readable as it looked when creating it.
contact info:
Brec Carson [email protected]…