Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Request For Clarification: Normative requirements of Date.parse() #3526

Open
linusg opened this issue Jan 21, 2025 · 1 comment
Open

Request For Clarification: Normative requirements of Date.parse() #3526

linusg opened this issue Jan 21, 2025 · 1 comment
Labels
editor call to be discussed in the next editor call

Comments

@linusg
Copy link
Member

linusg commented Jan 21, 2025

Opening this issue in response to tc39/test262#4382 (comment). See also #1374.

I'd like to have a better understanding of what exactly the current normative requirements for Date.parse() are. It starts out pretty clear, emphasis mine:

The function first attempts to parse the String according to the format described in Date Time String Format (21.4.1.32), including expanded years. If the String does not conform to that format the function may fall back to any implementation-specific heuristics or implementation-specific date formats. Strings that are unrecognizable or contain out-of-bounds format element values shall cause this function to return NaN.

This sounds like only supporting the Date Time String Format is a normative requirement. There is more prose after this that mentions a special case:

If x is any Date whose milliseconds amount is zero within a particular implementation of ECMAScript, then all of the following expressions should produce the same numeric value in that implementation, if all the properties referenced have their initial values:

x.valueOf()
Date.parse(x.toString())
Date.parse(x.toUTCString())
Date.parse(x.toISOString())

However, the expression

Date.parse(x.toLocaleString())

is not required to produce the same Number value as the preceding three expressions and, in general, the value produced by this function is implementation-defined when given any String value that does not conform to the Date Time String Format (21.4.1.32) and that could not be produced in that implementation by the toString or toUTCString method.

How are should and could supposed to be interpreted here? More specifically, is Date.parse("Thu, 01 Jan 1970 00:00:00 GMT") === 0 a normative requirement or may it return NaN?

@bakkot
Copy link
Contributor

bakkot commented Jan 22, 2025

This wording goes back to ES1, and we don't know exactly what was intended when it was written, although it actually predates the requirement to accept the Date Time String Format grammar and as such was originally the only input implementations were told to accept. Also note that ES1 was published only a few months after RFC 2119.

The current editors believe the intention was to make this a normative requirement.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
editor call to be discussed in the next editor call
Projects
None yet
Development

No branches or pull requests

3 participants