Skip to content

Commit 0993b75

Browse files
committed
Normative: Fix Instant rounding modes
As described in the documentation, the proposal champions' intention was for rounding of exact times to consider the Big Bang as the "zero" point, rather than the arbitrary zero point of the Unix epoch. The spec text didn't reflect this correctly.
1 parent 01c3495 commit 0993b75

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

spec/abstractops.html

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -776,6 +776,37 @@ <h1>
776776
</emu-note>
777777
</emu-clause>
778778

779+
<emu-clause id="sec-temporal-roundnumbertoincrementasifpositive" type="abstract operation">
780+
<h1>
781+
RoundNumberToIncrementAsIfPositive (
782+
_x_: a mathematical value,
783+
_increment_: an integer,
784+
_roundingMode_: *"ceil"*, *"floor"*, *"trunc"*, or *"halfExpand"*,
785+
): an integer
786+
</h1>
787+
<dl class="header">
788+
<dt>description</dt>
789+
<dd>
790+
It rounds _x_ to the nearest multiple of _increment_, up or down according to _roundingMode_, but always as if _x_ were positive.
791+
For example, *"floor"* and *"trunc"* behave identically.
792+
This is used when rounding exact times, where "rounding down" conceptually always means towards the beginning of time, even if the time is expressed as a negative amount of time relative to an epoch.
793+
</dd>
794+
</dl>
795+
<emu-alg>
796+
1. Let _quotient_ be _x_ / _increment_.
797+
1. Let _unsignedRoundingMode_ be GetUnsignedRoundingMode(_roundingMode_, *false*).
798+
1. Let _r1_ be the largest integer such that _r1_ &leq; _quotient_.
799+
1. Let _r2_ be the smallest integer such that _r2_ &gt; _quotient_.
800+
1. Let _rounded_ be ApplyUnsignedRoundingMode(_quotient_, _r1_, _r2_, _unsignedRoundingMode_).
801+
1. Return _rounded_ &times; _increment_.
802+
</emu-alg>
803+
<emu-note type="editor">
804+
<p>
805+
The rounding modes accepted by this abstract operation are intended to be the same as whatever is eventually standardized in the <a href="https://github.com/tc39/proposal-intl-numberformat-v3">Intl.NumberFormat V3</a> proposal.
806+
</p>
807+
</emu-note>
808+
</emu-clause>
809+
779810
<emu-clause id="sec-temporal-iso8601grammar">
780811
<h1>ISO 8601 grammar</h1>
781812
<p>

spec/instant.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -614,7 +614,7 @@ <h1>RoundTemporalInstant ( _ns_, _increment_, _unit_, _roundingMode_ )</h1>
614614
1. Else,
615615
1. Assert: _unit_ is *"nanosecond"*.
616616
1. Let _incrementNs_ be _increment_.
617-
1. Return RoundNumberToIncrement(ℝ(_ns_), _incrementNs_, _roundingMode_).
617+
1. Return RoundNumberToIncrementAsIfPositive(ℝ(_ns_), _incrementNs_, _roundingMode_).
618618
</emu-alg>
619619
</emu-clause>
620620

0 commit comments

Comments
 (0)