Skip to content

Commit 20e5c26

Browse files
longlhogibson042
andauthored
Normative: Add hourCycle to opt before passing to FormatMatcher (#571)
* Normative: Add hourCycle to opt before passing to FormatMatcher * address comments * small refactor * Update spec/datetimeformat.html Co-authored-by: Richard Gibson <[email protected]> * move hourCycle resolution down to closer to matcher initialization * move more stuff down * Update spec/datetimeformat.html Co-authored-by: Richard Gibson <[email protected]> Co-authored-by: Richard Gibson <[email protected]>
1 parent ee5ed53 commit 20e5c26

File tree

1 file changed

+27
-29
lines changed

1 file changed

+27
-29
lines changed

spec/datetimeformat.html

Lines changed: 27 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -123,15 +123,33 @@ <h1>InitializeDateTimeFormat ( _dateTimeFormat_, _locales_, _options_ )</h1>
123123
1. Throw a *RangeError* exception.
124124
1. Let _timeZone_ be CanonicalizeTimeZoneName(_timeZone_).
125125
1. Set _dateTimeFormat_.[[TimeZone]] to _timeZone_.
126-
1. Let _opt_ be a new Record.
126+
1. Let _formatOptions_ be a new Record.
127127
1. For each row of <emu-xref href="#table-datetimeformat-components"></emu-xref>, except the header row, in table order, do
128128
1. Let _prop_ be the name given in the Property column of the row.
129129
1. If _prop_ is *"fractionalSecondDigits"*, then
130130
1. Let _value_ be ? GetNumberOption(options, *"fractionalSecondDigits"*, 1, 3, *undefined*).
131131
1. Else,
132132
1. Let _value_ be ? GetOption(_options_, _prop_, *"string"*, &laquo; the strings given in the Values column of the row &raquo;, *undefined*).
133-
1. Set _opt_.[[&lt;_prop_&gt;]] to _value_.
133+
1. Set _formatOptions_.[[&lt;_prop_&gt;]] to _value_.
134134
1. Let _dataLocaleData_ be _localeData_.[[&lt;_dataLocale_&gt;]].
135+
1. Let _hcDefault_ be _dataLocaleData_.[[hourCycle]].
136+
1. Let _hc_ be _dateTimeFormat_.[[HourCycle]].
137+
1. If _hc_ is *null*, then
138+
1. Set _hc_ to _hcDefault_.
139+
1. If _hour12_ is *true*, then
140+
1. If _hcDefault_ is *"h11"* or *"h23"*, then
141+
1. Set _hc_ to *"h11"*.
142+
1. Else,
143+
1. Set _hc_ to *"h12"*.
144+
1. Else if _hour12_ is *false*, then
145+
1. If _hcDefault_ is *"h11"* or *"h23"*, then
146+
1. Set _hc_ to *"h23"*.
147+
1. Else,
148+
1. Set _hc_ to *"h24"*.
149+
1. Else,
150+
1. Assert: _hour12_ is *undefined*.
151+
1. Set _dateTimeFormat_.[[HourCycle]] to _hc_.
152+
1. Set _formatOptions_.[[hourCycle]] to _hc_.
135153
1. Let _matcher_ be ? GetOption(_options_, *"formatMatcher"*, *"string"*, &laquo; *"basic"*, *"best fit"* &raquo;, *"best fit"*).
136154
1. Let _dateStyle_ be ? GetOption(_options_, *"dateStyle"*, *"string"*, &laquo; *"full"*, *"long"*, *"medium"*, *"short"* &raquo;, *undefined*).
137155
1. Set _dateTimeFormat_.[[DateStyle]] to _dateStyle_.
@@ -140,50 +158,30 @@ <h1>InitializeDateTimeFormat ( _dateTimeFormat_, _locales_, _options_ )</h1>
140158
1. If _dateStyle_ is not *undefined* or _timeStyle_ is not *undefined*, then
141159
1. For each row in <emu-xref href="#table-datetimeformat-components"></emu-xref>, except the header row, do
142160
1. Let _prop_ be the name given in the Property column of the row.
143-
1. Let _p_ be _opt_.[[&lt;_prop_&gt;]].
161+
1. Let _p_ be _formatOptions_.[[&lt;_prop_&gt;]].
144162
1. If _p_ is not *undefined*, then
145163
1. Throw a *TypeError* exception.
146164
1. Let _styles_ be _dataLocaleData_.[[styles]].[[&lt;_calendar_&gt;]].
147165
1. Let _bestFormat_ be DateTimeStyleFormat(_dateStyle_, _timeStyle_, _styles_).
148166
1. Else,
149167
1. Let _formats_ be _dataLocaleData_.[[formats]].[[&lt;_calendar_&gt;]].
150168
1. If _matcher_ is *"basic"*, then
151-
1. Let _bestFormat_ be BasicFormatMatcher(_opt_, _formats_).
169+
1. Let _bestFormat_ be BasicFormatMatcher(_formatOptions_, _formats_).
152170
1. Else,
153-
1. Let _bestFormat_ be BestFitFormatMatcher(_opt_, _formats_).
171+
1. Let _bestFormat_ be BestFitFormatMatcher(_formatOptions_, _formats_).
154172
1. For each row in <emu-xref href="#table-datetimeformat-components"></emu-xref>, except the header row, in table order, do
155173
1. Let _prop_ be the name given in the Property column of the row.
156174
1. If _bestFormat_ has a field [[&lt;_prop_&gt;]], then
157175
1. Let _p_ be _bestFormat_.[[&lt;_prop_&gt;]].
158176
1. Set _dateTimeFormat_'s internal slot whose name is the Internal Slot column of the row to _p_.
159177
1. If _dateTimeFormat_.[[Hour]] is *undefined*, then
160178
1. Set _dateTimeFormat_.[[HourCycle]] to *undefined*.
179+
1. If _dateTimeformat_.[[HourCycle]] is *"h11"* or *"h12"*, then
180+
1. Let _pattern_ be _bestFormat_.[[pattern12]].
181+
1. Let _rangePatterns_ be _bestFormat_.[[rangePatterns12]].
182+
1. Else,
161183
1. Let _pattern_ be _bestFormat_.[[pattern]].
162184
1. Let _rangePatterns_ be _bestFormat_.[[rangePatterns]].
163-
1. Else,
164-
1. Let _hcDefault_ be _dataLocaleData_.[[hourCycle]].
165-
1. Let _hc_ be _dateTimeFormat_.[[HourCycle]].
166-
1. If _hc_ is *null*, then
167-
1. Set _hc_ to _hcDefault_.
168-
1. If _hour12_ is not *undefined*, then
169-
1. If _hour12_ is *true*, then
170-
1. If _hcDefault_ is *"h11"* or *"h23"*, then
171-
1. Set _hc_ to *"h11"*.
172-
1. Else,
173-
1. Set _hc_ to *"h12"*.
174-
1. Else,
175-
1. Assert: _hour12_ is *false*.
176-
1. If _hcDefault_ is *"h11"* or *"h23"*, then
177-
1. Set _hc_ to *"h23"*.
178-
1. Else,
179-
1. Set _hc_ to *"h24"*.
180-
1. Set _dateTimeFormat_.[[HourCycle]] to _hc_.
181-
1. If _dateTimeformat_.[[HourCycle]] is *"h11"* or *"h12"*, then
182-
1. Let _pattern_ be _bestFormat_.[[pattern12]].
183-
1. Let _rangePatterns_ be _bestFormat_.[[rangePatterns12]].
184-
1. Else,
185-
1. Let _pattern_ be _bestFormat_.[[pattern]].
186-
1. Let _rangePatterns_ be _bestFormat_.[[rangePatterns]].
187185
1. Set _dateTimeFormat_.[[Pattern]] to _pattern_.
188186
1. Set _dateTimeFormat_.[[RangePatterns]] to _rangePatterns_.
189187
1. Return _dateTimeFormat_.

0 commit comments

Comments
 (0)