Skip to content

Commit

Permalink
Editorial: Define IsValidTimeZoneName in terms of AvailableTimeZones
Browse files Browse the repository at this point in the history
AvailableTimeZones is an abstract operation defined in the
Intl.Enumeration proposal (though there is a small difference, see below.)
Sharing AvailableTimeZones between ECMA-262 and ECMA-402 should allow us
to stipulate that if an implementation supports any time zone for
formatting in Intl.DateTimeFormat, it must support it for Temporal as
well.

This change means IsValidTimeZoneName is no longer implementation-defined,
and does not need to exist in ECMA-402, only in 262.

Note, this requires a slightly different algorithm for AvailableTimeZones
than the one in the Intl.Enumeration proposal. Intl.Enumeration considered
it too risky for their Stage 4 bid to change this, despite being an
unobservable change, so we will have to make changes in ECMA-402 later,
after Intl.Enumeration reaches Stage 4.

See: #541
See: #519
  • Loading branch information
ptomato authored and Ms2ger committed Oct 11, 2022
1 parent 1b8940d commit d83dcf0
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 27 deletions.
2 changes: 1 addition & 1 deletion spec/abstractops.html
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ <h1>ToRelativeTemporalObject ( _options_ )</h1>
1. Let _timeZone_ be *undefined*.
1. Else,
1. If IsTimeZoneOffsetString(_timeZoneName_) is *false*, then
1. If ! IsValidTimeZoneName(_timeZoneName_) is *false*, throw a *RangeError* exception.
1. If IsValidTimeZoneName(_timeZoneName_) is *false*, throw a *RangeError* exception.
1. Set _timeZoneName_ to ! CanonicalizeTimeZoneName(_timeZoneName_).
1. Let _timeZone_ be ! CreateTemporalTimeZone(_timeZoneName_).
1. If _result_.[[TimeZone]].[[Z]] is *true*, then
Expand Down
53 changes: 38 additions & 15 deletions spec/intl.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,22 +32,21 @@ <h1><a href="https://tc39.es/ecma402/#sec-time-zone-names">Time Zone Names</a></
A conforming implementation must recognize *"UTC"* and all other Zone and Link names (and <strong>only</strong> such names), and use best available current and historical information about their offsets from UTC and their daylight saving time rules in calculations. However, the set of combinations of time zone name and language tag for which localized time zone names are available is implementation dependent.
</p>

<emu-clause id="sup-isvalidtimezonename">
<h1><a href="https://tc39.es/ecma402/#sec-isvalidtimezonename">IsValidTimeZoneName</a> ( _timeZone_ )</h1>
<del class="block">
<emu-clause id="sup-isvalidtimezonename">
<h1><a href="https://tc39.es/ecma402/#sec-isvalidtimezonename">IsValidTimeZoneName</a> ( _timeZone_ )</h1>

<ins class="block">
<p>This definition supersedes the definition provided in <emu-xref href="#sec-isvalidtimezonename"></emu-xref>.</p>
</ins>
<p>
The abstract operation IsValidTimeZoneName takes argument _timeZone_, a String value, and verifies that it represents a valid Zone or Link name of the IANA Time Zone Database.
</p>
<p>
The abstract operation IsValidTimeZoneName takes argument _timeZone_, a String value, and verifies that it represents a valid Zone or Link name of the IANA Time Zone Database.
</p>

<emu-alg>
1. If one of the Zone or Link names of the IANA Time Zone Database is an ASCII-case-insensitive match of _timeZone_, return *true*.
1. If _timeZone_ is an ASCII-case-insensitive match of *"UTC"*, return *true*.
1. Return *false*.
</emu-alg>
</emu-clause>
<emu-alg>
1. If one of the Zone or Link names of the IANA Time Zone Database is an ASCII-case-insensitive match of _timeZone_, return *true*.
1. If _timeZone_ is an ASCII-case-insensitive match of *"UTC"*, return *true*.
1. Return *false*.
</emu-alg>
</emu-clause>
</del>

