chinese-month-codes.js (2000B)
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 (M01-M12) in Chinese calendar 8 features: [Temporal, Intl.Era-monthcode] 9 ---*/ 10 11 // Test that all regular month codes M01-M12 are valid for the Chinese calendar 12 // The Chinese calendar is a lunisolar calendar, so months vary in length 13 // Leap months (M01L-M12L) are tested elsewhere 14 15 const calendar = "chinese"; 16 const monthCodes = [ 17 "M01", "M02", "M03", "M04", "M05", "M06", 18 "M07", "M08", "M09", "M10", "M11", "M12" 19 ]; 20 21 for (const monthCode of monthCodes) { 22 // Test creation with monthCode 23 const pmd = Temporal.PlainMonthDay.from({ calendar, monthCode, day: 1 }); 24 assert.sameValue(pmd.monthCode, monthCode, `monthCode ${monthCode} should be preserved`); 25 assert.sameValue(pmd.day, 1, "day should be 1"); 26 27 // Test with day 30 (months can have 29 or 30 days) 28 const pmd30 = Temporal.PlainMonthDay.from({ calendar, monthCode, day: 30 }); 29 assert.sameValue(pmd30.monthCode, monthCode, `${monthCode} with day 30 should be valid`); 30 assert.sameValue(pmd30.day, 30, `day should be 30 for ${monthCode}`); 31 32 // Test constrain overflow - Chinese months vary from 29-30 days 33 const constrained = Temporal.PlainMonthDay.from( 34 { calendar, monthCode, day: 31 }, 35 { overflow: "constrain" } 36 ); 37 assert.sameValue(constrained.monthCode, monthCode, `${monthCode} should be preserved with constrain`); 38 assert.sameValue(constrained.day, 30, `day 31 should be constrained to 30 for ${monthCode}`); 39 40 // Test reject overflow for day 31 41 assert.throws(RangeError, () => { 42 Temporal.PlainMonthDay.from({ calendar, monthCode, day: 31 }, { overflow: "reject" }); 43 }, `${monthCode} with day 31 should throw with reject overflow`); 44 } 45 46 reportCompare(0, 0);