Skip to content

Commit

Permalink
Temporal: Update tests to account for use of year in ToTemporalMonthDay
Browse files Browse the repository at this point in the history
  • Loading branch information
gibson042 committed Sep 18, 2024
1 parent 70cdc56 commit 9e34d1d
Showing 1 changed file with 31 additions and 12 deletions.
43 changes: 31 additions & 12 deletions test/intl402/Temporal/PlainMonthDay/from/reference-year-1972.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,28 @@ features: [Temporal]

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

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

assert.throws(
RangeError,
() => Temporal.PlainMonthDay.from({ year: 2021, monthCode: "M02", day: 29, calendar: "gregory" }, { overflow: "reject" }),
"RangeError thrown if monthCode and day does not exist in given year and overflow is reject"
);

assert.throws(
RangeError,
() => Temporal.PlainMonthDay.from({ year: 2021, month: 2, day: 29, calendar: "gregory" }, { overflow: "reject" }),
"RangeError thrown if calendar date does not exist in given year and overflow is reject"
"RangeError thrown if month and day does not exist in given year and overflow is reject"
);

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

const result5 = Temporal.PlainMonthDay.from({ year: 5781, monthCode: "M02", day: 30, calendar: "hebrew" });
TemporalHelpers.assertPlainMonthDay(
result5, "M02", 30,
"year is ignored if monthCode is given (Cheshvan 5781 has 29 days)",
1971
result5, "M02", 29,
"year and monthCode determine if calendar date exists, and reference year must agree (Cheshvan 5781 has 29 days)",
1972
);

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

const result7 = Temporal.PlainMonthDay.from({ monthCode: "M02", day: 30, calendar: "hebrew" });
TemporalHelpers.assertPlainMonthDay(
result7, "M02", 30,
"reference year must be the latest ISO year at or before 1972 that includes monthCode and day (Cheshvan 5781 has 29 days)",
1971
);

assert.throws(
RangeError,
() => Temporal.PlainMonthDay.from({ year: 5781, monthCode: "M02", day: 30, calendar: "hebrew" }, { overflow: "reject" }),
"RangeError thrown if monthCode and day does not exist in given year and overflow is reject"
);

assert.throws(
RangeError,
() => Temporal.PlainMonthDay.from({ year: 5781, month: 2, day: 30, calendar: "hebrew" }, { overflow: "reject" }),
"RangeError thrown if calendar date does not exist in given year and overflow is reject"
"RangeError thrown if month and day does not exist in given year and overflow is reject"
);

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

0 comments on commit 9e34d1d

Please sign in to comment.