Closed
Bug 1420028
Opened 7 years ago
Closed 6 years ago
Date.parse doesn't recognize certain outputs of Date.toUTCString
Categories
(Core :: JavaScript Engine, defect, P3)
Core
JavaScript Engine
Tracking
()
RESOLVED
FIXED
mozilla64
Tracking | Status | |
---|---|---|
firefox64 | --- | fixed |
People
(Reporter: xiaoyin.l, Assigned: anba)
References
(Blocks 1 open bug, )
Details
Attachments
(1 file, 1 obsolete file)
(deleted),
patch
|
anba
:
review+
|
Details | Diff | Splinter Review |
Version: Firefox 57.0
OS: all
Architecture: all
What steps will reproduce the problem?
1. Run the following code:
var d = new Date("0091-09-23"); Date.parse(d.toUTCString()) == d.valueOf();
var d = new Date("-000091-09-23"); Date.parse(d.toUTCString()) == d.valueOf();
var d = new Date("-002017-09-23"); Date.parse(d.toUTCString()) == d.valueOf();
What is the expected output?
They should all return true.
What do you see instead?
They returned false.
The spec section 20.3.3.2 requires the following expressions to produce the same value:
x.valueOf()
Date.parse(x.toString())
Date.parse(x.toUTCString())
Date.parse(x.toISOString())
But it seems in SpiderMonkey, Date.parse is unable to recognize negative years and years < 100 (zero-padded to 4 digits).
v8 and ChakraCore have the same issue. https://github.com/Microsoft/ChakraCore/pull/4318 is a patch to correct this issue in ChakraCore.
Reporter | ||
Updated•7 years ago
|
Assignee | ||
Updated•7 years ago
|
Assignee: nobody → andrebargull
Status: NEW → ASSIGNED
Assignee | ||
Comment 1•7 years ago
|
||
For the |new Date("0091-09-23")| case from comment #0:
- If the year is at least four characters long, don't try to swap it with days or months, or interpret as an offset from 1900 or 2000 [1].
For the negative year cases from comment #0:
- Added code to detect negative, possibly zero-padded years, so they aren't parsed as time zone offsets [2].
And also moved [3] to the lines where it applies and removed the duplicates at [4].
[1] https://searchfox.org/mozilla-central/rev/a5d613086ab4d0578510aabe8653e58dc8d7e3e2/js/src/jsdate.cpp#1213,1226,1236-1239
[2] https://searchfox.org/mozilla-central/rev/a5d613086ab4d0578510aabe8653e58dc8d7e3e2/js/src/jsdate.cpp#1047
[3] https://searchfox.org/mozilla-central/rev/a5d613086ab4d0578510aabe8653e58dc8d7e3e2/js/src/jsdate.cpp#1187-1192
[4] https://searchfox.org/mozilla-central/rev/a5d613086ab4d0578510aabe8653e58dc8d7e3e2/js/src/jsdate.cpp#1200-1202,1205-1207
Attachment #8931706 -
Flags: review?(jorendorff)
Updated•7 years ago
|
status-firefox59:
--- → affected
Priority: -- → P3
Comment 3•6 years ago
|
||
Some code it just takes 10 months to unravel, ok?
Just kidding. I'm sorry for missing this. Looking now.
Assignee | ||
Comment 4•6 years ago
|
||
(In reply to Jason Orendorff [:jorendorff] from comment #3)
> Some code it just takes 10 months to unravel, ok?
:-D
Comment 5•6 years ago
|
||
Comment on attachment 8931706 [details] [diff] [review]
bug1420028.patch
Review of attachment 8931706 [details] [diff] [review]:
-----------------------------------------------------------------
Thank you. This is great.
Attachment #8931706 -
Flags: review?(jorendorff) → review+
Updated•6 years ago
|
Flags: needinfo?(jorendorff)
Assignee | ||
Comment 6•6 years ago
|
||
Rebased to apply cleanly on inbound.
Attachment #8931706 -
Attachment is obsolete: true
Attachment #9011706 -
Flags: review+
Assignee | ||
Comment 7•6 years ago
|
||
Try: https://treeherder.mozilla.org/#/jobs?repo=try&revision=b618565fd602f25c9e968fea0a8ee0e3c0604baa
Keywords: checkin-needed
Pushed by nbeleuzu@mozilla.com:
https://hg.mozilla.org/integration/mozilla-inbound/rev/013059482f82
Handle UTC date/time strings in Date.parse(). r=jorendorff
Keywords: checkin-needed
Comment 9•6 years ago
|
||
bugherder |
Status: ASSIGNED → RESOLVED
Closed: 6 years ago
status-firefox64:
--- → fixed
Resolution: --- → FIXED
Target Milestone: --- → mozilla64
Updated•6 years ago
|
status-firefox59:
affected → ---
You need to log in
before you can comment on or make changes to this bug.
Description
•