Closed Bug 746529 Opened 12 years ago Closed 5 months ago

Date.parse strangeness with millisec/1000 > 0.999

Categories

(Core :: JavaScript: Standard Library, defect)

defect

Tracking

()

RESOLVED FIXED
121 Branch
Tracking Status
firefox121 --- fixed

People

(Reporter: roger.andrews, Assigned: vinny.diehl)

References

(Blocks 1 open bug)

Details

(Keywords: dev-doc-needed, parity-chrome)

Attachments

(1 file)

User Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:11.0) Gecko/20100101 Firefox/11.0
Build ID: 20120312181643

Steps to reproduce:

Date.parse("1970-01-01T00:00:00.99999999999999995")
Date.parse("1970-01-01T00:00:00.99999999999999996")

Date.parse("1970-02-01T00:00:00.99999999999999") % 1000
etc etc


Actual results:

(1) returned 999,
(2) returned 1000,
(3) returned 0 (mod 1000).

Note the precision of the millisecond field varies depending on the values of the higher fields (year/month/etc).


Expected results:

In the millisecond field: digits beyond the third should be ignored, i.e. the millisecond field should be rounded down to three decimal places.  Very low order digits should not affect the rounding.

(Then the precision of the millisecond field would also always be 3, regardless of the values of the higher fields.)
See Also: → 730838
Status: UNCONFIRMED → NEW
Ever confirmed: true
Assignee: general → nobody
Component: JavaScript Engine → JavaScript: Standard Library
OS: Windows 7 → All
Hardware: x86_64 → All
Severity: normal → S3

As far as I can tell, the rounding after the third digit is implementation defined. The spec only makes mention of 3 digits exactly in the Date Time String Format:

https://tc39.es/ecma262/#sec-date-time-string-format

YYYY-MM-DDTHH:mm:ss.sssZ
...
sss is the number of complete milliseconds since the start of the second as three decimal digits.

Clipping after 3 digits rather than rounding is Chrome behavior, and Firefox and Safari round at different points (Safari's behavior is especially bizarre):

Format JSC SM V8
"1970-01-01T00:00:00.9999999999999999990Z" NaN 1000 999
"1970-01-01T00:00:00.99999999999999996Z" 1000 1000 999
"1970-01-01T00:00:00.99999999999999995Z" 1000 999 999
"1970-01-01T00:00:00.9999999999999999Z" 1000 999 999
"1970-01-01T00:00:00.9999999999999998Z" 999 999 999
Keywords: parity-chrome

Previously, we would round up on the 17th digit, this change was made
for Chrome parity.

Assignee: nobody → vinny.diehl
Status: NEW → ASSIGNED
Pushed by arai_a@mac.com:
https://hg.mozilla.org/integration/autoland/rev/81243364a707
Truncate milliseconds after 3 digits r=arai
Status: ASSIGNED → RESOLVED
Closed: 5 months ago
Resolution: --- → FIXED
Target Milestone: --- → 121 Branch
Keywords: dev-doc-needed
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: