Bug 14176

Summary: Some date values not handled consistently with IE/Firefox
Product: WebKit Reporter: Arno Gourdol <arno>
Component: JavaScriptCoreAssignee: Nobody <webkit-unassigned>
Status: RESOLVED FIXED    
Severity: Normal CC: barraclough, mrowe, mvujovic, webkit.review.bot
Priority: P2    
Version: 523.x (Safari 3)   
Hardware: All   
OS: All   
URL: javascript:var d = new Date("November 06 2006, 17:53:01"); alert( d + "\nAbove document.write should have written: 'Mon Nov 6 17:53:01 PST 2006'");
Attachments:
Description Flags
Patch none

Arno Gourdol
Reported 2007-06-15 13:56:13 PDT
The following code snippet does not return the expected result. var d = new Date("November 06 2006, 17:53:01"); document.write( d + "<br>Above document.write should have written: 'Mon Nov 6 17:53:01 PST 2006' ); The correct answer is returned by IE and FireFox. Instead, the date returned is the string "Invalid Date".
Attachments
Patch (4.54 KB, patch)
2011-11-22 15:58 PST, Max Vujovic
no flags
David Gatwood
Comment 1 2008-04-10 19:34:24 PDT
I just ran into a very closely related bug in an existing website that probably subtly impacts a lot of other websites as well. The following script should show exactly the same date in both cases, and in FireFox and IE, it does. In Safari, it subtracts four minutes instead of four hours! Please spend some time on the date parser and fix these issues.... <script language="javascript" type="text/javascript"> var mydate = new Date("4/13/2008 12:00 AM GMT-4"); var mydate_b = new Date("4/13/2008 12:00 AM GMT-0400"); document.write(mydate + ' = ' + mydate_b); </script>
Max Vujovic
Comment 2 2011-11-22 15:58:24 PST
Created attachment 116287 [details] Patch I couldn't reproduce Arno's original bug in r100958. The code snippet outputs "Mon Nov 06 2006 17:53:01 GMT-0800 (PST)" instead of "Invalid Date" for me. However, I did reproduce David's bug in the second comment. WebKit interprets "GMT-4" as 4 minutes. On the other hand, IE, Firefox, and Opera interpret "GMT-4" as 4 hours. This case is defined as implementation specific in the ECMA Standard (See Section 15.9.4.2), but I think WebKit should match IE, FireFox, and Opera's behavior. WebKit's implementation reads in the number after "GMT-" and mods by 100 for the minute offset and divides by 100 for the hour offset for all numbers. On the other hand, IE, FireFox, and Opera only do this if the number is greater than or equal to 24. If the number is less than 24, they interpret it as an hour offset with no minutes. Interestingly, even "GMT-0004" is interpreted as four hours in IE, FireFox, and Opera. I used this test script to compare the behaviors: <script language="javascript" type="text/javascript"> document.write('"4/13/2008 12:00 AM GMT-4" parsed: ' + new Date('4/13/2008 12:00 AM GMT-4') + '<br/>'); document.write('"4/13/2008 12:00 AM GMT-23" parsed: ' + new Date('4/13/2008 12:00 AM GMT-23') + '<br/>'); document.write('"4/13/2008 12:00 AM GMT-023" parsed: ' + new Date('4/13/2008 12:00 AM GMT-023') + '<br/>'); document.write('"4/13/2008 12:00 AM GMT-0023" parsed: ' + new Date('4/13/2008 12:00 AM GMT-0023') + '<br/>'); document.write('"4/13/2008 12:00 AM GMT-24" parsed: ' + new Date('4/13/2008 12:00 AM GMT-24') + '<br/>'); document.write('"4/13/2008 12:00 AM GMT-024" parsed: ' + new Date('4/13/2008 12:00 AM GMT-024') + '<br/>'); document.write('"4/13/2008 12:00 AM GMT-0024" parsed: ' + new Date('4/13/2008 12:00 AM GMT-0024') + '<br/>'); document.write('"4/13/2008 12:00 AM GMT-0123" parsed: ' + new Date('4/13/2008 12:00 AM GMT-0123') + '<br/>'); </script> The results were: GMT-4 = 4 hours in IE, FireFox, and Opera vs. 4 minutes in WebKit GMT-23 = 23 hours in IE, FireFox, and Opera vs. 23 minutes in WebKit GMT-023 = same as above GMT-0023 = same as above GMT-24 = 24 minutes in all implementations (IE, FireFox, Opera, and WebKit) GMT-024= same as above GMT-0024 = same as above GMT-0123 = 1 hour, 23 minutes in all implementations (IE, FireFox, Opera, and WebKit) I've uploaded a patch that makes WebKit match the IE, FireFox, and Opera behavior.
Gavin Barraclough
Comment 3 2011-11-30 11:21:14 PST
Comment on attachment 116287 [details] Patch Looks great.
WebKit Review Bot
Comment 4 2011-11-30 18:15:31 PST
Comment on attachment 116287 [details] Patch Clearing flags on attachment: 116287 Committed r101582: <http://trac.webkit.org/changeset/101582>
WebKit Review Bot
Comment 5 2011-11-30 18:15:35 PST
All reviewed patches have been landed. Closing bug.
Note You need to log in before you can comment on or make changes to this bug.