chinese-leap-month-codes-common.js (2645B)
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 common leap month codes in Chinese calendar 8 features: [Temporal, Intl.Era-monthcode] 9 ---*/ 10 11 // Test common leap months in the Chinese calendar 12 // The Chinese calendar is a lunisolar calendar where leap months are inserted 13 // to keep the lunar year synchronized with the solar year. 14 // Common leap months (occurring more frequently in the astronomical cycle): 15 // M02L, M03L, M04L, M05L, M06L, M07L, M08L 16 // 17 // The distribution of leap months follows astronomical calculations. 18 // 19 // Note: M01L, M02L and M08L through M12L are temporarily omitted from this 20 // test because while any leap month can have 30 days, there isn't a year in the 21 // supported range where these months do, and it's not yet well-defined what 22 // reference ISO year should be used. 23 // See https://github.com/tc39/proposal-intl-era-monthcode/issues/60 24 25 const calendar = "chinese"; 26 27 // Test leap months M03L-M07L with day 30 28 // These are well-established leap months that can have 30 days 29 const leapMonthsWith30Days = ["M03L", "M04L", "M05L", "M06L", "M07L"]; 30 31 for (const monthCode of leapMonthsWith30Days) { 32 // Test creation with monthCode 33 const pmd = Temporal.PlainMonthDay.from({ calendar, monthCode, day: 1 }); 34 assert.sameValue(pmd.monthCode, monthCode, `leap monthCode ${monthCode} should be preserved`); 35 assert.sameValue(pmd.day, 1, `day should be 1 for ${monthCode}`); 36 37 // These leap months can have up to 30 days (minimum for PlainMonthDay) 38 const pmd30 = Temporal.PlainMonthDay.from({ calendar, monthCode, day: 30 }); 39 assert.sameValue(pmd30.monthCode, monthCode, `${monthCode} with day 30 should be valid`); 40 assert.sameValue(pmd30.day, 30, `day should be 30 for ${monthCode}`); 41 42 // Test constrain overflow - day 31 should be constrained to 30 43 const constrained = Temporal.PlainMonthDay.from( 44 { calendar, monthCode, day: 31 }, 45 { overflow: "constrain" } 46 ); 47 assert.sameValue(constrained.monthCode, monthCode, `${monthCode} should be preserved with constrain`); 48 assert.sameValue(constrained.day, 30, `day 31 should be constrained to 30 for ${monthCode}`); 49 50 // Test reject overflow - day 31 should throw 51 assert.throws(RangeError, () => { 52 Temporal.PlainMonthDay.from({ calendar, monthCode, day: 31 }, { overflow: "reject" }); 53 }, `${monthCode} with day 31 should throw with reject overflow`); 54 } 55 56 reportCompare(0, 0);