Closed Bug 1341481 Opened 8 years ago Closed 7 years ago

Date.toJSON returns null when other browsers have no issue.

Categories

(Core :: JavaScript: Standard Library, defect)

51 Branch
defect
Not set
normal

Tracking

()

RESOLVED DUPLICATE of bug 1275498

People

(Reporter: toms, Unassigned)

References

(Blocks 1 open bug)

Details

User Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2486.0 Safari/537.36 Edge/13.10586 Firefox for Android Actual results: In javascript I am passing a date in the following format: 22-FEB-2017. The code I use is: function formatDateToJSON(dt) { var d = new Date(dt); var jsonDate = d.toJSON().toString().replace("Z", ""); return jsonDate; } I get a null error because d.toJSON() returns a null. Expected results: I should have gotten a string back such as: "2017-02-22T08:00:00.000Z" This is what I get from Chrome and Safari.
Component: Untriaged → JavaScript Engine
Product: Firefox → Core
Firefox can't parse the date format you're using, that's why toJSON() is returning a null instead of a string (And that also means that toString() call is redundant) It's the dash between the month and year that's causing the issue, "22-FEB 2017" parses fine while "22 FEB-2017" results in an error.
But the issue is that the other browsers accept the two dashes fine while Mozilla does not.
Also, why would the 1st dash be OK and the 2nd not be OK?
Actually, IE won't work with any combination of taking dashes out. 22-FEB-2017, 22-FEB 2017, 22 FEB 2017. All give invalid date. None of these work. So I guess it is just that the browser companies can't seem to get a standard format for a standard JavaScript date object.
My mistake. IE will take 22 FEB 2017, as will all the other browsers. So I will have to just change the dashes to blanks. Thanks.
So, is this a wontfix and waiting to be closed, or should we implement "dd-MON-yyyy" support in the date parser?
Blocks: 1274354
Component: JavaScript Engine → JavaScript: Standard Library
Our current state of date parsing is not great. Mostly due to a not so helpful spec and years of different implementations in other browsers. Some work was started to fix this over in bug 1274354 but so far nothing conclusive has been decided. Maybe we should at least keep the bug up until we decide what to do with date parsing? I'll add a needinfo to Jason Orendorff who seem to be most knowledgable about the current state.
Flags: needinfo?(jorendorff)
Right, this is a known issue and we'd take a patch ... for a while TC39 had some interest in standardizing, but it never finished.
Status: UNCONFIRMED → RESOLVED
Closed: 7 years ago
Flags: needinfo?(jorendorff)
Resolution: --- → DUPLICATE
You need to log in before you can comment on or make changes to this bug.