Skip to content

Commit 3fb6c65

Browse files
ptomatoMs2ger
authored andcommitted
Intl Era Monthcode: Tests for constraining leap day in Indian calendar
Adds tests for constraining 31 Chaitra to 30 Chaitra when moving from a leap year to a common year, by the add(), subtract(), or with() methods.
1 parent 7d21b4a commit 3fb6c65

File tree

9 files changed

+351
-0
lines changed

9 files changed

+351
-0
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// Copyright (C) 2025 Igalia, S.L. All rights reserved.
2+
// This code is governed by the BSD license found in the LICENSE file.
3+
4+
/*---
5+
esid: sec-temporal.plaindate.prototype.add
6+
description: Check various basic calculations involving leap years (indian calendar)
7+
features: [Temporal, Intl.Era-monthcode]
8+
includes: [temporalHelpers.js]
9+
---*/
10+
11+
const calendar = "indian";
12+
const options = { overflow: "reject" };
13+
14+
const leapDay = Temporal.PlainDate.from({ year: 1946, monthCode: "M01", day: 31, calendar }, options);
15+
16+
const years1 = new Temporal.Duration(1);
17+
const years1n = new Temporal.Duration(-1);
18+
const years4 = new Temporal.Duration(4);
19+
const years4n = new Temporal.Duration(-4);
20+
21+
TemporalHelpers.assertPlainDate(
22+
leapDay.add(years1),
23+
1947, 1, "M01", 30, "Adding 1 year to leap day constrains to 30 Chaitra",
24+
"shaka", 1947);
25+
assert.throws(RangeError, function () {
26+
leapDay.add(years1, options);
27+
}, "Adding 1 year to leap day rejects");
28+
29+
TemporalHelpers.assertPlainDate(
30+
leapDay.add(years1n),
31+
1945, 1, "M01", 30, "Subtracting 1 year from leap day constrains to 30 Chaitra",
32+
"shaka", 1945);
33+
assert.throws(RangeError, function () {
34+
leapDay.add(years1n, options);
35+
}, "Subtracting 1 year from leap day rejects");
36+
37+
TemporalHelpers.assertPlainDate(
38+
leapDay.add(years4, options),
39+
1950, 1, "M01", 31, "Adding 4 years to leap day goes to the next leap day",
40+
"shaka", 1950);
41+
42+
TemporalHelpers.assertPlainDate(
43+
leapDay.add(years4n, options),
44+
1942, 1, "M01", 31, "Subtracting 4 years from leap day goes to the previous leap day",
45+
"shaka", 1942);
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// Copyright (C) 2025 Igalia, S.L. All rights reserved.
2+
// This code is governed by the BSD license found in the LICENSE file.
3+
4+
/*---
5+
esid: sec-temporal.plaindate.prototype.subtract
6+
description: Check various basic calculations involving leap years (indian calendar)
7+
features: [Temporal, Intl.Era-monthcode]
8+
includes: [temporalHelpers.js]
9+
---*/
10+
11+
const calendar = "indian";
12+
const options = { overflow: "reject" };
13+
14+
const leapDay = Temporal.PlainDate.from({ year: 1946, monthCode: "M01", day: 31, calendar }, options);
15+
16+
const years1 = new Temporal.Duration(-1);
17+
const years1n = new Temporal.Duration(1);
18+
const years4 = new Temporal.Duration(-4);
19+
const years4n = new Temporal.Duration(4);
20+
21+
TemporalHelpers.assertPlainDate(
22+
leapDay.subtract(years1),
23+
1947, 1, "M01", 30, "Adding 1 year to leap day constrains to 30 Chaitra",
24+
"shaka", 1947);
25+
assert.throws(RangeError, function () {
26+
leapDay.subtract(years1, options);
27+
}, "Adding 1 year to leap day rejects");
28+
29+
TemporalHelpers.assertPlainDate(
30+
leapDay.subtract(years1n),
31+
1945, 1, "M01", 30, "Subtracting 1 year from leap day constrains to 30 Chaitra",
32+
"shaka", 1945);
33+
assert.throws(RangeError, function () {
34+
leapDay.subtract(years1n, options);
35+
}, "Subtracting 1 year from leap day rejects");
36+
37+
TemporalHelpers.assertPlainDate(
38+
leapDay.subtract(years4, options),
39+
1950, 1, "M01", 31, "Adding 4 years to leap day goes to the next leap day",
40+
"shaka", 1950);
41+
42+
TemporalHelpers.assertPlainDate(
43+
leapDay.subtract(years4n, options),
44+
1942, 1, "M01", 31, "Subtracting 4 years from leap day goes to the previous leap day",
45+
"shaka", 1942);
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Copyright (C) 2025 Igalia, S.L. All rights reserved.
2+
// This code is governed by the BSD license found in the LICENSE file.
3+
4+
/*---
5+
esid: sec-temporal.plaindate.prototype.with
6+
description: Check various basic calculations involving leap years (indian calendar)
7+
features: [Temporal, Intl.Era-monthcode]
8+
includes: [temporalHelpers.js]
9+
---*/
10+
11+
const calendar = "indian";
12+
const options = { overflow: "reject" };
13+
14+
const leapDay = Temporal.PlainDate.from({ year: 1946, monthCode: "M01", day: 31, calendar }, options);
15+
16+
TemporalHelpers.assertPlainDate(
17+
leapDay.with({ year: 1947 }),
18+
1947, 1, "M01", 30, "Changing year to a common year on leap day constrains to 30 Chaitra",
19+
"shaka", 1947);
20+
assert.throws(RangeError, function () {
21+
leapDay.with({ year: 1947 }, options);
22+
}, "Changing year to a common year on leap day rejects");
23+
24+
TemporalHelpers.assertPlainDate(
25+
leapDay.with({ year: 1942 }, options),
26+
1942, 1, "M01", 31, "Changing year to another leap year on leap day does not reject",
27+
"shaka", 1942);
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// Copyright (C) 2025 Igalia, S.L. All rights reserved.
2+
// This code is governed by the BSD license found in the LICENSE file.
3+
4+
/*---
5+
esid: sec-temporal.plaindatetime.prototype.add
6+
description: Check various basic calculations involving leap years (indian calendar)
7+
features: [Temporal, Intl.Era-monthcode]
8+
includes: [temporalHelpers.js]
9+
---*/
10+
11+
const calendar = "indian";
12+
const options = { overflow: "reject" };
13+
14+
const leapDay = Temporal.PlainDateTime.from({ year: 1946, monthCode: "M01", day: 31, hour: 12, minute: 34, calendar }, options);
15+
16+
const years1 = new Temporal.Duration(1);
17+
const years1n = new Temporal.Duration(-1);
18+
const years4 = new Temporal.Duration(4);
19+
const years4n = new Temporal.Duration(-4);
20+
21+
TemporalHelpers.assertPlainDateTime(
22+
leapDay.add(years1),
23+
1947, 1, "M01", 30, 12, 34, 0, 0, 0, 0, "Adding 1 year to leap day constrains to 30 Chaitra",
24+
"shaka", 1947);
25+
assert.throws(RangeError, function () {
26+
leapDay.add(years1, options);
27+
}, "Adding 1 year to leap day rejects");
28+
29+
TemporalHelpers.assertPlainDateTime(
30+
leapDay.add(years1n),
31+
1945, 1, "M01", 30, 12, 34, 0, 0, 0, 0, "Subtracting 1 year from leap day constrains to 30 Chaitra",
32+
"shaka", 1945);
33+
assert.throws(RangeError, function () {
34+
leapDay.add(years1n, options);
35+
}, "Subtracting 1 year from leap day rejects");
36+
37+
TemporalHelpers.assertPlainDateTime(
38+
leapDay.add(years4, options),
39+
1950, 1, "M01", 31, 12, 34, 0, 0, 0, 0, "Adding 4 years to leap day goes to the next leap day",
40+
"shaka", 1950);
41+
42+
TemporalHelpers.assertPlainDateTime(
43+
leapDay.add(years4n, options),
44+
1942, 1, "M01", 31, 12, 34, 0, 0, 0, 0, "Subtracting 4 years from leap day goes to the previous leap day",
45+
"shaka", 1942);
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// Copyright (C) 2025 Igalia, S.L. All rights reserved.
2+
// This code is governed by the BSD license found in the LICENSE file.
3+
4+
/*---
5+
esid: sec-temporal.plaindatetime.prototype.subtract
6+
description: Check various basic calculations involving leap years (indian calendar)
7+
features: [Temporal, Intl.Era-monthcode]
8+
includes: [temporalHelpers.js]
9+
---*/
10+
11+
const calendar = "indian";
12+
const options = { overflow: "reject" };
13+
14+
const leapDay = Temporal.PlainDateTime.from({ year: 1946, monthCode: "M01", day: 31, hour: 12, minute: 34, calendar }, options);
15+
16+
const years1 = new Temporal.Duration(-1);
17+
const years1n = new Temporal.Duration(1);
18+
const years4 = new Temporal.Duration(-4);
19+
const years4n = new Temporal.Duration(4);
20+
21+
TemporalHelpers.assertPlainDateTime(
22+
leapDay.subtract(years1),
23+
1947, 1, "M01", 30, 12, 34, 0, 0, 0, 0, "Adding 1 year to leap day constrains to 30 Chaitra",
24+
"shaka", 1947);
25+
assert.throws(RangeError, function () {
26+
leapDay.subtract(years1, options);
27+
}, "Adding 1 year to leap day rejects");
28+
29+
TemporalHelpers.assertPlainDateTime(
30+
leapDay.subtract(years1n),
31+
1945, 1, "M01", 30, 12, 34, 0, 0, 0, 0, "Subtracting 1 year from leap day constrains to 30 Chaitra",
32+
"shaka", 1945);
33+
assert.throws(RangeError, function () {
34+
leapDay.subtract(years1n, options);
35+
}, "Subtracting 1 year from leap day rejects");
36+
37+
TemporalHelpers.assertPlainDateTime(
38+
leapDay.subtract(years4, options),
39+
1950, 1, "M01", 31, 12, 34, 0, 0, 0, 0, "Adding 4 years to leap day goes to the next leap day",
40+
"shaka", 1950);
41+
42+
TemporalHelpers.assertPlainDateTime(
43+
leapDay.subtract(years4n, options),
44+
1942, 1, "M01", 31, 12, 34, 0, 0, 0, 0, "Subtracting 4 years from leap day goes to the previous leap day",
45+
"shaka", 1942);
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Copyright (C) 2025 Igalia, S.L. All rights reserved.
2+
// This code is governed by the BSD license found in the LICENSE file.
3+
4+
/*---
5+
esid: sec-temporal.plaindatetime.prototype.with
6+
description: Check various basic calculations involving leap years (indian calendar)
7+
features: [Temporal, Intl.Era-monthcode]
8+
includes: [temporalHelpers.js]
9+
---*/
10+
11+
const calendar = "indian";
12+
const options = { overflow: "reject" };
13+
14+
const leapDay = Temporal.PlainDateTime.from({ year: 1946, monthCode: "M01", day: 31, hour: 12, minute: 34, calendar }, options);
15+
16+
TemporalHelpers.assertPlainDateTime(
17+
leapDay.with({ year: 1947 }),
18+
1947, 1, "M01", 30, 12, 34, 0, 0, 0, 0, "Changing year to a common year on leap day constrains to 30 Chaitra",
19+
"shaka", 1947);
20+
assert.throws(RangeError, function () {
21+
leapDay.with({ year: 1947 }, options);
22+
}, "Changing year to a common year on leap day rejects");
23+
24+
TemporalHelpers.assertPlainDateTime(
25+
leapDay.with({ year: 1942 }, options),
26+
1942, 1, "M01", 31, 12, 34, 0, 0, 0, 0, "Changing year to another leap year on leap day does not reject",
27+
"shaka", 1942);
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// Copyright (C) 2025 Igalia, S.L. All rights reserved.
2+
// This code is governed by the BSD license found in the LICENSE file.
3+
4+
/*---
5+
esid: sec-temporal.zoneddatetime.prototype.add
6+
description: Check various basic calculations involving leap years (indian calendar)
7+
features: [Temporal, Intl.Era-monthcode]
8+
includes: [temporalHelpers.js]
9+
---*/
10+
11+
const calendar = "indian";
12+
const options = { overflow: "reject" };
13+
14+
const leapDay = Temporal.ZonedDateTime.from({ year: 1946, monthCode: "M01", day: 31, hour: 12, minute: 34, timeZone: "UTC", calendar }, options);
15+
16+
const years1 = new Temporal.Duration(1);
17+
const years1n = new Temporal.Duration(-1);
18+
const years4 = new Temporal.Duration(4);
19+
const years4n = new Temporal.Duration(-4);
20+
21+
TemporalHelpers.assertPlainDateTime(
22+
leapDay.add(years1).toPlainDateTime(),
23+
1947, 1, "M01", 30, 12, 34, 0, 0, 0, 0, "Adding 1 year to leap day constrains to 30 Chaitra",
24+
"shaka", 1947);
25+
assert.throws(RangeError, function () {
26+
leapDay.add(years1, options);
27+
}, "Adding 1 year to leap day rejects");
28+
29+
TemporalHelpers.assertPlainDateTime(
30+
leapDay.add(years1n).toPlainDateTime(),
31+
1945, 1, "M01", 30, 12, 34, 0, 0, 0, 0, "Subtracting 1 year from leap day constrains to 30 Chaitra",
32+
"shaka", 1945);
33+
assert.throws(RangeError, function () {
34+
leapDay.add(years1n, options);
35+
}, "Subtracting 1 year from leap day rejects");
36+
37+
TemporalHelpers.assertPlainDateTime(
38+
leapDay.add(years4, options).toPlainDateTime(),
39+
1950, 1, "M01", 31, 12, 34, 0, 0, 0, 0, "Adding 4 years to leap day goes to the next leap day",
40+
"shaka", 1950);
41+
42+
TemporalHelpers.assertPlainDateTime(
43+
leapDay.add(years4n, options).toPlainDateTime(),
44+
1942, 1, "M01", 31, 12, 34, 0, 0, 0, 0, "Subtracting 4 years from leap day goes to the previous leap day",
45+
"shaka", 1942);
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// Copyright (C) 2025 Igalia, S.L. All rights reserved.
2+
// This code is governed by the BSD license found in the LICENSE file.
3+
4+
/*---
5+
esid: sec-temporal.zoneddatetime.prototype.subtract
6+
description: Check various basic calculations involving leap years (indian calendar)
7+
features: [Temporal, Intl.Era-monthcode]
8+
includes: [temporalHelpers.js]
9+
---*/
10+
11+
const calendar = "indian";
12+
const options = { overflow: "reject" };
13+
14+
const leapDay = Temporal.ZonedDateTime.from({ year: 1946, monthCode: "M01", day: 31, hour: 12, minute: 34, timeZone: "UTC", calendar }, options);
15+
16+
const years1 = new Temporal.Duration(-1);
17+
const years1n = new Temporal.Duration(1);
18+
const years4 = new Temporal.Duration(-4);
19+
const years4n = new Temporal.Duration(4);
20+
21+
TemporalHelpers.assertPlainDateTime(
22+
leapDay.subtract(years1).toPlainDateTime(),
23+
1947, 1, "M01", 30, 12, 34, 0, 0, 0, 0, "Adding 1 year to leap day constrains to 30 Chaitra",
24+
"shaka", 1947);
25+
assert.throws(RangeError, function () {
26+
leapDay.subtract(years1, options);
27+
}, "Adding 1 year to leap day rejects");
28+
29+
TemporalHelpers.assertPlainDateTime(
30+
leapDay.subtract(years1n).toPlainDateTime(),
31+
1945, 1, "M01", 30, 12, 34, 0, 0, 0, 0, "Subtracting 1 year from leap day constrains to 30 Chaitra",
32+
"shaka", 1945);
33+
assert.throws(RangeError, function () {
34+
leapDay.subtract(years1n, options);
35+
}, "Subtracting 1 year from leap day rejects");
36+
37+
TemporalHelpers.assertPlainDateTime(
38+
leapDay.subtract(years4, options).toPlainDateTime(),
39+
1950, 1, "M01", 31, 12, 34, 0, 0, 0, 0, "Adding 4 years to leap day goes to the next leap day",
40+
"shaka", 1950);
41+
42+
TemporalHelpers.assertPlainDateTime(
43+
leapDay.subtract(years4n, options).toPlainDateTime(),
44+
1942, 1, "M01", 31, 12, 34, 0, 0, 0, 0, "Subtracting 4 years from leap day goes to the previous leap day",
45+
"shaka", 1942);
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Copyright (C) 2025 Igalia, S.L. All rights reserved.
2+
// This code is governed by the BSD license found in the LICENSE file.
3+
4+
/*---
5+
esid: sec-temporal.zoneddatetime.prototype.with
6+
description: Check various basic calculations involving leap years (indian calendar)
7+
features: [Temporal, Intl.Era-monthcode]
8+
includes: [temporalHelpers.js]
9+
---*/
10+
11+
const calendar = "indian";
12+
const options = { overflow: "reject" };
13+
14+
const leapDay = Temporal.ZonedDateTime.from({ year: 1946, monthCode: "M01", day: 31, hour: 12, minute: 34, timeZone: "UTC", calendar }, options);
15+
16+
TemporalHelpers.assertPlainDateTime(
17+
leapDay.with({ year: 1947 }).toPlainDateTime(),
18+
1947, 1, "M01", 30, 12, 34, 0, 0, 0, 0, "Changing year to a common year on leap day constrains to 30 Chaitra",
19+
"shaka", 1947);
20+
assert.throws(RangeError, function () {
21+
leapDay.with({ year: 1947 }, options);
22+
}, "Changing year to a common year on leap day rejects");
23+
24+
TemporalHelpers.assertPlainDateTime(
25+
leapDay.with({ year: 1942 }, options).toPlainDateTime(),
26+
1942, 1, "M01", 31, 12, 34, 0, 0, 0, 0, "Changing year to another leap year on leap day does not reject",
27+
"shaka", 1942);

0 commit comments

Comments
 (0)