From 9202474dc2bc6560a990336a611c3e0dde8fbd92 Mon Sep 17 00:00:00 2001 From: "Michael J. Radwin" Date: Mon, 16 Oct 2023 18:14:52 -0700 Subject: [PATCH] More code style tweaks --- src/hdate.js | 1 + src/hebcal.js | 78 +++++++++++++++++++++++++++++---------------------- 2 files changed, 46 insertions(+), 33 deletions(-) diff --git a/src/hdate.js b/src/hdate.js index cce7dc9..f9fffbc 100644 --- a/src/hdate.js +++ b/src/hdate.js @@ -706,6 +706,7 @@ export class HDate { default: break; } + break; case 't': switch (c[1]) { case 'a': diff --git a/src/hebcal.js b/src/hebcal.js index 87a8dd6..771ef22 100644 --- a/src/hebcal.js +++ b/src/hebcal.js @@ -63,11 +63,15 @@ const MAJOR_FAST = flags.MAJOR_FAST; const ROSH_CHODESH = flags.ROSH_CHODESH; const PARSHA_HASHAVUA = flags.PARSHA_HASHAVUA; const DAF_YOMI = flags.DAF_YOMI; +const MISHNA_YOMI = flags.MISHNA_YOMI; +const NACH_YOMI = flags.NACH_YOMI; +const YERUSHALMI_YOMI = flags.YERUSHALMI_YOMI; const OMER_COUNT = flags.OMER_COUNT; const SHABBAT_MEVARCHIM = flags.SHABBAT_MEVARCHIM; const MINOR_HOLIDAY = flags.MINOR_HOLIDAY; const EREV = flags.EREV; const CHOL_HAMOED = flags.CHOL_HAMOED; +const YOM_KIPPUR_KATAN = flags.YOM_KIPPUR_KATAN; const unrecognizedAlreadyWarned = Object.create(null); const RECOGNIZED_OPTIONS = { @@ -328,33 +332,7 @@ export function getStartAndEnd(options) { */ function getMaskFromOptions(options) { if (typeof options.mask === 'number') { - const m = options.mask; - if (m & ROSH_CHODESH) delete options.noRoshChodesh; - if (m & MODERN_HOLIDAY) delete options.noModern; - if (m & MINOR_FAST) delete options.noMinorFast; - if (m & SPECIAL_SHABBAT) delete options.noSpecialShabbat; - if (m & PARSHA_HASHAVUA) options.sedrot = true; - if (m & DAF_YOMI) { - options.dailyLearning = options.dailyLearning || {}; - options.dailyLearning.dafYomi = true; - } - if (m & OMER_COUNT) options.omer = true; - if (m & SHABBAT_MEVARCHIM) options.shabbatMevarchim = true; - if (m & flags.MISHNA_YOMI) { - options.dailyLearning = options.dailyLearning || {}; - options.dailyLearning.mishnaYomi = true; - } - if (m & flags.NACH_YOMI) { - options.dailyLearning = options.dailyLearning || {}; - options.dailyLearning.nachYomi = true; - } - if (m & flags.YOM_KIPPUR_KATAN) options.yomKippurKatan = true; - if (m & flags.YERUSHALMI_YOMI) { - options.dailyLearning = options.dailyLearning || {}; - options.dailyLearning.yerushalmi = 1; - } - options.userMask = true; - return m; + return setOptionsFromMask(options); } const il = options.il || options.location?.il || false; let mask = 0; @@ -398,7 +376,7 @@ function getMaskFromOptions(options) { mask |= SHABBAT_MEVARCHIM; } if (options.yomKippurKatan) { - mask |= flags.YOM_KIPPUR_KATAN; + mask |= YOM_KIPPUR_KATAN; } if (options.dailyLearning) { const dailyLearning = options.dailyLearning; @@ -406,13 +384,13 @@ function getMaskFromOptions(options) { mask |= DAF_YOMI; } if (dailyLearning.mishnaYomi) { - mask |= flags.MISHNA_YOMI; + mask |= MISHNA_YOMI; } if (dailyLearning.nachYomi) { - mask |= flags.NACH_YOMI; + mask |= NACH_YOMI; } if (dailyLearning.yerushalmi) { - mask |= flags.YERUSHALMI_YOMI; + mask |= YERUSHALMI_YOMI; } } @@ -431,6 +409,40 @@ const hour12cc = { US: 1, CA: 1, BR: 1, AU: 1, NZ: 1, DO: 1, PR: 1, GR: 1, IN: 1, KR: 1, NP: 1, ZA: 1, }; +/** + * @private + * @param {CalOptions} options + * @return {number} + */ +function setOptionsFromMask(options) { + const m = options.mask; + if (m & ROSH_CHODESH) delete options.noRoshChodesh; + if (m & MODERN_HOLIDAY) delete options.noModern; + if (m & MINOR_FAST) delete options.noMinorFast; + if (m & SPECIAL_SHABBAT) delete options.noSpecialShabbat; + if (m & PARSHA_HASHAVUA) options.sedrot = true; + if (m & (DAF_YOMI | MISHNA_YOMI | NACH_YOMI | YERUSHALMI_YOMI)) { + options.dailyLearning = options.dailyLearning || {}; + if (m & DAF_YOMI) { + options.dailyLearning.dafYomi = true; + } + if (m & MISHNA_YOMI) { + options.dailyLearning.mishnaYomi = true; + } + if (m & NACH_YOMI) { + options.dailyLearning.nachYomi = true; + } + if (m & YERUSHALMI_YOMI) { + options.dailyLearning.yerushalmi = 1; + } + } + if (m & OMER_COUNT) options.omer = true; + if (m & SHABBAT_MEVARCHIM) options.shabbatMevarchim = true; + if (m & YOM_KIPPUR_KATAN) options.yomKippurKatan = true; + options.userMask = true; + return m; +} + /** * @private * @param {Event} ev @@ -923,7 +935,7 @@ function appendHolidayAndRelated(events, ev, options, candlesEv, dow) { return candlesEv; // holiday isn't observed here; bail out early } const eFlags = ev.getFlags(); - if ((!options.yomKippurKatan && (eFlags & flags.YOM_KIPPUR_KATAN)) || + if ((!options.yomKippurKatan && (eFlags & YOM_KIPPUR_KATAN)) || (options.noModern && (eFlags & MODERN_HOLIDAY))) { return candlesEv; // bail out early } @@ -956,7 +968,7 @@ function appendHolidayAndRelated(events, ev, options, candlesEv, dow) { candlesEv = undefined; } } - if (!options.noHolidays || (options.yomKippurKatan && (eFlags & flags.YOM_KIPPUR_KATAN))) { + if (!options.noHolidays || (options.yomKippurKatan && (eFlags & YOM_KIPPUR_KATAN))) { events.push(ev); // the original event itself } }