Skip to content

Commit

Permalink
Support hc extension key in DateTimeFormat with new option hourCycle. (
Browse files Browse the repository at this point in the history
  • Loading branch information
zbraniecki authored and caridy committed Jul 20, 2017
1 parent 2affb47 commit bb18b48
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 17 deletions.
2 changes: 1 addition & 1 deletion spec/annexes.html
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ <h1>Implementation Dependent Behaviour</h1>
The set of supported *"nu"* key values (numbering systems) per locale (<emu-xref href="#sec-intl.datetimeformat-internal-slots"></emu-xref>)
</li>
<li>
The default hour12 and hourNo0 settings per locale (<emu-xref href="#sec-intl.datetimeformat-internal-slots"></emu-xref>)
The default hourCycle setting per locale (<emu-xref href="#sec-intl.datetimeformat-internal-slots"></emu-xref>)
</li>
<li>
The set of supported date-time formats per locale beyond a core set, including the representations used for each component and the associated patterns (<emu-xref href="#sec-intl.datetimeformat-internal-slots"></emu-xref>)
Expand Down
49 changes: 33 additions & 16 deletions spec/datetimeformat.html
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ <h1>InitializeDateTimeFormat ( _dateTimeFormat_, _locales_, _options_ )</h1>
1. Let _r_ be ResolveLocale( %DateTimeFormat%.[[AvailableLocales]], _requestedLocales_, _opt_, %DateTimeFormat%.[[RelevantExtensionKeys]], _localeData_).
1. Set _dateTimeFormat_.[[Locale]] to _r_.[[locale]].
1. Set _dateTimeFormat_.[[Calendar]] to _r_.[[ca]].
1. Set _dateTimeFormat_.[[HourCycle]] to _r_.[[hc]].
1. Set _dateTimeFormat_.[[NumberingSystem]] to _r_.[[nu]].
1. Let _dataLocale_ be _r_.[[dataLocale]].
1. Let _tz_ be ? Get(_options_, *"timeZone"*).
Expand Down Expand Up @@ -113,14 +114,25 @@ <h1>InitializeDateTimeFormat ( _dateTimeFormat_, _locales_, _options_ )</h1>
1. Let _p_ be Get(_bestFormat_, _prop_).
1. If _p_ not *undefined*, then
1. Set _dateTimeFormat_'s internal slot whose name is the Internal Slot column of the row to _p_.
1. Let _hr12_ be ? GetOption(_options_, *"hour12"*, *"boolean"*, *undefined*, *undefined*).
1. If _dateTimeFormat_ has an internal slot [[Hour]], then
1. If _hr12_ is *undefined*, then
1. Let _hr12_ be Get(_dataLocaleData_, *"hour12"*).
1. Set _dateTimeFormat_.[[Hour12]] to _hr12_.
1. If _hr12_ is *true*, then
1. Let _hourNo0_ be Get(_dataLocaleData_, *"hourNo0"*).
1. Set _dateTimeFormat_.[[HourNo0]] to _hourNo0_.
1. Let _hc_ be ? GetOption(_options_, *"hourCycle"*, *"string"*, &laquo; *"h11"*, *"h12"*, *"h23"*, *"h24"* &raquo;, *undefined*).
1. Let _hr12_ be ? GetOption(_options_, *"hour12"*, *"boolean"*, *undefined*, *undefined*).
1. Let _hcDefault_ be Get(_dataLocaleData_, *"hourCycle"*).
1. If _hr12_ is not *undefined*, then
1. If _hr12_ is *true*, then
1. If _hcDefault_ is *"h11"* or *"h23"*, then
1. Set _hc_ to *"h11"*.
1. Else,
1. Set _hc_ to *"h12"*.
1. Else, if _hr12_ is *false*, then
1. If _hcDefault_ is *"h11"* or *"h23"*, then
1. Set _hc_ to *"h23"*.
1. Else,
1. Set _hc_ to *"h24"*.
1. If _hc_ is *undefined*, then
1. Set _hc_ to _hcDefault_
1. Set _dateTimeFormat_.[[HourCycle]] to _hc_.
1. If _dateTimeformat_.[[HourCycle]] is *"h11"* or *"h12"*, then
1. Let _pattern_ be Get(_bestFormat_, *"pattern12"*).
1. Else,
1. Let _pattern_ be Get(_bestFormat_, *"pattern"*).
Expand Down Expand Up @@ -278,9 +290,11 @@ <h1>PartitionDateTimePattern ( _dateTimeFormat_, _x_ )</h1>
1. Let _v_ be the value of _tm_'s field whose name is the Internal Slot column of the matching row.
1. If _p_ is *"year"* and _v_ ≤ 0, let _v_ be 1 - _v_.
1. If _p_ is *"month"*, increase _v_ by 1.
1. If _p_ is *"hour"* and _dateTimeFormat_.[[Hour12]] is *true*, then
1. If _p_ is *"hour"* and _dateTimeFormat_.[[HourCycle]] is *"h11"* or *"h12"*, then
1. Let _v_ be _v_ modulo 12.
1. If _v_ is 0 and _dateTimeFormat_.[[HourNo0]] is *true*, let _v_ be 12.
1. If _v_ is 0 and _dateTimeFormat_.[[HourCucle]] is *"h12"*, let _v_ be 12.
1. If _p_ is *"hour"* and _dateTimeFormat_.[[HourCycle]] is *"h24"*, then
1. If _v_ is 0, let _v_ be 24.
1. If _f_ is *"numeric"*, then
1. Let _fv_ be FormatNumber(_nf_, _v_).
1. Else if _f_ is *"2-digit"*, then
Expand Down Expand Up @@ -409,7 +423,7 @@ <h1>Intl.DateTimeFormat ( [ _locales_ [ , _options_ ] ] )</h1>

<emu-alg>
1. If NewTarget is *undefined*, let _newTarget_ be the active function object, else let _newTarget_ be NewTarget.
1. Let _dateTimeFormat_ be ? OrdinaryCreateFromConstructor(_newTarget_, `"%DateTimeFormatPrototype%"`, &laquo; [[InitializedIntlObject]], [[InitializedDateTimeFormat]], [[Locale]], [[Calendar]], [[NumberingSystem]], [[TimeZone]], [[Weekday]], [[Era]], [[Year]], [[Month]], [[Day]], [[Hour]], [[Minute]], [[Second]], [[TimeZoneName]], [[Hour12]], [[HourNo0]], [[Pattern]], [[BoundFormat]] &raquo;).
1. Let _dateTimeFormat_ be ? OrdinaryCreateFromConstructor(_newTarget_, `"%DateTimeFormatPrototype%"`, &laquo; [[InitializedIntlObject]], [[InitializedDateTimeFormat]], [[Locale]], [[Calendar]], [[NumberingSystem]], [[TimeZone]], [[Weekday]], [[Era]], [[Year]], [[Month]], [[Day]], [[Hour]], [[Minute]], [[Second]], [[TimeZoneName]], [[HourCycle]], [[Pattern]], [[BoundFormat]] &raquo;).
1. Perform ? InitializeDateTimeFormat(_dateTimeFormat_, _locales_, _options_).
</emu-alg>
<emu-normative-optional>
Expand Down Expand Up @@ -470,11 +484,11 @@ <h1>Internal slots</h1>
</p>

<p>
The value of the [[RelevantExtensionKeys]] internal slot is &laquo; `"ca"`, `"nu"` &raquo;.
The value of the [[RelevantExtensionKeys]] internal slot is &laquo; `"ca"`, `"nu"`, `"hc"` &raquo;.
</p>

<emu-note>
Unicode Technical Standard 35 describes three locale extension keys that are relevant to date and time formatting, "ca" for calendar, "tz" for time zone, and implicitly "nu" for the numbering system of the number format used for numbers within the date format. DateTimeFormat, however, requires that the time zone is specified through the timeZone property in the options objects.
Unicode Technical Standard 35 describes three locale extension keys that are relevant to date and time formatting, "ca" for calendar, "tz" for time zone, "hc" for hour cycle, and implicitly "nu" for the numbering system of the number format used for numbers within the date format. DateTimeFormat, however, requires that the time zone is specified through the timeZone property in the options objects.
</emu-note>

<p>
Expand All @@ -486,7 +500,7 @@ <h1>Internal slots</h1>
The array that is the value of the "nu" property of any locale property of [[LocaleData]] must not include the values "native", "traditio", or "finance".
</li>
<li>
[[LocaleData]][locale] must have hour12 and hourNo0 properties with Boolean values for all locale values.
[[LocaleData]][locale] must have hourCycle property with String values for all locale values.
</li>
<li>
[[LocaleData]][locale] must have a formats property for all locale values. The value of this property must be an array of objects, each of which has a subset of the properties shown in <emu-xref href="#table-datetimeformat-components"></emu-xref>, where each property must have one of the values specified for the property in <emu-xref href="#table-datetimeformat-components"></emu-xref>. Multiple objects in an array may use the same subset of the properties as long as they have different values for the properties. The following subsets must be available for each locale:
Expand Down Expand Up @@ -591,7 +605,11 @@ <h1>Intl.DateTimeFormat.prototype.resolvedOptions ()</h1>
</p>

<p>
The function returns a new object whose properties and attributes are set as if constructed by an object literal assigning to each of the following properties the value of the corresponding internal slot of this DateTimeFormat object (see <emu-xref href="#sec-properties-of-intl-datetimeformat-instances"></emu-xref>): locale, calendar, numberingSystem, timeZone, hour12, weekday, era, year, month, day, hour, minute, second, and timeZoneName. Properties whose corresponding internal slots have the value *undefined* are not assigned.
The function returns a new object whose properties and attributes are set as if constructed by an object literal assigning to each of the following properties the value of the corresponding internal slot of this DateTimeFormat object (see <emu-xref href="#sec-properties-of-intl-datetimeformat-instances"></emu-xref>): locale, calendar, numberingSystem, timeZone, hourCycle, weekday, era, year, month, day, hour, minute, second, and timeZoneName. Properties whose corresponding internal slots have the value *undefined* are not assigned.
</p>

<p>
For web compatibility reasons, if the property hourCycle is set, the corresponding property hour12 should be set as well.
</p>

<emu-note>
Expand Down Expand Up @@ -621,8 +639,7 @@ <h1>Properties of Intl.DateTimeFormat Instances</h1>
<li>[[NumberingSystem]] is a String value with the "type" given in Unicode Technical Standard 35 for the numbering system used for formatting.</li>
<li>[[TimeZone]] is a String value with the IANA time zone name of the time zone used for formatting.</li>
<li>[[Weekday]], [[Era]], [[Year]], [[Month]], [[Day]], [[Hour]], [[Minute]], [[Second]], [[TimeZoneName]] are each either *undefined*, indicating that the component is not used for formatting, or one of the String values given in <emu-xref href="#table-datetimeformat-components"></emu-xref>, indicating how the component should be presented in the formatted output.</li>
<li>[[Hour12]] is a Boolean value indicating whether 12-hour format (*true*) or 24-hour format (*false*) should be used. It is only used when [[Hour]] is not *undefined*.</li>
<li>[[HourNo0]] is a Boolean value indicating whether hours from 1 to 12 (*true*) or from 0 to 11 (*false*) should be used. It is only used when [[Hour12]] has the value *true*.</li>
<li>[[HourCycle]] is a String value indicating whether the 12-hour format (*"h11"*, *"h12"*) or the 24-hour format (*"h23"*, *"h24"*) should be used. *"h11"* and *"h23"* start with hour *0* and go up to *11* and *23* respectively. *"h12"* and *"h24"* start with hour *1* and go up to *12* and *24*. [[HourCycle]] is only used when [[Hour]] is not *undefined*.</li>
<li>[[Pattern]] is a String value as described in <emu-xref href="#sec-intl.datetimeformat-internal-slots"></emu-xref>.</li>
</ul>

Expand Down

0 comments on commit bb18b48

Please sign in to comment.