From 13dda2751f062aacbc70ae90322578b3316b8140 Mon Sep 17 00:00:00 2001 From: Philip Chimento Date: Thu, 14 Apr 2022 16:18:53 -0700 Subject: [PATCH] Define IsBuiltinCalendar in terms of AvailableCalendars AvailableCalendars is an abstract operation defined in the Intl.Enumeration proposal. Sharing AvailableCalendars between ECMA-262 and ECMA-402 should allow us to stipulate that if an implementation supports any calendar for formatting in Intl.DateTimeFormat, it must support it for Temporal as well. Note this is blocked on resolving whether AvailableCalendars should return only canonicalized names or also names like `islamicc` (instead of the canonical `islamic-civil`): https://github.com/tc39/proposal-intl-enumeration/issues/37 See: #541 --- spec/calendar.html | 81 ++++++++++++++++++++++++++++++++++++---------- spec/intl.html | 36 +++++++++++++++------ 2 files changed, 90 insertions(+), 27 deletions(-) diff --git a/spec/calendar.html b/spec/calendar.html index 820899953d..f761d1b1e4 100644 --- a/spec/calendar.html +++ b/spec/calendar.html @@ -5,13 +5,72 @@

Temporal.Calendar Objects

A Temporal.Calendar object is an Object representing a calendar.

+ +

Calendar Types

+ + +

+ This section shares some text with the Intl.Enumeration proposal. +

+
+ +

+ At a minimum, ECMAScript implementations must support a built-in calendar named *"iso8601"*, representing the ISO 8601 calendar. + In addition, implementations may support any number of other built-in calendars. +

+

+ ECMAScript implementations identify built-in calendars using a calendar type as defined by Unicode Technical Standard #35, Part 4, Section 2. + Their canonical form is a string containing all lower case letters with zero or more hyphens. +

+

+ The `Temporal.Calendar` constructor, when called with the name of a built-in calendar as the argument, will return a valid `Temporal.Calendar` object. + When called with any other string, it will throw a *RangeError* exception. +

+ + +

+ IsBuiltinCalendar ( + _id_: a String, + ): a Boolean +

+
+
description
+
The returned value is *true* if _id_ is a calendar type denoting a built-in calendar, and *false* otherwise.
+
+ + 1. Let _calendars_ be AvailableCalendars(). + 1. If _calendars_ contains _id_, return *true*. + 1. Return *false*. + +
+ + +

+ AvailableCalendars ( + ): a List of Strings +

+
+
description
+
The returned List contains a single calendar type, *"iso8601"*.
+
+ +

+ An ECMAScript implementation that includes the ECMA-402 Internationalization API must implement the AvailableCalendars 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 AvailableCalendars abstract operation is used. +

+ + 1. Return « *"iso8601"* ». + +
+
+

Abstract Operations for Temporal.Calendar Objects

CreateTemporalCalendar ( _identifier_ [ , _newTarget_ ] )

- 1. Assert: ! IsBuiltinCalendar(_identifier_) is *true*. + 1. Assert: IsBuiltinCalendar(_identifier_) is *true*. 1. If _newTarget_ is not provided, set _newTarget_ to %Temporal.Calendar%. 1. Let _object_ be ? OrdinaryCreateFromConstructor(_newTarget_, *"%Temporal.Calendar.prototype%"*, « [[InitializedTemporalCalendar]], [[Identifier]] »). 1. Set _object_.[[Identifier]] to _identifier_. @@ -19,22 +78,10 @@

CreateTemporalCalendar ( _identifier_ [ , _newTarget_ ] )

- -

IsBuiltinCalendar ( _id_ )

-

- An ECMAScript implementation that includes the ECMA-402 Internationalization API must implement the *IsBuiltinCalendar* 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 *IsBuiltinCalendar* abstract operation is used. -

- - 1. If _id_ is not *"iso8601"*, return *false*. - 1. Return *true*. - -
-

GetBuiltinCalendar ( _id_ )

- 1. If ! IsBuiltinCalendar(_id_) is *false*, throw a *RangeError* exception. + 1. If IsBuiltinCalendar(_id_) is *false*, throw a *RangeError* exception. 1. Return ! CreateTemporalCalendar(_id_).
@@ -249,9 +296,9 @@

ToTemporalCalendar ( _temporalCalendarLike_ )

1. Set _temporalCalendarLike_ to ? Get(_temporalCalendarLike_, *"calendar"*). 1. If Type(_temporalCalendarLike_) is Object and ? HasProperty(_temporalCalendarLike_, *"calendar"*) is *false*, return _temporalCalendarLike_. 1. Let _identifier_ be ? ToString(_temporalCalendarLike_). - 1. If ! IsBuiltinCalendar(_identifier_) is *false*, then + 1. If IsBuiltinCalendar(_identifier_) is *false*, then 1. Set _identifier_ to ? ParseTemporalCalendarString(_identifier_). - 1. If ! IsBuiltinCalendar(_identifier_) is *false*, throw a *RangeError* exception. + 1. If IsBuiltinCalendar(_identifier_) is *false*, throw a *RangeError* exception. 1. Return ! CreateTemporalCalendar(_identifier_).
@@ -671,7 +718,7 @@

Temporal.Calendar ( _id_ )

1. If NewTarget is *undefined*, then 1. Throw a *TypeError* exception. 1. Set _id_ to ? ToString(_id_). - 1. If ! IsBuiltinCalendar(_id_) is *false*, then + 1. If IsBuiltinCalendar(_id_) is *false*, then 1. Throw a *RangeError* exception. 1. Return ? CreateTemporalCalendar(_id_, NewTarget). diff --git a/spec/intl.html b/spec/intl.html index 3598c15559..9049de4f58 100644 --- a/spec/intl.html +++ b/spec/intl.html @@ -110,6 +110,32 @@

This definition supersedes the definition provided in .

+ + + +

Calendar Types

+ +

+ The ECMAScript 2022 Internationalization API Specification identifies calendars using a calendar type as defined by Unicode Technical Standard #35, Part 4, Section 2. Their canonical form is a string containing all lower case letters with zero or more hyphens. +

+ + +

+ AvailableCalendars ( + ): a List of Strings +

+
+
description
+
The returned List is ordered as if an Array of the same values had been sorted using %Array.prototype.sort% using *undefined* as _comparefn_, and contains unique calendar types identifying the calendars for which the implementation provides the functionality of Intl.DateTimeFormat objects. + The list must include *"gregory"* and *"iso8601"*.
+
redefinition
+
true
+
+ +

This definition supersedes the definition provided in .

+
+
+
@@ -1327,16 +1353,6 @@

Locale Sensiti

Abstract Operations for Temporal.Calendar Objects

- -

IsBuiltinCalendar ( _id_ )

-

This definition supersedes the definition provided in .

- - 1. Let _builtinCalendars_ be a List of Unicode BCP 47 calendar identifiers identifying the calendars for which the implementation provides the functionality of the constructed `Temporal.Calendar` objects. The list must include *"iso8601"*. The ordering is irrelevant. - 1. If _builtinCalendars_ contains _id_, return *true*. - 1. Return *false*. - -
-

CalendarEra ( _calendar_, _dateLike_ )