Closed Bug 1515318 Opened 6 years ago Closed 2 years ago

Parsing dd-MMM-yyyy date notation produces negative value

Categories

(Core :: JavaScript: Standard Library, defect, P3)

64 Branch
defect

Tracking

()

RESOLVED DUPLICATE of bug 1439800
Webcompat Priority ?

People

(Reporter: lholman, Unassigned)

Details

Attachments

(1 file)

Attached image 2018-12-19 08_47_19.png
User Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.110 Safari/537.36 Steps to reproduce: Open Developer tools and navigate to the console. Create a new date variable using a date string in the format "dd-MMM-yyyy" ex. var d = new Date('10-dec-2018') Actual results: The date returned is a negative value "Date -002018-12-10T04:56:02.000Z" Expected results: The date returned should not be a negative value. ex. var d = new Date('10-dec 2018') Removing the hyphen from in-front of the year produces a positive value.
Component: Untriaged → JavaScript Engine
Product: Firefox → Core

Oh, wow, treating the '-' as a minus sign is ... surprising.

lholman, for what it's worth, there is a standard format for dates, which you can use:
https://tc39.github.io/ecma262/#sec-date-time-string-format

Blocks: 1274354
Priority: -- → P3
Component: JavaScript Engine → JavaScript: Standard Library
See Also: → 1617562
Summary: Parsing standard date notation produces negative value → Parsing dd-MMM-yyyy date notation produces negative value
Severity: normal → S3

The severity field for this bug is relatively low, S3. However, the bug has 3 duplicates.
:sdetar, could you consider increasing the bug severity?

For more information, please visit auto_nag documentation.

Flags: needinfo?(sdetar)
Flags: needinfo?(sdetar)

This is now causing a web-compat issue on JAL's flight booking page, as seen in bug 1825938. Maybe it's worth bumping up the priority here?

Webcompat Priority: --- → ?
See Also: → 1825938
Flags: needinfo?(arai.unmht)

possible solution would be to check if the '-' immediately before the possible "year" follows another delimiter,
to distinguish new Date("10-dec-2018") and new Date("10-dec -2018").

Safari parses 10-dec-2018 as 2018-12-10 and 10-dec -2018 as -2018-12-10.

Flags: needinfo?(arai.unmht)
See Also: → 1439800
Status: UNCONFIRMED → RESOLVED
Closed: 2 years ago
Duplicate of bug: 1439800
Resolution: --- → DUPLICATE
No longer duplicate of this bug: 1600902
No longer duplicate of this bug: 1617562
No longer duplicate of this bug: 1785973
No longer blocks: 1274354
See Also: 1617562, 1825938, 1439800
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: