Skip to content

Commit db559da

Browse files
committed
Temporal: Add coverage for weird PlainMonthDay leap day constrain case
If you have a leap day, such as February 29, and you get input such as { monthCode: "M02", day: 30 }, { overflow: "constrain" }, then you want the day to be constrained to the leap day February 29, not February 28 as the maximum day would be in a common year. Add tests for this case for each supported calendar.
1 parent a7b720f commit db559da

2 files changed

Lines changed: 43 additions & 0 deletions

File tree

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
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.plainmonthday.from
6+
description: Properly constrain February 30 to February 29, not 28
7+
features: [Temporal]
8+
---*/
9+
10+
const md = Temporal.PlainMonthDay.from({ monthCode: "M02", day: 30 }, { overflow: "constrain" });
11+
assert.sameValue(md.day, 29, "M02-30 should constrain to 29, not 28");
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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.plainmonthday.from
6+
description: Properly constrain a day that is one past a leap day
7+
features: [Temporal]
8+
---*/
9+
10+
const tests = [
11+
["buddhist", "M02", 30],
12+
["chinese", "M01", 31],
13+
["coptic", "M13", 7],
14+
["dangi", "M01", 31],
15+
["ethioaa", "M13", 7],
16+
["ethiopic", "M13", 7],
17+
["gregory", "M02", 30],
18+
["hebrew", "M02", 31],
19+
["indian", "M01", 32],
20+
["islamic-civil", "M01", 31],
21+
["islamic-tbla", "M01", 31],
22+
["islamic-umalqura", "M01", 31],
23+
["japanese", "M02", 30],
24+
["persian", "M12", 31],
25+
["roc", "M02", 30],
26+
];
27+
28+
for (const [calendar, monthCode, day] of tests) {
29+
const md = Temporal.PlainMonthDay.from({ calendar, monthCode, day }, { overflow: "constrain" });
30+
assert.sameValue(md.day, day - 1,
31+
`${calendar}: ${monthCode}-${day} should constrain to ${day - 1}, not ${day - 2}`)
32+
}

0 commit comments

Comments
 (0)