Skip to content

Commit

Permalink
Editorial: Canonicalization operation for calendar IDs
Browse files Browse the repository at this point in the history
AvailableCalendars should return all possible aliases, so that other
places in the spec (e.g. in the future, validating a string calendar ID in
Temporal) can use them to determine whether a given input value is valid.
This input value can subsequently be canonicalized by another abstract
operation, CanonicalizeCalendar.

In Intl.supportedValuesOf(), on the other hand, we should not return all
possible aliases, so we filter them out using CanonicalizeCalendar before
returning the list of AvailableCalendars codes as an array to the caller.

See tc39/proposal-intl-enumeration#49. This is the
part of that PR that I consider relevant for the future integration of
Temporal. The time zone parts were already done as part of tc39#876. If
desired, I could implement the rest of that PR, adding
CanonicalizeCollation, CanonicalizeCurrency, CanonicalizeNumberingSystem,
and CanonicalizeUnit as well.

Closes: tc39#726
  • Loading branch information
ptomato committed May 8, 2024
1 parent ecfc42c commit e694fac
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
6 changes: 5 additions & 1 deletion spec/intl.html
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,11 @@ <h1>Intl.supportedValuesOf ( _key_ )</h1>
<emu-alg>
1. Let _key_ be ? ToString(_key_).
1. If _key_ is *"calendar"*, then
1. Let _list_ be AvailableCanonicalCalendars( ).
1. Let _list_ be a new empty List.
1. For each element _identifier_ of AvailableCalendars(), do
1. Let _canonical_ be CanonicalizeCalendar(_identifier_).
1. If _identifier_ is _canonical_, then
1. Append _canonical_ to _list_.
1. Else if _key_ is *"collation"*, then
1. Let _list_ be AvailableCanonicalCollations( ).
1. Else if _key_ is *"currency"*, then
Expand Down
24 changes: 21 additions & 3 deletions spec/locales-currencies-tz.html
Original file line number Diff line number Diff line change
Expand Up @@ -452,15 +452,33 @@ <h1>Calendar Types</h1>
This specification identifies calendars using a <dfn variants="calendar types">calendar type</dfn> as defined by <a href="https://unicode.org/reports/tr35/tr35-dates.html#Calendar_Elements">Unicode Technical Standard #35 Part 4 Dates, Section 2 Calendar Elements</a>. Their canonical form is a string containing only Unicode Basic Latin lowercase letters (U+0061 LATIN SMALL LETTER A through U+007A LATIN SMALL LETTER Z) with zero or more medial hyphens (U+002D HYPHEN-MINUS).
</p>

<emu-clause id="sec-availablecanonicalcalendars" type="implementation-defined abstract operation">
<emu-clause id="sec-availablecalendars" oldids="sec-availablecanonicalcalendars" type="implementation-defined abstract operation">
<h1>
AvailableCanonicalCalendars (
AvailableCalendars (
): a List of Strings
</h1>
<dl class="header">
<dt>description</dt>
<dd>The returned List is sorted according to lexicographic code unit order, and contains unique canonical calendar types identifying the calendars for which the implementation provides the functionality of Intl.DateTimeFormat objects. The list must include *"iso8601"*.</dd>
<dd>The returned List is sorted according to lexicographic code unit order, and contains unique calendar types identifying the calendars for which the implementation provides the functionality of Intl.DateTimeFormat objects. The list must include *"iso8601"*.</dd>
</dl>
</emu-clause>

<emu-clause id="sec-canonicalizecalendar" type="abstract operation">
<h1>
CanonicalizeCalendar (
_id_: a String that is a calendar type,
): a String that is a calendar type
</h1>
<dl class="header">
<dt>description</dt>
<dd>
The returned String is the canonical and case-regularized form of _id_.
</dd>
</dl>
<emu-alg>
1. Return the string _id_ after performing the algorithm steps to replace Unicode extension values with their canonical form per <a href="https://unicode.org/reports/tr35/#Canonical_Unicode_Locale_Identifiers">Unicode Technical Standard #35 LDML § 3.2.1 Canonical Unicode Locale Identifiers</a>, treating _id_ as an `uvalue` production.
1. NOTE: For example, if _id_ is *"ISLAMICC"*, return *"islamic-civil"*.
</emu-alg>
</emu-clause>
</emu-clause>
</emu-clause>

0 comments on commit e694fac

Please sign in to comment.