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

Date/parse/zero.js relies on implementation-specific behavior #4382

Open
linusg opened this issue Jan 19, 2025 · 4 comments
Open

Date/parse/zero.js relies on implementation-specific behavior #4382

linusg opened this issue Jan 19, 2025 · 4 comments

Comments

@linusg
Copy link
Member

linusg commented Jan 19, 2025

This test is for a non-normative note at the end of Date.parse(), which is only required to support the Date Time String Format. This works for parsing the output of toISOString(), but an engine is not required to make sense of toString() and toUTCString() datetime strings.

Engines with extended support for non-standard datetime strings already have their own tests for those so IMO this test should be removed. At the very least it needs a feature flag.

https://github.com/tc39/test262/blob/main/test/built-ins/Date/parse/zero.js

@ljharb
Copy link
Member

ljharb commented Jan 19, 2025

If all browsers currently comply already, though, then it's web reality, and we should probably update the spec to match.

@linusg
Copy link
Member Author

linusg commented Jan 19, 2025

Browsers tend to copy the supported datetime string formats from each other as soon as a website relies on one so they likely all support it. I'm not building a web-facing engine though so I refuse to do that unless the spec tells me to :)

@anba
Copy link
Contributor

anba commented Jan 21, 2025

It's probably best to file an issue at https://github.com/tc39/ecma262/ to clarify the "should" and "could" in https://tc39.es/ecma262/#sec-date.parse. Specifically:

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:

and:

[...] 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.

If these "should" are intended to be recommended but optional (similar to RFC 2119), then Note 1 in https://tc39.es/ecma262/#sec-date.prototype.tostring should probably slightly reworded so it doesn't sound like Date.parse can always interpret the result of Date.prototype.toString:

For any Date d such that d.[[DateValue]] is evenly divisible by 1000, the result of Date.parse(d.toString()) = d.valueOf().

@linusg
Copy link
Member Author

linusg commented Jan 21, 2025

Done: tc39/ecma262#3526

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants