From c2f2b4aacb93a46d4d84d16c68e301ef9fceaea1 Mon Sep 17 00:00:00 2001 From: Ben Allen Date: Wed, 22 May 2024 20:41:52 -0700 Subject: [PATCH] Normative: Limit valid values for DurationRecords as in Temporal.Duration 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) --- index.html | 2 +- spec.emu | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/index.html b/index.html index 7b63eff..b0f6771 100644 --- a/index.html +++ b/index.html @@ -2797,7 +2797,7 @@

1.1.4 DurationSign ( years, mont

1.1.5 IsValidDuration ( years, months, weeks, days, hours, minutes, seconds, milliseconds, microseconds, nanoseconds )

The abstract operation IsValidDuration takes arguments years (an integer), months (an integer), weeks (an integer), days (an integer), hours (an integer), minutes (an integer), seconds (an integer), milliseconds (an integer), microseconds (an integer), and nanoseconds (an integer) and returns a Boolean. It returns true if its arguments form valid input from which to construct a Duration Record, and false otherwise. It performs the following steps when called:

-
  1. Let sign be DurationSign(years, months, weeks, days, hours, minutes, seconds, milliseconds, microseconds, nanoseconds).
  2. For each value v of ยซ years, months, weeks, days, hours, minutes, seconds, milliseconds, microseconds, nanoseconds ยป, do
    1. If ๐”ฝ(v) is not finite, return false.
    2. If v < 0 and sign > 0, return false.
    3. If v > 0 and sign < 0, return false.
  3. Return true.
+
  1. Let sign be DurationSign(years, months, weeks, days, hours, minutes, seconds, milliseconds, microseconds, nanoseconds).
  2. For each value v of ยซ years, months, weeks, days, hours, minutes, seconds, milliseconds, microseconds, nanoseconds ยป, do
    1. If ๐”ฝ(v) is not finite, return false.
    2. If v < 0 and sign > 0, return false.
    3. If v > 0 and sign < 0, return false.
  3. If abs(years) โ‰ฅ 232, return false.
  4. If abs(months) โ‰ฅ 232, return false.
  5. If abs(weeks) โ‰ฅ 232, return false.
  6. Let normalizedSeconds be days ร— 86,400 + hours ร— 3600 + minutes ร— 60 + seconds + โ„(๐”ฝ(milliseconds)) ร— 10-3 + โ„(๐”ฝ(microseconds)) ร— 10-6 + โ„(๐”ฝ(nanoseconds)) ร— 10-9.
  7. NOTE: The above step cannot be implemented directly using floating-point arithmetic. Multiplying by 10-3, 10-6, and 10-9 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.
  8. If abs(normalizedSeconds) โ‰ฅ 253, return false.
  9. Return true.
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.
diff --git a/spec.emu b/spec.emu index 47a2815..0094b04 100644 --- a/spec.emu +++ b/spec.emu @@ -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_) ≥ 232, return *false*. + 1. If abs(_months_) ≥ 232, return *false*. + 1. If abs(_weeks_) ≥ 232, return *false*. + 1. Let _normalizedSeconds_ be _days_ × 86,400 + _hours_ × 3600 + _minutes_ × 60 + _seconds_ + โ„(๐”ฝ(_milliseconds_)) × 10-3 + โ„(๐”ฝ(_microseconds_)) × 10-6 + โ„(๐”ฝ(_nanoseconds_)) × 10-9. + 1. NOTE: The above step cannot be implemented directly using floating-point arithmetic. Multiplying by 10-3, 10-6, and 10-9 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_) ≥ 253, return *false*. 1. Return *true*. 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.