Opened 12 years ago

Closed 12 years ago

Last modified 10 years ago

#5047 closed defect (fixed)

dojo.date.add doesn't correctly calculate hours or weekdays for DST

Reported by: Bryan Forbes Owned by: Adam Peller
Priority: high Milestone: 1.0.1
Component: Date Version: 1.0
Keywords: patch Cc: Bryan Forbes
Blocked By: Blocking:

Description

I'm attaching a patch to update the date tests to compare what dojo.date.add is doing to what dojo.date.difference comes up with when comparing the resulting date to the original date. With dojo.date as it is, the hour test fails on DST days because add is using the [get|set]{Property} functions. Here's some results of some tests I've run:

Input:
// not using dojo.date (showing how dojo.date.add does it internally)
var d = new Date(2007, 10, 4);
var d1 = new Date(2007, 10, 4);
d1.setHours(1)
console.debug(d);
console.debug(d1);
console.debug((d1.getTime() - d.getTime()) / 1000 / 60 / 60); // difference in hours

// using dojo.date
var d2 = dojo.date.add(d, 'hour', 1);
console.debug(d2);
console.debug(dojo.date.difference(d, d2, 'hour'));

Output:
// not using dojo.date
Sun Nov 04 2007 00:00:00 GMT-0500 (CDT)
Sun Nov 04 2007 01:00:00 GMT-0600 (CST)
2
// using dojo.date
Sun Nov 04 2007 01:00:00 GMT-0600 (CST)
2

I've also attached a patch to fix dojo.date.add for hours by using the [getUTC|setUTC]{Property} methods. Since UTC doesn't have DST, you're basically adding right to the internal milliseconds representation of the date.

Attachments (2)

date_test.diff (7.3 KB) - added by Bryan Forbes 12 years ago.
date_fix.diff (357 bytes) - added by Bryan Forbes 12 years ago.

Download all attachments as: .zip

Change History (4)

Changed 12 years ago by Bryan Forbes

Attachment: date_test.diff added

Changed 12 years ago by Bryan Forbes

Attachment: date_fix.diff added

comment:1 Changed 12 years ago by Adam Peller

Summary: dojo.date.add doesn't correctly calculate hours or weekdaysdojo.date.add doesn't correctly calculate hours or weekdays for DST

comment:2 Changed 12 years ago by Adam Peller

Resolution: fixed
Status: newclosed

Fixed in [11448] and [11449]

Note: See TracTickets for help on using tickets.