Intl Era Monthcode: Tests for constraining day in Hebrew leap years

Adds tests for constraining 30 Adar I to 29 Adar when moving from a leap
year to a common year, by the add(), subtract(), or with() methods.

Constraining of the month code is already tested in
leap-months-hebrew.js.
This commit is contained in:
Philip Chimento 2025-11-27 12:18:38 -08:00 committed by Ms2ger
parent fe0e7c495b
commit fc5ea1f700
9 changed files with 300 additions and 0 deletions

View File

@ -0,0 +1,37 @@
// 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: Check constraining days due to leap years (hebrew calendar)
includes: [temporalHelpers.js]
features: [Temporal, Intl.Era-monthcode]
---*/
// Adar I (M05L) has 30 days, and in common years will be constrained to Adar
// (M06) which has 29 days.
// See also leap-months-hebrew.js and constrain-day-hebrew.js.
const calendar = "hebrew";
const options = { overflow: "reject" };
const years1 = new Temporal.Duration(1);
const years1n = new Temporal.Duration(-1);
const adarI = Temporal.PlainDate.from({ year: 5782, monthCode: "M05L", day: 30, calendar }, options);
TemporalHelpers.assertPlainDate(
adarI.add(years1),
5783, 6, "M06", 29, "Adding 1 year to 30 Adar I constrains to 29 Adar",
"am", 5783);
assert.throws(RangeError, function () {
adarI.add(years1, options);
}, "Adding 1 year to 30 Adar I rejects (either because the month or day would be constrained)");
TemporalHelpers.assertPlainDate(
adarI.add(years1n),
5781, 6, "M06", 29, "Subtracting 1 year from 30 Adar I constrains to 29 Adar",
"am", 5781);
assert.throws(RangeError, function () {
adarI.add(years1n, options);
}, "Subtracting 1 year from 30 Adar I rejects (either because the month or day would be constrained)");

View File

@ -0,0 +1,37 @@
// 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: Check constraining days due to leap years (hebrew calendar)
includes: [temporalHelpers.js]
features: [Temporal, Intl.Era-monthcode]
---*/
// Adar I (M05L) has 30 days, and in common years will be constrained to Adar
// (M06) which has 29 days.
// See also leap-months-hebrew.js and constrain-day-hebrew.js.
const calendar = "hebrew";
const options = { overflow: "reject" };
const years1 = new Temporal.Duration(-1);
const years1n = new Temporal.Duration(1);
const adarI = Temporal.PlainDate.from({ year: 5782, monthCode: "M05L", day: 30, calendar }, options);
TemporalHelpers.assertPlainDate(
adarI.subtract(years1),
5783, 6, "M06", 29, "Adding 1 year to 30 Adar I constrains to 29 Adar",
"am", 5783);
assert.throws(RangeError, function () {
adarI.subtract(years1, options);
}, "Adding 1 year to 30 Adar I rejects (either because the month or day would be constrained)");
TemporalHelpers.assertPlainDate(
adarI.subtract(years1n),
5781, 6, "M06", 29, "Subtracting 1 year from 30 Adar I constrains to 29 Adar",
"am", 5781);
assert.throws(RangeError, function () {
adarI.subtract(years1n, options);
}, "Subtracting 1 year from 30 Adar I rejects (either because the month or day would be constrained)");

View File

@ -0,0 +1,26 @@
// 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 due to leap years (hebrew calendar)
includes: [temporalHelpers.js]
features: [Temporal, Intl.Era-monthcode]
---*/
// Adar I (M05L) has 30 days, and in common years will be constrained to Adar
// (M06) which has 29 days.
// See also leap-months-hebrew.js and constrain-day-hebrew.js.
const calendar = "hebrew";
const options = { overflow: "reject" };
const adarI = Temporal.PlainDate.from({ year: 5782, monthCode: "M05L", day: 30, calendar }, options);
TemporalHelpers.assertPlainDate(
adarI.with({ year: 5783 }),
5783, 6, "M06", 29, "Changing 30 Adar I to common year constrains to 29 Adar",
"am", 5783);
assert.throws(RangeError, function () {
adarI.with({ year: 5783 }, options);
}, "Changing 30 Adar I to common year rejects (either because the month or day would be constrained)");

