From 01eb47d4f219530a3ee74a50c4fca46afec4bf83 Mon Sep 17 00:00:00 2001 From: Tim Chevalier Date: Fri, 1 Nov 2024 11:36:01 -0700 Subject: [PATCH] Add tests for adding negative durations to/subtracting durations from the last representable year/month of the ISO calendar See https://github.com/tc39/proposal-temporal/issues/3029 --- .../subtract-from-last-representable-month.js | 21 +++++++++++++++++++ .../subtract-from-last-representable-month.js | 21 +++++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100644 test/built-ins/Temporal/PlainYearMonth/prototype/add/subtract-from-last-representable-month.js create mode 100644 test/built-ins/Temporal/PlainYearMonth/prototype/subtract/subtract-from-last-representable-month.js diff --git a/test/built-ins/Temporal/PlainYearMonth/prototype/add/subtract-from-last-representable-month.js b/test/built-ins/Temporal/PlainYearMonth/prototype/add/subtract-from-last-representable-month.js new file mode 100644 index 0000000000..3c03b1bbca --- /dev/null +++ b/test/built-ins/Temporal/PlainYearMonth/prototype/add/subtract-from-last-representable-month.js @@ -0,0 +1,21 @@ +// 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.plainyearmonth.prototype.add +description: RangeError thrown when adding negative duration to last representable month. +features: [Temporal] +---*/ + +const lastMonth = new Temporal.PlainYearMonth(275760, 9); + +// See https://tc39.es/proposal-temporal/#sec-temporal-adddurationtoyearmonth +// (step 10d) +assert.throws(RangeError, () => lastMonth.add({seconds: -1})); +assert.throws(RangeError, () => lastMonth.add({minutes: -1})); +assert.throws(RangeError, () => lastMonth.add({hours: -1})); +assert.throws(RangeError, () => lastMonth.add({days: -1})); +assert.throws(RangeError, () => lastMonth.add({weeks: -1})); +assert.throws(RangeError, () => lastMonth.add({months: -1})); +assert.throws(RangeError, () => lastMonth.add({years: -1})); + diff --git a/test/built-ins/Temporal/PlainYearMonth/prototype/subtract/subtract-from-last-representable-month.js b/test/built-ins/Temporal/PlainYearMonth/prototype/subtract/subtract-from-last-representable-month.js new file mode 100644 index 0000000000..841d95f122 --- /dev/null +++ b/test/built-ins/Temporal/PlainYearMonth/prototype/subtract/subtract-from-last-representable-month.js @@ -0,0 +1,21 @@ +// 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.plainyearmonth.prototype.subtract +description: RangeError thrown when subtracting duration from last representable month. +features: [Temporal] +---*/ + +const lastMonth = new Temporal.PlainYearMonth(275760, 9); + +// See https://tc39.es/proposal-temporal/#sec-temporal-adddurationtoyearmonth +// (step 10d) +assert.throws(RangeError, () => lastMonth.subtract({seconds: 1})); +assert.throws(RangeError, () => lastMonth.subtract({minutes: 1})); +assert.throws(RangeError, () => lastMonth.subtract({hours: 1})); +assert.throws(RangeError, () => lastMonth.subtract({days: 1})); +assert.throws(RangeError, () => lastMonth.subtract({weeks: 1})); +assert.throws(RangeError, () => lastMonth.subtract({months: 1})); +assert.throws(RangeError, () => lastMonth.subtract({years: 1})); +