Skip to content

Commit cf9118b

Browse files
authored
Editorial: Align DifferenceTemporalInstant with similar AOs (#2241)
This commit editorially refactors DifferenceTemporalInstant to use a similar algorithm to what's used in other Difference* AOs like DifferenceTemporalPlainTime and DifferenceTemporalPlainDateTime.
1 parent 7fe29eb commit cf9118b

File tree

1 file changed

+5
-8
lines changed

1 file changed

+5
-8
lines changed

spec/instant.html

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -652,25 +652,22 @@ <h1>
652652
<dd>It computes the difference between the two times represented by _instant_ and _other_, optionally rounds it, and returns it as a Temporal.Duration object.</dd>
653653
</dl>
654654
<emu-alg>
655+
1. If _operation_ is ~since~, let _sign_ be -1. Otherwise, let _sign_ be 1.
655656
1. Set _other_ to ? ToTemporalInstant(_other_).
656-
1. If _operation_ is ~until~, then
657-
1. Let _first_ be _instant_.
658-
1. Let _second_ be _other_.
659-
1. Else,
660-
1. Let _first_ be _other_.
661-
1. Let _second_ be _instant_.
662657
1. Set _options_ to ? GetOptionsObject(_options_).
663658
1. Let _smallestUnit_ be ? ToSmallestTemporalUnit(_options_, « *"year"*, *"month"*, *"week"*, *"day"* », *"nanosecond"*).
664659
1. Let _defaultLargestUnit_ be ! LargerOfTwoTemporalUnits(*"second"*, _smallestUnit_).
665660
1. Let _largestUnit_ be ? ToLargestTemporalUnit(_options_, « *"year"*, *"month"*, *"week"*, *"day"* », *"auto"*, _defaultLargestUnit_).
666661
1. Perform ? ValidateTemporalUnitRange(_largestUnit_, _smallestUnit_).
667662
1. Let _roundingMode_ be ? ToTemporalRoundingMode(_options_, *"trunc"*).
663+
1. If _operation_ is ~since~, then
664+
1. Set _roundingMode_ to ! NegateTemporalRoundingMode(_roundingMode_).
668665
1. Let _maximum_ be ! MaximumTemporalDurationRoundingIncrement(_smallestUnit_).
669666
1. Let _roundingIncrement_ be ? ToTemporalRoundingIncrement(_options_, _maximum_, *false*).
670-
1. Let _roundedNs_ be ! DifferenceInstant(_first_.[[Nanoseconds]], _second_.[[Nanoseconds]], _roundingIncrement_, _smallestUnit_, _roundingMode_).
667+
1. Let _roundedNs_ be ! DifferenceInstant(_instant_.[[Nanoseconds]], _other_.[[Nanoseconds]], _roundingIncrement_, _smallestUnit_, _roundingMode_).
671668
1. Assert: The following steps cannot fail due to overflow in the Number domain because abs(_roundedNs_) &le; 2 &times; nsMaxInstant.
672669
1. Let _result_ be ! BalanceDuration(0, 0, 0, 0, 0, 0, _roundedNs_, _largestUnit_).
673-
1. Return ! CreateTemporalDuration(0, 0, 0, 0, _result_.[[Hours]], _result_.[[Minutes]], _result_.[[Seconds]], _result_.[[Milliseconds]], _result_.[[Microseconds]], _result_.[[Nanoseconds]]).
670+
1. Return ! CreateTemporalDuration(0, 0, 0, 0, _sign_ &times; _result_.[[Hours]], _sign_ &times; _result_.[[Minutes]], _sign_ &times; _result_.[[Seconds]], _sign_ &times; _result_.[[Milliseconds]], _sign_ &times; _result_.[[Microseconds]], _sign_ &times; _result_.[[Nanoseconds]]).
674671
</emu-alg>
675672
</emu-clause>
676673
<emu-clause id="sec-temporal-adddurationtoorsubtractdurationfrominstant" type="abstract operation">

0 commit comments

Comments
 (0)