Skip to content

Commit

Permalink
Normative: Add calendar and numberingSystem options
Browse files Browse the repository at this point in the history
This patch allows calendar and numberingSystem to be specified in
the options bag of the DateTimeFormat and NumberFormat constructors.
One use case for these options would be, when working with locales
which have two numbering systems and calendars in use--the UA default
may be the non-Western one, but in some contexts, it may be appropriate
to use the Western one. Currently, without the patch, it would be
necessary to parse the BCP 47 language tag in the application, but Intl
provides no library to do so. For example, this all occurs in this bug:
https://bugzilla.mozilla.org/show_bug.cgi?id=1370086

This patch validates the calendar and numbering system by comparing
them to the grammar allowed for Unicode extension tags, per the resolution
documented at #175 (comment)

Related bug: #105 . This patch leaves out "collation" because of a lack
of clear use cases.
  • Loading branch information
littledan committed Feb 27, 2018
1 parent ac3ce99 commit 3925958
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
10 changes: 10 additions & 0 deletions spec/datetimeformat.html
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,22 @@ <h1>InitializeDateTimeFormat ( _dateTimeFormat_, _locales_, _options_ )</h1>
The abstract operation InitializeDateTimeFormat accepts the arguments _dateTimeFormat_ (which must be an object), _locales_, and _options_. It initializes _dateTimeFormat_ as a DateTimeFormat object. This abstract operation functions as follows:
</p>

<p>
The following algorithm refers to <a href="http://www.unicode.org/reports/tr35/#Unicode_locale_identifier">UTS 35's Unicode Locale Identifier grammar</a>.
</p>

<emu-alg>
1. Let _requestedLocales_ be ? CanonicalizeLocaleList(_locales_).
1. Let _options_ be ? ToDateTimeOptions(_options_, `"any"`, `"date"`).
1. Let _opt_ be a new Record.
1. Let _matcher_ be ? GetOption(_options_, `"localeMatcher"`, `"string"`, &laquo; `"lookup"`, `"best fit"` &raquo;, `"best fit"`).
1. Set _opt_.[[localeMatcher]] to _matcher_.
1. Let _calendar_ be ? GetOption(_options_, `"calendar"`, `"string"`, *undefined*, *undefined*).
1. If _calendar_ does not match `type`, throw a *RangeError* exception.
1. Set _opt_.[[ca]] to _calendar_.
1. Let _numberingSystem_ be ? GetOption(_options_, `"numberingSystem"`, `"string"`, *undefined*, *undefined*).
1. If _numberingSystem_ does not match `type`, throw a *RangeError* exception.
1. Set _opt_.[[nu]] to _numberingSystem_.
1. Let _hour12_ be ? GetOption(_options_, `"hour12"`, `"boolean"`, *undefined*, *undefined*).
1. Let _hourCycle_ be ? GetOption(_options_, `"hourCycle"`, `"string"`, &laquo; `"h11"`, `"h12"`, `"h23"`, `"h24"` &raquo;, *undefined*).
1. If _hour12_ is not *undefined*, then
Expand Down
7 changes: 7 additions & 0 deletions spec/numberformat.html
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ <h1>InitializeNumberFormat ( _numberFormat_, _locales_, _options_ )</h1>
The abstract operation InitializeNumberFormat accepts the arguments _numberFormat_ (which must be an object), _locales_, and _options_. It initializes _numberFormat_ as a NumberFormat object. The following steps are taken:
</p>

<p>
The following algorithm refers to <a href="http://www.unicode.org/reports/tr35/#Unicode_locale_identifier">UTS 35's Unicode Locale Identifier grammar</a>.
</p>

<emu-alg>
1. Let _requestedLocales_ be ? CanonicalizeLocaleList(_locales_).
1. If _options_ is *undefined*, then
Expand All @@ -49,6 +53,9 @@ <h1>InitializeNumberFormat ( _numberFormat_, _locales_, _options_ )</h1>
1. Let _opt_ be a new Record.
1. Let _matcher_ be ? GetOption(_options_, `"localeMatcher"`, `"string"`, &laquo; `"lookup"`, `"best fit"` &raquo;, `"best fit"`).
1. Set _opt_.[[localeMatcher]] to _matcher_.
1. Let _numberingSystem_ be ? GetOption(_options_, `"numberingSystem"`, `"string"`, *undefined*, *undefined*).
1. If _numberingSystem_ does not match `type`, throw a *RangeError* exception.
1. Set _opt_.[[nu]] to _numberingSystem_.
1. Let _localeData_ be %NumberFormat%.[[LocaleData]].
1. Let _r_ be ResolveLocale(%NumberFormat%.[[AvailableLocales]], _requestedLocales_, _opt_, %NumberFormat%.[[RelevantExtensionKeys]], _localeData_).
1. Set _numberFormat_.[[Locale]] to _r_.[[locale]].
Expand Down

0 comments on commit 3925958

Please sign in to comment.