Ticket #5047 (closed defect: fixed)

Opened 13 months ago

Last modified 13 months ago

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

Reported by: BryanForbes Owned by: peller
Priority: high Milestone: 1.0.1
Component: Date Version: 1.0
Severity: blocker Keywords: patch
Cc: BryanForbes

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

date_test.diff (7.3 kB) - added by BryanForbes 13 months ago.
date_fix.diff (357 bytes) - added by BryanForbes 13 months ago.

Change History

Changed 13 months ago by BryanForbes

Changed 13 months ago by BryanForbes

Changed 13 months ago by peller

  • summary changed from dojo.date.add doesn't correctly calculate hours or weekdays to dojo.date.add doesn't correctly calculate hours or weekdays for DST

Changed 13 months ago by peller

  • status changed from new to closed
  • resolution set to fixed

Fixed in [11448] and [11449]

Note: See TracTickets for help on using tickets.