-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Normative: Use DefaultTimeZone to get the local time zone for Date #2781
Conversation
91ba8a2
to
4b01663
Compare
@tc39/ecma262-editors This is the PR that we discussed in the editor call yesterday, arising from tc39/proposal-temporal#2171 I put all the new AOs together into the Date section, let me know if they need to go anywhere else. The number of new AOs is not too bad but if needed I can cut it down a bit more:
|
4b01663
to
cef812d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have some comments around naming and incorrect references to Unix (cf. tc39/proposal-temporal#2175 ), but the bulk of this looks good.
TimeSeparator[?Extended] MinuteSecond | ||
TimeSeparator[?Extended] MinuteSecond TimeSeparator[?Extended] MinuteSecond Fraction? | ||
|
||
UTCOffsetString ::: |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've gone with this for now, but are you sure about having the "Temporal" name in there? It might be confusing since Temporal isn't part of the specification yet.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ahead of the Temporal proposal landing, "temporal" still makes sense as a generic adjective indicating relationship to time—necessary here because date and time representations can use ,
as a decimal separator and –
as a negative sign, neither of which are true of non-temporal (i.e., non-time-related) numeric strings in ECMAScript.
cef812d
to
02619ae
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just see a few more grammar points and stray references to IANA, and a possible improvement in operation naming.
02619ae
to
16dacb6
Compare
This reached consensus. The promised followup details regarding DST transitions: The requirements are described in GetNamedTimeZoneEpochNanoseconds (which returns a List of nanoseconds since epoch for a specific time zone name and local time) similar to the current text in LocalTZA: https://arai-a.github.io/ecma262-compare/?pr=2781#sec-getnamedtimezoneepochnanoseconds (emphasis mine)
And specified more precisely in UTC (which interprets its input as a number representing local time and returns a single milliseconds since epoch): https://arai-a.github.io/ecma262-compare/?pr=2781#sec-utc-t (emphasis mine)
|
I'm not sure there's really an effective test262 test possible for this; if I were to write one, it'd depend on implementation-defined date and time zone format strings. What else would be needed for merging this? |
@ptomato This does not require test262 tests to be merged. Waiting on 262 editor review. |
spec.html
Outdated
<dd>It returns a String value representing the host environment's current time zone, which is either a String representing a UTC offset for which IsTimeZoneOffsetString returns *true*, or a String identifier accepted by GetNamedTimeZoneEpochNanoseconds and GetNamedTimeZoneOffsetNanoseconds.</dd> | ||
</dl> | ||
|
||
<p>An ECMAScript implementation that includes the ECMA-402 Internationalization API must implement the DefaultTimeZone abstract operation as specified in the ECMA-402 specification.</p> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If a valid ECMA-262 implementation can return a UTC offset string from DefaultTimeZone, then ECMA-402 must not prohibit that (cf. API Overview: "This specification introduces new language values observable to ECMAScript code… and also refines the definition of some functions specified in ECMA-262 (as described below). Neither category prohibits behaviour that is otherwise permitted for values and interfaces defined in ECMA-262, in order to support adoption of this specification by any implementation of ECMA-262."). I believe this therefore affirms tc39/ecma402#683 .
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Concretely, should there be any change? Should we remove the paragraph starting "An ECMAScript implementation that includes the ECMA-402 ..." in anticipation of ECMA-402 no longer providing a definition for DefaultTimeZone?
(FWIW, I think ECMA-402's "A conforming implementation must recognize [...] Zone and Link names" makes it OK to also say that the return value of DefaultTimeZone must be one of them, but I see your point as well, so I don't see any reason to be strict about that.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think anything needs to change here, I'm just calling attention to a downstream consequence. We can remove that text when there is no longer an override, but I think it should remain until then.
99ef075
to
7e2fc84
Compare
Rebased; added the changes that Richard requested in a fixup commit. |
…c39#2781) Currently, it is technically possible for the following two operations to result in different local times and different time zones: > date = new Date() > date.toTimeString() '13:43:47 GMT-0700 (Pacific Daylight Time)' > new Intl.DateTimeFormat(undefined, {timeStyle: 'full'}).format(date) '1:43:47 p.m. Pacific Daylight Time' This is because Date gets its notion of the current system time zone from the operation LocalTZA, while Intl.DateTimeFormat uses the operation DefaultTimeZone from ECMA-402 to determine the current system time zone. This is a normative change because there was previously no requirement for these to be linked. However, they *should* definitely be linked, and no implementation that includes ECMA-402 that I'm aware of has a discrepancy between the two. This patch adds this requirement. This is accomplished by removing LocalTZA (which was actually two operations rolled into one, anyway) and redefining the LocalTime and UTC operations in terms of DefaultTimeZone, which moves into ECMA-262, as well as the two new operations GetNamedTimeZoneOffsetNanoseconds and GetNamedTimeZoneEpochNanoseconds. It essentially pushes the "implementation-definedness" of LocalTZA into GetNamedTimeZoneOffsetNanoseconds, GetNamedTimeZoneEpochNanoseconds, and DefaultTimeZone. Although it is a normative change because it adds the requirement for Date and Intl.DateTimeFormat to use the same default time zone, it should have no other effects. Despite specifying what LocalTZA used to do in terms of different operations, the observable effects are the same.
7e2fc84
to
43fd5f2
Compare
This will be necessary for the rebase on tc39/ecma262#2781 Delete the reference to LocalTZA which no longer exists in ECMA-262; this reference was already inside text to be deleted from ECMA-402 anyway. EnumerableOwnPropertyNames was renamed to EnumerableOwnProperties in tc39/ecma262#2899 so that change also needs to be made when pulling in the new biblio.
…tString During the editorial process for tc39/ecma262#2781 ParseTimeZoneOffsetString was changed to be infallible, and a second operation IsTimeZoneOffsetString was added as a predicate for whether a given string is parseable as a UTC offset.
This will be necessary for the rebase on tc39/ecma262#2781 Delete the reference to LocalTZA which no longer exists in ECMA-262; this reference was already inside text to be deleted from ECMA-402 anyway. EnumerableOwnPropertyNames was renamed to EnumerableOwnProperties in tc39/ecma262#2899 so that change also needs to be made when pulling in the new biblio.
…tString During the editorial process for tc39/ecma262#2781 ParseTimeZoneOffsetString was changed to be infallible, and a second operation IsTimeZoneOffsetString was added as a predicate for whether a given string is parseable as a UTC offset.
…tString During the editorial process for tc39/ecma262#2781 ParseTimeZoneOffsetString was changed to be infallible, and a second operation IsTimeZoneOffsetString was added as a predicate for whether a given string is parseable as a UTC offset. UPSTREAM_COMMIT=654e300db9882fc985840e11f35525864848f8fd
…tString During the editorial process for tc39/ecma262#2781 ParseTimeZoneOffsetString was changed to be infallible, and a second operation IsTimeZoneOffsetString was added as a predicate for whether a given string is parseable as a UTC offset. UPSTREAM_COMMIT=654e300db9882fc985840e11f35525864848f8fd
…tString During the editorial process for tc39/ecma262#2781 ParseTimeZoneOffsetString was changed to be infallible, and a second operation IsTimeZoneOffsetString was added as a predicate for whether a given string is parseable as a UTC offset. UPSTREAM_COMMIT=654e300db9882fc985840e11f35525864848f8fd
Following ISO-8601, tc39#2781 introduced U+2212 (Unicode minus) as an alias for the regular ASCII minus sign for use in time zone offsets. There's two new data that lead me to believe that this was a mistake, and that we should revert this change. The first is that the newly-released RFC 9557 (the string format standard that Temporal uses) disallows non-ASCII characters. Its predecessor RFC 3339 also disallows non-ASCII characters. So strings that follow the current (since 2022) ECMAScript spec could be rejected by RFC 9557 clients. The second new data is feedback from implementers of a Rust version of Temporal that this single obscure character in the grammar will incur a performance cost because they must now use Rust strings instead of plain U8 ASCII data. See tc39/proposal-temporal#2843 (comment) This performance issue doesn't seem to be limited to Rust. Any native implementation would likely benefit from being able to know that valid date/time input (both Date and Temporal) is always ASCII-only. I don't know whether all engines have actually implemented this 2022 grammar change. But it's also a safe bet that real-world usage of this Unicode character is likely minimal. So the web-compat risk seems small. If this PR is accepted, then we'll follow up with a normative Temporal PR to remove this character from Temporal as well.
Following ISO-8601, tc39#2781 introduced U+2212 (Unicode minus) as an alias for the regular ASCII minus sign for use in time zone offsets. There's two new data that lead me to believe that this was a mistake, and that we should revert this change. The first is that the newly-released RFC 9557 (the string format standard that Temporal uses) disallows non-ASCII characters. Its predecessor RFC 3339 also disallows non-ASCII characters. So strings that follow the current (since 2022) ECMAScript spec could be rejected by RFC 9557 clients. The second new data is feedback from implementers of a Rust version of Temporal that this single obscure character in the grammar will incur a performance cost because they must now use Rust strings instead of plain U8 ASCII data. See tc39/proposal-temporal#2843 (comment) This performance issue doesn't seem to be limited to Rust. Any native implementation would likely benefit from being able to know that valid date/time input (both Date and Temporal) is always ASCII-only. I don't know whether all engines have actually implemented this 2022 grammar change. But it's also a safe bet that real-world usage of this Unicode character is likely minimal. So the web-compat risk seems small. If this PR is accepted, then we'll follow up with a normative Temporal PR to remove this character from Temporal as well.
Following ISO-8601, tc39#2781 introduced U+2212 (Unicode minus) as an alias for the regular ASCII minus sign for use in time zone offsets. There's two new data that lead me to believe that this was a mistake, and that we should revert this change. The first is that the newly-released RFC 9557 (the string format standard that Temporal uses) disallows non-ASCII characters. Its predecessor RFC 3339 also disallows non-ASCII characters. So strings that follow the current (since 2022) ECMAScript spec could be rejected by RFC 9557 clients. The second new data is feedback from implementers of a Rust version of Temporal that this single obscure character in the grammar will incur a performance cost because they must now use Rust strings instead of plain U8 ASCII data. See tc39/proposal-temporal#2843 (comment) This performance issue doesn't seem to be limited to Rust. Any native implementation would likely benefit from being able to know that valid date/time input (both Date and Temporal) is always ASCII-only. I don't know whether all engines have actually implemented this 2022 grammar change. But it's also a safe bet that real-world usage of this Unicode character is likely minimal. So the web-compat risk seems small. If this PR is accepted, then we'll follow up with a normative Temporal PR to remove this character from Temporal as well.
Currently, it is technically possible for the following two operations to
result in different local times and different time zones:
This is because Date gets its notion of the current system time zone from
the operation LocalTZA, while Intl.DateTimeFormat uses the operation
DefaultTimeZone from ECMA-402 to determine the current system time zone.
This is a normative change because there was previously no requirement for
these to be linked. However, they should definitely be linked, and no
implementation that includes ECMA-402 that I'm aware of has a discrepancy
between the two. This patch adds this requirement.
This is accomplished by removing LocalTZA (which was actually two
operations rolled into one, anyway) and redefining the LocalTime and UTC
operations in terms of DefaultTimeZone, which moves into ECMA-262, as well
as the two new operations GetNamedTimeZoneOffsetNanoseconds and
GetNamedTimeZoneEpochNanoseconds.
It essentially pushes the "implementation-definedness" of LocalTZA into
GetNamedTimeZoneOffsetNanoseconds, GetNamedTimeZoneEpochNanoseconds, and
DefaultTimeZone.
Although it is a normative change because it adds the requirement for Date
and Intl.DateTimeFormat to use the same default time zone, it should have
no other effects. Despite specifying what LocalTZA used to do in terms of
different operations, the observable effects are the same.