Skip to content

Commit

Permalink
Editorial: Inline TimeDurationSeconds and TimeDurationSubseconds
Browse files Browse the repository at this point in the history
We originally planned to convert time durations to a record with a seconds
and subseconds field, but that was never necessary. Now that they are just
a mathematical value, we don't need to access them through these seconds
and subseconds operations.

See: #2953
  • Loading branch information
ptomato committed Oct 9, 2024
1 parent 4405f30 commit c5e6599
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 36 deletions.
36 changes: 3 additions & 33 deletions spec/duration.html
Original file line number Diff line number Diff line change
Expand Up @@ -909,7 +909,7 @@ <h1>
</dl>
<emu-alg>
1. Let _internalDuration_ be ToInternalDurationRecordWith24HourDays(_duration_).
1. Let _days_ be truncate(TimeDurationSeconds(_internalDuration_.[[Time]]) / 86400).
1. Let _days_ be truncate(_internalDuration_.[[Time]] / nsPerDay).
1. Return ? CreateDateDurationRecord(_internalDuration_.[[Date]].[[Years]], _internalDuration_.[[Date]].[[Months]], _internalDuration_.[[Date]].[[Weeks]], _days_).
</emu-alg>
</emu-clause>
Expand Down Expand Up @@ -1458,21 +1458,6 @@ <h1>
</emu-alg>
</emu-clause>

<emu-clause id="sec-temporal-timedurationseconds" type="abstract operation">
<h1>
TimeDurationSeconds (
_d_: a time duration,
): an integer in the interval from -2<sup>53</sup> (exclusive) to 2<sup>53</sup> (exclusive)
</h1>
<dl class="header">
<dt>description</dt>
<dd>It returns the integer number of seconds in _d_.</dd>
</dl>
<emu-alg>
1. Return truncate(_d_ / 10<sup>9</sup>).
</emu-alg>
</emu-clause>

<emu-clause id="sec-temporal-timedurationsign" type="abstract operation">
<h1>
TimeDurationSign (
Expand All @@ -1490,21 +1475,6 @@ <h1>
</emu-alg>
</emu-clause>

<emu-clause id="sec-temporal-timedurationsubseconds" type="abstract operation">
<h1>
TimeDurationSubseconds (
_d_: a time duration,
): an integer in the interval from -10<sup>9</sup> (exclusive) to 10<sup>9</sup> (exclusive)
</h1>
<dl class="header">
<dt>description</dt>
<dd>It returns the integer number of nanoseconds in the subsecond part of _d_.</dd>
</dl>
<emu-alg>
1. Return remainder(_d_, 10<sup>9</sup>).
</emu-alg>
</emu-clause>

<emu-clause id="sec-temporal-subtracttimeduration" type="abstract operation">
<h1>
SubtractTimeDuration (
Expand Down Expand Up @@ -1965,8 +1935,8 @@ <h1>
1. If DefaultTemporalLargestUnit(_duration_) is ~second~, ~millisecond~, ~microsecond~, or ~nanosecond~, set _zeroMinutesAndHigher_ to *true*.
1. Let _secondsDuration_ be TimeDurationFromComponents(0, 0, _duration_.[[Seconds]], _duration_.[[Milliseconds]], _duration_.[[Microseconds]], _duration_.[[Nanoseconds]]).
1. If _secondsDuration_ ≠ 0, or _zeroMinutesAndHigher_ is *true*, or _precision_ is not ~auto~, then
1. Let _secondsPart_ be abs(TimeDurationSeconds(_secondsDuration_)) formatted as a decimal number.
1. Let _subSecondsPart_ be FormatFractionalSeconds(abs(TimeDurationSubseconds(_secondsDuration_)), _precision_).
1. Let _secondsPart_ be abs(truncate(_secondsDuration_ / 10<sup>9</sup>)) formatted as a decimal number.
1. Let _subSecondsPart_ be FormatFractionalSeconds(abs(remainder(_secondsDuration_, 10<sup>9</sup>)), _precision_).
1. Set _timePart_ to the string concatenation of _timePart_, _secondsPart_, _subSecondsPart_, and the code unit 0x0053 (LATIN CAPITAL LETTER S).
1. Let _signPart_ be the code unit 0x002D (HYPHEN-MINUS) if _sign_ &lt; 0, and otherwise the empty String.
1. Let _result_ be the string concatenation of _signPart_, the code unit 0x0050 (LATIN CAPITAL LETTER P) and _datePart_.
Expand Down
5 changes: 2 additions & 3 deletions spec/plaintime.html
Original file line number Diff line number Diff line change
Expand Up @@ -862,9 +862,8 @@ <h1>
<dd></dd>
</dl>
<emu-alg>
1. Let _second_ be _time_.[[Second]] + TimeDurationSeconds(_timeDuration_).
1. Let _nanosecond_ be _time_.[[Nanosecond]] + TimeDurationSubseconds(_timeDuration_).
1. Return BalanceTime(_time_.[[Hour]], _time_.[[Minute]], _second_, _time_.[[Millisecond]], _time_.[[Microsecond]], _nanosecond_).
1. Return BalanceTime(_time_.[[Hour]], _time_.[[Minute]], _time_.[[Second]], _time_.[[Millisecond]], _time_.[[Microsecond]], _time_.[[Nanosecond]] + _timeDuration_).
1. NOTE: If using floating points to implement this operation, add the time components separately before balancing to avoid errors with unsafe integers.
</emu-alg>
</emu-clause>

Expand Down

0 comments on commit c5e6599

Please sign in to comment.