View File

@ -0,0 +1,37 @@
// 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: Check constraining days due to leap years (hebrew calendar)
includes: [temporalHelpers.js]
features: [Temporal, Intl.Era-monthcode]
---*/
// Adar I (M05L) has 30 days, and in common years will be constrained to Adar
// (M06) which has 29 days.
// See also leap-months-hebrew.js and constrain-day-hebrew.js.
const calendar = "hebrew";
const options = { overflow: "reject" };
const years1 = new Temporal.Duration(1);
const years1n = new Temporal.Duration(-1);
const adarI = Temporal.PlainDateTime.from({ year: 5782, monthCode: "M05L", day: 30, hour: 12, minute: 34, calendar }, options);
TemporalHelpers.assertPlainDateTime(
adarI.add(years1),
5783, 6, "M06", 29, 12, 34, 0, 0, 0, 0, "Adding 1 year to 30 Adar I constrains to 29 Adar",
"am", 5783);
assert.throws(RangeError, function () {
adarI.add(years1, options);
}, "Adding 1 year to 30 Adar I rejects (either because the month or day would be constrained)");
TemporalHelpers.assertPlainDateTime(
adarI.add(years1n),
5781, 6, "M06", 29, 12, 34, 0, 0, 0, 0, "Subtracting 1 year from 30 Adar I constrains to 29 Adar",
"am", 5781);
assert.throws(RangeError, function () {
adarI.add(years1n, options);
}, "Subtracting 1 year from 30 Adar I rejects (either because the month or day would be constrained)");

View File

@ -0,0 +1,37 @@
// 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: Check constraining days due to leap years (hebrew calendar)
includes: [temporalHelpers.js]
features: [Temporal, Intl.Era-monthcode]
---*/
// Adar I (M05L) has 30 days, and in common years will be constrained to Adar
// (M06) which has 29 days.
// See also leap-months-hebrew.js and constrain-day-hebrew.js.
const calendar = "hebrew";
const options = { overflow: "reject" };
const years1 = new Temporal.Duration(-1);
const years1n = new Temporal.Duration(1);
const adarI = Temporal.PlainDateTime.from({ year: 5782, monthCode: "M05L", day: 30, hour: 12, minute: 34, calendar }, options);
TemporalHelpers.assertPlainDateTime(
adarI.subtract(years1),
5783, 6, "M06", 29, 12, 34, 0, 0, 0, 0, "Adding 1 year to 30 Adar I constrains to 29 Adar",
"am", 5783);
assert.throws(RangeError, function () {
adarI.subtract(years1, options);
}, "Adding 1 year to 30 Adar I rejects (either because the month or day would be constrained)");
TemporalHelpers.assertPlainDateTime(
adarI.subtract(years1n),
5781, 6, "M06", 29, 12, 34, 0, 0, 0, 0, "Subtracting 1 year from 30 Adar I constrains to 29 Adar",
"am", 5781);
assert.throws(RangeError, function () {
adarI.subtract(years1n, options);
}, "Subtracting 1 year from 30 Adar I rejects (either because the month or day would be constrained)");

View File

@ -0,0 +1,26 @@
// 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 due to leap years (hebrew calendar)
includes: [temporalHelpers.js]
features: [Temporal, Intl.Era-monthcode]
---*/
// Adar I (M05L) has 30 days, and in common years will be constrained to Adar
// (M06) which has 29 days.
// See also leap-months-hebrew.js and constrain-day-hebrew.js.
const calendar = "hebrew";
const options = { overflow: "reject" };
const adarI = Temporal.PlainDateTime.from({ year: 5782, monthCode: "M05L", day: 30, hour: 12, minute: 34, calendar }, options);
TemporalHelpers.assertPlainDateTime(
adarI.with({ year: 5783 }),
5783, 6, "M06", 29, 12, 34, 0, 0, 0, 0,"Changing 30 Adar I to common year constrains to 29 Adar",
"am", 5783);
assert.throws(RangeError, function () {
adarI.with({ year: 5783 }, options);
}, "Changing 30 Adar I to common year rejects (either because the month or day would be constrained)");

View File

