From 61d0eb9167bbabf4de24741b5fbb6634e490d4b2 Mon Sep 17 00:00:00 2001 From: Tim Chevalier Date: Wed, 29 Oct 2025 18:04:05 -0700 Subject: [PATCH] Temporal: Add an overflow test for date addition with maximum year (#4618) * Temporal: Add an overflow test for date addition with maximum year * Add tests for other cases * Fix minimum dates * Add cases for adding/subtracting the negated duration to the opposite end of the allowed years --- .../add/overflow-adding-months-to-max-year.js | 15 +++++++++++++++ .../overflow-subtracting-months-from-min-year.js | 15 +++++++++++++++ .../add/overflow-adding-months-to-max-year.js | 15 +++++++++++++++ .../overflow-subtracting-months-from-min-year.js | 15 +++++++++++++++ .../add/overflow-adding-months-to-max-year.js | 15 +++++++++++++++ .../overflow-subtracting-months-from-min-year.js | 15 +++++++++++++++ .../add/overflow-adding-months-to-max-year.js | 15 +++++++++++++++ .../overflow-subtracting-months-from-min-year.js | 15 +++++++++++++++ 8 files changed, 120 insertions(+) create mode 100644 test/built-ins/Temporal/PlainDate/prototype/add/overflow-adding-months-to-max-year.js create mode 100644 test/built-ins/Temporal/PlainDate/prototype/subtract/overflow-subtracting-months-from-min-year.js create mode 100644 test/built-ins/Temporal/PlainDateTime/prototype/add/overflow-adding-months-to-max-year.js create mode 100644 test/built-ins/Temporal/PlainDateTime/prototype/subtract/overflow-subtracting-months-from-min-year.js create mode 100644 test/built-ins/Temporal/PlainYearMonth/prototype/add/overflow-adding-months-to-max-year.js create mode 100644 test/built-ins/Temporal/PlainYearMonth/prototype/subtract/overflow-subtracting-months-from-min-year.js create mode 100644 test/built-ins/Temporal/ZonedDateTime/prototype/add/overflow-adding-months-to-max-year.js create mode 100644 test/built-ins/Temporal/ZonedDateTime/prototype/subtract/overflow-subtracting-months-from-min-year.js diff --git a/test/built-ins/Temporal/PlainDate/prototype/add/overflow-adding-months-to-max-year.js b/test/built-ins/Temporal/PlainDate/prototype/add/overflow-adding-months-to-max-year.js new file mode 100644 index 0000000000..c839823790 --- /dev/null +++ b/test/built-ins/Temporal/PlainDate/prototype/add/overflow-adding-months-to-max-year.js @@ -0,0 +1,15 @@ +// Copyright (C) 2025 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plaindate.prototype.add +description: Adding months to maximum year should throw +features: [Temporal] +---*/ + +const maxYear = new Temporal.PlainDate(275760, 1, 1); +const duration = new Temporal.Duration(0, 5432, 5432, 0, 0, 0, 0, 0, 0, 0); +assert.throws(RangeError, () => maxYear.add(duration)); + +const minYear = new Temporal.PlainDate(-271821, 4, 19); +assert.throws(RangeError, () => minYear.add(duration.negated())); diff --git a/test/built-ins/Temporal/PlainDate/prototype/subtract/overflow-subtracting-months-from-min-year.js b/test/built-ins/Temporal/PlainDate/prototype/subtract/overflow-subtracting-months-from-min-year.js new file mode 100644 index 0000000000..818080c1b4 --- /dev/null +++ b/test/built-ins/Temporal/PlainDate/prototype/subtract/overflow-subtracting-months-from-min-year.js @@ -0,0 +1,15 @@ +// Copyright (C) 2025 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plaindate.prototype.subtract +description: Subtracting months from minimum year should throw +features: [Temporal] +---*/ + +const minYear = new Temporal.PlainDate(-271821, 4, 19); +const duration = new Temporal.Duration(0, 5432, 5432, 0, 0, 0, 0, 0, 0, 0); +assert.throws(RangeError, () => minYear.subtract(duration)); + +const maxYear = new Temporal.PlainDate(275760, 1, 1); +assert.throws(RangeError, () => maxYear.subtract(duration.negated())); diff --git a/test/built-ins/Temporal/PlainDateTime/prototype/add/overflow-adding-months-to-max-year.js b/test/built-ins/Temporal/PlainDateTime/prototype/add/overflow-adding-months-to-max-year.js new file mode 100644 index 0000000000..bfcc008281 --- /dev/null +++ b/test/built-ins/Temporal/PlainDateTime/prototype/add/overflow-adding-months-to-max-year.js @@ -0,0 +1,15 @@ +// Copyright (C) 2025 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plaindatetime.prototype.add +description: Adding months to maximum year should throw +features: [Temporal] +---*/ + +const maxYear = new Temporal.PlainDateTime(275760, 1, 1); +const duration = new Temporal.Duration(0, 5432, 5432, 0, 0, 0, 0, 0, 0, 0); +assert.throws(RangeError, () => maxYear.add(duration)); + +const minYear = new Temporal.PlainDateTime(-271821, 4, 19, 0, 0, 0, 0, 0, 1); +assert.throws(RangeError, () => minYear.add(duration.negated())); diff --git a/test/built-ins/Temporal/PlainDateTime/prototype/subtract/overflow-subtracting-months-from-min-year.js b/test/built-ins/Temporal/PlainDateTime/prototype/subtract/overflow-subtracting-months-from-min-year.js new file mode 100644 index 0000000000..93fd563731 --- /dev/null +++ b/test/built-ins/Temporal/PlainDateTime/prototype/subtract/overflow-subtracting-months-from-min-year.js @@ -0,0 +1,15 @@ +// Copyright (C) 2025 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plaindatetime.prototype.subtract +description: Subtracting months from minimum year should throw +features: [Temporal] +---*/ + +const minYear = new Temporal.PlainDateTime(-271821, 4, 19, 0, 0, 0, 0, 0, 1); +const duration = new Temporal.Duration(0, 5432, 5432, 0, 0, 0, 0, 0, 0, 0); +assert.throws(RangeError, () => minYear.subtract(duration)); + +const maxYear = new Temporal.PlainDateTime(275760, 1, 1); +assert.throws(RangeError, () => maxYear.subtract(duration.negated())); diff --git a/test/built-ins/Temporal/PlainYearMonth/prototype/add/overflow-adding-months-to-max-year.js b/test/built-ins/Temporal/PlainYearMonth/prototype/add/overflow-adding-months-to-max-year.js new file mode 100644 index 0000000000..85f468ae85 --- /dev/null +++ b/test/built-ins/Temporal/PlainYearMonth/prototype/add/overflow-adding-months-to-max-year.js @@ -0,0 +1,15 @@ +// Copyright (C) 2025 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plainyearmonth.prototype.add +description: Adding months to maximum year should throw +features: [Temporal] +---*/ + +const maxYear = new Temporal.PlainYearMonth(275760, 1); +const duration = new Temporal.Duration(0, 5432, 5432, 0, 0, 0, 0, 0, 0, 0); +assert.throws(RangeError, () => maxYear.add(duration)); + +const minYear = new Temporal.PlainYearMonth(-271821, 4); +assert.throws(RangeError, () => minYear.add(duration.negated())); diff --git a/test/built-ins/Temporal/PlainYearMonth/prototype/subtract/overflow-subtracting-months-from-min-year.js b/test/built-ins/Temporal/PlainYearMonth/prototype/subtract/overflow-subtracting-months-from-min-year.js new file mode 100644 index 0000000000..794761b1fd --- /dev/null +++ b/test/built-ins/Temporal/PlainYearMonth/prototype/subtract/overflow-subtracting-months-from-min-year.js @@ -0,0 +1,15 @@ +// Copyright (C) 2025 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plainyearmonth.prototype.subtract +description: Subtracting months from minimum year should throw +features: [Temporal] +---*/ + +const minYear = new Temporal.PlainYearMonth(-271821, 4); +const duration = new Temporal.Duration(0, 5432, 5432, 0, 0, 0, 0, 0, 0, 0); +assert.throws(RangeError, () => minYear.subtract(duration)); + +const maxYear = new Temporal.PlainYearMonth(275760, 1); +assert.throws(RangeError, () => maxYear.subtract(duration.negated())); diff --git a/test/built-ins/Temporal/ZonedDateTime/prototype/add/overflow-adding-months-to-max-year.js b/test/built-ins/Temporal/ZonedDateTime/prototype/add/overflow-adding-months-to-max-year.js new file mode 100644 index 0000000000..57f12c1e5a --- /dev/null +++ b/test/built-ins/Temporal/ZonedDateTime/prototype/add/overflow-adding-months-to-max-year.js @@ -0,0 +1,15 @@ +// Copyright (C) 2025 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.zoneddatetime.prototype.add +description: Adding months to maximum year should throw +features: [Temporal] +---*/ + +const maxYear = new Temporal.PlainDate(275760, 1, 1).toZonedDateTime("UTC"); +const duration = new Temporal.Duration(0, 5432, 5432, 0, 0, 0, 0, 0, 0, 0); +assert.throws(RangeError, () => maxYear.add(duration)); + +const minYear = new Temporal.ZonedDateTime(-(864n * 10n ** 19n), "UTC"); +assert.throws(RangeError, () => minYear.add(duration.negated())); diff --git a/test/built-ins/Temporal/ZonedDateTime/prototype/subtract/overflow-subtracting-months-from-min-year.js b/test/built-ins/Temporal/ZonedDateTime/prototype/subtract/overflow-subtracting-months-from-min-year.js new file mode 100644 index 0000000000..b16643b08a --- /dev/null +++ b/test/built-ins/Temporal/ZonedDateTime/prototype/subtract/overflow-subtracting-months-from-min-year.js @@ -0,0 +1,15 @@ +// Copyright (C) 2025 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.zoneddatetime.prototype.subtract +description: Subtracting months from minimum year should throw +features: [Temporal] +---*/ + +const minYear = new Temporal.ZonedDateTime(-(864n * 10n ** 19n), "UTC"); +const duration = new Temporal.Duration(0, 5432, 5432, 0, 0, 0, 0, 0, 0, 0); +assert.throws(RangeError, () => minYear.subtract(duration)); + +const maxYear = new Temporal.PlainDateTime(275760, 1, 1).toZonedDateTime("UTC"); +assert.throws(RangeError, () => maxYear.subtract(duration.negated()));