reference-year-1972.js (3663B)
1 // |reftest| skip-if(!this.hasOwnProperty('Temporal')) -- Temporal is not enabled unconditionally 2 // Copyright (C) 2023 Igalia, S.L. All rights reserved. 3 // This code is governed by the BSD license found in the LICENSE file. 4 5 /*--- 6 esid: sec-temporal.plainmonthday.from 7 description: Deterministic choosing of the reference year 8 includes: [temporalHelpers.js] 9 features: [Temporal] 10 ---*/ 11 12 const result1 = Temporal.PlainMonthDay.from({ year: 2021, monthCode: "M02", day: 29, calendar: "gregory" }); 13 TemporalHelpers.assertPlainMonthDay( 14 result1, "M02", 28, 15 "year and monthCode determine if calendar date exists, but reference year should be 1972", 16 1972 17 ); 18 19 const result2 = Temporal.PlainMonthDay.from({ year: 2021, month: 2, day: 29, calendar: "gregory" }, { overflow: "constrain" }); 20 TemporalHelpers.assertPlainMonthDay( 21 result2, "M02", 28, 22 "year and month determine if calendar date exists, but reference year should be 1972", 23 1972 24 ); 25 26 assert.throws( 27 RangeError, 28 () => Temporal.PlainMonthDay.from({ year: 2021, monthCode: "M02", day: 29, calendar: "gregory" }, { overflow: "reject" }), 29 "RangeError thrown if monthCode and day does not exist in given year and overflow is reject" 30 ); 31 32 assert.throws( 33 RangeError, 34 () => Temporal.PlainMonthDay.from({ year: 2021, month: 2, day: 29, calendar: "gregory" }, { overflow: "reject" }), 35 "RangeError thrown if month and day does not exist in given year and overflow is reject" 36 ); 37 38 const result3 = Temporal.PlainMonthDay.from({ monthCode: "M01", day: 1, calendar: "hebrew" }); 39 TemporalHelpers.assertPlainMonthDay( 40 result3, "M01", 1, 41 "reference year should be 1972 if date exists in 1972", 42 1972 43 ); 44 45 const result4 = Temporal.PlainMonthDay.from({ monthCode: "M05L", day: 1, calendar: "hebrew" }); 46 TemporalHelpers.assertPlainMonthDay( 47 result4, "M05L", 1, 48 "reference year should be the latest ISO year before 1972 if date does not exist in 1972", 49 1970 50 ); 51 52 const result5 = Temporal.PlainMonthDay.from({ year: 5781, monthCode: "M02", day: 30, calendar: "hebrew" }); 53 TemporalHelpers.assertPlainMonthDay( 54 result5, "M02", 29, 55 "year and monthCode determine if calendar date exists, and reference year must agree (Cheshvan 5781 has 29 days)", 56 1972 57 ); 58 59 const result6 = Temporal.PlainMonthDay.from({ year: 5781, month: 2, day: 30, calendar: "hebrew" }, { overflow: "constrain" }); 60 TemporalHelpers.assertPlainMonthDay( 61 result6, "M02", 29, 62 "year and month determine if calendar date exists, and reference year must agree (Cheshvan 5781 has 29 days)", 63 1972 64 ); 65 66 const result7 = Temporal.PlainMonthDay.from({ monthCode: "M02", day: 30, calendar: "hebrew" }); 67 TemporalHelpers.assertPlainMonthDay( 68 result7, "M02", 30, 69 "reference year must be the latest ISO year at or before 1972 that includes monthCode and day (Cheshvan 5781 has 29 days)", 70 1971 71 ); 72 73 assert.throws( 74 RangeError, 75 () => Temporal.PlainMonthDay.from({ year: 5781, monthCode: "M02", day: 30, calendar: "hebrew" }, { overflow: "reject" }), 76 "RangeError thrown if monthCode and day does not exist in given year and overflow is reject" 77 ); 78 79 assert.throws( 80 RangeError, 81 () => Temporal.PlainMonthDay.from({ year: 5781, month: 2, day: 30, calendar: "hebrew" }, { overflow: "reject" }), 82 "RangeError thrown if month and day does not exist in given year and overflow is reject" 83 ); 84 85 const result8 = Temporal.PlainMonthDay.from({ monthCode: "M04", day: 26, calendar: "hebrew" }); 86 TemporalHelpers.assertPlainMonthDay( 87 result8, "M04", 26, 88 "reference date should be the later one, if two options exist in ISO year 1972", 89 1972 90 ); 91 assert.sameValue(result8.toString(), "1972-12-31[u-ca=hebrew]", "reference date"); 92 93 reportCompare(0, 0);