<emu-clause id="sup-canonicalizetimezonename" type="abstract operation">
<h1>
Expand All @@ -73,6 +72,30 @@ <h1>
<p>This definition supersedes the definition provided in <emu-xref href="#sec-canonicalizetimezonename"></emu-xref>.</p>
</ins>
</emu-clause>

<ins class="block">
<emu-clause id="sup-availabletimezones" type="implementation-defined abstract operation">
<h1>
AvailableTimeZones (
): a List of Strings
</h1>
<dl class="header">
<dt>description</dt>
<dd>The returned List is a sorted List of supported Zone and Link names in the IANA Time Zone Database.</dd>
<dt>redefinition</dt>
<dd>true</dd>
</dl>
<emu-alg>
1. Let _timeZones_ be a List containing the String value of each Zone or Link name in the IANA Time Zone Database that is supported by the implementation.
1. Assert: _timeZones_ contains *"UTC"*.
1. Assert: _timeZones_ does not contain any element that does not identify a Zone or Link name in the IANA Time Zone Database.
1. Sort _timeZones_ in order as if an Array of the same values had been sorted using %Array.prototype.sort% with *undefined* as _comparefn_.
1. Return _timeZones_.
</emu-alg>

<p>This definition supersedes the definition provided in <emu-xref href="#sec-availabletimezones"></emu-xref>.</p>
</emu-clause>
</ins>
</emu-clause>

<emu-clause id="sec-abstract-operations">
Expand Down Expand Up @@ -193,7 +216,7 @@ <h1>InitializeDateTimeFormat ( _dateTimeFormat_, _locales_, _options_ )</h1>
1. Set _timeZone_ to DefaultTimeZone().
1. Else,
1. Set _timeZone_ to ? ToString(_timeZone_).
1. If the result of ! IsValidTimeZoneName(_timeZone_) is *false*, then
1. If the result of IsValidTimeZoneName(_timeZone_) is *false*, then
1. Throw a *RangeError* exception.
1. Set _timeZone_ to ! CanonicalizeTimeZoneName(_timeZone_).
1. Set _dateTimeFormat_.[[TimeZone]] to _timeZone_.
Expand Down
42 changes: 32 additions & 10 deletions spec/timezone.html
Original file line number Diff line number Diff line change
Expand Up @@ -38,26 +38,23 @@ <h1>Time Zone Names</h1>
<h1>
IsValidTimeZoneName (
_timeZone_: a String,
)
): a Boolean
</h1>
<dl class="header">
<dt>description</dt>
<dd>It returns *true* if _timeZone_ is an ASCII-case-insensitive match for a built-in time zone name and *false* otherwise.</dd>
<dd>The returned value is *true* if _timeZone_ is an ASCII-case-insensitive match for a supported time zone name, and *false* otherwise.</dd>
</dl>
<p>
An ECMAScript implementation that includes the ECMA-402 Internationalization API must implement the IsValidTimeZoneName abstract operation as specified in the ECMA-402 specification.
</p>
<p>
Once IsValidTimeZoneName(_timeZone_) has returned *true*, for the lifetime of the surrounding agent, IsValidTimeZoneName(_variant_) must return *true* if _variant_ is an ASCII-case-insensitive match for either _timeZone_ or CanonicalizeTimeZoneName(_timeZone_).
</p>
<p>
For the purposes of this section, a String value _A_ is an ASCII-case-insensitive match for String value _B_ if the String value derived from _A_ by replacing each occurrence of a lowercase ASCII letter code unit (0x0061 through 0x007A, inclusive) with the corresponding uppercase ASCII letter code unit (0x0041 through 0x005A, inclusive) while preserving all other code units is exactly the same sequence of code units as the String value that is derived from _B_ in the same way.
</p>
<p>The minimum implementation of IsValidTimeZoneName for ECMAScript implementations that do not include the ECMA-402 API, supporting only the *"UTC"* time zone, performs the following steps when called:
</p>

