Skip to content

Commit

Permalink
Normative: Limit valid values for DurationRecords as in Temporal.Dura…
Browse files Browse the repository at this point in the history
…tion

Normative: Upcoming revisions to Temporal will limit the valid values for Temporal.Duration. This commit applies the same limits on valid values for Intl.DurationFormat DurationRecords. (#173)
  • Loading branch information
ben-allen committed May 23, 2024
1 parent 4359f3f commit c2f2b4a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion index.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions spec.emu
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,12 @@ contributors: Ujjwal Sharma, Younies Mahmoud
1. If 𝔽(_v_) is not finite, return *false*.
1. If _v_ < 0 and _sign_ > 0, return *false*.
1. If _v_ > 0 and _sign_ < 0, return *false*.
1. If abs(_years_) &ge; 2<sup>32</sup>, return *false*.
1. If abs(_months_) &ge; 2<sup>32</sup>, return *false*.
1. If abs(_weeks_) &ge; 2<sup>32</sup>, return *false*.
1. Let _normalizedSeconds_ be _days_ &times; 86,400 + _hours_ &times; 3600 + _minutes_ &times; 60 + _seconds_ + ℝ(𝔽(_milliseconds_)) &times; 10<sup>-3</sup> + ℝ(𝔽(_microseconds_)) &times; 10<sup>-6</sup> + ℝ(𝔽(_nanoseconds_)) &times; 10<sup>-9</sup>.
1. NOTE: The above step cannot be implemented directly using floating-point arithmetic. Multiplying by 10<sup>-3</sup>, 10<sup>-6</sup>, and 10<sup>-9</sup> respectively may be imprecise when _milliseconds_, _microseconds_, or _nanoseconds_ is an unsafe integer. This multiplication can be implemented in C++ with an implementation of `std::remquo()` with sufficient bits in the quotient. String manipulation will also give an exact result, since the multiplication is by a power of 10.
1. If abs(_normalizedSeconds_) &ge; 2<sup>53</sup>, return *false*.
1. Return *true*.
</emu-alg>
<emu-note>The abstract operations ToIntegerIfIntegral, ToDurationRecord, DurationSign, and IsValidDuration take the same parameters as the abstract operations of the same name in the Temporal proposal's specification, and will be removed in favor of those abstract operations if the Temporal proposal becomes part of ECMA-402 before this proposal does.</emu-note>
Expand Down

0 comments on commit c2f2b4a

Please sign in to comment.