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).
This commit is contained in:
Philip Chimento 2025-11-18 20:57:21 -08:00 committed by Ms2ger
parent 1648f70ba4
commit caef6b2082
12 changed files with 336 additions and 0 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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