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

Editorial: Refactor add/subtract to common AOs #2166

Merged
merged 10 commits into from
May 5, 2022
30 changes: 20 additions & 10 deletions spec/duration.html
Original file line number Diff line number Diff line change
Expand Up @@ -383,11 +383,7 @@ <h1>Temporal.Duration.prototype.add ( _other_ [ , _options_ ] )</h1>
<emu-alg>
1. Let _duration_ be the *this* value.
1. Perform ? RequireInternalSlot(_duration_, [[InitializedTemporalDuration]]).
1. Set _other_ to ? ToTemporalDurationRecord(_other_).
1. Set _options_ to ? GetOptionsObject(_options_).
1. Let _relativeTo_ be ? ToRelativeTemporalObject(_options_).
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_).
1. Return ! CreateTemporalDuration(_result_.[[Years]], _result_.[[Months]], _result_.[[Weeks]], _result_.[[Days]], _result_.[[Hours]], _result_.[[Minutes]], _result_.[[Seconds]], _result_.[[Milliseconds]], _result_.[[Microseconds]], _result_.[[Nanoseconds]]).
1. Return ? AddTemporalDuration(1, _duration_, _other_, _options_).
</emu-alg>
</emu-clause>

Expand All @@ -400,11 +396,7 @@ <h1>Temporal.Duration.prototype.subtract ( _other_ [ , _options_ ] )</h1>
<emu-alg>
1. Let _duration_ be the *this* value.
1. Perform ? RequireInternalSlot(_duration_, [[InitializedTemporalDuration]]).
1. Set _other_ to ? ToTemporalDurationRecord(_other_).
1. Set _options_ to ? GetOptionsObject(_options_).
1. Let _relativeTo_ be ? ToRelativeTemporalObject(_options_).
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_).
1. Return ! CreateTemporalDuration(_result_.[[Years]], _result_.[[Months]], _result_.[[Weeks]], _result_.[[Days]], _result_.[[Hours]], _result_.[[Minutes]], _result_.[[Seconds]], _result_.[[Milliseconds]], _result_.[[Microseconds]], _result_.[[Nanoseconds]]).
1. Return ? AddTemporalDuration(-1, _duration_, _other_, _options_).
</emu-alg>
</emu-clause>

Expand Down Expand Up @@ -1847,5 +1839,23 @@ <h1>
1. Return _result_.
</emu-alg>
</emu-clause>

<emu-clause id="sec-temporal-addtemporalduration" aoid="AddTemporalDuration">
<h1>
AddTemporalDuration (
_sign_: 1 or -1,
_duration_: a Temporal.Duration,
_other_: an ECMAScript language value,
_options_: an Object or *undefined*,
FrankYFTang marked this conversation as resolved.
Show resolved Hide resolved
): a Temporal.Duration
FrankYFTang marked this conversation as resolved.
Show resolved Hide resolved
</h1>
<emu-alg>
1. Set _other_ to ? ToTemporalDurationRecord(_other_).
1. Set _options_ to ? GetOptionsObject(_options_).
1. Let _relativeTo_ be ? ToRelativeTemporalObject(_options_).
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]], _sign_ &times; _other_.[[Years]], _sign_ &times; _other_.[[Months]], _sign_ &times; _other_.[[Weeks]], _sign_ &times; _other_.[[Days]], _sign_ &times; _other_.[[Hours]], _sign_ &times; _other_.[[Minutes]], _sign_ &times; _other_.[[Seconds]], _sign_ &times; _other_.[[Milliseconds]], _sign_ &times; _other_.[[Microseconds]], _sign_ &times; _other_.[[Nanoseconds]], _relativeTo_).
1. Return ! CreateTemporalDuration(_result_.[[Years]], _result_.[[Months]], _result_.[[Weeks]], _result_.[[Days]], _result_.[[Hours]], _result_.[[Minutes]], _result_.[[Seconds]], _result_.[[Milliseconds]], _result_.[[Microseconds]], _result_.[[Nanoseconds]]).
</emu-alg>
</emu-clause>
</emu-clause>
</emu-clause>
22 changes: 16 additions & 6 deletions spec/instant.html
Original file line number Diff line number Diff line change
Expand Up @@ -226,9 +226,7 @@ <h1>Temporal.Instant.prototype.add ( _temporalDurationLike_ )</h1>
<emu-alg>
1. Let _instant_ be the *this* value.
1. Perform ? RequireInternalSlot(_instant_, [[InitializedTemporalInstant]]).
1. Let _duration_ be ? ToLimitedTemporalDuration(_temporalDurationLike_, « *"years"*, *"months"*, *"weeks"*, *"days"* »).
1. Let _ns_ be ? AddInstant(_instant_.[[Nanoseconds]], _duration_.[[Hours]], _duration_.[[Minutes]], _duration_.[[Seconds]], _duration_.[[Milliseconds]], _duration_.[[Microseconds]], _duration_.[[Nanoseconds]]).
1. Return ! CreateTemporalInstant(_ns_).
1. Return ? AddTemporalInstant(1, _instant_, _temporalDurationLike_).
</emu-alg>
</emu-clause>

