Skip to content

Commit de3a117

Browse files
gibson042ptomato
authored andcommitted
Temporal: Update tests to account for use of year in ToTemporalMonthDay
Ref tc39/proposal-temporal#2863 Normative PR: tc39/proposal-temporal#2940
1 parent dfece8c commit de3a117

File tree

1 file changed

+31
-12
lines changed

1 file changed

+31
-12
lines changed

test/intl402/Temporal/PlainMonthDay/from/reference-year-1972.js

+31-12
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,28 @@ features: [Temporal]
1010

1111
const result1 = Temporal.PlainMonthDay.from({ year: 2021, monthCode: "M02", day: 29, calendar: "gregory" });
1212
TemporalHelpers.assertPlainMonthDay(
13-
result1, "M02", 29,
14-
"year is ignored and reference year should be 1972 if monthCode is given",
13+
result1, "M02", 28,
14+
"year and monthCode determine if calendar date exists, but reference year should be 1972",
1515
1972
1616
);
1717

1818
const result2 = Temporal.PlainMonthDay.from({ year: 2021, month: 2, day: 29, calendar: "gregory" }, { overflow: "constrain" });
1919
TemporalHelpers.assertPlainMonthDay(
2020
result2, "M02", 28,
21-
"if monthCode is not given, year is used to determine if calendar date exists, but reference year should still be 1972",
21+
"year and month determine if calendar date exists, but reference year should be 1972",
2222
1972
2323
);
2424

25+
assert.throws(
26+
RangeError,
27+
() => Temporal.PlainMonthDay.from({ year: 2021, monthCode: "M02", day: 29, calendar: "gregory" }, { overflow: "reject" }),
28+
"RangeError thrown if monthCode and day does not exist in given year and overflow is reject"
29+
);
30+
2531
assert.throws(
2632
RangeError,
2733
() => Temporal.PlainMonthDay.from({ year: 2021, month: 2, day: 29, calendar: "gregory" }, { overflow: "reject" }),
28-
"RangeError thrown if calendar date does not exist in given year and overflow is reject"
34+
"RangeError thrown if month and day does not exist in given year and overflow is reject"
2935
);
3036

3137
const result3 = Temporal.PlainMonthDay.from({ monthCode: "M01", day: 1, calendar: "hebrew" });
@@ -44,28 +50,41 @@ TemporalHelpers.assertPlainMonthDay(
4450

4551
const result5 = Temporal.PlainMonthDay.from({ year: 5781, monthCode: "M02", day: 30, calendar: "hebrew" });
4652
TemporalHelpers.assertPlainMonthDay(
47-
result5, "M02", 30,
48-
"year is ignored if monthCode is given (Cheshvan 5781 has 29 days)",
49-
1971
53+
result5, "M02", 29,
54+
"year and monthCode determine if calendar date exists, and reference year must agree (Cheshvan 5781 has 29 days)",
55+
1972
5056
);
5157

5258
const result6 = Temporal.PlainMonthDay.from({ year: 5781, month: 2, day: 30, calendar: "hebrew" }, { overflow: "constrain" });
5359
TemporalHelpers.assertPlainMonthDay(
5460
result6, "M02", 29,
55-
"if monthCode is not given, year is used to determine if calendar date exists, but reference year still correct",
61+
"year and month determine if calendar date exists, and reference year must agree (Cheshvan 5781 has 29 days)",
5662
1972
5763
);
5864

65+
const result7 = Temporal.PlainMonthDay.from({ monthCode: "M02", day: 30, calendar: "hebrew" });
66+
TemporalHelpers.assertPlainMonthDay(
67+
result7, "M02", 30,
68+
"reference year must be the latest ISO year at or before 1972 that includes monthCode and day (Cheshvan 5781 has 29 days)",
69+
1971
70+
);
71+
72+
assert.throws(
73+
RangeError,
74+
() => Temporal.PlainMonthDay.from({ year: 5781, monthCode: "M02", day: 30, calendar: "hebrew" }, { overflow: "reject" }),
75+
"RangeError thrown if monthCode and day does not exist in given year and overflow is reject"
76+
);
77+
5978
assert.throws(
6079
RangeError,
6180
() => Temporal.PlainMonthDay.from({ year: 5781, month: 2, day: 30, calendar: "hebrew" }, { overflow: "reject" }),
62-
"RangeError thrown if calendar date does not exist in given year and overflow is reject"
81+
"RangeError thrown if month and day does not exist in given year and overflow is reject"
6382
);
6483

65-
const result7 = Temporal.PlainMonthDay.from({ monthCode: "M04", day: 26, calendar: "hebrew" });
84+
const result8 = Temporal.PlainMonthDay.from({ monthCode: "M04", day: 26, calendar: "hebrew" });
6685
TemporalHelpers.assertPlainMonthDay(
67-
result7, "M04", 26,
86+
result8, "M04", 26,
6887
"reference date should be the later one, if two options exist in ISO year 1972",
6988
1972
7089
);
71-
assert.sameValue(result7.toString(), "1972-12-31[u-ca=hebrew]", "reference date");
90+
assert.sameValue(result8.toString(), "1972-12-31[u-ca=hebrew]", "reference date");

0 commit comments

Comments
 (0)