From f4a987fe3ce0c6d6c36e325fc455aedb6d1724d5 Mon Sep 17 00:00:00 2001 From: Philip Chimento Date: Wed, 2 Oct 2024 14:59:37 -0700 Subject: [PATCH] Temporal: Additional tests for cases where date addition goes out of range See tc39/proposal-temporal#2985 --- .../prototype/round/next-day-out-of-range.js | 18 ++++++++++++++++++ .../hoursInDay/next-day-out-of-range.js | 13 +++++++++++++ .../round/day-rounding-out-of-range.js | 13 +++++++++++++ 3 files changed, 44 insertions(+) create mode 100644 test/built-ins/Temporal/Duration/prototype/round/next-day-out-of-range.js create mode 100644 test/built-ins/Temporal/ZonedDateTime/prototype/hoursInDay/next-day-out-of-range.js create mode 100644 test/built-ins/Temporal/ZonedDateTime/prototype/round/day-rounding-out-of-range.js diff --git a/test/built-ins/Temporal/Duration/prototype/round/next-day-out-of-range.js b/test/built-ins/Temporal/Duration/prototype/round/next-day-out-of-range.js new file mode 100644 index 0000000000..0a41bc6084 --- /dev/null +++ b/test/built-ins/Temporal/Duration/prototype/round/next-day-out-of-range.js @@ -0,0 +1,18 @@ +// Copyright (C) 2024 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.zoneddatetime.prototype.hoursinday +description: > + Finding the boundary with the next day may throw if the instance is at the + upper edge of the representable range +features: [Temporal] +---*/ + +const instance = new Temporal.Duration(); +const relativeTo = new Temporal.ZonedDateTime(86400_0000_0000_000_000_000n, "UTC"); +assert.throws( + RangeError, + () => instance.round({ largestUnit: "days", smallestUnit: "minutes", relativeTo }), + "Next day boundary is out of range" +); diff --git a/test/built-ins/Temporal/ZonedDateTime/prototype/hoursInDay/next-day-out-of-range.js b/test/built-ins/Temporal/ZonedDateTime/prototype/hoursInDay/next-day-out-of-range.js new file mode 100644 index 0000000000..5ecc9cee17 --- /dev/null +++ b/test/built-ins/Temporal/ZonedDateTime/prototype/hoursInDay/next-day-out-of-range.js @@ -0,0 +1,13 @@ +// Copyright (C) 2024 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.zoneddatetime.prototype.hoursinday +description: > + Finding the boundary with the next day may throw if the instance is at the + upper edge of the representable range +features: [Temporal] +---*/ + +const z = new Temporal.ZonedDateTime(86400_0000_0000_000_000_000n, "UTC"); +assert.throws(RangeError, () => z.hoursInDay, "Next day boundary is out of range"); diff --git a/test/built-ins/Temporal/ZonedDateTime/prototype/round/day-rounding-out-of-range.js b/test/built-ins/Temporal/ZonedDateTime/prototype/round/day-rounding-out-of-range.js new file mode 100644 index 0000000000..c6861e757f --- /dev/null +++ b/test/built-ins/Temporal/ZonedDateTime/prototype/round/day-rounding-out-of-range.js @@ -0,0 +1,13 @@ +// Copyright (C) 2024 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.zoneddatetime.prototype.round +description: > + Finding the upper bound for day rounding may fail if the instance is at the + upper edge of the representable range +features: [Temporal] +---*/ + +const instance = new Temporal.ZonedDateTime(86400_0000_0000_000_000_000n, "UTC"); +assert.throws(RangeError, () => instance.round({ smallestUnit: 'day' }), "Upper bound for rounding is out of range");