Intl Era Monthcode: Leap month tests for with() methods

Adds coverage for the constrain behaviour around leap months when using
the with() method to change the year, for the three calendars with leap
months.
This commit is contained in:
Philip Chimento 2025-11-16 13:09:37 -08:00 committed by Ms2ger
parent 359a303fb1
commit 8e3516bffd
9 changed files with 279 additions and 0 deletions

View File

@ -0,0 +1,33 @@
// 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 leap months when year changes in chinese calendar
features: [Temporal]
includes: [temporalHelpers.js]
---*/
const calendar = "chinese";
const options = { overflow: "reject" };
const leapMonth = Temporal.PlainDate.from({ year: 2017, monthCode: "M06L", day: 1, calendar }, options);
TemporalHelpers.assertPlainDate(
leapMonth.with({ year: 2025 }, options),
2025, 7, "M06L", 1, "month not constrained when moving to another leap year with M06L");
TemporalHelpers.assertPlainDate(
leapMonth.with({ year: 2020 }),
2020, 7, "M06", 1, "month constrained when moving to another leap year without M06L");
assert.throws(RangeError, function () {
leapMonth.with({ year: 2020 }, options);
}, "reject when moving to another leap year without M06L");
TemporalHelpers.assertPlainDate(
leapMonth.with({ year: 2024 }),
2024, 6, "M06", 1, "month constrained when moving to a common year");
assert.throws(RangeError, function () {
leapMonth.with({ year: 2024 }, options);
}, "reject when moving to a common year");

View File

@ -0,0 +1,33 @@
// 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 leap months when year changes in dangi calendar
features: [Temporal]
includes: [temporalHelpers.js]
---*/
const calendar = "dangi";
const options = { overflow: "reject" };
const leapMonth = Temporal.PlainDate.from({ year: 2017, monthCode: "M05L", day: 1, calendar }, options);
TemporalHelpers.assertPlainDate(
leapMonth.with({ year: 2009 }, options),
2009, 6, "M05L", 1, "month not constrained when moving to another leap year with M05L");
TemporalHelpers.assertPlainDate(
leapMonth.with({ year: 2020 }),
2020, 6, "M05", 1, "month constrained when moving to another leap year without M05L");
assert.throws(RangeError, function () {
leapMonth.with({ year: 2020 }, options);
}, "reject when moving to another leap year without M05L");
TemporalHelpers.assertPlainDate(
leapMonth.with({ year: 2024 }),
2024, 5, "M05", 1, "month constrained when moving to a common year");
assert.throws(RangeError, function () {
leapMonth.with({ year: 2024 }, options);
}, "reject when moving to a common year");

View File

@ -0,0 +1,27 @@
// 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 leap months when year changes in hebrew calendar
features: [Temporal]
includes: [temporalHelpers.js]
---*/
const calendar = "hebrew";
const options = { overflow: "reject" };
const leapMonth = Temporal.PlainDate.from({ year: 5784, monthCode: "M05L", day: 1, calendar }, options);
TemporalHelpers.assertPlainDate(
leapMonth.with({ year: 5782 }, options),
5782, 6, "M05L", 1, "month not constrained when moving to another leap year",
"am", 5782);
TemporalHelpers.assertPlainDate(
leapMonth.with({ year: 5783 }),
5783, 6, "M06", 1, "month constrained when moving to a common year",
"am", 5783);
assert.throws(RangeError, function () {
leapMonth.with({ year: 5783 }, options);
}, "reject when moving to a common year");

View File

@ -0,0 +1,33 @@
// 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 leap months when year changes in chinese calendar
features: [Temporal]
includes: [temporalHelpers.js]
---*/
const calendar = "chinese";
const options = { overflow: "reject" };
const leapMonth = Temporal.PlainDateTime.from({ year: 2017, monthCode: "M06L", day: 1, hour: 12, minute: 34, calendar }, options);
TemporalHelpers.assertPlainDateTime(
leapMonth.with({ year: 2025 }, options),
2025, 7, "M06L", 1, 12, 34, 0, 0, 0, 0, "month not constrained when moving to another leap year with M06L");
TemporalHelpers.assertPlainDateTime(
leapMonth.with({ year: 2020 }),
2020, 7, "M06", 1, 12, 34, 0, 0, 0, 0, "month constrained when moving to another leap year without M06L");
assert.throws(RangeError, function () {
leapMonth.with({ year: 2020 }, options);
}, "reject when moving to another leap year without M06L");
TemporalHelpers.assertPlainDateTime(
leapMonth.with({ year: 2024 }),
2024, 6, "M06", 1, 12, 34, 0, 0, 0, 0, "month constrained when moving to a common year");
assert.throws(RangeError, function () {
leapMonth.with({ year: 2024 }, options);
}, "reject when moving to a common year");

View File

@ -0,0 +1,33 @@
// 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 leap months when year changes in dangi calendar
features: [Temporal]
includes: [temporalHelpers.js]
---*/
const calendar = "dangi";
const options = { overflow: "reject" };
const leapMonth = Temporal.PlainDateTime.from({ year: 2017, monthCode: "M05L", day: 1, hour: 12, minute: 34, calendar }, options);
TemporalHelpers.assertPlainDateTime(
leapMonth.with({ year: 2009 }, options),
2009, 6, "M05L", 1, 12, 34, 0, 0, 0, 0, "month not constrained when moving to another leap year with M05L");
TemporalHelpers.assertPlainDateTime(
leapMonth.with({ year: 2020 }),
2020, 6, "M05", 1, 12, 34, 0, 0, 0, 0, "month constrained when moving to another leap year without M05L");
assert.throws(RangeError, function () {
leapMonth.with({ year: 2020 }, options);
}, "reject when moving to another leap year without M05L");
TemporalHelpers.assertPlainDateTime(
leapMonth.with({ year: 2024 }),
2024, 5, "M05", 1, 12, 34, 0, 0, 0, 0, "month constrained when moving to a common year");
assert.throws(RangeError, function () {
leapMonth.with({ year: 2024 }, options);
}, "reject when moving to a common year");

