Skip to content

Commit

Permalink
Normative: Fix Instant rounding modes
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ptomato committed May 19, 2022
1 parent 8f90398 commit 2fadbea
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
31 changes: 31 additions & 0 deletions spec/abstractops.html
Expand Up @@ -837,6 +837,37 @@ <h1>
</emu-note>
</emu-clause>

<emu-clause id="sec-temporal-roundnumbertoincrementasifpositive" type="abstract operation">
<h1>
RoundNumberToIncrementAsIfPositive (
_x_: a mathematical value,
_increment_: an integer,
_roundingMode_: *"ceil"*, *"floor"*, *"trunc"*, or *"halfExpand"*,
): an integer
</h1>
<dl class="header">
<dt>description</dt>
<dd>
It rounds _x_ to the nearest multiple of _increment_, up or down according to _roundingMode_, but always as if _x_ were positive.
For example, *"floor"* and *"trunc"* behave identically.
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.
</dd>
</dl>
<emu-alg>
1. Let _quotient_ be _x_ / _increment_.
1. Let _unsignedRoundingMode_ be GetUnsignedRoundingMode(_roundingMode_, *false*).
1. Let _r1_ be the largest integer such that _r1__quotient_.
1. Let _r2_ be the smallest integer such that _r2_ &gt; _quotient_.
1. Let _rounded_ be ApplyUnsignedRoundingMode(_quotient_, _r1_, _r2_, _unsignedRoundingMode_).
1. Return _rounded_ &times; _increment_.
</emu-alg>
<emu-note type="editor">
<p>
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.
</p>
</emu-note>
</emu-clause>

<emu-clause id="sec-temporal-iso8601grammar">
<h1>ISO 8601 grammar</h1>
<p>
Expand Down
2 changes: 1 addition & 1 deletion spec/instant.html
Expand Up @@ -615,7 +615,7 @@ <h1>RoundTemporalInstant ( _ns_, _increment_, _unit_, _roundingMode_ )</h1>
1. Else,
1. Assert: _unit_ is *"nanosecond"*.
1. Let _incrementNs_ be _increment_.
1. Return RoundNumberToIncrement(ℝ(_ns_), _incrementNs_, _roundingMode_).
1. Return RoundNumberToIncrementAsIfPositive(ℝ(_ns_), _incrementNs_, _roundingMode_).
</emu-alg>
</emu-clause>

Expand Down

0 comments on commit 2fadbea

Please sign in to comment.