<emu-alg>
1. If _timeZone_ is an ASCII-case-insensitive match for *"UTC"*, return *true*.
1. Let _timeZones_ be AvailableTimeZones().
1. For each String _candidate_ in _timeZones_, do
1. If _timeZone_ is an ASCII-case-insensitive match for _candidate_, return *true*.
1. Return *false*.
</emu-alg>
</emu-clause>
Expand All @@ -84,6 +81,31 @@ <h1>
1. Return *"UTC"*.
</emu-alg>
</emu-clause>

<emu-clause id="sec-availabletimezones" type="implementation-defined abstract operation">
<h1>
AvailableTimeZones (
): a List of Strings
</h1>
<dl class="header">
<dt>description</dt>
<dd>The returned List is a sorted List of identifiers for time zones for which the implementation includes local political rules, and aliases for those identifiers.</dd>
</dl>

<p>
An ECMAScript implementation that includes the ECMA-402 Internationalization API must implement the AvailableTimeZones abstract operation as specified in the ECMA-402 specification.
If an ECMAScript implementation does not include the ECMA-402 API the following specification of the AvailableTimeZones abstract operation is used.
</p>
<emu-alg>
1. Let _timeZones_ be the List of String values representing time zones supported by the implementation.
1. Assert: _timeZones_ contains *"UTC"*.
1. Sort _timeZones_ in order as if an Array of the same values had been sorted using %Array.prototype.sort% with *undefined* as _comparefn_.
1. Return _timeZones_.
</emu-alg>
<emu-note><p>
For example, an ECMAScript implementation that does not include local political rules for any time zone could return a List with the single String *"UTC"* here.
</p></emu-note>
</emu-clause>
</emu-clause>

<emu-clause id="sec-temporal-timezone-constructor">
Expand Down Expand Up @@ -114,7 +136,7 @@ <h1>Temporal.TimeZone ( _identifier_ )</h1>
1. Throw a *TypeError* exception.
1. Set _identifier_ to ? ToString(_identifier_).
1. If IsTimeZoneOffsetString(_identifier_) is *false*, then
1. If ! IsValidTimeZoneName(_identifier_) is *false*, then
1. If IsValidTimeZoneName(_identifier_) is *false*, then
1. Throw a *RangeError* exception.
1. Set _identifier_ to ! CanonicalizeTimeZoneName(_identifier_).
1. Return ? CreateTemporalTimeZone(_identifier_, NewTarget).
Expand Down Expand Up @@ -515,7 +537,7 @@ <h1>ToTemporalTimeZone ( _temporalTimeZoneLike_ )</h1>
1. If _parseResult_.[[Name]] is not *undefined*, then
1. Let _name_ be _parseResult_.[[Name]].
1. If IsTimeZoneOffsetString(_name_) is *false*, then
1. If ! IsValidTimeZoneName(_name_) is *false*, throw a *RangeError* exception.
1. If IsValidTimeZoneName(_name_) is *false*, throw a *RangeError* exception.
1. Set _name_ to ! CanonicalizeTimeZoneName(_name_).
1. Return ! CreateTemporalTimeZone(_name_).
1. If _parseResult_.[[Z]] is *true*, return ! CreateTemporalTimeZone(*"UTC"*).
Expand Down
2 changes: 1 addition & 1 deletion spec/zoneddatetime.html
Original file line number Diff line number Diff line change
Expand Up @@ -1115,7 +1115,7 @@ <h1>
1. Let _timeZoneName_ be _result_.[[TimeZone]].[[Name]].
1. Assert: _timeZoneName_ is not *undefined*.
1. If IsTimeZoneOffsetString(_timeZoneName_) is *false*, then
1. If ! IsValidTimeZoneName(_timeZoneName_) is *false*, throw a *RangeError* exception.
1. If IsValidTimeZoneName(_timeZoneName_) is *false*, throw a *RangeError* exception.
1. Set _timeZoneName_ to ! CanonicalizeTimeZoneName(_timeZoneName_).
1. Let _offsetString_ be _result_.[[TimeZone]].[[OffsetString]].
1. If _result_.[[TimeZone]].[[Z]] is *true*, then
Expand Down

0 comments on commit d83dcf0

Please sign in to comment.