View File

@ -0,0 +1,27 @@
// 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 leap months when year changes in hebrew calendar
features: [Temporal]
includes: [temporalHelpers.js]
---*/
const calendar = "hebrew";
const options = { overflow: "reject" };
const leapMonth = Temporal.PlainDateTime.from({ year: 5784, monthCode: "M05L", day: 1, hour: 12, minute: 34, calendar }, options);
TemporalHelpers.assertPlainDateTime(
leapMonth.with({ year: 5782 }, options),
5782, 6, "M05L", 1, 12, 34, 0, 0, 0, 0, "month not constrained when moving to another leap year",
"am", 5782);
TemporalHelpers.assertPlainDateTime(
leapMonth.with({ year: 5783 }),
5783, 6, "M06", 1, 12, 34, 0, 0, 0, 0, "month constrained when moving to a common year",
"am", 5783);
assert.throws(RangeError, function () {
leapMonth.with({ year: 5783 }, options);
}, "reject when moving to a common year");

View File

@ -0,0 +1,33 @@
// 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 leap months when year changes in chinese calendar
features: [Temporal]
includes: [temporalHelpers.js]
---*/
const calendar = "chinese";
const options = { overflow: "reject" };
const leapMonth = Temporal.ZonedDateTime.from({ year: 2017, monthCode: "M06L", day: 1, hour: 12, minute: 34, timeZone: "UTC", calendar }, options);
TemporalHelpers.assertPlainDateTime(
leapMonth.with({ year: 2025 }, options).toPlainDateTime(),
2025, 7, "M06L", 1, 12, 34, 0, 0, 0, 0, "month not constrained when moving to another leap year with M06L");
TemporalHelpers.assertPlainDateTime(
leapMonth.with({ year: 2020 }).toPlainDateTime(),
2020, 7, "M06", 1, 12, 34, 0, 0, 0, 0, "month constrained when moving to another leap year without M06L");
assert.throws(RangeError, function () {
leapMonth.with({ year: 2020 }, options);
}, "reject when moving to another leap year without M06L");
TemporalHelpers.assertPlainDateTime(
leapMonth.with({ year: 2024 }).toPlainDateTime(),
2024, 6, "M06", 1, 12, 34, 0, 0, 0, 0, "month constrained when moving to a common year");
assert.throws(RangeError, function () {
leapMonth.with({ year: 2024 }, options);
}, "reject when moving to a common year");

View File

@ -0,0 +1,33 @@
// 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 leap months when year changes in dangi calendar
features: [Temporal]
includes: [temporalHelpers.js]
---*/
const calendar = "dangi";
const options = { overflow: "reject" };
const leapMonth = Temporal.ZonedDateTime.from({ year: 2017, monthCode: "M05L", day: 1, hour: 12, minute: 34, timeZone: "UTC", calendar }, options);
TemporalHelpers.assertPlainDateTime(
leapMonth.with({ year: 2009 }, options).toPlainDateTime(),
2009, 6, "M05L", 1, 12, 34, 0, 0, 0, 0, "month not constrained when moving to another leap year with M05L");
TemporalHelpers.assertPlainDateTime(
leapMonth.with({ year: 2020 }).toPlainDateTime(),
2020, 6, "M05", 1, 12, 34, 0, 0, 0, 0, "month constrained when moving to another leap year without M05L");
assert.throws(RangeError, function () {
leapMonth.with({ year: 2020 }, options);
}, "reject when moving to another leap year without M05L");
TemporalHelpers.assertPlainDateTime(
leapMonth.with({ year: 2024 }).toPlainDateTime(),
2024, 5, "M05", 1, 12, 34, 0, 0, 0, 0, "month constrained when moving to a common year");
assert.throws(RangeError, function () {
leapMonth.with({ year: 2024 }, options);
}, "reject when moving to a common year");

View File

@ -0,0 +1,27 @@
// 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 leap months when year changes in hebrew calendar
features: [Temporal]
includes: [temporalHelpers.js]
---*/
const calendar = "hebrew";
const options = { overflow: "reject" };
const leapMonth = Temporal.ZonedDateTime.from({ year: 5784, monthCode: "M05L", day: 1, hour: 12, minute: 34, timeZone: "UTC", calendar }, options);
TemporalHelpers.assertPlainDateTime(
leapMonth.with({ year: 5782 }, options).toPlainDateTime(),
5782, 6, "M05L", 1, 12, 34, 0, 0, 0, 0, "month not constrained when moving to another leap year",
"am", 5782);
TemporalHelpers.assertPlainDateTime(
leapMonth.with({ year: 5783 }).toPlainDateTime(),
5783, 6, "M06", 1, 12, 34, 0, 0, 0, 0, "month constrained when moving to a common year",
"am", 5783);
assert.throws(RangeError, function () {
leapMonth.with({ year: 5783 }, options);
}, "reject when moving to a common year");