From e7364ea7dc36a466edb2db5ef0a8e66da8dabb7d Mon Sep 17 00:00:00 2001 From: Philip Chimento Date: Tue, 17 Jan 2023 12:44:16 -0800 Subject: [PATCH] Temporal: Tests for upper limit on rounding increments Previously in a few cases (calendar units in Duration) the value for the roundingIncrement option had no upper limit, other than having to be finite. These tests cover a normative change limiting it to 1e9. Normative PR: https://github.com/tc39/proposal-temporal/pull/2480 --- .../round/roundingincrement-non-integer.js | 23 +++++++++++++++++++ .../round/roundingincrement-out-of-range.js | 19 +++++++++++++++ .../round/roundingincrement-non-integer.js | 13 +++++++---- .../round/roundingincrement-out-of-range.js | 11 +++++++-- .../since/roundingincrement-non-integer.js | 13 +++++++---- .../since/roundingincrement-out-of-range.js | 11 +++++++-- .../until/roundingincrement-non-integer.js | 13 +++++++---- .../until/roundingincrement-out-of-range.js | 11 +++++++-- .../since/roundingincrement-non-integer.js | 15 ++++++++---- .../since/roundingincrement-out-of-range.js | 11 +++++++-- .../until/roundingincrement-non-integer.js | 15 ++++++++---- .../until/roundingincrement-out-of-range.js | 11 +++++++-- .../round/roundingincrement-non-integer.js | 13 +++++++---- .../round/roundingincrement-out-of-range.js | 11 +++++++-- .../since/roundingincrement-non-integer.js | 15 ++++++++---- .../since/roundingincrement-out-of-range.js | 11 +++++++-- .../until/roundingincrement-non-integer.js | 15 ++++++++---- .../until/roundingincrement-out-of-range.js | 11 +++++++-- .../round/roundingincrement-non-integer.js | 13 +++++++---- .../round/roundingincrement-out-of-range.js | 11 +++++++-- .../since/roundingincrement-non-integer.js | 13 +++++++---- .../since/roundingincrement-out-of-range.js | 11 +++++++-- .../until/roundingincrement-non-integer.js | 13 +++++++---- .../until/roundingincrement-out-of-range.js | 11 +++++++-- .../since/roundingincrement-non-integer.js | 15 ++++++++---- .../since/roundingincrement-out-of-range.js | 11 +++++++-- .../until/roundingincrement-non-integer.js | 15 ++++++++---- .../until/roundingincrement-out-of-range.js | 11 +++++++-- .../round/roundingincrement-non-integer.js | 13 +++++++---- .../round/roundingincrement-out-of-range.js | 11 +++++++-- .../since/roundingincrement-non-integer.js | 15 ++++++++---- .../since/roundingincrement-out-of-range.js | 11 +++++++-- .../until/roundingincrement-non-integer.js | 15 ++++++++---- .../until/roundingincrement-out-of-range.js | 11 +++++++-- test/staging/Temporal/Instant/old/round.js | 8 ------- 35 files changed, 346 insertions(+), 104 deletions(-) create mode 100644 test/built-ins/Temporal/Duration/prototype/round/roundingincrement-non-integer.js create mode 100644 test/built-ins/Temporal/Duration/prototype/round/roundingincrement-out-of-range.js diff --git a/test/built-ins/Temporal/Duration/prototype/round/roundingincrement-non-integer.js b/test/built-ins/Temporal/Duration/prototype/round/roundingincrement-non-integer.js new file mode 100644 index 0000000000..f416f0fc12 --- /dev/null +++ b/test/built-ins/Temporal/Duration/prototype/round/roundingincrement-non-integer.js @@ -0,0 +1,23 @@ +// Copyright (C) 2023 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.duration.prototype.round +description: Rounding for roundingIncrement option +info: | + sec-temporal-totemporalroundingincrement: + 3. Let _integerIncrement_ be truncate(ℝ(_increment_)). +includes: [temporalHelpers.js] +features: [Temporal] +---*/ + +const instance = new Temporal.Duration(1); +const options = { + smallestUnit: "years", + roundingMode: "expand", + relativeTo: new Temporal.PlainDate(2000, 1, 1), +}; +const result = instance.round({ ...options, roundingIncrement: 2.5 }); +TemporalHelpers.assertDuration(result, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, "roundingIncrement 2.5 truncates to 2"); +const result2 = instance.round({ ...options, roundingIncrement: 1e9 + 0.5 }); +TemporalHelpers.assertDuration(result2, 1e9, 0, 0, 0, 0, 0, 0, 0, 0, 0, "roundingIncrement 1e9 + 0.5 truncates to 1e9"); diff --git a/test/built-ins/Temporal/Duration/prototype/round/roundingincrement-out-of-range.js b/test/built-ins/Temporal/Duration/prototype/round/roundingincrement-out-of-range.js new file mode 100644 index 0000000000..31471ee0e5 --- /dev/null +++ b/test/built-ins/Temporal/Duration/prototype/round/roundingincrement-out-of-range.js @@ -0,0 +1,19 @@ +// Copyright (C) 2023 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.duration.prototype.round +description: RangeError thrown when roundingIncrement option out of range +info: | + sec-temporal-totemporalroundingincrement: + 4. If _integerIncrement_ < 1 or _integerIncrement_ > 109, throw a *RangeError* exception. +features: [Temporal] +---*/ + +const instance = new Temporal.Duration(1); +const options = { smallestUnit: "years", relativeTo: new Temporal.PlainDate(2000, 1, 1) }; +assert.throws(RangeError, () => instance.round({ ...options, roundingIncrement: -Infinity })); +assert.throws(RangeError, () => instance.round({ ...options, roundingIncrement: -1 })); +assert.throws(RangeError, () => instance.round({ ...options, roundingIncrement: 0 })); +assert.throws(RangeError, () => instance.round({ ...options, roundingIncrement: 1e9 + 1 })); +assert.throws(RangeError, () => instance.round({ ...options, roundingIncrement: Infinity })); diff --git a/test/built-ins/Temporal/Instant/prototype/round/roundingincrement-non-integer.js b/test/built-ins/Temporal/Instant/prototype/round/roundingincrement-non-integer.js index 859b767b10..0ff268223a 100644 --- a/test/built-ins/Temporal/Instant/prototype/round/roundingincrement-non-integer.js +++ b/test/built-ins/Temporal/Instant/prototype/round/roundingincrement-non-integer.js @@ -5,11 +5,16 @@ esid: sec-temporal.instant.prototype.round description: Rounding for roundingIncrement option info: | - sec-temporal-totemporalroundingincrement step 7: - 7. Set _increment_ to floor(ℝ(_increment_)). + ToTemporalRoundingIncrement ( _normalizedOptions_ ) + + 1. Let _increment_ be ? GetOption(_normalizedOptions_, *"roundingIncrement"*, *"number"*, *undefined*, *1*𝔽). + 2. If _increment_ is not finite, throw a *RangeError* exception. + 3. Let _integerIncrement_ be truncate(ℝ(_increment_)). + 4. If _integerIncrement_ < 1 or _integerIncrement_ > 109, throw a *RangeError* exception. + 5. Return _integerIncrement_. features: [Temporal] ---*/ const instant = new Temporal.Instant(1_000_000_000_000_000_005n); -const result = instant.round({ smallestUnit: "nanosecond", roundingIncrement: 2.5 }); -assert.sameValue(result.epochNanoseconds, 1_000_000_000_000_000_006n, "roundingIncrement 2.5 floors to 2"); +const result = instant.round({ smallestUnit: "nanosecond", roundingIncrement: 2.5, roundingMode: "expand" }); +assert.sameValue(result.epochNanoseconds, 1_000_000_000_000_000_006n, "roundingIncrement 2.5 truncates to 2"); diff --git a/test/built-ins/Temporal/Instant/prototype/round/roundingincrement-out-of-range.js b/test/built-ins/Temporal/Instant/prototype/round/roundingincrement-out-of-range.js index 93f3e3273a..5e124be528 100644 --- a/test/built-ins/Temporal/Instant/prototype/round/roundingincrement-out-of-range.js +++ b/test/built-ins/Temporal/Instant/prototype/round/roundingincrement-out-of-range.js @@ -5,8 +5,13 @@ esid: sec-temporal.instant.prototype.round description: RangeError thrown when roundingIncrement option out of range info: | - sec-temporal-totemporalroundingincrement step 6: - 6. If _increment_ < 1 or _increment_ > _maximum_, throw a *RangeError* exception. + ToTemporalRoundingIncrement ( _normalizedOptions_ ) + + 1. Let _increment_ be ? GetOption(_normalizedOptions_, *"roundingIncrement"*, *"number"*, *undefined*, *1*𝔽). + 2. If _increment_ is not finite, throw a *RangeError* exception. + 3. Let _integerIncrement_ be truncate(ℝ(_increment_)). + 4. If _integerIncrement_ < 1 or _integerIncrement_ > 109, throw a *RangeError* exception. + 5. Return _integerIncrement_. features: [Temporal] ---*/ @@ -14,4 +19,6 @@ const instant = new Temporal.Instant(1_000_000_000_000_000_005n); assert.throws(RangeError, () => instant.round({ smallestUnit: "nanoseconds", roundingIncrement: -Infinity })); assert.throws(RangeError, () => instant.round({ smallestUnit: "nanoseconds", roundingIncrement: -1 })); assert.throws(RangeError, () => instant.round({ smallestUnit: "nanoseconds", roundingIncrement: 0 })); +assert.throws(RangeError, () => instant.round({ smallestUnit: "nanoseconds", roundingIncrement: 0.9 })); +assert.throws(RangeError, () => instant.round({ smallestUnit: "nanoseconds", roundingIncrement: 1e9 + 1 })); assert.throws(RangeError, () => instant.round({ smallestUnit: "nanoseconds", roundingIncrement: Infinity })); diff --git a/test/built-ins/Temporal/Instant/prototype/since/roundingincrement-non-integer.js b/test/built-ins/Temporal/Instant/prototype/since/roundingincrement-non-integer.js index 4df25adc67..064ae3d304 100644 --- a/test/built-ins/Temporal/Instant/prototype/since/roundingincrement-non-integer.js +++ b/test/built-ins/Temporal/Instant/prototype/since/roundingincrement-non-integer.js @@ -5,13 +5,18 @@ esid: sec-temporal.instant.prototype.since description: Rounding for roundingIncrement option info: | - sec-temporal-totemporalroundingincrement step 7: - 7. Set _increment_ to floor(ℝ(_increment_)). + ToTemporalRoundingIncrement ( _normalizedOptions_ ) + + 1. Let _increment_ be ? GetOption(_normalizedOptions_, *"roundingIncrement"*, *"number"*, *undefined*, *1*𝔽). + 2. If _increment_ is not finite, throw a *RangeError* exception. + 3. Let _integerIncrement_ be truncate(ℝ(_increment_)). + 4. If _integerIncrement_ < 1 or _integerIncrement_ > 109, throw a *RangeError* exception. + 5. Return _integerIncrement_. includes: [temporalHelpers.js] features: [Temporal] ---*/ const earlier = new Temporal.Instant(1_000_000_000_000_000_000n); const later = new Temporal.Instant(1_000_000_000_000_000_005n); -const result = later.since(earlier, { roundingIncrement: 2.5 }); -TemporalHelpers.assertDuration(result, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, "roundingIncrement 2.5 floors to 2"); +const result = later.since(earlier, { roundingIncrement: 2.5, roundingMode: "trunc" }); +TemporalHelpers.assertDuration(result, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, "roundingIncrement 2.5 truncates to 2"); diff --git a/test/built-ins/Temporal/Instant/prototype/since/roundingincrement-out-of-range.js b/test/built-ins/Temporal/Instant/prototype/since/roundingincrement-out-of-range.js index a82d37683e..5fe6285f5f 100644 --- a/test/built-ins/Temporal/Instant/prototype/since/roundingincrement-out-of-range.js +++ b/test/built-ins/Temporal/Instant/prototype/since/roundingincrement-out-of-range.js @@ -5,8 +5,13 @@ esid: sec-temporal.instant.prototype.since description: RangeError thrown when roundingIncrement option out of range info: | - sec-temporal-totemporalroundingincrement step 6: - 6. If _increment_ < 1 or _increment_ > _maximum_, throw a *RangeError* exception. + ToTemporalRoundingIncrement ( _normalizedOptions_ ) + + 1. Let _increment_ be ? GetOption(_normalizedOptions_, *"roundingIncrement"*, *"number"*, *undefined*, *1*𝔽). + 2. If _increment_ is not finite, throw a *RangeError* exception. + 3. Let _integerIncrement_ be truncate(ℝ(_increment_)). + 4. If _integerIncrement_ < 1 or _integerIncrement_ > 109, throw a *RangeError* exception. + 5. Return _integerIncrement_. features: [Temporal] ---*/ @@ -15,4 +20,6 @@ const later = new Temporal.Instant(1_000_000_000_000_000_005n); assert.throws(RangeError, () => later.since(earlier, { roundingIncrement: -Infinity })); assert.throws(RangeError, () => later.since(earlier, { roundingIncrement: -1 })); assert.throws(RangeError, () => later.since(earlier, { roundingIncrement: 0 })); +assert.throws(RangeError, () => later.since(earlier, { roundingIncrement: 0.9 })); +assert.throws(RangeError, () => later.since(earlier, { roundingIncrement: 1e9 + 1 })); assert.throws(RangeError, () => later.since(earlier, { roundingIncrement: Infinity })); diff --git a/test/built-ins/Temporal/Instant/prototype/until/roundingincrement-non-integer.js b/test/built-ins/Temporal/Instant/prototype/until/roundingincrement-non-integer.js index 0f5e2acbf8..3f03ed2474 100644 --- a/test/built-ins/Temporal/Instant/prototype/until/roundingincrement-non-integer.js +++ b/test/built-ins/Temporal/Instant/prototype/until/roundingincrement-non-integer.js @@ -5,13 +5,18 @@ esid: sec-temporal.instant.prototype.until description: Rounding for roundingIncrement option info: | - sec-temporal-totemporalroundingincrement step 7: - 7. Set _increment_ to floor(ℝ(_increment_)). + ToTemporalRoundingIncrement ( _normalizedOptions_ ) + + 1. Let _increment_ be ? GetOption(_normalizedOptions_, *"roundingIncrement"*, *"number"*, *undefined*, *1*𝔽). + 2. If _increment_ is not finite, throw a *RangeError* exception. + 3. Let _integerIncrement_ be truncate(ℝ(_increment_)). + 4. If _integerIncrement_ < 1 or _integerIncrement_ > 109, throw a *RangeError* exception. + 5. Return _integerIncrement_. includes: [temporalHelpers.js] features: [Temporal] ---*/ const earlier = new Temporal.Instant(1_000_000_000_000_000_000n); const later = new Temporal.Instant(1_000_000_000_000_000_005n); -const result = earlier.until(later, { roundingIncrement: 2.5 }); -TemporalHelpers.assertDuration(result, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, "roundingIncrement 2.5 floors to 2"); +const result = earlier.until(later, { roundingIncrement: 2.5, roundingMode: "trunc" }); +TemporalHelpers.assertDuration(result, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, "roundingIncrement 2.5 truncates to 2"); diff --git a/test/built-ins/Temporal/Instant/prototype/until/roundingincrement-out-of-range.js b/test/built-ins/Temporal/Instant/prototype/until/roundingincrement-out-of-range.js index 738a8070e3..abaab32a9f 100644 --- a/test/built-ins/Temporal/Instant/prototype/until/roundingincrement-out-of-range.js +++ b/test/built-ins/Temporal/Instant/prototype/until/roundingincrement-out-of-range.js @@ -5,8 +5,13 @@ esid: sec-temporal.instant.prototype.until description: RangeError thrown when roundingIncrement option out of range info: | - sec-temporal-totemporalroundingincrement step 6: - 6. If _increment_ < 1 or _increment_ > _maximum_, throw a *RangeError* exception. + ToTemporalRoundingIncrement ( _normalizedOptions_ ) + + 1. Let _increment_ be ? GetOption(_normalizedOptions_, *"roundingIncrement"*, *"number"*, *undefined*, *1*𝔽). + 2. If _increment_ is not finite, throw a *RangeError* exception. + 3. Let _integerIncrement_ be truncate(ℝ(_increment_)). + 4. If _integerIncrement_ < 1 or _integerIncrement_ > 109, throw a *RangeError* exception. + 5. Return _integerIncrement_. features: [Temporal] ---*/ @@ -15,4 +20,6 @@ const later = new Temporal.Instant(1_000_000_000_000_000_005n); assert.throws(RangeError, () => earlier.until(later, { roundingIncrement: -Infinity })); assert.throws(RangeError, () => earlier.until(later, { roundingIncrement: -1 })); assert.throws(RangeError, () => earlier.until(later, { roundingIncrement: 0 })); +assert.throws(RangeError, () => earlier.until(later, { roundingIncrement: 0.9 })); +assert.throws(RangeError, () => earlier.until(later, { roundingIncrement: 1e9 + 1 })); assert.throws(RangeError, () => earlier.until(later, { roundingIncrement: Infinity })); diff --git a/test/built-ins/Temporal/PlainDate/prototype/since/roundingincrement-non-integer.js b/test/built-ins/Temporal/PlainDate/prototype/since/roundingincrement-non-integer.js index e1a4608236..593bea879d 100644 --- a/test/built-ins/Temporal/PlainDate/prototype/since/roundingincrement-non-integer.js +++ b/test/built-ins/Temporal/PlainDate/prototype/since/roundingincrement-non-integer.js @@ -5,13 +5,20 @@ esid: sec-temporal.plaindate.prototype.since description: Rounding for roundingIncrement option info: | - sec-temporal-totemporalroundingincrement step 7: - 7. Set _increment_ to floor(ℝ(_increment_)). + ToTemporalRoundingIncrement ( _normalizedOptions_ ) + + 1. Let _increment_ be ? GetOption(_normalizedOptions_, *"roundingIncrement"*, *"number"*, *undefined*, *1*𝔽). + 2. If _increment_ is not finite, throw a *RangeError* exception. + 3. Let _integerIncrement_ be truncate(ℝ(_increment_)). + 4. If _integerIncrement_ < 1 or _integerIncrement_ > 109, throw a *RangeError* exception. + 5. Return _integerIncrement_. includes: [temporalHelpers.js] features: [Temporal] ---*/ const earlier = new Temporal.PlainDate(2000, 5, 2); const later = new Temporal.PlainDate(2000, 5, 7); -const result = later.since(earlier, { roundingIncrement: 2.5 }); -TemporalHelpers.assertDuration(result, 0, 0, 0, 4, 0, 0, 0, 0, 0, 0, "roundingIncrement 2.5 floors to 2"); +const result = later.since(earlier, { roundingIncrement: 2.5, roundingMode: "trunc" }); +TemporalHelpers.assertDuration(result, 0, 0, 0, 4, 0, 0, 0, 0, 0, 0, "roundingIncrement 2.5 truncates to 2"); +const result2 = later.since(earlier, { smallestUnit: "days", roundingIncrement: 1e9 + 0.5, roundingMode: "expand" }); +TemporalHelpers.assertDuration(result2, 0, 0, 0, 1e9, 0, 0, 0, 0, 0, 0, "roundingIncrement 1e9 + 0.5 truncates to 1e9"); diff --git a/test/built-ins/Temporal/PlainDate/prototype/since/roundingincrement-out-of-range.js b/test/built-ins/Temporal/PlainDate/prototype/since/roundingincrement-out-of-range.js index 5fef7e40de..e225687107 100644 --- a/test/built-ins/Temporal/PlainDate/prototype/since/roundingincrement-out-of-range.js +++ b/test/built-ins/Temporal/PlainDate/prototype/since/roundingincrement-out-of-range.js @@ -5,8 +5,13 @@ esid: sec-temporal.plaindate.prototype.since description: RangeError thrown when roundingIncrement option out of range info: | - sec-temporal-totemporalroundingincrement step 6: - 6. If _increment_ < 1 or _increment_ > _maximum_, throw a *RangeError* exception. + ToTemporalRoundingIncrement ( _normalizedOptions_ ) + + 1. Let _increment_ be ? GetOption(_normalizedOptions_, *"roundingIncrement"*, *"number"*, *undefined*, *1*𝔽). + 2. If _increment_ is not finite, throw a *RangeError* exception. + 3. Let _integerIncrement_ be truncate(ℝ(_increment_)). + 4. If _integerIncrement_ < 1 or _integerIncrement_ > 109, throw a *RangeError* exception. + 5. Return _integerIncrement_. features: [Temporal] ---*/ @@ -15,4 +20,6 @@ const later = new Temporal.PlainDate(2000, 5, 7); assert.throws(RangeError, () => later.since(earlier, { roundingIncrement: -Infinity })); assert.throws(RangeError, () => later.since(earlier, { roundingIncrement: -1 })); assert.throws(RangeError, () => later.since(earlier, { roundingIncrement: 0 })); +assert.throws(RangeError, () => later.since(earlier, { roundingIncrement: 0.9 })); +assert.throws(RangeError, () => later.since(earlier, { roundingIncrement: 1e9 + 1 })); assert.throws(RangeError, () => later.since(earlier, { roundingIncrement: Infinity })); diff --git a/test/built-ins/Temporal/PlainDate/prototype/until/roundingincrement-non-integer.js b/test/built-ins/Temporal/PlainDate/prototype/until/roundingincrement-non-integer.js index a5da75f9c5..21aa74b055 100644 --- a/test/built-ins/Temporal/PlainDate/prototype/until/roundingincrement-non-integer.js +++ b/test/built-ins/Temporal/PlainDate/prototype/until/roundingincrement-non-integer.js @@ -5,13 +5,20 @@ esid: sec-temporal.plaindate.prototype.until description: Rounding for roundingIncrement option info: | - sec-temporal-totemporalroundingincrement step 7: - 7. Set _increment_ to floor(ℝ(_increment_)). + ToTemporalRoundingIncrement ( _normalizedOptions_ ) + + 1. Let _increment_ be ? GetOption(_normalizedOptions_, *"roundingIncrement"*, *"number"*, *undefined*, *1*𝔽). + 2. If _increment_ is not finite, throw a *RangeError* exception. + 3. Let _integerIncrement_ be truncate(ℝ(_increment_)). + 4. If _integerIncrement_ < 1 or _integerIncrement_ > 109, throw a *RangeError* exception. + 5. Return _integerIncrement_. includes: [temporalHelpers.js] features: [Temporal] ---*/ const earlier = new Temporal.PlainDate(2000, 5, 2); const later = new Temporal.PlainDate(2000, 5, 7); -const result = earlier.until(later, { roundingIncrement: 2.5 }); -TemporalHelpers.assertDuration(result, 0, 0, 0, 4, 0, 0, 0, 0, 0, 0, "roundingIncrement 2.5 floors to 2"); +const result = earlier.until(later, { roundingIncrement: 2.5, roundingMode: "trunc" }); +TemporalHelpers.assertDuration(result, 0, 0, 0, 4, 0, 0, 0, 0, 0, 0, "roundingIncrement 2.5 truncates to 2"); +const result2 = earlier.until(later, { smallestUnit: "days", roundingIncrement: 1e9 + 0.5, roundingMode: "expand" }); +TemporalHelpers.assertDuration(result2, 0, 0, 0, 1e9, 0, 0, 0, 0, 0, 0, "roundingIncrement 1e9 + 0.5 truncates to 1e9"); diff --git a/test/built-ins/Temporal/PlainDate/prototype/until/roundingincrement-out-of-range.js b/test/built-ins/Temporal/PlainDate/prototype/until/roundingincrement-out-of-range.js index e0da8b519d..d77ebd173f 100644 --- a/test/built-ins/Temporal/PlainDate/prototype/until/roundingincrement-out-of-range.js +++ b/test/built-ins/Temporal/PlainDate/prototype/until/roundingincrement-out-of-range.js @@ -5,8 +5,13 @@ esid: sec-temporal.plaindate.prototype.until description: RangeError thrown when roundingIncrement option out of range info: | - sec-temporal-totemporalroundingincrement step 6: - 6. If _increment_ < 1 or _increment_ > _maximum_, throw a *RangeError* exception. + ToTemporalRoundingIncrement ( _normalizedOptions_ ) + + 1. Let _increment_ be ? GetOption(_normalizedOptions_, *"roundingIncrement"*, *"number"*, *undefined*, *1*𝔽). + 2. If _increment_ is not finite, throw a *RangeError* exception. + 3. Let _integerIncrement_ be truncate(ℝ(_increment_)). + 4. If _integerIncrement_ < 1 or _integerIncrement_ > 109, throw a *RangeError* exception. + 5. Return _integerIncrement_. features: [Temporal] ---*/ @@ -15,4 +20,6 @@ const later = new Temporal.PlainDate(2000, 5, 7); assert.throws(RangeError, () => earlier.until(later, { roundingIncrement: -Infinity })); assert.throws(RangeError, () => earlier.until(later, { roundingIncrement: -1 })); assert.throws(RangeError, () => earlier.until(later, { roundingIncrement: 0 })); +assert.throws(RangeError, () => earlier.until(later, { roundingIncrement: 0.9 })); +assert.throws(RangeError, () => earlier.until(later, { roundingIncrement: 1e9 + 1 })); assert.throws(RangeError, () => earlier.until(later, { roundingIncrement: Infinity })); diff --git a/test/built-ins/Temporal/PlainDateTime/prototype/round/roundingincrement-non-integer.js b/test/built-ins/Temporal/PlainDateTime/prototype/round/roundingincrement-non-integer.js index baa035eb76..9d7fe8806c 100644 --- a/test/built-ins/Temporal/PlainDateTime/prototype/round/roundingincrement-non-integer.js +++ b/test/built-ins/Temporal/PlainDateTime/prototype/round/roundingincrement-non-integer.js @@ -5,12 +5,17 @@ esid: sec-temporal.plaindatetime.prototype.round description: Rounding for roundingIncrement option info: | - sec-temporal-totemporalroundingincrement step 7: - 7. Set _increment_ to floor(ℝ(_increment_)). + ToTemporalRoundingIncrement ( _normalizedOptions_ ) + + 1. Let _increment_ be ? GetOption(_normalizedOptions_, *"roundingIncrement"*, *"number"*, *undefined*, *1*𝔽). + 2. If _increment_ is not finite, throw a *RangeError* exception. + 3. Let _integerIncrement_ be truncate(ℝ(_increment_)). + 4. If _integerIncrement_ < 1 or _integerIncrement_ > 109, throw a *RangeError* exception. + 5. Return _integerIncrement_. includes: [temporalHelpers.js] features: [Temporal] ---*/ const datetime = new Temporal.PlainDateTime(2000, 5, 2, 12, 34, 56, 0, 0, 5); -const result = datetime.round({ smallestUnit: "nanosecond", roundingIncrement: 2.5 }); -TemporalHelpers.assertPlainDateTime(result, 2000, 5, "M05", 2, 12, 34, 56, 0, 0, 6, "roundingIncrement 2.5 floors to 2"); +const result = datetime.round({ smallestUnit: "nanosecond", roundingIncrement: 2.5, roundingMode: "expand" }); +TemporalHelpers.assertPlainDateTime(result, 2000, 5, "M05", 2, 12, 34, 56, 0, 0, 6, "roundingIncrement 2.5 truncates to 2"); diff --git a/test/built-ins/Temporal/PlainDateTime/prototype/round/roundingincrement-out-of-range.js b/test/built-ins/Temporal/PlainDateTime/prototype/round/roundingincrement-out-of-range.js index f35ed2e16b..a18dbd8135 100644 --- a/test/built-ins/Temporal/PlainDateTime/prototype/round/roundingincrement-out-of-range.js +++ b/test/built-ins/Temporal/PlainDateTime/prototype/round/roundingincrement-out-of-range.js @@ -5,8 +5,13 @@ esid: sec-temporal.plaindatetime.prototype.round description: RangeError thrown when roundingIncrement option out of range info: | - sec-temporal-totemporalroundingincrement step 6: - 6. If _increment_ < 1 or _increment_ > _maximum_, throw a *RangeError* exception. + ToTemporalRoundingIncrement ( _normalizedOptions_ ) + + 1. Let _increment_ be ? GetOption(_normalizedOptions_, *"roundingIncrement"*, *"number"*, *undefined*, *1*𝔽). + 2. If _increment_ is not finite, throw a *RangeError* exception. + 3. Let _integerIncrement_ be truncate(ℝ(_increment_)). + 4. If _integerIncrement_ < 1 or _integerIncrement_ > 109, throw a *RangeError* exception. + 5. Return _integerIncrement_. features: [Temporal] ---*/ @@ -14,4 +19,6 @@ const datetime = new Temporal.PlainDateTime(2000, 5, 2, 12, 34, 56, 0, 0, 5); assert.throws(RangeError, () => datetime.round({ smallestUnit: "nanoseconds", roundingIncrement: -Infinity })); assert.throws(RangeError, () => datetime.round({ smallestUnit: "nanoseconds", roundingIncrement: -1 })); assert.throws(RangeError, () => datetime.round({ smallestUnit: "nanoseconds", roundingIncrement: 0 })); +assert.throws(RangeError, () => datetime.round({ smallestUnit: "nanoseconds", roundingIncrement: 0.9 })); +assert.throws(RangeError, () => datetime.round({ smallestUnit: "nanoseconds", roundingIncrement: 1e9 + 1 })); assert.throws(RangeError, () => datetime.round({ smallestUnit: "nanoseconds", roundingIncrement: Infinity })); diff --git a/test/built-ins/Temporal/PlainDateTime/prototype/since/roundingincrement-non-integer.js b/test/built-ins/Temporal/PlainDateTime/prototype/since/roundingincrement-non-integer.js index 05265ab0b1..9a06c6ec06 100644 --- a/test/built-ins/Temporal/PlainDateTime/prototype/since/roundingincrement-non-integer.js +++ b/test/built-ins/Temporal/PlainDateTime/prototype/since/roundingincrement-non-integer.js @@ -5,13 +5,20 @@ esid: sec-temporal.plaindatetime.prototype.since description: Rounding for roundingIncrement option info: | - sec-temporal-totemporalroundingincrement step 7: - 7. Set _increment_ to floor(ℝ(_increment_)). + ToTemporalRoundingIncrement ( _normalizedOptions_ ) + + 1. Let _increment_ be ? GetOption(_normalizedOptions_, *"roundingIncrement"*, *"number"*, *undefined*, *1*𝔽). + 2. If _increment_ is not finite, throw a *RangeError* exception. + 3. Let _integerIncrement_ be truncate(ℝ(_increment_)). + 4. If _integerIncrement_ < 1 or _integerIncrement_ > 109, throw a *RangeError* exception. + 5. Return _integerIncrement_. includes: [temporalHelpers.js] features: [Temporal] ---*/ const earlier = new Temporal.PlainDateTime(2000, 5, 2, 12, 34, 56, 0, 0, 0); const later = new Temporal.PlainDateTime(2000, 5, 2, 12, 34, 56, 0, 0, 5); -const result = later.since(earlier, { roundingIncrement: 2.5 }); -TemporalHelpers.assertDuration(result, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, "roundingIncrement 2.5 floors to 2"); +const result = later.since(earlier, { roundingIncrement: 2.5, roundingMode: "trunc" }); +TemporalHelpers.assertDuration(result, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, "roundingIncrement 2.5 truncates to 2"); +const result2 = later.since(earlier, { smallestUnit: "days", roundingIncrement: 1e9 + 0.5, roundingMode: "expand" }); +TemporalHelpers.assertDuration(result2, 0, 0, 0, 1e9, 0, 0, 0, 0, 0, 0, "roundingIncrement 1e9 + 0.5 truncates to 1e9"); diff --git a/test/built-ins/Temporal/PlainDateTime/prototype/since/roundingincrement-out-of-range.js b/test/built-ins/Temporal/PlainDateTime/prototype/since/roundingincrement-out-of-range.js index b274fab67a..65041a39cd 100644 --- a/test/built-ins/Temporal/PlainDateTime/prototype/since/roundingincrement-out-of-range.js +++ b/test/built-ins/Temporal/PlainDateTime/prototype/since/roundingincrement-out-of-range.js @@ -5,8 +5,13 @@ esid: sec-temporal.plaindatetime.prototype.since description: RangeError thrown when roundingIncrement option out of range info: | - sec-temporal-totemporalroundingincrement step 6: - 6. If _increment_ < 1 or _increment_ > _maximum_, throw a *RangeError* exception. + ToTemporalRoundingIncrement ( _normalizedOptions_ ) + + 1. Let _increment_ be ? GetOption(_normalizedOptions_, *"roundingIncrement"*, *"number"*, *undefined*, *1*𝔽). + 2. If _increment_ is not finite, throw a *RangeError* exception. + 3. Let _integerIncrement_ be truncate(ℝ(_increment_)). + 4. If _integerIncrement_ < 1 or _integerIncrement_ > 109, throw a *RangeError* exception. + 5. Return _integerIncrement_. features: [Temporal] ---*/ @@ -15,4 +20,6 @@ const later = new Temporal.PlainDateTime(2000, 5, 2, 12, 34, 56, 0, 0, 5); assert.throws(RangeError, () => later.since(earlier, { roundingIncrement: -Infinity })); assert.throws(RangeError, () => later.since(earlier, { roundingIncrement: -1 })); assert.throws(RangeError, () => later.since(earlier, { roundingIncrement: 0 })); +assert.throws(RangeError, () => later.since(earlier, { roundingIncrement: 0.9 })); +assert.throws(RangeError, () => later.since(earlier, { roundingIncrement: 1e9 + 1 })); assert.throws(RangeError, () => later.since(earlier, { roundingIncrement: Infinity })); diff --git a/test/built-ins/Temporal/PlainDateTime/prototype/until/roundingincrement-non-integer.js b/test/built-ins/Temporal/PlainDateTime/prototype/until/roundingincrement-non-integer.js index add5d0fd1f..d0ea4644b0 100644 --- a/test/built-ins/Temporal/PlainDateTime/prototype/until/roundingincrement-non-integer.js +++ b/test/built-ins/Temporal/PlainDateTime/prototype/until/roundingincrement-non-integer.js @@ -5,13 +5,20 @@ esid: sec-temporal.plaindatetime.prototype.until description: Rounding for roundingIncrement option info: | - sec-temporal-totemporalroundingincrement step 7: - 7. Set _increment_ to floor(ℝ(_increment_)). + ToTemporalRoundingIncrement ( _normalizedOptions_ ) + + 1. Let _increment_ be ? GetOption(_normalizedOptions_, *"roundingIncrement"*, *"number"*, *undefined*, *1*𝔽). + 2. If _increment_ is not finite, throw a *RangeError* exception. + 3. Let _integerIncrement_ be truncate(ℝ(_increment_)). + 4. If _integerIncrement_ < 1 or _integerIncrement_ > 109, throw a *RangeError* exception. + 5. Return _integerIncrement_. includes: [temporalHelpers.js] features: [Temporal] ---*/ const earlier = new Temporal.PlainDateTime(2000, 5, 2, 12, 34, 56, 0, 0, 0); const later = new Temporal.PlainDateTime(2000, 5, 2, 12, 34, 56, 0, 0, 5); -const result = earlier.until(later, { roundingIncrement: 2.5 }); -TemporalHelpers.assertDuration(result, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, "roundingIncrement 2.5 floors to 2"); +const result = earlier.until(later, { roundingIncrement: 2.5, roundingMode: "trunc" }); +TemporalHelpers.assertDuration(result, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, "roundingIncrement 2.5 truncates to 2"); +const result2 = earlier.until(later, { smallestUnit: "days", roundingIncrement: 1e9 + 0.5, roundingMode: "expand" }); +TemporalHelpers.assertDuration(result2, 0, 0, 0, 1e9, 0, 0, 0, 0, 0, 0, "roundingIncrement 1e9 + 0.5 truncates to 1e9"); diff --git a/test/built-ins/Temporal/PlainDateTime/prototype/until/roundingincrement-out-of-range.js b/test/built-ins/Temporal/PlainDateTime/prototype/until/roundingincrement-out-of-range.js index 6fa1d3ee8f..035235e932 100644 --- a/test/built-ins/Temporal/PlainDateTime/prototype/until/roundingincrement-out-of-range.js +++ b/test/built-ins/Temporal/PlainDateTime/prototype/until/roundingincrement-out-of-range.js @@ -5,8 +5,13 @@ esid: sec-temporal.plaindatetime.prototype.until description: RangeError thrown when roundingIncrement option out of range info: | - sec-temporal-totemporalroundingincrement step 6: - 6. If _increment_ < 1 or _increment_ > _maximum_, throw a *RangeError* exception. + ToTemporalRoundingIncrement ( _normalizedOptions_ ) + + 1. Let _increment_ be ? GetOption(_normalizedOptions_, *"roundingIncrement"*, *"number"*, *undefined*, *1*𝔽). + 2. If _increment_ is not finite, throw a *RangeError* exception. + 3. Let _integerIncrement_ be truncate(ℝ(_increment_)). + 4. If _integerIncrement_ < 1 or _integerIncrement_ > 109, throw a *RangeError* exception. + 5. Return _integerIncrement_. features: [Temporal] ---*/ @@ -15,4 +20,6 @@ const later = new Temporal.PlainDateTime(2000, 5, 2, 12, 34, 56, 0, 0, 5); assert.throws(RangeError, () => earlier.until(later, { roundingIncrement: -Infinity })); assert.throws(RangeError, () => earlier.until(later, { roundingIncrement: -1 })); assert.throws(RangeError, () => earlier.until(later, { roundingIncrement: 0 })); +assert.throws(RangeError, () => earlier.until(later, { roundingIncrement: 0.9 })); +assert.throws(RangeError, () => earlier.until(later, { roundingIncrement: 1e9 + 1 })); assert.throws(RangeError, () => earlier.until(later, { roundingIncrement: Infinity })); diff --git a/test/built-ins/Temporal/PlainTime/prototype/round/roundingincrement-non-integer.js b/test/built-ins/Temporal/PlainTime/prototype/round/roundingincrement-non-integer.js index fcee98cb7b..26e7595b20 100644 --- a/test/built-ins/Temporal/PlainTime/prototype/round/roundingincrement-non-integer.js +++ b/test/built-ins/Temporal/PlainTime/prototype/round/roundingincrement-non-integer.js @@ -5,12 +5,17 @@ esid: sec-temporal.plaintime.prototype.round description: Rounding for roundingIncrement option info: | - sec-temporal-totemporalroundingincrement step 7: - 7. Set _increment_ to floor(ℝ(_increment_)). + ToTemporalRoundingIncrement ( _normalizedOptions_ ) + + 1. Let _increment_ be ? GetOption(_normalizedOptions_, *"roundingIncrement"*, *"number"*, *undefined*, *1*𝔽). + 2. If _increment_ is not finite, throw a *RangeError* exception. + 3. Let _integerIncrement_ be truncate(ℝ(_increment_)). + 4. If _integerIncrement_ < 1 or _integerIncrement_ > 109, throw a *RangeError* exception. + 5. Return _integerIncrement_. includes: [temporalHelpers.js] features: [Temporal] ---*/ const time = new Temporal.PlainTime(12, 34, 56, 0, 0, 5); -const result = time.round({ smallestUnit: "nanosecond", roundingIncrement: 2.5 }); -TemporalHelpers.assertPlainTime(result, 12, 34, 56, 0, 0, 6, "roundingIncrement 2.5 floors to 2"); +const result = time.round({ smallestUnit: "nanosecond", roundingIncrement: 2.5, roundingMode: "expand" }); +TemporalHelpers.assertPlainTime(result, 12, 34, 56, 0, 0, 6, "roundingIncrement 2.5 truncates to 2"); diff --git a/test/built-ins/Temporal/PlainTime/prototype/round/roundingincrement-out-of-range.js b/test/built-ins/Temporal/PlainTime/prototype/round/roundingincrement-out-of-range.js index fb0493f205..001916d19c 100644 --- a/test/built-ins/Temporal/PlainTime/prototype/round/roundingincrement-out-of-range.js +++ b/test/built-ins/Temporal/PlainTime/prototype/round/roundingincrement-out-of-range.js @@ -5,8 +5,13 @@ esid: sec-temporal.plaintime.prototype.round description: RangeError thrown when roundingIncrement option out of range info: | - sec-temporal-totemporalroundingincrement step 6: - 6. If _increment_ < 1 or _increment_ > _maximum_, throw a *RangeError* exception. + ToTemporalRoundingIncrement ( _normalizedOptions_ ) + + 1. Let _increment_ be ? GetOption(_normalizedOptions_, *"roundingIncrement"*, *"number"*, *undefined*, *1*𝔽). + 2. If _increment_ is not finite, throw a *RangeError* exception. + 3. Let _integerIncrement_ be truncate(ℝ(_increment_)). + 4. If _integerIncrement_ < 1 or _integerIncrement_ > 109, throw a *RangeError* exception. + 5. Return _integerIncrement_. features: [Temporal] ---*/ @@ -14,4 +19,6 @@ const time = new Temporal.PlainTime(12, 34, 56, 0, 0, 5); assert.throws(RangeError, () => time.round({ smallestUnit: "nanoseconds", roundingIncrement: -Infinity })); assert.throws(RangeError, () => time.round({ smallestUnit: "nanoseconds", roundingIncrement: -1 })); assert.throws(RangeError, () => time.round({ smallestUnit: "nanoseconds", roundingIncrement: 0 })); +assert.throws(RangeError, () => time.round({ smallestUnit: "nanoseconds", roundingIncrement: 0.9 })); +assert.throws(RangeError, () => time.round({ smallestUnit: "nanoseconds", roundingIncrement: 1e9 + 1 })); assert.throws(RangeError, () => time.round({ smallestUnit: "nanoseconds", roundingIncrement: Infinity })); diff --git a/test/built-ins/Temporal/PlainTime/prototype/since/roundingincrement-non-integer.js b/test/built-ins/Temporal/PlainTime/prototype/since/roundingincrement-non-integer.js index 2795f426db..f90a54ef85 100644 --- a/test/built-ins/Temporal/PlainTime/prototype/since/roundingincrement-non-integer.js +++ b/test/built-ins/Temporal/PlainTime/prototype/since/roundingincrement-non-integer.js @@ -5,13 +5,18 @@ esid: sec-temporal.plaintime.prototype.since description: Rounding for roundingIncrement option info: | - sec-temporal-totemporalroundingincrement step 7: - 7. Set _increment_ to floor(ℝ(_increment_)). + ToTemporalRoundingIncrement ( _normalizedOptions_ ) + + 1. Let _increment_ be ? GetOption(_normalizedOptions_, *"roundingIncrement"*, *"number"*, *undefined*, *1*𝔽). + 2. If _increment_ is not finite, throw a *RangeError* exception. + 3. Let _integerIncrement_ be truncate(ℝ(_increment_)). + 4. If _integerIncrement_ < 1 or _integerIncrement_ > 109, throw a *RangeError* exception. + 5. Return _integerIncrement_. includes: [temporalHelpers.js] features: [Temporal] ---*/ const earlier = new Temporal.PlainTime(12, 34, 56, 0, 0, 0); const later = new Temporal.PlainTime(12, 34, 56, 0, 0, 5); -const result = later.since(earlier, { roundingIncrement: 2.5 }); -TemporalHelpers.assertDuration(result, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, "roundingIncrement 2.5 floors to 2"); +const result = later.since(earlier, { roundingIncrement: 2.5, roundingMode: "trunc" }); +TemporalHelpers.assertDuration(result, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, "roundingIncrement 2.5 truncates to 2"); diff --git a/test/built-ins/Temporal/PlainTime/prototype/since/roundingincrement-out-of-range.js b/test/built-ins/Temporal/PlainTime/prototype/since/roundingincrement-out-of-range.js index 6e3d7a1c8b..a79e94dfb2 100644 --- a/test/built-ins/Temporal/PlainTime/prototype/since/roundingincrement-out-of-range.js +++ b/test/built-ins/Temporal/PlainTime/prototype/since/roundingincrement-out-of-range.js @@ -5,8 +5,13 @@ esid: sec-temporal.plaintime.prototype.since description: RangeError thrown when roundingIncrement option out of range info: | - sec-temporal-totemporalroundingincrement step 6: - 6. If _increment_ < 1 or _increment_ > _maximum_, throw a *RangeError* exception. + ToTemporalRoundingIncrement ( _normalizedOptions_ ) + + 1. Let _increment_ be ? GetOption(_normalizedOptions_, *"roundingIncrement"*, *"number"*, *undefined*, *1*𝔽). + 2. If _increment_ is not finite, throw a *RangeError* exception. + 3. Let _integerIncrement_ be truncate(ℝ(_increment_)). + 4. If _integerIncrement_ < 1 or _integerIncrement_ > 109, throw a *RangeError* exception. + 5. Return _integerIncrement_. features: [Temporal] ---*/ @@ -15,4 +20,6 @@ const later = new Temporal.PlainTime(12, 34, 56, 0, 0, 5); assert.throws(RangeError, () => later.since(earlier, { roundingIncrement: -Infinity })); assert.throws(RangeError, () => later.since(earlier, { roundingIncrement: -1 })); assert.throws(RangeError, () => later.since(earlier, { roundingIncrement: 0 })); +assert.throws(RangeError, () => later.since(earlier, { roundingIncrement: 0.9 })); +assert.throws(RangeError, () => later.since(earlier, { roundingIncrement: 1e9 + 1 })); assert.throws(RangeError, () => later.since(earlier, { roundingIncrement: Infinity })); diff --git a/test/built-ins/Temporal/PlainTime/prototype/until/roundingincrement-non-integer.js b/test/built-ins/Temporal/PlainTime/prototype/until/roundingincrement-non-integer.js index f875e90a7f..1d3afac975 100644 --- a/test/built-ins/Temporal/PlainTime/prototype/until/roundingincrement-non-integer.js +++ b/test/built-ins/Temporal/PlainTime/prototype/until/roundingincrement-non-integer.js @@ -5,13 +5,18 @@ esid: sec-temporal.plaintime.prototype.until description: Rounding for roundingIncrement option info: | - sec-temporal-totemporalroundingincrement step 7: - 7. Set _increment_ to floor(ℝ(_increment_)). + ToTemporalRoundingIncrement ( _normalizedOptions_ ) + + 1. Let _increment_ be ? GetOption(_normalizedOptions_, *"roundingIncrement"*, *"number"*, *undefined*, *1*𝔽). + 2. If _increment_ is not finite, throw a *RangeError* exception. + 3. Let _integerIncrement_ be truncate(ℝ(_increment_)). + 4. If _integerIncrement_ < 1 or _integerIncrement_ > 109, throw a *RangeError* exception. + 5. Return _integerIncrement_. includes: [temporalHelpers.js] features: [Temporal] ---*/ const earlier = new Temporal.PlainTime(12, 34, 56, 0, 0, 0); const later = new Temporal.PlainTime(12, 34, 56, 0, 0, 5); -const result = earlier.until(later, { roundingIncrement: 2.5 }); -TemporalHelpers.assertDuration(result, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, "roundingIncrement 2.5 floors to 2"); +const result = earlier.until(later, { roundingIncrement: 2.5, roundingMode: "trunc" }); +TemporalHelpers.assertDuration(result, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, "roundingIncrement 2.5 truncates to 2"); diff --git a/test/built-ins/Temporal/PlainTime/prototype/until/roundingincrement-out-of-range.js b/test/built-ins/Temporal/PlainTime/prototype/until/roundingincrement-out-of-range.js index 064f18ed40..b761bc3d62 100644 --- a/test/built-ins/Temporal/PlainTime/prototype/until/roundingincrement-out-of-range.js +++ b/test/built-ins/Temporal/PlainTime/prototype/until/roundingincrement-out-of-range.js @@ -5,8 +5,13 @@ esid: sec-temporal.plaintime.prototype.until description: RangeError thrown when roundingIncrement option out of range info: | - sec-temporal-totemporalroundingincrement step 6: - 6. If _increment_ < 1 or _increment_ > _maximum_, throw a *RangeError* exception. + ToTemporalRoundingIncrement ( _normalizedOptions_ ) + + 1. Let _increment_ be ? GetOption(_normalizedOptions_, *"roundingIncrement"*, *"number"*, *undefined*, *1*𝔽). + 2. If _increment_ is not finite, throw a *RangeError* exception. + 3. Let _integerIncrement_ be truncate(ℝ(_increment_)). + 4. If _integerIncrement_ < 1 or _integerIncrement_ > 109, throw a *RangeError* exception. + 5. Return _integerIncrement_. features: [Temporal] ---*/ @@ -15,4 +20,6 @@ const later = new Temporal.PlainTime(12, 34, 56, 0, 0, 5); assert.throws(RangeError, () => earlier.until(later, { roundingIncrement: -Infinity })); assert.throws(RangeError, () => earlier.until(later, { roundingIncrement: -1 })); assert.throws(RangeError, () => earlier.until(later, { roundingIncrement: 0 })); +assert.throws(RangeError, () => earlier.until(later, { roundingIncrement: 0.9 })); +assert.throws(RangeError, () => earlier.until(later, { roundingIncrement: 1e9 + 1 })); assert.throws(RangeError, () => earlier.until(later, { roundingIncrement: Infinity })); diff --git a/test/built-ins/Temporal/PlainYearMonth/prototype/since/roundingincrement-non-integer.js b/test/built-ins/Temporal/PlainYearMonth/prototype/since/roundingincrement-non-integer.js index 0b9cc88ef3..985ee9f20b 100644 --- a/test/built-ins/Temporal/PlainYearMonth/prototype/since/roundingincrement-non-integer.js +++ b/test/built-ins/Temporal/PlainYearMonth/prototype/since/roundingincrement-non-integer.js @@ -5,13 +5,20 @@ esid: sec-temporal.plainyearmonth.prototype.since description: Rounding for roundingIncrement option info: | - sec-temporal-totemporalroundingincrement step 7: - 7. Set _increment_ to floor(ℝ(_increment_)). + ToTemporalRoundingIncrement ( _normalizedOptions_ ) + + 1. Let _increment_ be ? GetOption(_normalizedOptions_, *"roundingIncrement"*, *"number"*, *undefined*, *1*𝔽). + 2. If _increment_ is not finite, throw a *RangeError* exception. + 3. Let _integerIncrement_ be truncate(ℝ(_increment_)). + 4. If _integerIncrement_ < 1 or _integerIncrement_ > 109, throw a *RangeError* exception. + 5. Return _integerIncrement_. includes: [temporalHelpers.js] features: [Temporal] ---*/ const earlier = new Temporal.PlainYearMonth(2000, 5); const later = new Temporal.PlainYearMonth(2000, 10); -const result = later.since(earlier, { roundingIncrement: 2.5 }); -TemporalHelpers.assertDuration(result, 0, 4, 0, 0, 0, 0, 0, 0, 0, 0, "roundingIncrement 2.5 floors to 2"); +const result = later.since(earlier, { roundingIncrement: 2.5, roundingMode: "trunc" }); +TemporalHelpers.assertDuration(result, 0, 4, 0, 0, 0, 0, 0, 0, 0, 0, "roundingIncrement 2.5 truncates to 2"); +const result2 = later.since(earlier, { smallestUnit: "months", roundingIncrement: 1e9 + 0.5, roundingMode: "expand" }); +TemporalHelpers.assertDuration(result2, 0, 1e9, 0, 0, 0, 0, 0, 0, 0, 0, "roundingIncrement 1e9 + 0.5 truncates to 1e9"); diff --git a/test/built-ins/Temporal/PlainYearMonth/prototype/since/roundingincrement-out-of-range.js b/test/built-ins/Temporal/PlainYearMonth/prototype/since/roundingincrement-out-of-range.js index 50710ab183..c65a701c21 100644 --- a/test/built-ins/Temporal/PlainYearMonth/prototype/since/roundingincrement-out-of-range.js +++ b/test/built-ins/Temporal/PlainYearMonth/prototype/since/roundingincrement-out-of-range.js @@ -5,8 +5,13 @@ esid: sec-temporal.plainyearmonth.prototype.since description: RangeError thrown when roundingIncrement option out of range info: | - sec-temporal-totemporalroundingincrement step 6: - 6. If _increment_ < 1 or _increment_ > _maximum_, throw a *RangeError* exception. + ToTemporalRoundingIncrement ( _normalizedOptions_ ) + + 1. Let _increment_ be ? GetOption(_normalizedOptions_, *"roundingIncrement"*, *"number"*, *undefined*, *1*𝔽). + 2. If _increment_ is not finite, throw a *RangeError* exception. + 3. Let _integerIncrement_ be truncate(ℝ(_increment_)). + 4. If _integerIncrement_ < 1 or _integerIncrement_ > 109, throw a *RangeError* exception. + 5. Return _integerIncrement_. features: [Temporal] ---*/ @@ -15,4 +20,6 @@ const later = new Temporal.PlainYearMonth(2000, 10); assert.throws(RangeError, () => later.since(earlier, { roundingIncrement: -Infinity })); assert.throws(RangeError, () => later.since(earlier, { roundingIncrement: -1 })); assert.throws(RangeError, () => later.since(earlier, { roundingIncrement: 0 })); +assert.throws(RangeError, () => later.since(earlier, { roundingIncrement: 0.9 })); +assert.throws(RangeError, () => later.since(earlier, { roundingIncrement: 1e9 + 1 })); assert.throws(RangeError, () => later.since(earlier, { roundingIncrement: Infinity })); diff --git a/test/built-ins/Temporal/PlainYearMonth/prototype/until/roundingincrement-non-integer.js b/test/built-ins/Temporal/PlainYearMonth/prototype/until/roundingincrement-non-integer.js index 013e60247d..0f7f40bec5 100644 --- a/test/built-ins/Temporal/PlainYearMonth/prototype/until/roundingincrement-non-integer.js +++ b/test/built-ins/Temporal/PlainYearMonth/prototype/until/roundingincrement-non-integer.js @@ -5,13 +5,20 @@ esid: sec-temporal.plainyearmonth.prototype.until description: Rounding for roundingIncrement option info: | - sec-temporal-totemporalroundingincrement step 7: - 7. Set _increment_ to floor(ℝ(_increment_)). + ToTemporalRoundingIncrement ( _normalizedOptions_ ) + + 1. Let _increment_ be ? GetOption(_normalizedOptions_, *"roundingIncrement"*, *"number"*, *undefined*, *1*𝔽). + 2. If _increment_ is not finite, throw a *RangeError* exception. + 3. Let _integerIncrement_ be truncate(ℝ(_increment_)). + 4. If _integerIncrement_ < 1 or _integerIncrement_ > 109, throw a *RangeError* exception. + 5. Return _integerIncrement_. includes: [temporalHelpers.js] features: [Temporal] ---*/ const earlier = new Temporal.PlainYearMonth(2000, 5); const later = new Temporal.PlainYearMonth(2000, 10); -const result = earlier.until(later, { roundingIncrement: 2.5 }); -TemporalHelpers.assertDuration(result, 0, 4, 0, 0, 0, 0, 0, 0, 0, 0, "roundingIncrement 2.5 floors to 2"); +const result = earlier.until(later, { roundingIncrement: 2.5, roundingMode: "trunc" }); +TemporalHelpers.assertDuration(result, 0, 4, 0, 0, 0, 0, 0, 0, 0, 0, "roundingIncrement 2.5 truncates to 2"); +const result2 = earlier.until(later, { smallestUnit: "months", roundingIncrement: 1e9 + 0.5, roundingMode: "expand" }); +TemporalHelpers.assertDuration(result2, 0, 1e9, 0, 0, 0, 0, 0, 0, 0, 0, "roundingIncrement 1e9 + 0.5 truncates to 1e9"); diff --git a/test/built-ins/Temporal/PlainYearMonth/prototype/until/roundingincrement-out-of-range.js b/test/built-ins/Temporal/PlainYearMonth/prototype/until/roundingincrement-out-of-range.js index a798154825..05493ee8d3 100644 --- a/test/built-ins/Temporal/PlainYearMonth/prototype/until/roundingincrement-out-of-range.js +++ b/test/built-ins/Temporal/PlainYearMonth/prototype/until/roundingincrement-out-of-range.js @@ -5,8 +5,13 @@ esid: sec-temporal.plainyearmonth.prototype.until description: RangeError thrown when roundingIncrement option out of range info: | - sec-temporal-totemporalroundingincrement step 6: - 6. If _increment_ < 1 or _increment_ > _maximum_, throw a *RangeError* exception. + ToTemporalRoundingIncrement ( _normalizedOptions_ ) + + 1. Let _increment_ be ? GetOption(_normalizedOptions_, *"roundingIncrement"*, *"number"*, *undefined*, *1*𝔽). + 2. If _increment_ is not finite, throw a *RangeError* exception. + 3. Let _integerIncrement_ be truncate(ℝ(_increment_)). + 4. If _integerIncrement_ < 1 or _integerIncrement_ > 109, throw a *RangeError* exception. + 5. Return _integerIncrement_. features: [Temporal] ---*/ @@ -15,4 +20,6 @@ const later = new Temporal.PlainYearMonth(2000, 10); assert.throws(RangeError, () => earlier.until(later, { roundingIncrement: -Infinity })); assert.throws(RangeError, () => earlier.until(later, { roundingIncrement: -1 })); assert.throws(RangeError, () => earlier.until(later, { roundingIncrement: 0 })); +assert.throws(RangeError, () => earlier.until(later, { roundingIncrement: 0.9 })); +assert.throws(RangeError, () => earlier.until(later, { roundingIncrement: 1e9 + 1 })); assert.throws(RangeError, () => earlier.until(later, { roundingIncrement: Infinity })); diff --git a/test/built-ins/Temporal/ZonedDateTime/prototype/round/roundingincrement-non-integer.js b/test/built-ins/Temporal/ZonedDateTime/prototype/round/roundingincrement-non-integer.js index 4bf9d4f417..d40add035b 100644 --- a/test/built-ins/Temporal/ZonedDateTime/prototype/round/roundingincrement-non-integer.js +++ b/test/built-ins/Temporal/ZonedDateTime/prototype/round/roundingincrement-non-integer.js @@ -5,11 +5,16 @@ esid: sec-temporal.zoneddatetime.prototype.round description: Rounding for roundingIncrement option info: | - sec-temporal-totemporalroundingincrement step 7: - 7. Set _increment_ to floor(ℝ(_increment_)). + ToTemporalRoundingIncrement ( _normalizedOptions_ ) + + 1. Let _increment_ be ? GetOption(_normalizedOptions_, *"roundingIncrement"*, *"number"*, *undefined*, *1*𝔽). + 2. If _increment_ is not finite, throw a *RangeError* exception. + 3. Let _integerIncrement_ be truncate(ℝ(_increment_)). + 4. If _integerIncrement_ < 1 or _integerIncrement_ > 109, throw a *RangeError* exception. + 5. Return _integerIncrement_. features: [Temporal] ---*/ const datetime = new Temporal.ZonedDateTime(1_000_000_000_000_000_005n, "UTC"); -const result = datetime.round({ smallestUnit: "nanosecond", roundingIncrement: 2.5 }); -assert.sameValue(result.epochNanoseconds, 1_000_000_000_000_000_006n, "roundingIncrement 2.5 floors to 2"); +const result = datetime.round({ smallestUnit: "nanosecond", roundingIncrement: 2.5, roundingMode: "expand" }); +assert.sameValue(result.epochNanoseconds, 1_000_000_000_000_000_006n, "roundingIncrement 2.5 truncates to 2"); diff --git a/test/built-ins/Temporal/ZonedDateTime/prototype/round/roundingincrement-out-of-range.js b/test/built-ins/Temporal/ZonedDateTime/prototype/round/roundingincrement-out-of-range.js index 61763f2f09..04940cde36 100644 --- a/test/built-ins/Temporal/ZonedDateTime/prototype/round/roundingincrement-out-of-range.js +++ b/test/built-ins/Temporal/ZonedDateTime/prototype/round/roundingincrement-out-of-range.js @@ -5,8 +5,13 @@ esid: sec-temporal.zoneddatetime.prototype.round description: RangeError thrown when roundingIncrement option out of range info: | - sec-temporal-totemporalroundingincrement step 6: - 6. If _increment_ < 1 or _increment_ > _maximum_, throw a *RangeError* exception. + ToTemporalRoundingIncrement ( _normalizedOptions_ ) + + 1. Let _increment_ be ? GetOption(_normalizedOptions_, *"roundingIncrement"*, *"number"*, *undefined*, *1*𝔽). + 2. If _increment_ is not finite, throw a *RangeError* exception. + 3. Let _integerIncrement_ be truncate(ℝ(_increment_)). + 4. If _integerIncrement_ < 1 or _integerIncrement_ > 109, throw a *RangeError* exception. + 5. Return _integerIncrement_. features: [Temporal] ---*/ @@ -14,4 +19,6 @@ const datetime = new Temporal.ZonedDateTime(1_000_000_000_000_000_005n, "UTC"); assert.throws(RangeError, () => datetime.round({ smallestUnit: "nanoseconds", roundingIncrement: -Infinity })); assert.throws(RangeError, () => datetime.round({ smallestUnit: "nanoseconds", roundingIncrement: -1 })); assert.throws(RangeError, () => datetime.round({ smallestUnit: "nanoseconds", roundingIncrement: 0 })); +assert.throws(RangeError, () => datetime.round({ smallestUnit: "nanoseconds", roundingIncrement: 0.9 })); +assert.throws(RangeError, () => datetime.round({ smallestUnit: "nanoseconds", roundingIncrement: 1e9 + 1 })); assert.throws(RangeError, () => datetime.round({ smallestUnit: "nanoseconds", roundingIncrement: Infinity })); diff --git a/test/built-ins/Temporal/ZonedDateTime/prototype/since/roundingincrement-non-integer.js b/test/built-ins/Temporal/ZonedDateTime/prototype/since/roundingincrement-non-integer.js index d228d8fcef..5c31c391ae 100644 --- a/test/built-ins/Temporal/ZonedDateTime/prototype/since/roundingincrement-non-integer.js +++ b/test/built-ins/Temporal/ZonedDateTime/prototype/since/roundingincrement-non-integer.js @@ -5,13 +5,20 @@ esid: sec-temporal.zoneddatetime.prototype.since description: Rounding for roundingIncrement option info: | - sec-temporal-totemporalroundingincrement step 7: - 7. Set _increment_ to floor(ℝ(_increment_)). + ToTemporalRoundingIncrement ( _normalizedOptions_ ) + + 1. Let _increment_ be ? GetOption(_normalizedOptions_, *"roundingIncrement"*, *"number"*, *undefined*, *1*𝔽). + 2. If _increment_ is not finite, throw a *RangeError* exception. + 3. Let _integerIncrement_ be truncate(ℝ(_increment_)). + 4. If _integerIncrement_ < 1 or _integerIncrement_ > 109, throw a *RangeError* exception. + 5. Return _integerIncrement_. includes: [temporalHelpers.js] features: [Temporal] ---*/ const earlier = new Temporal.ZonedDateTime(1_000_000_000_000_000_000n, "UTC"); const later = new Temporal.ZonedDateTime(1_000_000_000_000_000_005n, "UTC"); -const result = later.since(earlier, { roundingIncrement: 2.5 }); -TemporalHelpers.assertDuration(result, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, "roundingIncrement 2.5 floors to 2"); +const result = later.since(earlier, { roundingIncrement: 2.5, roundingMode: "trunc" }); +TemporalHelpers.assertDuration(result, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, "roundingIncrement 2.5 truncates to 2"); +const result2 = later.since(earlier, { smallestUnit: "days", roundingIncrement: 1e9 + 0.5, roundingMode: "expand" }); +TemporalHelpers.assertDuration(result2, 0, 0, 0, 1e9, 0, 0, 0, 0, 0, 0, "roundingIncrement 1e9 + 0.5 truncates to 1e9"); diff --git a/test/built-ins/Temporal/ZonedDateTime/prototype/since/roundingincrement-out-of-range.js b/test/built-ins/Temporal/ZonedDateTime/prototype/since/roundingincrement-out-of-range.js index 81bd48e8a1..fb3306638d 100644 --- a/test/built-ins/Temporal/ZonedDateTime/prototype/since/roundingincrement-out-of-range.js +++ b/test/built-ins/Temporal/ZonedDateTime/prototype/since/roundingincrement-out-of-range.js @@ -5,8 +5,13 @@ esid: sec-temporal.zoneddatetime.prototype.since description: RangeError thrown when roundingIncrement option out of range info: | - sec-temporal-totemporalroundingincrement step 6: - 6. If _increment_ < 1 or _increment_ > _maximum_, throw a *RangeError* exception. + ToTemporalRoundingIncrement ( _normalizedOptions_ ) + + 1. Let _increment_ be ? GetOption(_normalizedOptions_, *"roundingIncrement"*, *"number"*, *undefined*, *1*𝔽). + 2. If _increment_ is not finite, throw a *RangeError* exception. + 3. Let _integerIncrement_ be truncate(ℝ(_increment_)). + 4. If _integerIncrement_ < 1 or _integerIncrement_ > 109, throw a *RangeError* exception. + 5. Return _integerIncrement_. features: [Temporal] ---*/ @@ -15,4 +20,6 @@ const later = new Temporal.ZonedDateTime(1_000_000_000_000_000_005n, "UTC"); assert.throws(RangeError, () => later.since(earlier, { roundingIncrement: -Infinity })); assert.throws(RangeError, () => later.since(earlier, { roundingIncrement: -1 })); assert.throws(RangeError, () => later.since(earlier, { roundingIncrement: 0 })); +assert.throws(RangeError, () => later.since(earlier, { roundingIncrement: 0.9 })); +assert.throws(RangeError, () => later.since(earlier, { roundingIncrement: 1e9 + 1 })); assert.throws(RangeError, () => later.since(earlier, { roundingIncrement: Infinity })); diff --git a/test/built-ins/Temporal/ZonedDateTime/prototype/until/roundingincrement-non-integer.js b/test/built-ins/Temporal/ZonedDateTime/prototype/until/roundingincrement-non-integer.js index 7302c42955..eacbc18066 100644 --- a/test/built-ins/Temporal/ZonedDateTime/prototype/until/roundingincrement-non-integer.js +++ b/test/built-ins/Temporal/ZonedDateTime/prototype/until/roundingincrement-non-integer.js @@ -5,13 +5,20 @@ esid: sec-temporal.zoneddatetime.prototype.until description: Rounding for roundingIncrement option info: | - sec-temporal-totemporalroundingincrement step 7: - 7. Set _increment_ to floor(ℝ(_increment_)). + ToTemporalRoundingIncrement ( _normalizedOptions_ ) + + 1. Let _increment_ be ? GetOption(_normalizedOptions_, *"roundingIncrement"*, *"number"*, *undefined*, *1*𝔽). + 2. If _increment_ is not finite, throw a *RangeError* exception. + 3. Let _integerIncrement_ be truncate(ℝ(_increment_)). + 4. If _integerIncrement_ < 1 or _integerIncrement_ > 109, throw a *RangeError* exception. + 5. Return _integerIncrement_. includes: [temporalHelpers.js] features: [Temporal] ---*/ const earlier = new Temporal.ZonedDateTime(1_000_000_000_000_000_000n, "UTC"); const later = new Temporal.ZonedDateTime(1_000_000_000_000_000_005n, "UTC"); -const result = earlier.until(later, { roundingIncrement: 2.5 }); -TemporalHelpers.assertDuration(result, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, "roundingIncrement 2.5 floors to 2"); +const result = earlier.until(later, { roundingIncrement: 2.5, roundingMode: "trunc" }); +TemporalHelpers.assertDuration(result, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, "roundingIncrement 2.5 truncates to 2"); +const result2 = earlier.until(later, { smallestUnit: "days", roundingIncrement: 1e9 + 0.5, roundingMode: "expand" }); +TemporalHelpers.assertDuration(result2, 0, 0, 0, 1e9, 0, 0, 0, 0, 0, 0, "roundingIncrement 1e9 + 0.5 truncates to 1e9"); diff --git a/test/built-ins/Temporal/ZonedDateTime/prototype/until/roundingincrement-out-of-range.js b/test/built-ins/Temporal/ZonedDateTime/prototype/until/roundingincrement-out-of-range.js index d47d2f76ec..685302647d 100644 --- a/test/built-ins/Temporal/ZonedDateTime/prototype/until/roundingincrement-out-of-range.js +++ b/test/built-ins/Temporal/ZonedDateTime/prototype/until/roundingincrement-out-of-range.js @@ -5,8 +5,13 @@ esid: sec-temporal.zoneddatetime.prototype.until description: RangeError thrown when roundingIncrement option out of range info: | - sec-temporal-totemporalroundingincrement step 6: - 6. If _increment_ < 1 or _increment_ > _maximum_, throw a *RangeError* exception. + ToTemporalRoundingIncrement ( _normalizedOptions_ ) + + 1. Let _increment_ be ? GetOption(_normalizedOptions_, *"roundingIncrement"*, *"number"*, *undefined*, *1*𝔽). + 2. If _increment_ is not finite, throw a *RangeError* exception. + 3. Let _integerIncrement_ be truncate(ℝ(_increment_)). + 4. If _integerIncrement_ < 1 or _integerIncrement_ > 109, throw a *RangeError* exception. + 5. Return _integerIncrement_. features: [Temporal] ---*/ @@ -15,4 +20,6 @@ const later = new Temporal.ZonedDateTime(1_000_000_000_000_000_005n, "UTC"); assert.throws(RangeError, () => earlier.until(later, { roundingIncrement: -Infinity })); assert.throws(RangeError, () => earlier.until(later, { roundingIncrement: -1 })); assert.throws(RangeError, () => earlier.until(later, { roundingIncrement: 0 })); +assert.throws(RangeError, () => earlier.until(later, { roundingIncrement: 0.9 })); +assert.throws(RangeError, () => earlier.until(later, { roundingIncrement: 1e9 + 1 })); assert.throws(RangeError, () => earlier.until(later, { roundingIncrement: Infinity })); diff --git a/test/staging/Temporal/Instant/old/round.js b/test/staging/Temporal/Instant/old/round.js index fd142c5c55..01b88205dc 100644 --- a/test/staging/Temporal/Instant/old/round.js +++ b/test/staging/Temporal/Instant/old/round.js @@ -70,14 +70,6 @@ assert.sameValue(`${ inst.round({ smallestUnit: "millisecond", roundingIncrement: 86400000 }) }`, expected); -assert.sameValue(`${ inst.round({ - smallestUnit: "microsecond", - roundingIncrement: 86400000000 -}) }`, expected); -assert.sameValue(`${ inst.round({ - smallestUnit: "nanosecond", - roundingIncrement: 86400000000000 -}) }`, expected); // allows increments that divide evenly into solar days assert(inst.round({