Skip to content

Commit 36f1baa

Browse files
committed
Editorial: Merge SubtractTimeDuration into AddTimeDuration
This previously needed to be a separate operation because you can't just negate a record. Now that time durations are a number, you can negate them, so no need for a subtraction operation when we already have an addition operation.
1 parent c5e6599 commit 36f1baa

File tree

2 files changed

+4
-22
lines changed

2 files changed

+4
-22
lines changed

polyfill/lib/ecmascript.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3272,7 +3272,7 @@ function NudgeToDayOrTime(duration, destEpochNs, largestUnit, increment, smalles
32723272
let remainder = roundedNorm;
32733273
if (TemporalUnitCategory(largestUnit) === 'date') {
32743274
days = roundedWholeDays;
3275-
remainder = roundedNorm.subtract(TimeDuration.fromComponents(roundedWholeDays * 24, 0, 0, 0, 0, 0));
3275+
remainder = roundedNorm.add(TimeDuration.fromComponents(-roundedWholeDays * 24, 0, 0, 0, 0, 0));
32763276
}
32773277

32783278
const dateDuration = AdjustDateDurationRecord(duration.date, days);

spec/duration.html

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1475,24 +1475,6 @@ <h1>
14751475
</emu-alg>
14761476
</emu-clause>
14771477

1478-
<emu-clause id="sec-temporal-subtracttimeduration" type="abstract operation">
1479-
<h1>
1480-
SubtractTimeDuration (
1481-
_one_: a time duration,
1482-
_two_: a time duration,
1483-
): either a normal completion containing a time duration or a throw completion
1484-
</h1>
1485-
<dl class="header">
1486-
<dt>description</dt>
1487-
<dd>It returns a time duration that is the difference between _one_ and _two_, throwing an exception if the result is greater than the maximum time duration.</dd>
1488-
</dl>
1489-
<emu-alg>
1490-
1. Let _result_ be _one_ - _two_.
1491-
1. If abs(_result_) > maxTimeDuration, throw a *RangeError* exception.
1492-
1. Return _result_.
1493-
</emu-alg>
1494-
</emu-clause>
1495-
14961478
<emu-clause id="sec-zerotimeduration" type="abstract operation">
14971479
<h1>ZeroTimeDuration ( ): a time duration</h1>
14981480
<dl class="header">
@@ -1729,7 +1711,7 @@ <h1>
17291711
1. Assert: TimeDurationSign(_daySpan_) = _sign_.
17301712
1. Let _unitLength_ be the value in the "Length in Nanoseconds" column of the row of <emu-xref href="#table-temporal-units"></emu-xref> whose "Value" column contains _unit_.
17311713
1. Let _roundedTimeDuration_ be ? RoundTimeDurationToIncrement(_duration_.[[Time]], _increment_ × _unitLength_, _roundingMode_).
1732-
1. Let _beyondDaySpan_ be ? SubtractTimeDuration(_roundedTimeDuration_, _daySpan_).
1714+
1. Let _beyondDaySpan_ be ? AddTimeDuration(_roundedTimeDuration_, -_daySpan_).
17331715
1. If TimeDurationSign(_beyondDaySpan_) ≠ -_sign_, then
17341716
1. Let _didRoundBeyondDay_ be *true*.
17351717
1. Let _dayDelta_ be _sign_.
@@ -1766,7 +1748,7 @@ <h1>
17661748
1. Let _timeDuration_ be ! Add24HourDaysToTimeDuration(_duration_.[[Time]], _duration_.[[Date]].[[Days]]).
17671749
1. Let _unitLength_ be the value in the "Length in Nanoseconds" column of the row of <emu-xref href="#table-temporal-units"></emu-xref> whose "Value" column contains _smallestUnit_.
17681750
1. Let _roundedNorm_ be ? RoundTimeDurationToIncrement(_timeDuration_, _unitLength_ × _increment_, _roundingMode_).
1769-
1. Let _diffNorm_ be ! SubtractTimeDuration(_roundedNorm_, _timeDuration_).
1751+
1. Let _diffNorm_ be ! AddTimeDuration(_roundedNorm_, -_timeDuration_).
17701752
1. Let _wholeDays_ be truncate(DivideTimeDuration(_timeDuration_, nsPerDay)).
17711753
1. Let _roundedWholeDays_ be truncate(DivideTimeDuration(_roundedNorm_, nsPerDay)).
17721754
1. Let _dayDelta_ be _roundedWholeDays_ - _wholeDays_.
@@ -1777,7 +1759,7 @@ <h1>
17771759
1. Let _remainder_ be _roundedNorm_.
17781760
1. If TemporalUnitCategory(_largestUnit_) is ~date~, then
17791761
1. Set _days_ to _roundedWholeDays_.
1780-
1. Set _remainder_ to ! SubtractTimeDuration(_roundedNorm_, TimeDurationFromComponents(_roundedWholeDays_ * HoursPerDay, 0, 0, 0, 0, 0)).
1762+
1. Set _remainder_ to ! AddTimeDuration(_roundedNorm_, TimeDurationFromComponents(-_roundedWholeDays_ * HoursPerDay, 0, 0, 0, 0, 0)).
17811763
1. Let _dateDuration_ be ? AdjustDateDurationRecord(_duration_.[[Date]], _days_).
17821764
1. Let _resultDuration_ be ? CombineDateAndTimeDuration(_dateDuration_, _remainder_).
17831765
1. Return Duration Nudge Result Record { [[Duration]]: _resultDuration_, [[NudgedEpochNs]]: _nudgedEpochNs_, [[DidExpandCalendarUnit]]: _didExpandDays_ }.

0 commit comments

Comments
 (0)