indian-month-codes.js (2892B)
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 month codes (M01-M12) in Indian calendar 8 features: [Temporal, Intl.Era-monthcode] 9 ---*/ 10 11 // Test that all month codes M01-M12 are valid for the Indian calendar 12 // Indian calendar month lengths: 13 // - M01-M06: 31 days 14 // - M07-M12: 30 days 15 16 const calendar = "indian"; 17 18 // Months with 31 days 19 const monthsWith31Days = ["M01", "M02", "M03", "M04", "M05", "M06"]; 20 21 for (const monthCode of monthsWith31Days) { 22 const pmd = Temporal.PlainMonthDay.from({ calendar, monthCode, day: 1 }); 23 assert.sameValue(pmd.monthCode, monthCode, `monthCode ${monthCode} should be preserved`); 24 assert.sameValue(pmd.day, 1, `day should be 1 for ${monthCode}`); 25 26 const pmd31 = Temporal.PlainMonthDay.from({ calendar, monthCode, day: 31 }); 27 assert.sameValue(pmd31.monthCode, monthCode, `${monthCode} with day 31 should be valid`); 28 assert.sameValue(pmd31.day, 31, `day should be 31 for ${monthCode}`); 29 30 const constrained = Temporal.PlainMonthDay.from( 31 { calendar, monthCode, day: 32 }, 32 { overflow: "constrain" } 33 ); 34 assert.sameValue(constrained.monthCode, monthCode, `${monthCode} should be preserved with constrain`); 35 assert.sameValue(constrained.day, 31, `day 32 should be constrained to 31 for ${monthCode}`); 36 37 assert.throws(RangeError, () => { 38 Temporal.PlainMonthDay.from({ calendar, monthCode, day: 32 }, { overflow: "reject" }); 39 }, `${monthCode} with day 32 should throw with reject overflow`); 40 } 41 42 // Months with 30 days 43 const monthsWith30Days = ["M07", "M08", "M09", "M10", "M11", "M12"]; 44 45 for (const monthCode of monthsWith30Days) { 46 const pmd = Temporal.PlainMonthDay.from({ calendar, monthCode, day: 1 }); 47 assert.sameValue(pmd.monthCode, monthCode, `monthCode ${monthCode} should be preserved`); 48 assert.sameValue(pmd.day, 1, `day should be 1 for ${monthCode}`); 49 50 const pmd30 = Temporal.PlainMonthDay.from({ calendar, monthCode, day: 30 }); 51 assert.sameValue(pmd30.monthCode, monthCode, `${monthCode} with day 30 should be valid`); 52 assert.sameValue(pmd30.day, 30, `day should be 30 for ${monthCode}`); 53 54 const constrained = Temporal.PlainMonthDay.from( 55 { calendar, monthCode, day: 31 }, 56 { overflow: "constrain" } 57 ); 58 assert.sameValue(constrained.monthCode, monthCode, `${monthCode} should be preserved with constrain`); 59 assert.sameValue(constrained.day, 30, `day 31 should be constrained to 30 for ${monthCode}`); 60 61 assert.throws(RangeError, () => { 62 Temporal.PlainMonthDay.from({ calendar, monthCode, day: 31 }, { overflow: "reject" }); 63 }, `${monthCode} with day 31 should throw with reject overflow`); 64 } 65 66 reportCompare(0, 0);