chinese-30-day-leap-months.js (2076B)
1 // |reftest| skip-if(!this.hasOwnProperty('Temporal')) -- Temporal is not enabled unconditionally 2 // Copyright (C) 2024 Mozilla Corporation. 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 features: [Temporal] 8 description: Check correct results for 30-day leap months 9 includes: [temporalHelpers.js] 10 ---*/ 11 12 // Common leap months should find a result not too far into the past. 13 // 14 // Month -> ISO year 15 // 16 // M01L <uncommon> 17 // M02L 1765 18 // M03L 1955 19 // M04L 1944 20 // M05L 1952 21 // M06L 1941 22 // M07L 1938 23 // M08L 1718 24 // M09L <uncommon> 25 // M10L <uncommon> 26 // M11L <uncommon> 27 // M12L <uncommon> 28 // 29 // M02L and M08L with 29 days is common, but with 30 is actually rather uncommon. 30 // 31 // See also "The Mathematics of the Chinese Calendar", Table 21 [1] for a 32 // distribution of leap months. 33 // 34 // [1] https://www.xirugu.com/CHI500/Dates_Time/Chinesecalender.pdf 35 36 // In this test, we skip the months whose most recent year is outside 37 // the range 1900-2100. 38 const monthCodesWithYears = [ 39 { monthCode: "M03L", referenceYear: 1955 }, 40 { monthCode: "M04L", referenceYear: 1944 }, 41 { monthCode: "M05L", referenceYear: 1952 }, 42 { monthCode: "M06L", referenceYear: 1941 }, 43 { monthCode: "M07L", referenceYear: 1938 } 44 ]; 45 46 const calendar = "chinese"; 47 48 // Months can have up to 30 days. 49 const day = 30; 50 51 for (let {monthCode, referenceYear} of monthCodesWithYears) { 52 let pmd = Temporal.PlainMonthDay.from({calendar, monthCode, day}); 53 TemporalHelpers.assertPlainMonthDay(pmd, monthCode, day, monthCode, referenceYear); 54 55 let constrain = Temporal.PlainMonthDay.from({calendar, monthCode, day: day + 1}, {overflow: "constrain"}); 56 TemporalHelpers.assertPlainMonthDay(constrain, monthCode, day, `${monthCode} (constrained)`, referenceYear); 57 assert.sameValue(constrain.equals(pmd), true); 58 59 assert.throws(RangeError, () => { 60 Temporal.PlainMonthDay.from({calendar, monthCode, day: day + 1}, {overflow: "reject"}); 61 }); 62 } 63 64 65 reportCompare(0, 0);