Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support hc extension key in DateTimeFormat. #135

Merged
merged 7 commits into from
Jul 20, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -410,7 +424,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 @@ -471,11 +485,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 @@ -487,7 +501,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 @@ -592,7 +606,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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add support here for emulating the old hour12 field in resolvedOptions when hourCycle is one of the forms supported by it?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure what are you asking here @littledan, can you clarify?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If anyone is using the hour12 field of the resolvedOptions(), this patch makes it go away. That risks web compatibility. For that reason, I'd rather we not merge this patch.

One way to resolve this would be to hold around the hour12 option that the users passed in, and then just pass that back out. I'd suggest, on the other hand, to just use the [[HourCycle]] internal slot that we already have: if the hourCycle is one of the two values that hour12 would provide, then use that in an hour12 property; otherwise, omit the hour12 property.

In my opinion, it's OK to have hour12 in the output even if it wasn't in the input. This is just another instance of the pattern where resolvedOptions has options that the user didn't provide, but were chosen by, e.g., locale selection or matching a pattern.

I've made this suggestion a couple times in the past; I must not have been explaining myself clearly. I'll follow up with spec text to explain the change.

Copy link
Contributor

@caridy caridy Jul 7, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, you're absolutely right! I didn't think of this before. And yes, I agree with always providing the value of hour12 as part of the resolvedOptions. As part of the documentation of the process for this kind of changes, I will document this as well. @zbraniecki can you update the PR?

</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 @@ -622,8 +640,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