Skip to content

Commit

Permalink
Split out SubtractTime as an abstract operation
Browse files Browse the repository at this point in the history
It's odd that we have AddTime but not SubtractTime. Regardless, we'll
need to have it as a separate operation since it will be used from two
places for negative duration support.
  • Loading branch information
ptomato committed Aug 25, 2020
1 parent d8fa7b1 commit 8cb2490
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions spec/time.html
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,6 @@ <h1>Temporal.Time.prototype.plus ( _temporalDurationLike_ [ , _options_ ] )</h1>
1. Let _duration_ be ? ToLimitedTemporalDuration(_temporalDurationLike_, « »).
1. Perform ? ToTemporalDisambiguation(_options_).
1. Let _result_ be ? AddTime(_temporalTime_.[[Hour]], _temporalTime_.[[Minute]], _temporalTime_.[[Second]], _temporalTime_.[[Millisecond]], _temporalTime_.[[Microsecond]], _temporalTime_.[[Nanosecond]], _duration_.[[Hours]], _duration_.[[Minutes]], _duration_.[[Seconds]], _duration_.[[Milliseconds]], _duration_.[[Microseconds]], _duration_.[[Nanoseconds]]).
1. Let _result_ be ? BalanceTime(_hour_, _minute_, _second_, _millisecond_, _microsecond_, _nanosecond_).
1. Return ? CreateTemporalTimeFromInstance(_temporalTime_, _result_.[[Hour]], _result_.[[Minute]], _result_.[[Second]], _result_.[[Millisecond]], _result_.[[Microsecond]], _result_.[[Nanosecond]]).
</emu-alg>
</emu-clause>
Expand All @@ -228,13 +227,7 @@ <h1>Temporal.Time.prototype.minus ( _temporalDurationLike_ [ , _options_ ] )</h1
1. Perform ? RequireInternalSlot(_temporalTime_, [[InitializedTemporalTime]]).
1. Let _duration_ be ? ToLimitedTemporalDuration(_temporalDurationLike_, « »).
1. Perform ? ToTemporalDisambiguation(_options_).
1. Let _hour_ be _temporalTime_.[[Hour]] - _duration_.[[Hour]].
1. Let _minute_ be _temporalTime_.[[Minute]] - _duration_.[[Minute]].
1. Let _second_ be _temporalTime_.[[Second]] - _duration_.[[Second]].
1. Let _millisecond_ be _temporalTime_.[[Millisecond]] - _duration_.[[Millisecond]].
1. Let _microsecond_ be _temporalTime_.[[Microsecond]] - _duration_.[[Microsecond]].
1. Let _nanosecond_ be _temporalTime_.[[Nanosecond]] - _duration_.[[Nanosecond]].
1. Let _result_ be ? BalanceTime(_hour_, _minute_, _second_, _millisecond_, _microsecond_, _nanosecond_).
1. Let _result_ be ? SubtractTime(_temporalTime_.[[Hour]], _temporalTime_.[[Minute]], _temporalTime_.[[Second]], _temporalTime_.[[Millisecond]], _temporalTime_.[[Microsecond]], _temporalTime_.[[Nanosecond]], _duration_.[[Hours]], _duration_.[[Minutes]], _duration_.[[Seconds]], _duration_.[[Milliseconds]], _duration_.[[Microseconds]], _duration_.[[Nanoseconds]]).
1. Return ? CreateTemporalTimeFromInstance(_temporalTime_, _result_.[[Hour]], _result_.[[Minute]], _result_.[[Second]], _result_.[[Millisecond]], _result_.[[Microsecond]], _result_.[[Nanosecond]]).
</emu-alg>
</emu-clause>
Expand Down Expand Up @@ -717,5 +710,19 @@ <h1>AddTime ( _hour_, _minute_, _second_, _millisecond_, _microsecond_, _nanosec
1. Return ? BalanceTime(_hour_, _minute_, _second_, _millisecond_, _microsecond_, _nanosecond_).
</emu-alg>
</emu-clause>

<emu-clause id="sec-temporal-subtracttime" aoid="SubtractTime">
<h1>SubtractTime ( _hour_, _minute_, _second_, _millisecond_, _microsecond_, _nanosecond_, _hours_, _minutes_, _seconds_, _milliseconds_, _microseconds_, _nanoseconds_ )</h1>
<emu-alg>
1. Assert: _hour_, _minute_, _second_, _millisecond_, _microsecond_, _nanosecond_, _hours_, _minutes_, _seconds_, _milliseconds_, _microseconds_, and _nanoseconds_ are integer Number values.
1. Let _hour_ be _temporalTime_.[[Hour]] - _duration_.[[Hour]].
1. Let _minute_ be _temporalTime_.[[Minute]] - _duration_.[[Minute]].
1. Let _second_ be _temporalTime_.[[Second]] - _duration_.[[Second]].
1. Let _millisecond_ be _temporalTime_.[[Millisecond]] - _duration_.[[Millisecond]].
1. Let _microsecond_ be _temporalTime_.[[Microsecond]] - _duration_.[[Microsecond]].
1. Let _nanosecond_ be _temporalTime_.[[Nanosecond]] - _duration_.[[Nanosecond]].
1. Return ? BalanceTime(_hour_, _minute_, _second_, _millisecond_, _microsecond_, _nanosecond_).
</emu-alg>
</emu-clause>
</emu-clause>
</emu-clause>

0 comments on commit 8cb2490

Please sign in to comment.