hebrew-month-codes.js (2929B)
1 // |reftest| skip-if(!this.hasOwnProperty('Temporal')) -- Temporal is not enabled unconditionally 2 // Copyright (C) 2025 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: PlainMonthDay can be created for all regular month codes and leap month in Hebrew calendar 8 features: [Temporal, Intl.Era-monthcode] 9 ---*/ 10 11 // Test that all regular month codes M01-M12 and leap month M05L are valid for the Hebrew calendar 12 13 const calendar = "hebrew"; 14 15 // Months with 30 days maximum 16 // M05L is the leap month (Adar I); in leap years M05L is Adar I and M06 is Adar II 17 const monthsWith30Days = ["M01", "M02", "M03", "M05", "M05L", "M07", "M09", "M11"]; 18 19 for (const monthCode of monthsWith30Days) { 20 const pmd = Temporal.PlainMonthDay.from({ calendar, monthCode, day: 1 }); 21 assert.sameValue(pmd.monthCode, monthCode, `monthCode ${monthCode} should be preserved`); 22 assert.sameValue(pmd.day, 1, "day should be 1"); 23 24 const pmd30 = Temporal.PlainMonthDay.from({ calendar, monthCode, day: 30 }); 25 assert.sameValue(pmd30.monthCode, monthCode, `${monthCode} with day 30 should be valid`); 26 assert.sameValue(pmd30.day, 30, `day should be 30 for ${monthCode}`); 27 28 const constrained = Temporal.PlainMonthDay.from( 29 { calendar, monthCode, day: 31 }, 30 { overflow: "constrain" } 31 ); 32 assert.sameValue(constrained.monthCode, monthCode, `${monthCode} should be preserved with constrain`); 33 assert.sameValue(constrained.day, 30, `day 31 should be constrained to 30 for ${monthCode}`); 34 35 assert.throws(RangeError, () => { 36 Temporal.PlainMonthDay.from({ calendar, monthCode, day: 31 }, { overflow: "reject" }); 37 }, `${monthCode} with day 31 should throw with reject overflow`); 38 } 39 40 // Months with 29 days maximum 41 const monthsWith29Days = ["M04", "M06", "M08", "M10", "M12"]; 42 43 for (const monthCode of monthsWith29Days) { 44 const pmd = Temporal.PlainMonthDay.from({ calendar, monthCode, day: 1 }); 45 assert.sameValue(pmd.monthCode, monthCode, `monthCode ${monthCode} should be preserved`); 46 assert.sameValue(pmd.day, 1, "day should be 1"); 47 48 const pmd29 = Temporal.PlainMonthDay.from({ calendar, monthCode, day: 29 }); 49 assert.sameValue(pmd29.monthCode, monthCode, `${monthCode} with day 29 should be valid`); 50 assert.sameValue(pmd29.day, 29, `day should be 29 for ${monthCode}`); 51 52 const constrained = Temporal.PlainMonthDay.from( 53 { calendar, monthCode, day: 30 }, 54 { overflow: "constrain" } 55 ); 56 assert.sameValue(constrained.monthCode, monthCode, `${monthCode} should be preserved with constrain`); 57 assert.sameValue(constrained.day, 29, `day 30 should be constrained to 29 for ${monthCode}`); 58 59 assert.throws(RangeError, () => { 60 Temporal.PlainMonthDay.from({ calendar, monthCode, day: 30 }, { overflow: "reject" }); 61 }, `${monthCode} with day 30 should throw with reject overflow`); 62 } 63 64 reportCompare(0, 0);