Expand All @@ -241,9 +239,7 @@ <h1>Temporal.Instant.prototype.subtract ( _temporalDurationLike_ )</h1>
<emu-alg>
1. Let _instant_ be the *this* value.
1. Perform ? RequireInternalSlot(_instant_, [[InitializedTemporalInstant]]).
1. Let _duration_ be ? ToLimitedTemporalDuration(_temporalDurationLike_, « *"years"*, *"months"*, *"weeks"*, *"days"* »).
1. Let _ns_ be ? AddInstant(_instant_.[[Nanoseconds]], -_duration_.[[Hours]], -_duration_.[[Minutes]], -_duration_.[[Seconds]], -_duration_.[[Milliseconds]], -_duration_.[[Microseconds]], -_duration_.[[Nanoseconds]]).
1. Return ! CreateTemporalInstant(_ns_).
1. Return ? AddTemporalInstant(-1, _instant_, _temporalDurationLike_).
</emu-alg>
</emu-clause>

Expand Down Expand Up @@ -647,5 +643,19 @@ <h1>TemporalInstantToString ( _instant_, _timeZone_, _precision_ )</h1>
1. Return the string-concatenation of _dateTimeString_ and _timeZoneString_.
</emu-alg>
</emu-clause>
<emu-clause id="sec-temporal-addtemporalinstant" aoid="AddTemporalInstant">
<h1>
AddTemporalInstant (
_sign_: 1 or -1,
_instant_: a Temporal.Instant,
_temporalDurationLike_: an ECMAScript language value,
): a Temporal.Instant
FrankYFTang marked this conversation as resolved.
Show resolved Hide resolved
</h1>
<emu-alg>
1. Let _duration_ be ? ToLimitedTemporalDuration(_temporalDurationLike_, « *"years"*, *"months"*, *"weeks"*, *"days"* »).
1. Let _ns_ be ? AddInstant(_instant_.[[Nanoseconds]], _sign_ &times; _duration_.[[Hours]], _sign_ &times; _duration_.[[Minutes]], _sign_ &times; _duration_.[[Seconds]], _sign_ &times; _duration_.[[Milliseconds]], _sign_ &times; _duration_.[[Microseconds]], _sign_ &times; _duration_.[[Nanoseconds]]).
1. Return ! CreateTemporalInstant(_ns_).
</emu-alg>
</emu-clause>
</emu-clause>
</emu-clause>
33 changes: 21 additions & 12 deletions spec/plaindatetime.html
Original file line number Diff line number Diff line change
Expand Up @@ -452,12 +452,7 @@ <h1>Temporal.PlainDateTime.prototype.add ( _temporalDurationLike_ [ , _options_
<emu-alg>
1. Let _dateTime_ be the *this* value.
1. Perform ? RequireInternalSlot(_dateTime_, [[InitializedTemporalDateTime]]).
1. Let _duration_ be ? ToTemporalDurationRecord(_temporalDurationLike_).
1. Set _options_ to ? GetOptionsObject(_options_).
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_).
1. Assert: IsValidISODate(_result_.[[Year]], _result_.[[Month]], _result_.[[Day]]) is *true*.
1. Assert: IsValidTime(_result_.[[Hour]], _result_.[[Minute]], _result_.[[Second]], _result_.[[Millisecond]], _result_.[[Microsecond]], _result_.[[Nanosecond]]) is *true*.
1. Return ? CreateTemporalDateTime(_result_.[[Year]], _result_.[[Month]], _result_.[[Day]], _result_.[[Hour]], _result_.[[Minute]], _result_.[[Second]], _result_.[[Millisecond]], _result_.[[Microsecond]], _result_.[[Nanosecond]], _dateTime_.[[Calendar]]).
1. Return ? AddTemporalPlainDateTime(1, _dateTime_, _temporalDurationLike_, _options_).
</emu-alg>
</emu-clause>

Expand All @@ -470,12 +465,7 @@ <h1>Temporal.PlainDateTime.prototype.subtract ( _temporalDurationLike_ [ , _opti
<emu-alg>
1. Let _dateTime_ be the *this* value.
1. Perform ? RequireInternalSlot(_dateTime_, [[InitializedTemporalDateTime]]).
1. Let _duration_ be ? ToTemporalDurationRecord(_temporalDurationLike_).
1. Set _options_ to ? GetOptionsObject(_options_).
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_).
1. Assert: IsValidISODate(_result_.[[Year]], _result_.[[Month]], _result_.[[Day]]) is *true*.
1. Assert: IsValidTime(_result_.[[Hour]], _result_.[[Minute]], _result_.[[Second]], _result_.[[Millisecond]], _result_.[[Microsecond]], _result_.[[Nanosecond]]) is *true*.
1. Return ? CreateTemporalDateTime(_result_.[[Year]], _result_.[[Month]], _result_.[[Day]], _result_.[[Hour]], _result_.[[Minute]], _result_.[[Second]], _result_.[[Millisecond]], _result_.[[Microsecond]], _result_.[[Nanosecond]], _dateTime_.[[Calendar]]).
1. Return ? AddTemporalPlainDateTime(-1, _dateTime_, _temporalDurationLike_, _options_).
</emu-alg>
</emu-clause>

Expand Down Expand Up @@ -1157,5 +1147,24 @@ <h1>
1. Return ! CreateDurationRecord(_dateDifference_.[[Years]], _dateDifference_.[[Months]], _dateDifference_.[[Weeks]], _balanceResult_.[[Days]], _balanceResult_.[[Hours]], _balanceResult_.[[Minutes]], _balanceResult_.[[Seconds]], _balanceResult_.[[Milliseconds]], _balanceResult_.[[Microseconds]], _balanceResult_.[[Nanoseconds]]).
</emu-alg>
</emu-clause>
<emu-clause id="sec-temporal-addtemporalplaindatetime" aoid="AddTemporalPlainDateTime">
<h1>
AddTemporalPlainDateTime (
_sign_: 1 or -1,
_dateTime_: a Temporal.PlainDateTime,
_temporalDurationLike_: an ECMAScript language value,
_options_: an Object or *undefined*,
FrankYFTang marked this conversation as resolved.
Show resolved Hide resolved
): a Temporal.PlainDateTime
FrankYFTang marked this conversation as resolved.
Show resolved Hide resolved
</h1>
<emu-alg>
1. Let _duration_ be ? ToTemporalDurationRecord(_temporalDurationLike_).
1. Set _options_ to ? GetOptionsObject(_options_).
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]], _sign_ &times; _duration_.[[Years]], _sign_ &times; _duration_.[[Months]], _sign_ &times; _duration_.[[Weeks]], _sign_ &times; _duration_.[[Days]], _sign_ &times; _duration_.[[Hours]], _sign_ &times; _duration_.[[Minutes]], _sign_ &times; _duration_.[[Seconds]], _sign_ &times; _duration_.[[Milliseconds]], _sign_ &times; _duration_.[[Microseconds]], _sign_ &times; _duration_.[[Nanoseconds]], _options_).
1. Assert: IsValidISODate(_result_.[[Year]], _result_.[[Month]], _result_.[[Day]]) is *true*.
1. Assert: IsValidTime(_result_.[[Hour]], _result_.[[Minute]], _result_.[[Second]], _result_.[[Millisecond]], _result_.[[Microsecond]], _result_.[[Nanosecond]]) is *true*.
1. Return ? CreateTemporalDateTime(_result_.[[Year]], _result_.[[Month]], _result_.[[Day]], _result_.[[Hour]], _result_.[[Minute]], _result_.[[Second]], _result_.[[Millisecond]], _result_.[[Microsecond]], _result_.[[Nanosecond]], _dateTime_.[[Calendar]]).
</emu-alg>
</emu-alg>
ptomato marked this conversation as resolved.
Show resolved Hide resolved
</emu-clause>
</emu-clause>
</emu-clause>
25 changes: 17 additions & 8 deletions spec/plaintime.html
Original file line number Diff line number Diff line change
Expand Up @@ -210,10 +210,7 @@ <h1>Temporal.PlainTime.prototype.add ( _temporalDurationLike_ )</h1>
<emu-alg>
1. Let _temporalTime_ be the *this* value.
1. Perform ? RequireInternalSlot(_temporalTime_, [[InitializedTemporalTime]]).
1. Let _duration_ be ? ToTemporalDurationRecord(_temporalDurationLike_).
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]]).
1. Assert: IsValidTime(_result_.[[Hour]], _result_.[[Minute]], _result_.[[Second]], _result_.[[Millisecond]], _result_.[[Microsecond]], _result_.[[Nanosecond]]) is *true*.
1. Return ? CreateTemporalTime(_result_.[[Hour]], _result_.[[Minute]], _result_.[[Second]], _result_.[[Millisecond]], _result_.[[Microsecond]], _result_.[[Nanosecond]]).
1. Return ? AddTemporalPlainTime(1, _temporalTime_, _temporalTime_).
</emu-alg>
</emu-clause>

