WebKit Bugzilla
New
Browse
Log In
×
Sign in with GitHub
or
Remember my login
Create Account
·
Forgot Password
Forgotten password account recovery
RESOLVED INVALID
32358
Date object generates error for DD/MM/YYYY dates
https://bugs.webkit.org/show_bug.cgi?id=32358
Summary
Date object generates error for DD/MM/YYYY dates
Estêvão Samuel Procópio Amaral
Reported
2009-12-09 18:48:29 PST
When creating a date object with new Date("27/12/2009") (DD/MM/YYYY) an error is thrown saying it's an invalid date. JavaScriptCore expects dates in MM/DD/YYYY format and isn't able to parse DD/MM/YYYY dates.
Attachments
Patch to make JavaScriptCore parse DD/MM/YYYY dates correctly
(1.92 KB, patch)
2009-12-09 18:58 PST
,
Estêvão Samuel Procópio Amaral
oliver
: review-
Details
Formatted Diff
Diff
patch to handle dd/mm/yyyy format
(725 bytes, patch)
2009-12-14 23:15 PST
,
rahul abrol
no flags
Details
Formatted Diff
Diff
View All
Add attachment
proposed patch, testcase, etc.
Estêvão Samuel Procópio Amaral
Comment 1
2009-12-09 18:58:51 PST
Created
attachment 44588
[details]
Patch to make JavaScriptCore parse DD/MM/YYYY dates correctly
WebKit Review Bot
Comment 2
2009-12-09 19:00:31 PST
style-queue ran check-webkit-style on
attachment 44588
[details]
without any errors.
Oliver Hunt
Comment 3
2009-12-09 19:50:06 PST
Comment on
attachment 44588
[details]
Patch to make JavaScriptCore parse DD/MM/YYYY dates correctly You need to include a testcase for this and i am concerned that will produce incorrect behaviour for new Date("10/11/2009") for instance R- for the absence of tests (although i am concerned about the behaviour i'll wait on a testcase first)
Alexey Proskuryakov
Comment 4
2009-12-09 23:30:34 PST
Looking at ECMA-262, I don't see why either should be supported - per 15.9.1.15, the date-only format is YYYY-MM-DD. Does this work in any other browser?
Sam Weinig
Comment 5
2009-12-09 23:31:00 PST
What does the spec say about this? What do other browsers do? Is this fixing a bug in a real site?
Estêvão Samuel Procópio Amaral
Comment 6
2009-12-10 02:04:44 PST
I came back to give me a R- and point the same issue that
comment #3
did. I'm also concerned about dates with days and months in the same, month-valid range. I'll write some test cases and check it out, but no idea about how to identify, in this cases, if the date is in MM/DD/YYYY or DD/MM/YYYY. Shouldn't this parser be using information about the locale of the running system? About
comment #4
, well, this date format is used in many countries, including here in Brazil (see
http://en.wikipedia.org/wiki/Calendar_date#dd.2Fmm.2Fyyyy.2C_dd.mm.yyyy.2C_or_dd-mm-yyyy_.28day.2C_month.2C_year.29
for a list). And about
comment #5
, yes. It's for fixing a real issue. I run through this issue yesterday trying to set the date I used in the example in a web app we're developping. This form demonstrates the problem, if you want to take a look:
http://void.ufvjm.edu.br/woa2/index.php/date
. The validation, which uses new Date(value), says the date is invalid although it's a real date in my location.
rahul abrol
Comment 7
2009-12-14 23:15:37 PST
Created
attachment 44848
[details]
patch to handle dd/mm/yyyy format this seems to work, if someone wants to write the testcase for it. it assumes mm/dd/yyyy format unless 12 < month < 32, in which case it assumes dd/mm/yyyy. this is how opera handles it. firefox 3.5 just adds on the extra months, so 27/12/2009 is parsed as dec 12 2009 + 15 months = mar 12 2011.
Karl Dubost
Comment 8
2024-12-01 18:46:49 PST
`new Date("27/12/2009")` will generate `Invalid Date` in any browsers ``` Safari Technology Preview 208 20621.1.5.1 Firefox Nightly 135.0a1 13524.11.25 Google Chrome Canary 133.0.6871.0 6871.0 ```
Karl Dubost
Comment 9
2024-12-01 18:58:54 PST
In
https://tc39.es/ecma262/multipage/numbers-and-dates.html#sec-date-constructor
Else if numberOfArgs = 1, then
> … > ii. If v is a String, then > 1. Assert: The next step never returns an abrupt completion because v is a String. > 2. Let tv be the result of parsing v as a date, in exactly the same manner as for the parse method (21.4.3.2).
Which leads to
https://tc39.es/ecma262/multipage/numbers-and-dates.html#sec-date.parse
With formats
https://tc39.es/ecma262/multipage/numbers-and-dates.html#sec-date-time-string-format
new Date("27/12/2009") Invalid Date new Date("2009/12/27") Sun Dec 27 2009 00:00:00 GMT+0900 (Japan Standard Time) new Date("2009-12-27") Sun Dec 27 2009 09:00:00 GMT+0900 (Japan Standard Time) new Date("27-12-2009") Invalid Date new Date("27/12/2009") Invalid Date Browsers are interoperable on this.
Note
You need to
log in
before you can comment on or make changes to this bug.
Top of Page
Format For Printing
XML
Clone This Bug