@ -0,0 +1,37 @@
// 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: Check constraining days due to leap years (hebrew calendar)
includes: [temporalHelpers.js]
features: [Temporal, Intl.Era-monthcode]
---*/
// Adar I (M05L) has 30 days, and in common years will be constrained to Adar
// (M06) which has 29 days.
// See also leap-months-hebrew.js and constrain-day-hebrew.js.
const calendar = "hebrew";
const options = { overflow: "reject" };
const years1 = new Temporal.Duration(1);
const years1n = new Temporal.Duration(-1);
const adarI = Temporal.ZonedDateTime.from({ year: 5782, monthCode: "M05L", day: 30, hour: 12, minute: 34, timeZone: "UTC", calendar }, options);
TemporalHelpers.assertPlainDateTime(
adarI.add(years1).toPlainDateTime(),
5783, 6, "M06", 29, 12, 34, 0, 0, 0, 0, "Adding 1 year to 30 Adar I constrains to 29 Adar",
"am", 5783);
assert.throws(RangeError, function () {
adarI.add(years1, options);
}, "Adding 1 year to 30 Adar I rejects (either because the month or day would be constrained)");
TemporalHelpers.assertPlainDateTime(
adarI.add(years1n).toPlainDateTime(),
5781, 6, "M06", 29, 12, 34, 0, 0, 0, 0, "Subtracting 1 year from 30 Adar I constrains to 29 Adar",
"am", 5781);
assert.throws(RangeError, function () {
adarI.add(years1n, options);
}, "Subtracting 1 year from 30 Adar I rejects (either because the month or day would be constrained)");

View File

@ -0,0 +1,37 @@
// 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: Check constraining days due to leap years (hebrew calendar)
includes: [temporalHelpers.js]
features: [Temporal, Intl.Era-monthcode]
---*/
// Adar I (M05L) has 30 days, and in common years will be constrained to Adar
// (M06) which has 29 days.
// See also leap-months-hebrew.js and constrain-day-hebrew.js.
const calendar = "hebrew";
const options = { overflow: "reject" };
const years1 = new Temporal.Duration(-1);
const years1n = new Temporal.Duration(1);
const adarI = Temporal.ZonedDateTime.from({ year: 5782, monthCode: "M05L", day: 30, hour: 12, minute: 34, timeZone: "UTC", calendar }, options);
TemporalHelpers.assertPlainDateTime(
adarI.subtract(years1).toPlainDateTime(),
5783, 6, "M06", 29, 12, 34, 0, 0, 0, 0, "Adding 1 year to 30 Adar I constrains to 29 Adar",
"am", 5783);
assert.throws(RangeError, function () {
adarI.subtract(years1, options);
}, "Adding 1 year to 30 Adar I rejects (either because the month or day would be constrained)");
TemporalHelpers.assertPlainDateTime(
adarI.subtract(years1n).toPlainDateTime(),
5781, 6, "M06", 29, 12, 34, 0, 0, 0, 0, "Subtracting 1 year from 30 Adar I constrains to 29 Adar",
"am", 5781);
assert.throws(RangeError, function () {
adarI.subtract(years1n, options);
}, "Subtracting 1 year from 30 Adar I rejects (either because the month or day would be constrained)");

View File

@ -0,0 +1,26 @@
// 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 due to leap years (hebrew calendar)
includes: [temporalHelpers.js]
features: [Temporal, Intl.Era-monthcode]
---*/
// Adar I (M05L) has 30 days, and in common years will be constrained to Adar
// (M06) which has 29 days.
// See also leap-months-hebrew.js and constrain-day-hebrew.js.
const calendar = "hebrew";
const options = { overflow: "reject" };
const adarI = Temporal.ZonedDateTime.from({ year: 5782, monthCode: "M05L", day: 30, hour: 12, minute: 34, timeZone: "UTC", calendar }, options);
TemporalHelpers.assertPlainDateTime(
adarI.with({ year: 5783 }).toPlainDateTime(),
5783, 6, "M06", 29, 12, 34, 0, 0, 0, 0,"Changing 30 Adar I to common year constrains to 29 Adar",
"am", 5783);
assert.throws(RangeError, function () {
adarI.with({ year: 5783 }, options);
}, "Changing 30 Adar I to common year rejects (either because the month or day would be constrained)");