Expand All @@ -226,10 +223,7 @@ <h1>Temporal.PlainTime.prototype.subtract ( _temporalDurationLike_ )</h1>
<emu-alg>
1. Let _temporalTime_ be the *this* value.
1. Perform ? RequireInternalSlot(_temporalTime_, [[InitializedTemporalTime]]).
1. Let _duration_ be ? ToTemporalDurationRecord(_temporalDurationLike_).
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]]).
1. Assert: IsValidTime(_result_.[[Hour]], _result_.[[Minute]], _result_.[[Second]], _result_.[[Millisecond]], _result_.[[Microsecond]], _result_.[[Nanosecond]]) is *true*.
1. Return ? CreateTemporalTime(_result_.[[Hour]], _result_.[[Minute]], _result_.[[Second]], _result_.[[Millisecond]], _result_.[[Microsecond]], _result_.[[Nanosecond]]).
1. Return ? AddTemporalPlainTime(-1, _temporalTime_, _temporalTime_).
</emu-alg>
</emu-clause>

Expand Down Expand Up @@ -963,5 +957,20 @@ <h1>RoundTime ( _hour_, _minute_, _second_, _millisecond_, _microsecond_, _nanos
1. Return ! BalanceTime(_hour_, _minute_, _second_, _millisecond_, _microsecond_, _result_).
</emu-alg>
</emu-clause>
<emu-clause id="sec-temporal-addtemporalplaintime" aoid="AddTemporalPlainTime">
<h1>
AddTemporalPlainTime (
_sign_: 1 or -1,
_temporalTime_: a Temporal.PlainTime,
_temporalDurationLike_: an ECMAScript language value,
): a Temporal.PlainTime
FrankYFTang marked this conversation as resolved.
Show resolved Hide resolved
</h1>
<emu-alg>
1. Let _duration_ be ? ToTemporalDurationRecord(_temporalDurationLike_).
1. Let _result_ be ! AddTime(_temporalTime_.[[ISOHour]], _temporalTime_.[[ISOMinute]], _temporalTime_.[[ISOSecond]], _temporalTime_.[[ISOMillisecond]], _temporalTime_.[[ISOMicrosecond]], _temporalTime_.[[ISONanosecond]], _sign_ &times; _duration_.[[Hours]], _sign_ &times; _duration_.[[Minutes]], _sign_ &times; _duration_.[[Seconds]], _sign_ &times; _duration_.[[Milliseconds]], _sign_ &times; _duration_.[[Microseconds]], _sign_ &times; _duration_.[[Nanoseconds]]).
1. Assert: IsValidTime(_result_.[[Hour]], _result_.[[Minute]], _result_.[[Second]], _result_.[[Millisecond]], _result_.[[Microsecond]], _result_.[[Nanosecond]]) is *true*.
1. Return ? CreateTemporalTime(_result_.[[Hour]], _result_.[[Minute]], _result_.[[Second]], _result_.[[Millisecond]], _result_.[[Microsecond]], _result_.[[Nanosecond]]).
</emu-alg>
</emu-clause>
</emu-clause>
</emu-clause>
Loading