Opened 16 years ago

Last modified 15 years ago

#2024 closed defect

timezone offset error in getWeekOfYear v0.3.1 — at Initial Version

Reported by: [email protected] Owned by: anonymous
Priority: high Milestone: 0.9
Component: Date Version: 0.4
Keywords: Cc: [email protected]
Blocked By: Blocking:

Description

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 );

}

Change History (0)

Note: See TracTickets for help on using tickets.