There is something fishy about the calculation of far future dates when done on the browser side (Safari 5.0.1), passing strings into the Date() constructor:
I narrowed it down to the February-March transition in year 22034:
d = new Date('1 Mar 22034')
Tue Feb 28 22034 00:00:00 GMT+0000 (GMT)
Feeding it any later date, the constructor always returns a Date object off-by-one day!
What about earlier dates? The last day in February looks good:
d=new Date('28 Feb 22034')
Tue Feb 28 22034 00:00:00 GMT+0000 (GMT)
My gut-feeling tells me that looks like a leap-year related bug. But what is the pattern in play here, what could be the explanation of the bug?
Edit:
How about if we ask for February 29th?
d=new Date('29 Feb 22034')
Wed Mar 01 22034 00:00:00 GMT+0000 (GMT)
That returns the last of Feb + 1 day (its standard behavior).
It's because the date format you're giving
new Date()
is non-standard. The fact you're getting anything is because Safari is doing you a favor. (See section 15.9.1.15 of the spec for valid formats; basically a simplified ISO-8601. And having any standard for parsing date/time strings is relatively new [5th edition].)If you use a standard constructor, e.g.,
new Date (22034, 2, 1)
(months start at zero, so that's March 1, 22034), it works fine. You can test it like this (live copy):Which for me using Safari for Windows results in:
As you can see, the first line shows the incorrect date, while the second line shows the correct one.
The standard constructor also works correctly in Chrome, Opera, and Firefox (all under Ubuntu), IE6, IE7, and IE8: http://jsbin.com/ogiqu
If it were really true that Safari couldn't handle that date (as opposed to not parsing the non-standard string you gave it reliably), it would be a surprising Safari-specific bug. From section 15.9.1.1 of the spec:
But as Safari seems to handle it fine when you don't ask it to go off-piste, apparently the problem is in the parsing code for non-standard strings.