From caef6b2082e328d485d74eede71815de6bc8bcb2 Mon Sep 17 00:00:00 2001 From: Philip Chimento Date: Tue, 18 Nov 2025 20:57:21 -0800 Subject: [PATCH] Intl Era Monthcode: Tests for with() around Gregorian-like leap years Adds tests for with() in the four calendars with Gregorian-like leap years (buddhist, gregory, japanese, roc). --- .../prototype/with/leap-year-buddhist.js | 28 +++++++++++++++++++ .../prototype/with/leap-year-gregory.js | 28 +++++++++++++++++++ .../prototype/with/leap-year-japanese.js | 28 +++++++++++++++++++ .../PlainDate/prototype/with/leap-year-roc.js | 28 +++++++++++++++++++ .../prototype/with/leap-year-buddhist.js | 28 +++++++++++++++++++ .../prototype/with/leap-year-gregory.js | 28 +++++++++++++++++++ .../prototype/with/leap-year-japanese.js | 28 +++++++++++++++++++ .../prototype/with/leap-year-roc.js | 28 +++++++++++++++++++ .../prototype/with/leap-year-buddhist.js | 28 +++++++++++++++++++ .../prototype/with/leap-year-gregory.js | 28 +++++++++++++++++++ .../prototype/with/leap-year-japanese.js | 28 +++++++++++++++++++ .../prototype/with/leap-year-roc.js | 28 +++++++++++++++++++ 12 files changed, 336 insertions(+) create mode 100644 test/intl402/Temporal/PlainDate/prototype/with/leap-year-buddhist.js create mode 100644 test/intl402/Temporal/PlainDate/prototype/with/leap-year-gregory.js create mode 100644 test/intl402/Temporal/PlainDate/prototype/with/leap-year-japanese.js create mode 100644 test/intl402/Temporal/PlainDate/prototype/with/leap-year-roc.js create mode 100644 test/intl402/Temporal/PlainDateTime/prototype/with/leap-year-buddhist.js create mode 100644 test/intl402/Temporal/PlainDateTime/prototype/with/leap-year-gregory.js create mode 100644 test/intl402/Temporal/PlainDateTime/prototype/with/leap-year-japanese.js create mode 100644 test/intl402/Temporal/PlainDateTime/prototype/with/leap-year-roc.js create mode 100644 test/intl402/Temporal/ZonedDateTime/prototype/with/leap-year-buddhist.js create mode 100644 test/intl402/Temporal/ZonedDateTime/prototype/with/leap-year-gregory.js create mode 100644 test/intl402/Temporal/ZonedDateTime/prototype/with/leap-year-japanese.js create mode 100644 test/intl402/Temporal/ZonedDateTime/prototype/with/leap-year-roc.js diff --git a/test/intl402/Temporal/PlainDate/prototype/with/leap-year-buddhist.js b/test/intl402/Temporal/PlainDate/prototype/with/leap-year-buddhist.js new file mode 100644 index 0000000000..07d9cbfb9f --- /dev/null +++ b/test/intl402/Temporal/PlainDate/prototype/with/leap-year-buddhist.js @@ -0,0 +1,28 @@ +// 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.with +description: Check constraining days when year changes (buddhist calendar) +features: [Temporal, Intl.Era-monthcode] +includes: [temporalHelpers.js] +---*/ + +const calendar = "buddhist"; +const options = { overflow: "reject" }; + +const leapDay = Temporal.PlainDate.from({ year: 2559, monthCode: "M02", day: 29, calendar }, options); + +TemporalHelpers.assertPlainDate( + leapDay.with({ year: 2555 }, options), + 2555, 2, "M02", 29, "day not constrained when moving to another leap year", + "be", 2555); + +TemporalHelpers.assertPlainDate( + leapDay.with({ year: 2561 }), + 2561, 2, "M02", 28, "day constrained when moving to a common year", + "be", 2561); + +assert.throws(RangeError, function () { + leapDay.with({ year: 2561 }, options); +}, "reject when moving to a common year"); diff --git a/test/intl402/Temporal/PlainDate/prototype/with/leap-year-gregory.js b/test/intl402/Temporal/PlainDate/prototype/with/leap-year-gregory.js new file mode 100644 index 0000000000..a90c740ef0 --- /dev/null +++ b/test/intl402/Temporal/PlainDate/prototype/with/leap-year-gregory.js @@ -0,0 +1,28 @@ +// 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.with +description: Check constraining days when year changes (gregory calendar) +features: [Temporal, Intl.Era-monthcode] +includes: [temporalHelpers.js] +---*/ + +const calendar = "gregory"; +const options = { overflow: "reject" }; + +const leapDay = Temporal.PlainDate.from({ year: 2016, monthCode: "M02", day: 29, calendar }, options); + +TemporalHelpers.assertPlainDate( + leapDay.with({ year: 2012 }, options), + 2012, 2, "M02", 29, "day not constrained when moving to another leap year", + "ce", 2012); + +TemporalHelpers.assertPlainDate( + leapDay.with({ year: 2018 }), + 2018, 2, "M02", 28, "day constrained when moving to a common year", + "ce", 2018); + +assert.throws(RangeError, function () { + leapDay.with({ year: 2018 }, options); +}, "reject when moving to a common year"); diff --git a/test/intl402/Temporal/PlainDate/prototype/with/leap-year-japanese.js b/test/intl402/Temporal/PlainDate/prototype/with/leap-year-japanese.js new file mode 100644 index 0000000000..e2ca310dfb --- /dev/null +++ b/test/intl402/Temporal/PlainDate/prototype/with/leap-year-japanese.js @@ -0,0 +1,28 @@ +// 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.with +description: Check constraining days when year changes (japanese calendar) +features: [Temporal, Intl.Era-monthcode] +includes: [temporalHelpers.js] +---*/ + +const calendar = "japanese"; +const options = { overflow: "reject" }; + +const leapDay = Temporal.PlainDate.from({ year: 2016, monthCode: "M02", day: 29, calendar }, options); + +TemporalHelpers.assertPlainDate( + leapDay.with({ year: 2012 }, options), + 2012, 2, "M02", 29, "day not constrained when moving to another leap year", + "heisei", 24); + +TemporalHelpers.assertPlainDate( + leapDay.with({ year: 2018 }), + 2018, 2, "M02", 28, "day constrained when moving to a common year", + "heisei", 30); + +assert.throws(RangeError, function () { + leapDay.with({ year: 2018 }, options); +}, "reject when moving to a common year"); diff --git a/test/intl402/Temporal/PlainDate/prototype/with/leap-year-roc.js b/test/intl402/Temporal/PlainDate/prototype/with/leap-year-roc.js new file mode 100644 index 0000000000..16254c887a --- /dev/null +++ b/test/intl402/Temporal/PlainDate/prototype/with/leap-year-roc.js @@ -0,0 +1,28 @@ +// 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.with +description: Check constraining days when year changes (roc calendar) +features: [Temporal, Intl.Era-monthcode] +includes: [temporalHelpers.js] +---*/ + +const calendar = "roc"; +const options = { overflow: "reject" }; + +const leapDay = Temporal.PlainDate.from({ year: 105, monthCode: "M02", day: 29, calendar }, options); + +TemporalHelpers.assertPlainDate( + leapDay.with({ year: 101 }, options), + 101, 2, "M02", 29, "day not constrained when moving to another leap year", + "roc", 101); + +TemporalHelpers.assertPlainDate( + leapDay.with({ year: 107 }), + 107, 2, "M02", 28, "day constrained when moving to a common year", + "roc", 107); + +assert.throws(RangeError, function () { + leapDay.with({ year: 107 }, options); +}, "reject when moving to a common year"); diff --git a/test/intl402/Temporal/PlainDateTime/prototype/with/leap-year-buddhist.js b/test/intl402/Temporal/PlainDateTime/prototype/with/leap-year-buddhist.js new file mode 100644 index 0000000000..f81143e6e0 --- /dev/null +++ b/test/intl402/Temporal/PlainDateTime/prototype/with/leap-year-buddhist.js @@ -0,0 +1,28 @@ +// 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.with +description: Check constraining days when year changes (buddhist calendar) +features: [Temporal, Intl.Era-monthcode] +includes: [temporalHelpers.js] +---*/ + +const calendar = "buddhist"; +const options = { overflow: "reject" }; + +const leapDay = Temporal.PlainDateTime.from({ year: 2559, monthCode: "M02", day: 29, hour: 12, minute: 34, calendar }, options); + +TemporalHelpers.assertPlainDateTime( + leapDay.with({ year: 2555 }, options), + 2555, 2, "M02", 29, 12, 34, 0, 0, 0, 0,"day not constrained when moving to another leap year", + "be", 2555); + +TemporalHelpers.assertPlainDateTime( + leapDay.with({ year: 2561 }), + 2561, 2, "M02", 28, 12, 34, 0, 0, 0, 0,"day constrained when moving to a common year", + "be", 2561); + +assert.throws(RangeError, function () { + leapDay.with({ year: 2561 }, options); +}, "reject when moving to a common year"); diff --git a/test/intl402/Temporal/PlainDateTime/prototype/with/leap-year-gregory.js b/test/intl402/Temporal/PlainDateTime/prototype/with/leap-year-gregory.js new file mode 100644 index 0000000000..289a6ef5cc --- /dev/null +++ b/test/intl402/Temporal/PlainDateTime/prototype/with/leap-year-gregory.js @@ -0,0 +1,28 @@ +// 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.with +description: Check constraining days when year changes (gregory calendar) +features: [Temporal, Intl.Era-monthcode] +includes: [temporalHelpers.js] +---*/ + +const calendar = "gregory"; +const options = { overflow: "reject" }; + +const leapDay = Temporal.PlainDateTime.from({ year: 2016, monthCode: "M02", day: 29, hour: 12, minute: 34, calendar }, options); + +TemporalHelpers.assertPlainDateTime( + leapDay.with({ year: 2012 }, options), + 2012, 2, "M02", 29, 12, 34, 0, 0, 0, 0,"day not constrained when moving to another leap year", + "ce", 2012); + +TemporalHelpers.assertPlainDateTime( + leapDay.with({ year: 2018 }), + 2018, 2, "M02", 28, 12, 34, 0, 0, 0, 0,"day constrained when moving to a common year", + "ce", 2018); + +assert.throws(RangeError, function () { + leapDay.with({ year: 2018 }, options); +}, "reject when moving to a common year"); diff --git a/test/intl402/Temporal/PlainDateTime/prototype/with/leap-year-japanese.js b/test/intl402/Temporal/PlainDateTime/prototype/with/leap-year-japanese.js new file mode 100644 index 0000000000..c3af480a8e --- /dev/null +++ b/test/intl402/Temporal/PlainDateTime/prototype/with/leap-year-japanese.js @@ -0,0 +1,28 @@ +// 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.with +description: Check constraining days when year changes (japanese calendar) +features: [Temporal, Intl.Era-monthcode] +includes: [temporalHelpers.js] +---*/ + +const calendar = "japanese"; +const options = { overflow: "reject" }; + +const leapDay = Temporal.PlainDateTime.from({ year: 2016, monthCode: "M02", day: 29, hour: 12, minute: 34, calendar }, options); + +TemporalHelpers.assertPlainDateTime( + leapDay.with({ year: 2012 }, options), + 2012, 2, "M02", 29, 12, 34, 0, 0, 0, 0,"day not constrained when moving to another leap year", + "heisei", 24); + +TemporalHelpers.assertPlainDateTime( + leapDay.with({ year: 2018 }), + 2018, 2, "M02", 28, 12, 34, 0, 0, 0, 0,"day constrained when moving to a common year", + "heisei", 30); + +assert.throws(RangeError, function () { + leapDay.with({ year: 2018 }, options); +}, "reject when moving to a common year"); diff --git a/test/intl402/Temporal/PlainDateTime/prototype/with/leap-year-roc.js b/test/intl402/Temporal/PlainDateTime/prototype/with/leap-year-roc.js new file mode 100644 index 0000000000..bdf6aecbde --- /dev/null +++ b/test/intl402/Temporal/PlainDateTime/prototype/with/leap-year-roc.js @@ -0,0 +1,28 @@ +// 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.with +description: Check constraining days when year changes (roc calendar) +features: [Temporal, Intl.Era-monthcode] +includes: [temporalHelpers.js] +---*/ + +const calendar = "roc"; +const options = { overflow: "reject" }; + +const leapDay = Temporal.PlainDateTime.from({ year: 105, monthCode: "M02", day: 29, hour: 12, minute: 34, calendar }, options); + +TemporalHelpers.assertPlainDateTime( + leapDay.with({ year: 101 }, options), + 101, 2, "M02", 29, 12, 34, 0, 0, 0, 0,"day not constrained when moving to another leap year", + "roc", 101); + +TemporalHelpers.assertPlainDateTime( + leapDay.with({ year: 107 }), + 107, 2, "M02", 28, 12, 34, 0, 0, 0, 0,"day constrained when moving to a common year", + "roc", 107); + +assert.throws(RangeError, function () { + leapDay.with({ year: 107 }, options); +}, "reject when moving to a common year"); diff --git a/test/intl402/Temporal/ZonedDateTime/prototype/with/leap-year-buddhist.js b/test/intl402/Temporal/ZonedDateTime/prototype/with/leap-year-buddhist.js new file mode 100644 index 0000000000..f4f62c5a77 --- /dev/null +++ b/test/intl402/Temporal/ZonedDateTime/prototype/with/leap-year-buddhist.js @@ -0,0 +1,28 @@ +// 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.with +description: Check constraining days when year changes (buddhist calendar) +features: [Temporal, Intl.Era-monthcode] +includes: [temporalHelpers.js] +---*/ + +const calendar = "buddhist"; +const options = { overflow: "reject" }; + +const leapDay = Temporal.ZonedDateTime.from({ year: 2559, monthCode: "M02", day: 29, hour: 12, minute: 34, timeZone: "UTC", calendar }, options); + +TemporalHelpers.assertPlainDateTime( + leapDay.with({ year: 2555 }, options).toPlainDateTime(), + 2555, 2, "M02", 29, 12, 34, 0, 0, 0, 0,"day not constrained when moving to another leap year", + "be", 2555); + +TemporalHelpers.assertPlainDateTime( + leapDay.with({ year: 2561 }).toPlainDateTime(), + 2561, 2, "M02", 28, 12, 34, 0, 0, 0, 0,"day constrained when moving to a common year", + "be", 2561); + +assert.throws(RangeError, function () { + leapDay.with({ year: 2561 }, options); +}, "reject when moving to a common year"); diff --git a/test/intl402/Temporal/ZonedDateTime/prototype/with/leap-year-gregory.js b/test/intl402/Temporal/ZonedDateTime/prototype/with/leap-year-gregory.js new file mode 100644 index 0000000000..8098411399 --- /dev/null +++ b/test/intl402/Temporal/ZonedDateTime/prototype/with/leap-year-gregory.js @@ -0,0 +1,28 @@ +// 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.with +description: Check constraining days when year changes (gregory calendar) +features: [Temporal, Intl.Era-monthcode] +includes: [temporalHelpers.js] +---*/ + +const calendar = "gregory"; +const options = { overflow: "reject" }; + +const leapDay = Temporal.ZonedDateTime.from({ year: 2016, monthCode: "M02", day: 29, hour: 12, minute: 34, timeZone: "UTC", calendar }, options); + +TemporalHelpers.assertPlainDateTime( + leapDay.with({ year: 2012 }, options).toPlainDateTime(), + 2012, 2, "M02", 29, 12, 34, 0, 0, 0, 0,"day not constrained when moving to another leap year", + "ce", 2012); + +TemporalHelpers.assertPlainDateTime( + leapDay.with({ year: 2018 }).toPlainDateTime(), + 2018, 2, "M02", 28, 12, 34, 0, 0, 0, 0,"day constrained when moving to a common year", + "ce", 2018); + +assert.throws(RangeError, function () { + leapDay.with({ year: 2018 }, options); +}, "reject when moving to a common year"); diff --git a/test/intl402/Temporal/ZonedDateTime/prototype/with/leap-year-japanese.js b/test/intl402/Temporal/ZonedDateTime/prototype/with/leap-year-japanese.js new file mode 100644 index 0000000000..acd8a36e2c --- /dev/null +++ b/test/intl402/Temporal/ZonedDateTime/prototype/with/leap-year-japanese.js @@ -0,0 +1,28 @@ +// 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.with +description: Check constraining days when year changes (japanese calendar) +features: [Temporal, Intl.Era-monthcode] +includes: [temporalHelpers.js] +---*/ + +const calendar = "japanese"; +const options = { overflow: "reject" }; + +const leapDay = Temporal.ZonedDateTime.from({ year: 2016, monthCode: "M02", day: 29, hour: 12, minute: 34, timeZone: "UTC", calendar }, options); + +TemporalHelpers.assertPlainDateTime( + leapDay.with({ year: 2012 }, options).toPlainDateTime(), + 2012, 2, "M02", 29, 12, 34, 0, 0, 0, 0,"day not constrained when moving to another leap year", + "heisei", 24); + +TemporalHelpers.assertPlainDateTime( + leapDay.with({ year: 2018 }).toPlainDateTime(), + 2018, 2, "M02", 28, 12, 34, 0, 0, 0, 0,"day constrained when moving to a common year", + "heisei", 30); + +assert.throws(RangeError, function () { + leapDay.with({ year: 2018 }, options); +}, "reject when moving to a common year"); diff --git a/test/intl402/Temporal/ZonedDateTime/prototype/with/leap-year-roc.js b/test/intl402/Temporal/ZonedDateTime/prototype/with/leap-year-roc.js new file mode 100644 index 0000000000..ff55462f43 --- /dev/null +++ b/test/intl402/Temporal/ZonedDateTime/prototype/with/leap-year-roc.js @@ -0,0 +1,28 @@ +// 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.with +description: Check constraining days when year changes (roc calendar) +features: [Temporal, Intl.Era-monthcode] +includes: [temporalHelpers.js] +---*/ + +const calendar = "roc"; +const options = { overflow: "reject" }; + +const leapDay = Temporal.ZonedDateTime.from({ year: 105, monthCode: "M02", day: 29, hour: 12, minute: 34, timeZone: "UTC", calendar }, options); + +TemporalHelpers.assertPlainDateTime( + leapDay.with({ year: 101 }, options).toPlainDateTime(), + 101, 2, "M02", 29, 12, 34, 0, 0, 0, 0,"day not constrained when moving to another leap year", + "roc", 101); + +TemporalHelpers.assertPlainDateTime( + leapDay.with({ year: 107 }).toPlainDateTime(), + 107, 2, "M02", 28, 12, 34, 0, 0, 0, 0,"day constrained when moving to a common year", + "roc", 107); + +assert.throws(RangeError, function () { + leapDay.with({ year: 107 }, options); +}, "reject when moving to a common year");