hebrew-keviah.js (1582B)
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.plaindate.from 7 description: Check that computed kevi'ah symbols for years are in the valid set 8 features: [Temporal, Intl.Era-monthcode] 9 ---*/ 10 11 // Ensure kevi'ah is correct. 12 // 13 // https://en.wikipedia.org/wiki/Hebrew_calendar#Keviah 14 15 function KeviahSymbol(year) { 16 let startOfYear = Temporal.PlainDate.from({ 17 calendar: "hebrew", 18 year, 19 monthCode: "M01", 20 day: 1, 21 }); 22 23 let firstDayOfPesach = Temporal.PlainDate.from({ 24 calendar: "hebrew", 25 year, 26 monthCode: "M07", 27 day: 15, 28 }); 29 30 let yearSymbol = { 31 353: "D", // deficient 32 354: "R", // regular 33 355: "C", // complete 34 35 383: "D", // deficient, leap year 36 384: "R", // regular, leap year 37 385: "C", // complete, leap year 38 }; 39 40 // Week starts on Sunday. 41 let daySymbol = date => (date.dayOfWeek % 7) + 1; 42 43 let {daysInYear} = startOfYear; 44 assert.sameValue(daysInYear in yearSymbol, true); 45 46 return `${daySymbol(startOfYear)}${yearSymbol[daysInYear]}${daySymbol(firstDayOfPesach)}`; 47 } 48 49 const validKeviahSymbols = new Set([ 50 "2D3", "2C5", "2D5", "2C7", 51 "3R5", "3R7", 52 "5R7", "5C1", "5D1", "5C3", 53 "7D1", "7C3", "7D3", "7C5" 54 ]); 55 56 for (let year = 3700; year <= 5800; ++year) { 57 let sym = KeviahSymbol(year); 58 assert.sameValue(validKeviahSymbols.has(sym), true, `${year} -> ${sym}`); 59 } 60 61 reportCompare(0, 0);