Skip to content

Commit a68b97b

Browse files
ptomatoMs2ger
authored andcommitted
Editorial: Move string-parsing code into ToTemporalDurationRecord
This code is repeated at both of the pre-existing call sites of ToTemporalDurationRecord, so it makes sense to move it into ToTemporalDurationRecord. With that, ToLimitedTemporalDuration with an empty List of disallowed fields becomes equivalent to ToTemporalDurationRecord, so make that change as well. Now, ToLimitedTemporalDuration is only used where the allowed fields are actually limited: in Instant.prototype.add and subtract.
1 parent 00958d0 commit a68b97b

File tree

5 files changed

+18
-23
lines changed

5 files changed

+18
-23
lines changed

spec/duration.html

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ <h1>Temporal.Duration.prototype.add ( _other_ [ , _options_ ] )</h1>
383383
<emu-alg>
384384
1. Let _duration_ be the *this* value.
385385
1. Perform ? RequireInternalSlot(_duration_, [[InitializedTemporalDuration]]).
386-
1. Set _other_ to ? ToLimitedTemporalDuration(_other_, « »).
386+
1. Set _other_ to ? ToTemporalDurationRecord(_other_).
387387
1. Set _options_ to ? GetOptionsObject(_options_).
388388
1. Let _relativeTo_ be ? ToRelativeTemporalObject(_options_).
389389
1. Let _result_ be ? AddDuration(_duration_.[[Years]], _duration_.[[Months]], _duration_.[[Weeks]], _duration_.[[Days]], _duration_.[[Hours]], _duration_.[[Minutes]], _duration_.[[Seconds]], _duration_.[[Milliseconds]], _duration_.[[Microseconds]], _duration_.[[Nanoseconds]], _other_.[[Years]], _other_.[[Months]], _other_.[[Weeks]], _other_.[[Days]], _other_.[[Hours]], _other_.[[Minutes]], _other_.[[Seconds]], _other_.[[Milliseconds]], _other_.[[Microseconds]], _other_.[[Nanoseconds]], _relativeTo_).
@@ -400,7 +400,7 @@ <h1>Temporal.Duration.prototype.subtract ( _other_ [ , _options_ ] )</h1>
400400
<emu-alg>
401401
1. Let _duration_ be the *this* value.
402402
1. Perform ? RequireInternalSlot(_duration_, [[InitializedTemporalDuration]]).
403-
1. Set _other_ to ? ToLimitedTemporalDuration(_other_, « »).
403+
1. Set _other_ to ? ToTemporalDurationRecord(_other_).
404404
1. Set _options_ to ? GetOptionsObject(_options_).
405405
1. Let _relativeTo_ be ? ToRelativeTemporalObject(_options_).
406406
1. Let _result_ be ? AddDuration(_duration_.[[Years]], _duration_.[[Months]], _duration_.[[Weeks]], _duration_.[[Days]], _duration_.[[Hours]], _duration_.[[Minutes]], _duration_.[[Seconds]], _duration_.[[Milliseconds]], _duration_.[[Microseconds]], _duration_.[[Nanoseconds]], −_other_.[[Years]], −_other_.[[Months]], −_other_.[[Weeks]], −_other_.[[Days]], −_other_.[[Hours]], −_other_.[[Minutes]], −_other_.[[Seconds]], −_other_.[[Milliseconds]], −_other_.[[Microseconds]], −_other_.[[Nanoseconds]], _relativeTo_).
@@ -913,28 +913,27 @@ <h1>
913913
<dd>It returns its argument _item_ if it is already a Temporal.Duration instance, converts _item_ to a new Temporal.Duration instance if possible and returns that, and throws otherwise.</dd>
914914
</dl>
915915
<emu-alg>
916-
1. If Type(_item_) is Object, then
917-
1. If _item_ has an [[InitializedTemporalDuration]] internal slot, then
918-
1. Return _item_.
919-
1. Let _result_ be ? ToTemporalDurationRecord(_item_).
920-
1. Else,
921-
1. Let _string_ be ? ToString(_item_).
922-
1. Let _result_ be ? ParseTemporalDurationString(_string_).
916+
1. If Type(_item_) is Object and _item_ has an [[InitializedTemporalDuration]] internal slot, then
917+
1. Return _item_.
918+
1. Let _result_ be ? ToTemporalDurationRecord(_item_).
923919
1. Return ! CreateTemporalDuration(_result_.[[Years]], _result_.[[Months]], _result_.[[Weeks]], _result_.[[Days]], _result_.[[Hours]], _result_.[[Minutes]], _result_.[[Seconds]], _result_.[[Milliseconds]], _result_.[[Microseconds]], _result_.[[Nanoseconds]]).
924920
</emu-alg>
925921
</emu-clause>
926922

