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
This commit is contained in:
Tim Chevalier 2025-10-29 18:04:05 -07:00 committed by GitHub
parent 759fe87f1c
commit 61d0eb9167
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 120 additions and 0 deletions

View File

@ -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()));

View File

@ -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()));

View File

@ -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()));

View File

@ -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()));

View File

@ -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()));

View File

@ -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()));

View File

@ -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()));

View File

@ -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()));