Skip to content

Commit e35d54c

Browse files
committed
Editorial: Split GetTemporalUnitValuedOption with ValidateTemporalUnitValue
1 parent ed49b0b commit e35d54c

File tree

6 files changed

+66
-41
lines changed

6 files changed

+66
-41
lines changed

spec/abstractops.html

Lines changed: 42 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -548,51 +548,58 @@ <h1>
548548
GetTemporalUnitValuedOption (
549549
_options_: an Object,
550550
_key_: a property key,
551-
_unitGroup_: ~date~, ~time~, or ~datetime~,
552-
_default_: ~required~, ~unset~, ~auto~, or a Temporal unit,
553-
optional _extraValues_: a List of either Temporal units or ~auto~,
551+
_default_: ~required~ or ~unset~,
554552
): either a normal completion containing either a Temporal unit, ~unset~, or ~auto~, or a throw completion
555553
</h1>
556554
<dl class="header">
557555
<dt>description</dt>
558-
<dd>It attempts to read from the specified property of _options_ a Temporal unit that is <emu-not-ref>covered</emu-not-ref> by the union of _unitGroup_ and _extraValues_, substituting _default_ if the property value is *undefined*.</dd>
556+
<dd>It attempts to read a Temporal unit from the specified property of _options_.</dd>
559557
</dl>
560558
<p>Both singular and plural unit names are accepted, but only the singular form is used internally.</p>
561559
<emu-alg>
562-
1. Let _allowedValues_ be a new empty List.
560+
1. Let _allowedStrings_ be a new empty List.
561+
1. Append *"auto"* to _allowedStrings_.
563562
1. For each row of <emu-xref href="#table-temporal-units"></emu-xref>, except the header row, in table order, do
564-
1. Let _unit_ be the value in the "Value" column of the row.
565-
1. If the "Category" column of the row is ~date~ and _unitGroup_ is ~date~ or ~datetime~, append _unit_ to _allowedValues_.
566-
1. Else if the "Category" column of the row is ~time~ and _unitGroup_ is ~time~ or ~datetime~, append _unit_ to _allowedValues_.
567-
1. If _extraValues_ is present, then
568-
1. Set _allowedValues_ to the list-concatenation of _allowedValues_ and _extraValues_.
563+
1. Let _singularName_ be the value in the "Singular property name" column of the row.
564+
1. Append _singularName_ to _allowedStrings_.
565+
1. Let _pluralName_ be the value in the "Plural property name" column of the row.
566+
1. Append _pluralName_ to _allowedStrings_.
567+
1. NOTE: For each singular Temporal unit name that is contained within _allowedStrings_, the corresponding plural name is also contained within it.
569568
1. If _default_ is ~unset~, then
570569
1. Let _defaultValue_ be *undefined*.
571-
1. Else if _default_ is ~required~, then
572-
1. Let _defaultValue_ be ~required~.
573-
1. Else if _default_ is ~auto~, then
574-
1. Append _default_ to _allowedValues_.
575-
1. Let _defaultValue_ be *"auto"*.
576570
1. Else,
577-
1. Assert: _allowedValues_ contains _default_.
578-
1. Let _defaultValue_ be the value in the "Singular property name" column of <emu-xref href="#table-temporal-units"></emu-xref> corresponding to the row with _default_ in the "Value" column.
579-
1. Let _allowedStrings_ be a new empty List.
580-
1. For each element _value_ of _allowedValues_, do
581-
1. If _value_ is ~auto~, then
582-
1. Append *"auto"* to _allowedStrings_.
583-
1. Else,
584-
1. Let _singularName_ be the value in the "Singular property name" column of <emu-xref href="#table-temporal-units"></emu-xref> corresponding to the row with _value_ in the "Value" column.
585-
1. Append _singularName_ to _allowedStrings_.
586-
1. Let _pluralName_ be the value in the "Plural property name" column of the corresponding row.
587-
1. Append _pluralName_ to _allowedStrings_.
588-
1. NOTE: For each singular Temporal unit name that is contained within _allowedStrings_, the corresponding plural name is also contained within it.
571+
1. Let _defaultValue_ be _default_.
589572
1. Let _value_ be ? GetOption(_options_, _key_, ~string~, _allowedStrings_, _defaultValue_).
590573
1. If _value_ is *undefined*, return ~unset~.
591574
1. If _value_ is *"auto"*, return ~auto~.
592575
1. Return the value in the "Value" column of <emu-xref href="#table-temporal-units"></emu-xref> corresponding to the row with _value_ in its "Singular property name" or "Plural property name" column.
593576
</emu-alg>
594577
</emu-clause>
595578

579+
<emu-clause id="sec-temporal-validatetemporalunitvaluedoption" type="abstract operation">
580+
<h1>
581+
ValidateTemporalUnitValue (
582+
_value_: a Temporal unit, ~unset~, or ~auto~,
583+
_unitGroup_: ~date~, ~time~, or ~datetime~,
584+
optional _extraValues_: a List of either Temporal units or ~auto~,
585+
): either a normal completion containing ~unused~ or a throw completion
586+
</h1>
587+
<dl class="header">
588+
<dt>description</dt>
589+
<dd>It validates that the result of GetTemporalUnitValuedOption is <emu-not-ref>covered</emu-not-ref> by the union of _unitGroup_ and _extraValues_.</dd>
590+
</dl>
591+
<emu-alg>
592+
1. Let _allowedValues_ be a new empty List.
593+
1. For each row of <emu-xref href="#table-temporal-units"></emu-xref>, except the header row, in table order, do
594+
1. Let _unit_ be the value in the "Value" column of the row.
595+
1. If the "Category" column of the row is ~date~ and _unitGroup_ is ~date~ or ~datetime~, append _unit_ to _allowedValues_.
596+
1. Else if the "Category" column of the row is ~time~ and _unitGroup_ is ~time~ or ~datetime~, append _unit_ to _allowedValues_.
597+
1. If _extraValues_ is present, then
598+
1. Set _allowedValues_ to the list-concatenation of _allowedValues_ and _extraValues_.
599+
1. If _allowedValues_ does not contain _value_, throw a RangeError exception.
600+
</emu-alg>
601+
</emu-clause>
602+
596603
<emu-clause id="sec-temporal-gettemporalrelativetooption" type="abstract operation">
597604
<h1>
598605
GetTemporalRelativeToOption (
@@ -1864,13 +1871,19 @@ <h1>
18641871
</dl>
18651872
<emu-alg>
18661873
1. NOTE: The following steps read options and perform independent validation in alphabetical order.
1867-
1. Let _largestUnit_ be ? GetTemporalUnitValuedOption(_options_, *"largestUnit"*, _unitGroup_, ~auto~).
1874+
1. Let _largestUnit_ be ? GetTemporalUnitValuedOption(_options_, *"largestUnit"*, ~auto~).
1875+
1. Perform ? ValidateTemporalUnitValue(_largestUnit_, _unitGroup_).
18681876
1. If _disallowedUnits_ contains _largestUnit_, throw a *RangeError* exception.
18691877
1. Let _roundingIncrement_ be ? GetRoundingIncrementOption(_options_).
18701878
1. Let _roundingMode_ be ? GetRoundingModeOption(_options_, ~trunc~).
18711879
1. If _operation_ is ~since~, then
18721880
1. Set _roundingMode_ to NegateRoundingMode(_roundingMode_).
1873-
1. Let _smallestUnit_ be ? GetTemporalUnitValuedOption(_options_, *"smallestUnit"*, _unitGroup_, _fallbackSmallestUnit_).
1881+
1. Let _smallestUnitOrUnset_ be ? GetTemporalUnitValuedOption(_options_, *"smallestUnit"*, ~unset~).
1882+
1. Perform ? ValidateTemporalUnitValue(_smallestUnitOrUnset_, _unitGroup_).
1883+
1. If _smallestUnitOrUnset_ is ~unset~, then
1884+
1. Set _smallestUnit_ to _fallbackSmallestUnit_.
1885+
1. Else,
1886+
1. Set _smallestUnit_ to _smallestUnitOrUnset_.
18741887
1. If _disallowedUnits_ contains _smallestUnit_, throw a *RangeError* exception.
18751888
1. Let _defaultLargestUnit_ be LargerOfTwoTemporalUnits(_smallestLargestDefaultUnit_, _smallestUnit_).
18761889
1. If _largestUnit_ is ~auto~, set _largestUnit_ to _defaultLargestUnit_.

spec/duration.html

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -402,13 +402,15 @@ <h1>Temporal.Duration.prototype.round ( _roundTo_ )</h1>
402402
1. Let _smallestUnitPresent_ be *true*.
403403
1. Let _largestUnitPresent_ be *true*.
404404
1. NOTE: The following steps read options and perform independent validation in alphabetical order (GetTemporalRelativeToOption reads *"relativeTo"*, GetRoundingIncrementOption reads *"roundingIncrement"* and GetRoundingModeOption reads *"roundingMode"*).
405-
1. Let _largestUnit_ be ? GetTemporalUnitValuedOption(_roundTo_, *"largestUnit"*, ~datetime~, ~unset~, « ~auto~ »).
405+
1. Let _largestUnit_ be ? GetTemporalUnitValuedOption(_roundTo_, *"largestUnit"*, ~unset~).
406+
1. Perform ? ValidateTemporalUnitValue(_largestUnit_, ~datetime~, « ~auto~ »).
406407
1. Let _relativeToRecord_ be ? GetTemporalRelativeToOption(_roundTo_).
407408
1. Let _zonedRelativeTo_ be _relativeToRecord_.[[ZonedRelativeTo]].
408409
1. Let _plainRelativeTo_ be _relativeToRecord_.[[PlainRelativeTo]].
409410
1. Let _roundingIncrement_ be ? GetRoundingIncrementOption(_roundTo_).
410411
1. Let _roundingMode_ be ? GetRoundingModeOption(_roundTo_, ~half-expand~).
411-
1. Let _smallestUnit_ be ? GetTemporalUnitValuedOption(_roundTo_, *"smallestUnit"*, ~datetime~, ~unset~).
412+
1. Let _smallestUnit_ be ? GetTemporalUnitValuedOption(_roundTo_, *"smallestUnit"*, ~unset~).
413+
1. Perform ? ValidateTemporalUnitValue(_smallestUnit_, ~datetime~).
412414
1. If _smallestUnit_ is ~unset~, then
413415
1. Set _smallestUnitPresent_ to *false*.
414416
1. Set _smallestUnit_ to ~nanosecond~.
@@ -476,7 +478,8 @@ <h1>Temporal.Duration.prototype.total ( _totalOf_ )</h1>
476478
1. Let _relativeToRecord_ be ? GetTemporalRelativeToOption(_totalOf_).
477479
1. Let _zonedRelativeTo_ be _relativeToRecord_.[[ZonedRelativeTo]].
478480
1. Let _plainRelativeTo_ be _relativeToRecord_.[[PlainRelativeTo]].
479-
1. Let _unit_ be ? GetTemporalUnitValuedOption(_totalOf_, *"unit"*, ~datetime~, ~required~).
481+
1. Let _unit_ be ? GetTemporalUnitValuedOption(_totalOf_, *"unit"*, ~required~).
482+
1. Perform ? ValidateTemporalUnitValue(_unit_, ~datetime~).
480483
1. If _zonedRelativeTo_ is not *undefined*, then
481484
1. Let _internalDuration_ be ToInternalDurationRecord(_duration_).
482485
1. Let _timeZone_ be _zonedRelativeTo_.[[TimeZone]].
@@ -512,7 +515,8 @@ <h1>Temporal.Duration.prototype.toString ( [ _options_ ] )</h1>
512515
1. NOTE: The following steps read options and perform independent validation in alphabetical order (GetTemporalFractionalSecondDigitsOption reads *"fractionalSecondDigits"* and GetRoundingModeOption reads *"roundingMode"*).
513516
1. Let _digits_ be ? GetTemporalFractionalSecondDigitsOption(_resolvedOptions_).
514517
1. Let _roundingMode_ be ? GetRoundingModeOption(_resolvedOptions_, ~trunc~).
515-
1. Let _smallestUnit_ be ? GetTemporalUnitValuedOption(_resolvedOptions_, *"smallestUnit"*, ~time~, ~unset~).
518+
1. Let _smallestUnit_ be ? GetTemporalUnitValuedOption(_resolvedOptions_, *"smallestUnit"*, ~unset~).
519+
1. Perform ? ValidateTemporalUnitValue(_smallestUnit_, ~time~).
516520
1. If _smallestUnit_ is ~hour~ or ~minute~, throw a *RangeError* exception.
517521
1. Let _precision_ be ToSecondsStringPrecisionRecord(_smallestUnit_, _digits_).
518522
1. If _precision_.[[Unit]] is ~nanosecond~ and _precision_.[[Increment]] = 1, then

spec/instant.html

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,8 @@ <h1>Temporal.Instant.prototype.round ( _roundTo_ )</h1>
193193
1. NOTE: The following steps read options and perform independent validation in alphabetical order (GetRoundingIncrementOption reads *"roundingIncrement"* and GetRoundingModeOption reads *"roundingMode"*).
194194
1. Let _roundingIncrement_ be ? GetRoundingIncrementOption(_roundTo_).
195195
1. Let _roundingMode_ be ? GetRoundingModeOption(_roundTo_, ~half-expand~).
196-
1. Let _smallestUnit_ be ? GetTemporalUnitValuedOption(_roundTo_, *"smallestUnit"*, ~time~, ~required~).
196+
1. Let _smallestUnit_ be ? GetTemporalUnitValuedOption(_roundTo_, *"smallestUnit"*, ~required~).
197+
1. Perform ? ValidateTemporalUnitValue(_smallestUnit_, ~time~).
197198
1. If _smallestUnit_ is ~hour~, then
198199
1. Let _maximum_ be HoursPerDay.
199200
1. Else if _smallestUnit_ is ~minute~, then
@@ -235,7 +236,8 @@ <h1>Temporal.Instant.prototype.toString ( [ _options_ ] )</h1>
235236
1. NOTE: The following steps read options and perform independent validation in alphabetical order (GetTemporalFractionalSecondDigitsOption reads *"fractionalSecondDigits"* and GetRoundingModeOption reads *"roundingMode"*).
236237
1. Let _digits_ be ? GetTemporalFractionalSecondDigitsOption(_resolvedOptions_).
237238
1. Let _roundingMode_ be ? GetRoundingModeOption(_resolvedOptions_, ~trunc~).
238-
1. Let _smallestUnit_ be ? GetTemporalUnitValuedOption(_resolvedOptions_, *"smallestUnit"*, ~time~, ~unset~).
239+
1. Let _smallestUnit_ be ? GetTemporalUnitValuedOption(_resolvedOptions_, *"smallestUnit"*, ~unset~).
240+
1. Perform ? ValidateTemporalUnitValue(_smallestUnit_, ~time~).
239241
1. If _smallestUnit_ is ~hour~, throw a *RangeError* exception.
240242
1. Let _timeZone_ be ? Get(_resolvedOptions_, *"timeZone"*).
241243
1. If _timeZone_ is not *undefined*, then

spec/plaindatetime.html

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -502,7 +502,8 @@ <h1>Temporal.PlainDateTime.prototype.round ( _roundTo_ )</h1>
502502
1. NOTE: The following steps read options and perform independent validation in alphabetical order (GetRoundingIncrementOption reads *"roundingIncrement"* and GetRoundingModeOption reads *"roundingMode"*).
503503
1. Let _roundingIncrement_ be ? GetRoundingIncrementOption(_roundTo_).
504504
1. Let _roundingMode_ be ? GetRoundingModeOption(_roundTo_, ~half-expand~).
505-
1. Let _smallestUnit_ be ? GetTemporalUnitValuedOption(_roundTo_, *"smallestUnit"*, ~time~, ~required~, « ~day~ »).
505+
1. Let _smallestUnit_ be ? GetTemporalUnitValuedOption(_roundTo_, *"smallestUnit"*, ~required~).
506+
1. Perform ? ValidateTemporalUnitValue(_smallestUnit_, ~time~, « ~day~ »).
506507
1. If _smallestUnit_ is ~day~, then
507508
1. Let _maximum_ be 1.
508509
1. Let _inclusive_ be *true*.
@@ -541,7 +542,8 @@ <h1>Temporal.PlainDateTime.prototype.toString ( [ _options_ ] )</h1>
541542
1. Let _showCalendar_ be ? GetTemporalShowCalendarNameOption(_resolvedOptions_).
542543
1. Let _digits_ be ? GetTemporalFractionalSecondDigitsOption(_resolvedOptions_).
543544
1. Let _roundingMode_ be ? GetRoundingModeOption(_resolvedOptions_, ~trunc~).
544-
1. Let _smallestUnit_ be ? GetTemporalUnitValuedOption(_resolvedOptions_, *"smallestUnit"*, ~time~, ~unset~).
545+
1. Let _smallestUnit_ be ? GetTemporalUnitValuedOption(_resolvedOptions_, *"smallestUnit"*, ~unset~).
546+
1. Perform ? ValidateTemporalUnitValue(_smallestUnit_, ~time~).
545547
1. If _smallestUnit_ is ~hour~, throw a *RangeError* exception.
546548
1. Let _precision_ be ToSecondsStringPrecisionRecord(_smallestUnit_, _digits_).
547549
1. Let _result_ be RoundISODateTime(_plainDateTime_.[[ISODateTime]], _precision_.[[Increment]], _precision_.[[Unit]], _roundingMode_).

spec/plaintime.html

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,8 @@ <h1>Temporal.PlainTime.prototype.round ( _roundTo_ )</h1>
272272
1. NOTE: The following steps read options and perform independent validation in alphabetical order (GetRoundingIncrementOption reads *"roundingIncrement"* and GetRoundingModeOption reads *"roundingMode"*).
273273
1. Let _roundingIncrement_ be ? GetRoundingIncrementOption(_roundTo_).
274274
1. Let _roundingMode_ be ? GetRoundingModeOption(_roundTo_, ~half-expand~).
275-
1. Let _smallestUnit_ be ? GetTemporalUnitValuedOption(_roundTo_, *"smallestUnit"*, ~time~, ~required~).
275+
1. Let _smallestUnit_ be ? GetTemporalUnitValuedOption(_roundTo_, *"smallestUnit"*, ~required~).
276+
1. Perform ? ValidateTemporalUnitValue(_smallestUnit_, ~time~).
276277
1. Let _maximum_ be MaximumTemporalDurationRoundingIncrement(_smallestUnit_).
277278
1. Assert: _maximum_ is not ~unset~.
278279
1. Perform ? ValidateTemporalRoundingIncrement(_roundingIncrement_, _maximum_, *false*).
@@ -303,7 +304,8 @@ <h1>Temporal.PlainTime.prototype.toString ( [ _options_ ] )</h1>
303304
1. NOTE: The following steps read options and perform independent validation in alphabetical order (GetTemporalFractionalSecondDigitsOption reads *"fractionalSecondDigits"* and GetRoundingModeOption reads *"roundingMode"*).
304305
1. Let _digits_ be ? GetTemporalFractionalSecondDigitsOption(_resolvedOptions_).
305306
1. Let _roundingMode_ be ? GetRoundingModeOption(_resolvedOptions_, ~trunc~).
306-
1. Let _smallestUnit_ be ? GetTemporalUnitValuedOption(_resolvedOptions_, *"smallestUnit"*, ~time~, ~unset~).
307+
1. Let _smallestUnit_ be ? GetTemporalUnitValuedOption(_resolvedOptions_, *"smallestUnit"*, ~unset~).
308+
1. Perform ? ValidateTemporalUnitValue(_smallestUnit_, ~time~).
307309
1. If _smallestUnit_ is ~hour~, throw a *RangeError* exception.
308310
1. Let _precision_ be ToSecondsStringPrecisionRecord(_smallestUnit_, _digits_).
309311
1. Let _roundResult_ be RoundTime(_plainTime_.[[Time]], _precision_.[[Increment]], _precision_.[[Unit]], _roundingMode_).

spec/zoneddatetime.html

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -633,7 +633,8 @@ <h1>Temporal.ZonedDateTime.prototype.round ( _roundTo_ )</h1>
633633
1. NOTE: The following steps read options and perform independent validation in alphabetical order (GetRoundingIncrementOption reads *"roundingIncrement"* and GetRoundingModeOption reads *"roundingMode"*).
634634
1. Let _roundingIncrement_ be ? GetRoundingIncrementOption(_roundTo_).
635635
1. Let _roundingMode_ be ? GetRoundingModeOption(_roundTo_, ~half-expand~).
636-
1. Let _smallestUnit_ be ? GetTemporalUnitValuedOption(_roundTo_, *"smallestUnit"*, ~time~, ~required~, « ~day~ »).
636+
1. Let _smallestUnit_ be ? GetTemporalUnitValuedOption(_roundTo_, *"smallestUnit"*, ~required~).
637+
1. Perform ? ValidateTemporalUnitValue(_smallestUnit_, ~time~, « ~day~ »).
637638
1. If _smallestUnit_ is ~day~, then
638639
1. Let _maximum_ be 1.
639640
1. Let _inclusive_ be *true*.
@@ -692,7 +693,8 @@ <h1>Temporal.ZonedDateTime.prototype.toString ( [ _options_ ] )</h1>
692693
1. Let _digits_ be ? GetTemporalFractionalSecondDigitsOption(_resolvedOptions_).
693694
1. Let _showOffset_ be ? GetTemporalShowOffsetOption(_resolvedOptions_).
694695
1. Let _roundingMode_ be ? GetRoundingModeOption(_resolvedOptions_, ~trunc~).
695-
1. Let _smallestUnit_ be ? GetTemporalUnitValuedOption(_resolvedOptions_, *"smallestUnit"*, ~time~, ~unset~).
696+
1. Let _smallestUnit_ be ? GetTemporalUnitValuedOption(_resolvedOptions_, *"smallestUnit"*, ~unset~).
697+
1. Perform ? ValidateTemporalUnitValue(_smallestUnit_, ~time~).
696698
1. If _smallestUnit_ is ~hour~, throw a *RangeError* exception.
697699
1. Let _showTimeZone_ be ? GetTemporalShowTimeZoneNameOption(_resolvedOptions_).
698700
1. Let _precision_ be ToSecondsStringPrecisionRecord(_smallestUnit_, _digits_).

0 commit comments

Comments
 (0)