Opened 13 years ago

Closed 12 years ago

Last modified 3 years ago

#3112 closed defect (fixed)

0.9: Date diff function fails in UT on IE 7 and IE 6

Reported by: Jared Jurkiewicz Owned by: Adam Peller
Priority: high Milestone: 0.9beta
Component: Date Version: 0.9
Keywords: Cc:
Blocked By: Blocking:

Description (last modified by bill)

0.9: Date diff function fails in UT on IE 7 and IE 6

_AssertFailure: [object Error]: assertEqual() failed: expected |1| but got |1000|

[object Error]

ERROR IN:

function test_date_diff(t){ var dtA = null; First date to compare var dtB = null; Second date to compare var interv = ; Interval to compare on (e.g., year, month) interv = "year"; dtA = new Date(2005, 11, 27); dtB = new Date(2006, 11, 27); t.is(1, dojo.date.difference(dtA, dtB, interv)); dtA = new Date(2000, 11, 31); dtB = new Date(2001, 0, 1); t.is(1, dojo.date.difference(dtA, dtB, interv)); interv = "quarter"; dtA = new Date(2000, 1, 29); dtB = new Date(2001, 2, 1); t.is(4, dojo.date.difference(dtA, dtB, interv)); dtA = new Date(2000, 11, 1); dtB = new Date(2001, 0, 1); t.is(1, dojo.date.difference(dtA, dtB, interv)); interv = "month"; dtA = new Date(2000, 1, 29); dtB = new Date(2001, 2, 1); t.is(13, dojo.date.difference(dtA, dtB, interv)); dtA = new Date(2000, 11, 1); dtB = new Date(2001, 0, 1); t.is(1, dojo.date.difference(dtA, dtB, interv)); interv = "week"; dtA = new Date(2000, 1, 1); dtB = new Date(2000, 1, 8); t.is(1, dojo.date.difference(dtA, dtB, interv)); dtA = new Date(2000, 1, 28); dtB = new Date(2000, 2, 6); t.is(1, dojo.date.difference(dtA, dtB, interv)); dtA = new Date(2000, 2, 6); dtB = new Date(2000, 1, 28); t.is(-1, dojo.date.difference(dtA, dtB, interv)); interv = "day"; dtA = new Date(2000, 1, 29); dtB = new Date(2000, 2, 1); t.is(1, dojo.date.difference(dtA, dtB, interv)); dtA = new Date(2000, 11, 31); dtB = new Date(2001, 0, 1); t.is(1, dojo.date.difference(dtA, dtB, interv)); DST leap -- check for rounding err This is dependent on US calendar, but shouldn't break in other locales dtA = new Date(2005, 3, 3); dtB = new Date(2005, 3, 4); t.is(1, dojo.date.difference(dtA, dtB, interv)); interv = "weekday"; dtA = new Date(2006, 7, 3); dtB = new Date(2006, 7, 11); t.is(6, dojo.date.difference(dtA, dtB, interv)); Positive diffs dtA = new Date(2006, 7, 4); dtB = new Date(2006, 7, 11); t.is(5, dojo.date.difference(dtA, dtB, interv)); dtA = new Date(2006, 7, 5); dtB = new Date(2006, 7, 11); t.is(5, dojo.date.difference(dtA, dtB, interv)); dtA = new Date(2006, 7, 6); dtB = new Date(2006, 7, 11); t.is(5, dojo.date.difference(dtA, dtB, interv)); dtA = new Date(2006, 7, 7); dtB = new Date(2006, 7, 11); t.is(4, dojo.date.difference(dtA, dtB, interv)); dtA = new Date(2006, 7, 7); dtB = new Date(2006, 7, 13); t.is(4, dojo.date.difference(dtA, dtB, interv)); dtA = new Date(2006, 7, 7); dtB = new Date(2006, 7, 14); t.is(5, dojo.date.difference(dtA, dtB, interv)); dtA = new Date(2006, 7, 7); dtB = new Date(2006, 7, 15); t.is(6, dojo.date.difference(dtA, dtB, interv)); dtA = new Date(2006, 7, 7); dtB = new Date(2006, 7, 28); t.is(15, dojo.date.difference(dtA, dtB, interv)); dtA = new Date(2006, 2, 2); dtB = new Date(2006, 2, 28); t.is(18, dojo.date.difference(dtA, dtB, interv)); Negative diffs dtA = new Date(2006, 7, 11); dtB = new Date(2006, 7, 4); t.is(-5, dojo.date.difference(dtA, dtB, interv)); dtA = new Date(2006, 7, 11); dtB = new Date(2006, 7, 5); t.is(-4, dojo.date.difference(dtA, dtB, interv)); dtA = new Date(2006, 7, 11); dtB = new Date(2006, 7, 6); t.is(-4, dojo.date.difference(dtA, dtB, interv)); dtA = new Date(2006, 7, 11); dtB = new Date(2006, 7, 7); t.is(-4, dojo.date.difference(dtA, dtB, interv)); dtA = new Date(2006, 7, 13); dtB = new Date(2006, 7, 7); t.is(-5, dojo.date.difference(dtA, dtB, interv)); dtA = new Date(2006, 7, 14); dtB = new Date(2006, 7, 7); t.is(-5, dojo.date.difference(dtA, dtB, interv)); dtA = new Date(2006, 7, 15); dtB = new Date(2006, 7, 7); t.is(-6, dojo.date.difference(dtA, dtB, interv)); dtA = new Date(2006, 7, 28); dtB = new Date(2006, 7, 7); t.is(-15, dojo.date.difference(dtA, dtB, interv)); dtA = new Date(2006, 2, 28); dtB = new Date(2006, 2, 2); t.is(-18, dojo.date.difference(dtA, dtB, interv)); Two days on the same weekend -- no weekday diff dtA = new Date(2006, 7, 5); dtB = new Date(2006, 7, 6); t.is(0, dojo.date.difference(dtA, dtB, interv)); interv = "hour"; dtA = new Date(2000, 11, 31, 23); dtB = new Date(2001, 0, 1, 0); t.is(1, dojo.date.difference(dtA, dtB, interv)); dtA = new Date(2000, 11, 31, 12); dtB = new Date(2001, 0, 1, 0); t.is(12, dojo.date.difference(dtA, dtB, interv)); interv = "minute"; dtA = new Date(2000, 11, 31, 23, 59); dtB = new Date(2001, 0, 1, 0, 0); t.is(1, dojo.date.difference(dtA, dtB, interv)); dtA = new Date(2000, 1, 28, 23, 59); dtB = new Date(2000, 1, 29, 0, 0); t.is(1, dojo.date.difference(dtA, dtB, interv)); interv = "second"; dtA = new Date(2000, 11, 31, 23, 59, 59); dtB = new Date(2001, 0, 1, 0, 0, 0); t.is(1, dojo.date.difference(dtA, dtB, interv)); interv = "millisecond"; dtA = new Date(2000, 11, 31, 23, 59, 59, 999); dtB = new Date(2001, 0, 1, 0, 0, 0, 0); t.is(1, dojo.date.difference(dtA, dtB, interv)); dtA = new Date(2000, 11, 31, 23, 59, 59, 0); dtB = new Date(2001, 0, 1, 0, 0, 0, 0); t.is(1000, dojo.date.difference(dtA, dtB, interv)); }

FAILED test: test_date_diff

Change History (7)

comment:1 Changed 13 years ago by Adam Peller

Owner: changed from psowden to Adam Peller

comment:2 Changed 13 years ago by Adam Peller

works for me

comment:3 Changed 13 years ago by Jared Jurkiewicz

I updated again a bit ago and there were some changes in _base files. When I did that everything started working again. I guess this was some sort of base point in time issue?

comment:4 Changed 13 years ago by Jared Jurkiewicz

Spoke too soon. Just re-ran the UT on IE 7, failed again.

------------------------------------------------------------ GROUP "tests.date.math" has 3 tests to run PASSED test: test_date_compare PASSED test: test_date_add

_AssertFailure: [object Error]: assertEqual() failed: expected |1| but got |1000|

[object Error]

ERROR IN:

function test_date_diff(t){ var dtA = null; First date to compare var dtB = null; Second date to compare var interv = ; Interval to compare on (e.g., year, month) interv = "year"; dtA = new Date(2005, 11, 27); dtB = new Date(2006, 11, 27); t.is(1, dojo.date.difference(dtA, dtB, interv)); dtA = new Date(2000, 11, 31); dtB = new Date(2001, 0, 1); t.is(1, dojo.date.difference(dtA, dtB, interv)); interv = "quarter"; dtA = new Date(2000, 1, 29); dtB = new Date(2001, 2, 1); t.is(4, dojo.date.difference(dtA, dtB, interv)); dtA = new Date(2000, 11, 1); dtB = new Date(2001, 0, 1); t.is(1, dojo.date.difference(dtA, dtB, interv)); interv = "month"; dtA = new Date(2000, 1, 29); dtB = new Date(2001, 2, 1); t.is(13, dojo.date.difference(dtA, dtB, interv)); dtA = new Date(2000, 11, 1); dtB = new Date(2001, 0, 1); t.is(1, dojo.date.difference(dtA, dtB, interv)); interv = "week"; dtA = new Date(2000, 1, 1); dtB = new Date(2000, 1, 8); t.is(1, dojo.date.difference(dtA, dtB, interv)); dtA = new Date(2000, 1, 28); dtB = new Date(2000, 2, 6); t.is(1, dojo.date.difference(dtA, dtB, interv)); dtA = new Date(2000, 2, 6); dtB = new Date(2000, 1, 28); t.is(-1, dojo.date.difference(dtA, dtB, interv)); interv = "day"; dtA = new Date(2000, 1, 29); dtB = new Date(2000, 2, 1); t.is(1, dojo.date.difference(dtA, dtB, interv)); dtA = new Date(2000, 11, 31); dtB = new Date(2001, 0, 1); t.is(1, dojo.date.difference(dtA, dtB, interv)); DST leap -- check for rounding err This is dependent on US calendar, but shouldn't break in other locales dtA = new Date(2005, 3, 3); dtB = new Date(2005, 3, 4); t.is(1, dojo.date.difference(dtA, dtB, interv)); interv = "weekday"; dtA = new Date(2006, 7, 3); dtB = new Date(2006, 7, 11); t.is(6, dojo.date.difference(dtA, dtB, interv)); Positive diffs dtA = new Date(2006, 7, 4); dtB = new Date(2006, 7, 11); t.is(5, dojo.date.difference(dtA, dtB, interv)); dtA = new Date(2006, 7, 5); dtB = new Date(2006, 7, 11); t.is(5, dojo.date.difference(dtA, dtB, interv)); dtA = new Date(2006, 7, 6); dtB = new Date(2006, 7, 11); t.is(5, dojo.date.difference(dtA, dtB, interv)); dtA = new Date(2006, 7, 7); dtB = new Date(2006, 7, 11); t.is(4, dojo.date.difference(dtA, dtB, interv)); dtA = new Date(2006, 7, 7); dtB = new Date(2006, 7, 13); t.is(4, dojo.date.difference(dtA, dtB, interv)); dtA = new Date(2006, 7, 7); dtB = new Date(2006, 7, 14); t.is(5, dojo.date.difference(dtA, dtB, interv)); dtA = new Date(2006, 7, 7); dtB = new Date(2006, 7, 15); t.is(6, dojo.date.difference(dtA, dtB, interv)); dtA = new Date(2006, 7, 7); dtB = new Date(2006, 7, 28); t.is(15, dojo.date.difference(dtA, dtB, interv)); dtA = new Date(2006, 2, 2); dtB = new Date(2006, 2, 28); t.is(18, dojo.date.difference(dtA, dtB, interv)); Negative diffs dtA = new Date(2006, 7, 11); dtB = new Date(2006, 7, 4); t.is(-5, dojo.date.difference(dtA, dtB, interv)); dtA = new Date(2006, 7, 11); dtB = new Date(2006, 7, 5); t.is(-4, dojo.date.difference(dtA, dtB, interv)); dtA = new Date(2006, 7, 11); dtB = new Date(2006, 7, 6); t.is(-4, dojo.date.difference(dtA, dtB, interv)); dtA = new Date(2006, 7, 11); dtB = new Date(2006, 7, 7); t.is(-4, dojo.date.difference(dtA, dtB, interv)); dtA = new Date(2006, 7, 13); dtB = new Date(2006, 7, 7); t.is(-5, dojo.date.difference(dtA, dtB, interv)); dtA = new Date(2006, 7, 14); dtB = new Date(2006, 7, 7); t.is(-5, dojo.date.difference(dtA, dtB, interv)); dtA = new Date(2006, 7, 15); dtB = new Date(2006, 7, 7); t.is(-6, dojo.date.difference(dtA, dtB, interv)); dtA = new Date(2006, 7, 28); dtB = new Date(2006, 7, 7); t.is(-15, dojo.date.difference(dtA, dtB, interv)); dtA = new Date(2006, 2, 28); dtB = new Date(2006, 2, 2); t.is(-18, dojo.date.difference(dtA, dtB, interv)); Two days on the same weekend -- no weekday diff dtA = new Date(2006, 7, 5); dtB = new Date(2006, 7, 6); t.is(0, dojo.date.difference(dtA, dtB, interv)); interv = "hour"; dtA = new Date(2000, 11, 31, 23); dtB = new Date(2001, 0, 1, 0); t.is(1, dojo.date.difference(dtA, dtB, interv)); dtA = new Date(2000, 11, 31, 12); dtB = new Date(2001, 0, 1, 0); t.is(12, dojo.date.difference(dtA, dtB, interv)); interv = "minute"; dtA = new Date(2000, 11, 31, 23, 59); dtB = new Date(2001, 0, 1, 0, 0); t.is(1, dojo.date.difference(dtA, dtB, interv)); dtA = new Date(2000, 1, 28, 23, 59); dtB = new Date(2000, 1, 29, 0, 0); t.is(1, dojo.date.difference(dtA, dtB, interv)); interv = "second"; dtA = new Date(2000, 11, 31, 23, 59, 59); dtB = new Date(2001, 0, 1, 0, 0, 0); t.is(1, dojo.date.difference(dtA, dtB, interv)); interv = "millisecond"; dtA = new Date(2000, 11, 31, 23, 59, 59, 999); dtB = new Date(2001, 0, 1, 0, 0, 0, 0); t.is(1, dojo.date.difference(dtA, dtB, interv)); dtA = new Date(2000, 11, 31, 23, 59, 59, 0); dtB = new Date(2001, 0, 1, 0, 0, 0, 0); t.is(1000, dojo.date.difference(dtA, dtB, interv)); }

FAILED test: test_date_diff ------------------------------------------------------------

comment:5 Changed 12 years ago by Adam Peller

Status: newassigned

Fascinating.

new Date(new Date(2000,11,31,23,59,59,999)).getMilliseconds()

yields "0" in IE. Basically, in IE, the Date constructor, copies all fields except milliseconds. I'm guessing that milliseconds don't matter anywhere else in our code, really, so this is the only place we get bitten by this.

There are two ways to fix this: 'cast' the date down to a number before making a new date object out of it, or just remove that line and require that args be passed in as dates, not numbers. Given the mission of 0.9, I'm going with the latter.

comment:6 Changed 12 years ago by Adam Peller

Resolution: fixed
Status: assignedclosed

(In [8721]) Fix millisecond problem on IE by removing timestamp-style arguments, plus some style fixes.Fixes #3112

comment:7 Changed 3 years ago by bill

Description: modified (diff)

For the record, new Date(otherDate) is not part of the Date API at all, see https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Date.

Note: See TracTickets for help on using tickets.