927923
<emu-clause id="sec-temporal-totemporaldurationrecord" type="abstract operation">
928924
<h1>
929925
ToTemporalDurationRecord (
930-
_temporalDurationLike_: an Object,
926+
_temporalDurationLike_: an ECMAScript language value,
931927
)
932928
</h1>
933929
<dl class="header">
934930
<dt>description</dt>
935931
<dd>It converts _temporalDurationLike_ to a Duration Record and returns it.</dd>
936932
</dl>
937933
<emu-alg>
934+
1. If Type(_temporalDurationLike_) is not Object, then
935+
1. Let _string_ be ? ToString(_temporalDurationLike_).
936+
1. Return ? ParseTemporalDurationString(_string_).
938937
1. If _temporalDurationLike_ has an [[InitializedTemporalDuration]] internal slot, then
939938
1. Return ! CreateDurationRecord(_temporalDurationLike_.[[Years]], _temporalDurationLike_.[[Months]], _temporalDurationLike_.[[Weeks]], _temporalDurationLike_.[[Days]], _temporalDurationLike_.[[Hours]], _temporalDurationLike_.[[Minutes]], _temporalDurationLike_.[[Seconds]], _temporalDurationLike_.[[Milliseconds]], _temporalDurationLike_.[[Microseconds]], _temporalDurationLike_.[[Nanoseconds]]).
940939
1. Let _result_ be a new Duration Record.
@@ -1784,11 +1783,7 @@ <h1>
17841783
<dd>It converts _temporalDurationLike_ to a Duration Record, and returns it, ensuring that all of the fields listed in _disallowedFields_ are zero.</dd>
17851784
</dl>
17861785
<emu-alg>
1787-
1. If Type(_temporalDurationLike_) is not Object, then
1788-
1. Let _str_ be ? ToString(_temporalDurationLike_).
1789-
1. Let _duration_ be ? ParseTemporalDurationString(_str_).
1790-
1. Else,
1791-
1. Let _duration_ be ? ToTemporalDurationRecord(_temporalDurationLike_).
1786+
1. Let _duration_ be ? ToTemporalDurationRecord(_temporalDurationLike_).
17921787
1. For each row of <emu-xref href="#table-temporal-duration-record-fields"></emu-xref>, except the header row, in table order, do
17931788
1. Let _prop_ be the Property Name value of the current row.
17941789
1. Let _value_ be _duration_'s field whose name is the Field Name value of the current row.

spec/plaindatetime.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,7 @@ <h1>Temporal.PlainDateTime.prototype.add ( _temporalDurationLike_ [ , _options_
452452
<emu-alg>
453453
1. Let _dateTime_ be the *this* value.
454454
1. Perform ? RequireInternalSlot(_dateTime_, [[InitializedTemporalDateTime]]).
455-
1. Let _duration_ be ? ToLimitedTemporalDuration(_temporalDurationLike_, « »).
455+
1. Let _duration_ be ? ToTemporalDurationRecord(_temporalDurationLike_).
456456
1. Set _options_ to ? GetOptionsObject(_options_).
457457
1. Let _result_ be ? AddDateTime(_dateTime_.[[ISOYear]], _dateTime_.[[ISOMonth]], _dateTime_.[[ISODay]], _dateTime_.[[ISOHour]], _dateTime_.[[ISOMinute]], _dateTime_.[[ISOSecond]], _dateTime_.[[ISOMillisecond]], _dateTime_.[[ISOMicrosecond]], _dateTime_.[[ISONanosecond]], _dateTime_.[[Calendar]], _duration_.[[Years]], _duration_.[[Months]], _duration_.[[Weeks]], _duration_.[[Days]], _duration_.[[Hours]], _duration_.[[Minutes]], _duration_.[[Seconds]], _duration_.[[Milliseconds]], _duration_.[[Microseconds]], _duration_.[[Nanoseconds]], _options_).
458458
1. Assert: ! IsValidISODate(_result_.[[Year]], _result_.[[Month]], _result_.[[Day]]) is *true*.
@@ -470,7 +470,7 @@ <h1>Temporal.PlainDateTime.prototype.subtract ( _temporalDurationLike_ [ , _opti
470470
<emu-alg>
471471
1. Let _dateTime_ be the *this* value.
472472
1. Perform ? RequireInternalSlot(_dateTime_, [[InitializedTemporalDateTime]]).
473-
1. Let _duration_ be ? ToLimitedTemporalDuration(_temporalDurationLike_, « »).
473+
1. Let _duration_ be ? ToTemporalDurationRecord(_temporalDurationLike_).
474474
1. Set _options_ to ? GetOptionsObject(_options_).
475475
1. Let _result_ be ? AddDateTime(_dateTime_.[[ISOYear]], _dateTime_.[[ISOMonth]], _dateTime_.[[ISODay]], _dateTime_.[[ISOHour]], _dateTime_.[[ISOMinute]], _dateTime_.[[ISOSecond]], _dateTime_.[[ISOMillisecond]], _dateTime_.[[ISOMicrosecond]], _dateTime_.[[ISONanosecond]], _dateTime_.[[Calendar]], −_duration_.[[Years]], −_duration_.[[Months]], −_duration_.[[Weeks]], −_duration_.[[Days]], −_duration_.[[Hours]], −_duration_.[[Minutes]], −_duration_.[[Seconds]], −_duration_.[[Milliseconds]], −_duration_.[[Microseconds]], −_duration_.[[Nanoseconds]], _options_).
476476
1. Assert: ! IsValidISODate(_result_.[[Year]], _result_.[[Month]], _result_.[[Day]]) is *true*.

spec/plaintime.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ <h1>Temporal.PlainTime.prototype.add ( _temporalDurationLike_ )</h1>
210210
<emu-alg>
211211
1. Let _temporalTime_ be the *this* value.
212212
1. Perform ? RequireInternalSlot(_temporalTime_, [[InitializedTemporalTime]]).
213-
1. Let _duration_ be ? ToLimitedTemporalDuration(_temporalDurationLike_, « »).
213+
1. Let _duration_ be ? ToTemporalDurationRecord(_temporalDurationLike_).
214214
1. Let _result_ be ! AddTime(_temporalTime_.[[ISOHour]], _temporalTime_.[[ISOMinute]], _temporalTime_.[[ISOSecond]], _temporalTime_.[[ISOMillisecond]], _temporalTime_.[[ISOMicrosecond]], _temporalTime_.[[ISONanosecond]], _duration_.[[Hours]], _duration_.[[Minutes]], _duration_.[[Seconds]], _duration_.[[Milliseconds]], _duration_.[[Microseconds]], _duration_.[[Nanoseconds]]).
215215
1. Assert: ! IsValidTime(_result_.[[Hour]], _result_.[[Minute]], _result_.[[Second]], _result_.[[Millisecond]], _result_.[[Microsecond]], _result_.[[Nanosecond]]) is *true*.
216216
1. Return ? CreateTemporalTime(_result_.[[Hour]], _result_.[[Minute]], _result_.[[Second]], _result_.[[Millisecond]], _result_.[[Microsecond]], _result_.[[Nanosecond]]).
@@ -226,7 +226,7 @@ <h1>Temporal.PlainTime.prototype.subtract ( _temporalDurationLike_ )</h1>
226226
<emu-alg>
227227
1. Let _temporalTime_ be the *this* value.
228228
1. Perform ? RequireInternalSlot(_temporalTime_, [[InitializedTemporalTime]]).
229-
1. Let _duration_ be ? ToLimitedTemporalDuration(_temporalDurationLike_, « »).
229+
1. Let _duration_ be ? ToTemporalDurationRecord(_temporalDurationLike_).
230230
1. Let _result_ be ! AddTime(_temporalTime_.[[ISOHour]], _temporalTime_.[[ISOMinute]], _temporalTime_.[[ISOSecond]], _temporalTime_.[[ISOMillisecond]], _temporalTime_.[[ISOMicrosecond]], _temporalTime_.[[ISONanosecond]], −_duration_.[[Hours]], −_duration_.[[Minutes]], −_duration_.[[Seconds]], −_duration_.[[Milliseconds]], −_duration_.[[Microseconds]], −_duration_.[[Nanoseconds]]).
231231
1. Assert: ! IsValidTime(_result_.[[Hour]], _result_.[[Minute]], _result_.[[Second]], _result_.[[Millisecond]], _result_.[[Microsecond]], _result_.[[Nanosecond]]) is *true*.
232232
1. Return ? CreateTemporalTime(_result_.[[Hour]], _result_.[[Minute]], _result_.[[Second]], _result_.[[Millisecond]], _result_.[[Microsecond]], _result_.[[Nanosecond]]).

spec/plainyearmonth.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ <h1>Temporal.PlainYearMonth.prototype.add ( _temporalDurationLike_ [ , _options_
251251
<emu-alg>
252252
1. Let _yearMonth_ be the *this* value.
253253
1. Perform ? RequireInternalSlot(_yearMonth_, [[InitializedTemporalYearMonth]]).
254-
1. Let _duration_ be ? ToLimitedTemporalDuration(_temporalDurationLike_, « »).
254+
1. Let _duration_ be ? ToTemporalDurationRecord(_temporalDurationLike_).
255255
1. Let _balanceResult_ be ? BalanceDuration(_duration_.[[Days]], _duration_.[[Hours]], _duration_.[[Minutes]], _duration_.[[Seconds]], _duration_.[[Milliseconds]], _duration_.[[Microseconds]], _duration_.[[Nanoseconds]], *"day"*).
256256
1. Set _options_ to ? GetOptionsObject(_options_).
257257
1. Let _calendar_ be _yearMonth_.[[Calendar]].
@@ -283,7 +283,7 @@ <h1>Temporal.PlainYearMonth.prototype.subtract ( _temporalDurationLike_ [ , _opt
283283
<emu-alg>
284284
1. Let _yearMonth_ be the *this* value.
285285
1. Perform ? RequireInternalSlot(_yearMonth_, [[InitializedTemporalYearMonth]]).
286-
1. Let _duration_ be ? ToLimitedTemporalDuration(_temporalDurationLike_, « »).
286+
1. Let _duration_ be ? ToTemporalDurationRecord(_temporalDurationLike_).
287287
1. Let _balanceResult_ be ? BalanceDuration(_duration_.[[Days]], _duration_.[[Hours]], _duration_.[[Minutes]], _duration_.[[Seconds]], _duration_.[[Milliseconds]], _duration_.[[Microseconds]], _duration_.[[Nanoseconds]], *"day"*).
288288
1. Set _options_ to ? GetOptionsObject(_options_).
289289
1. Let _calendar_ be _yearMonth_.[[Calendar]].

spec/zoneddatetime.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -667,7 +667,7 @@ <h1>Temporal.ZonedDateTime.prototype.add ( _temporalDurationLike_ [ , _options_
667667
<emu-alg>
668668
1. Let _zonedDateTime_ be the *this* value.
669669
1. Perform ? RequireInternalSlot(_zonedDateTime_, [[InitializedTemporalZonedDateTime]]).
670-
1. Let _duration_ be ? ToLimitedTemporalDuration(_temporalDurationLike_, « »).
670+
1. Let _duration_ be ? ToTemporalDurationRecord(_temporalDurationLike_).
671671
1. Set _options_ to ? GetOptionsObject(_options_).
672672
1. Let _timeZone_ be _zonedDateTime_.[[TimeZone]].
673673
1. Let _calendar_ be _zonedDateTime_.[[Calendar]].
@@ -685,7 +685,7 @@ <h1>Temporal.ZonedDateTime.prototype.subtract ( _temporalDurationLike_ [ , _opti
685685
<emu-alg>
686686
1. Let _zonedDateTime_ be the *this* value.
687687
1. Perform ? RequireInternalSlot(_zonedDateTime_, [[InitializedTemporalZonedDateTime]]).
688-
1. Let _duration_ be ? ToLimitedTemporalDuration(_temporalDurationLike_, « »).
688+
1. Let _duration_ be ? ToTemporalDurationRecord(_temporalDurationLike_).
689689
1. Set _options_ to ? GetOptionsObject(_options_).
690690
1. Let _timeZone_ be _zonedDateTime_.[[TimeZone]].
691691
1. Let _calendar_ be _zonedDateTime_.[[Calendar]].

0 commit comments

Comments
 (0)