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)

defect

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)

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.
Assignee: nobody → andrebargull
Status: NEW → ASSIGNED
Blocks: 1274354
Attached patch bug1420028.patch (obsolete) (deleted) — Splinter Review
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)
Priority: -- → P3
NI for review ping.
Flags: needinfo?(jorendorff)
Some code it just takes 10 months to unravel, ok? Just kidding. I'm sorry for missing this. Looking now.
(In reply to Jason Orendorff [:jorendorff] from comment #3) > Some code it just takes 10 months to unravel, ok? :-D
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+
Flags: needinfo?(jorendorff)
Attached patch bug1420028.patch (deleted) — Splinter Review
Rebased to apply cleanly on inbound.
Attachment #8931706 - Attachment is obsolete: true
Attachment #9011706 - Flags: review+
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
Status: ASSIGNED → RESOLVED
Closed: 6 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla64
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: