Closed Bug 4088 Opened 26 years ago Closed

Date parsing gets 12:30 AM wrong.

Categories

(Core :: JavaScript Engine, defect, P3)

defect

Tracking

()

VERIFIED FIXED

People

(Reporter: mike+mozilla, Assigned: mike+mozilla)

Details

js> d = new Date('1/1/1999 12:30 AM')
Fri Jan 01 12:30:00 PST 1999
js>  d = new Date('1/1/1999 12:30 PM')
Sat Jan 02 00:30:00 PST 1999

... This also occurs in our Java implementation.  Looks like I copied the
parsing code a little too faithfully.
Checked in a fix to the tip, SpiderMonkeyDev_BRANCH, SpiderMonkey140_BRANCH, and
the java implementation.  The fix checks for 12:XX AM (subtract 12 for this
case, otherwise do nothing for AM) and checks for 12:XX PM (subtract 12 for any
hour except 12; leave 12:XX PM alone.)

This fix also applies the hour <= 12 check to the AM case that previously only
applied to the PM case (because no time adjustment was done for AM.)  This means
that the date string '1/1/1999 13:30 AM' no longer produces a valid date.  I'm
guessing that this will be ok, because '1/1/1999 13:30 PM' never did.

Old behavior:
js> d = new Date('1/1/1999 13:30 AM')
Fri Jan 01 13:30:00 GMT-0800 (PST) 1999
js> d = new Date('1/1/1999 13:30 PM')
Invalid Date
js> d = new Date('1/1/1999 12:30 AM')
Fri Jan 01 12:30:00 GMT-0800 (PST) 1999
js> d = new Date('1/1/1999 12:30 PM')
Sat Jan 02 00:30:00 GMT-0800 (PST) 1999

New behavior:
js> d = new Date('1/1/1999 13:30 AM')
Invalid Date
js> d = new Date('1/1/1999 13:30 PM')
Invalid Date
js> d = new Date('1/1/1999 12:30 AM')
Fri Jan 01 00:30:00 GMT-0800 (PST) 1999
js> d = new Date('1/1/1999 12:30 PM')
Fri Jan 01 12:30:00 GMT-0800 (PST) 1999
Checked in a fix to the tip, SpiderMonkeyDev_BRANCH, SpiderMonkey140_BRANCH, and
the java implementation.  The fix checks for 12:XX AM (subtract 12 for this
case, otherwise do nothing for AM) and checks for 12:XX PM (subtract 12 for any
hour except 12; leave 12:XX PM alone.)

This fix also applies the hour <= 12 check to the AM case that previously only
applied to the PM case (because no time adjustment was done for AM.)  This means
that the date string '1/1/1999 13:30 AM' no longer produces a valid date.  I'm
guessing that this will be ok, because '1/1/1999 13:30 PM' never did.

Old behavior:
js> d = new Date('1/1/1999 13:30 AM')
Fri Jan 01 13:30:00 GMT-0800 (PST) 1999
js> d = new Date('1/1/1999 13:30 PM')
Invalid Date
js> d = new Date('1/1/1999 12:30 AM')
Fri Jan 01 12:30:00 GMT-0800 (PST) 1999
js> d = new Date('1/1/1999 12:30 PM')
Sat Jan 02 00:30:00 GMT-0800 (PST) 1999

New behavior:
js> d = new Date('1/1/1999 13:30 AM')
Invalid Date
js> d = new Date('1/1/1999 13:30 PM')
Invalid Date
js> d = new Date('1/1/1999 12:30 AM')
Fri Jan 01 00:30:00 GMT-0800 (PST) 1999
js> d = new Date('1/1/1999 12:30 PM')
Fri Jan 01 12:30:00 GMT-0800 (PST) 1999
so are you going to write some test cases for Date.parse.  :)
Changing component to "Javascript Engine".  "Javascript" component is being
retired.
Status: RESOLVED → VERIFIED
checked in a regression test:  mozilla/js/tests/ecma/Date/15.9.4.2-1.js
You need to log in before you can comment on or make changes to this bug.