From 05c1981719f51b04e5db1bae7e4fc232f44d9ff3 Mon Sep 17 00:00:00 2001 From: "Michael J. Radwin" Date: Thu, 10 Dec 2020 14:59:34 -0800 Subject: [PATCH] Don't generate Candle-lighting events for Chanukah when options.noHolidays present --- package.json | 18 +++++++++--------- src/candles.js | 31 +++++++++++++++++++++++++++++-- src/candles.spec.js | 23 +++++++++++++++++++++-- src/hebcal.js | 2 +- 4 files changed, 60 insertions(+), 14 deletions(-) diff --git a/package.json b/package.json index d089b06..b41cb0b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@hebcal/core", - "version": "2.7.0", + "version": "2.8.0", "author": "Michael J. Radwin (https://github.com/mjradwin)", "contributors": [ "Eyal Schachter (https://github.com/Scimonster)", @@ -65,23 +65,23 @@ }, "devDependencies": { "@ava/babel": "^1.0.1", - "@babel/core": "^7.12.8", - "@babel/preset-env": "^7.12.7", - "@babel/register": "^7.12.1", + "@babel/core": "^7.12.10", + "@babel/preset-env": "^7.12.10", + "@babel/register": "^7.12.10", "@hebcal/solar-calc": "^1.0.4", - "@rollup/plugin-babel": "^5.2.1", + "@rollup/plugin-babel": "^5.2.2", "@rollup/plugin-commonjs": "^16.0.0", "@rollup/plugin-json": "^4.1.0", "@rollup/plugin-node-resolve": "^10.0.0", - "ava": "^3.13.0", - "core-js": "^3.7.0", - "eslint": "^7.14.0", + "ava": "^3.14.0", + "core-js": "^3.8.1", + "eslint": "^7.15.0", "eslint-config-google": "^0.14.0", "gematriya": "^2.0.0", "jsdoc": "^3.6.6", "jsdoc-to-markdown": "^6.0.1", "nyc": "^15.1.0", - "rollup": "^2.33.3", + "rollup": "^2.34.2", "rollup-plugin-terser": "^7.0.2", "tsd-jsdoc": "^2.5.0", "ttag-cli": "^1.8.8" diff --git a/src/candles.js b/src/candles.js index 1e62d1f..efbb662 100644 --- a/src/candles.js +++ b/src/candles.js @@ -8,6 +8,16 @@ const days = { SAT: 6, }; +/** + * @private + * This method returns the tzais (nightfall) based on the opinion of the + * Geonim calculated as 30 minutes after sunset during the equinox + * (on March 16, about 4 days before the astronomical equinox, the day that + * a solar hour is 60 minutes) in Yerushalayim. + * @see {https://kosherjava.com/zmanim/docs/api/com/kosherjava/zmanim/ComplexZmanimCalendar.html#getTzaisGeonim7Point083Degrees()} + */ +const TZEIT_3MEDIUM_STARS = 7.083; + /** * @private * @param {Intl.DateTimeFormat} timeFormat @@ -212,7 +222,7 @@ export function makeFastStartEnd(ev, hd, location, timeFormat) { const begin = makeTimedEvent(hd, sunset, 'Fast begins', ev, timeFormat); return [begin, null]; } else if (desc === 'Tish\'a B\'Av') { - const end = makeTimedEvent(hd, zmanim.tzeit(7.083), 'Fast ends', ev, timeFormat); + const end = makeTimedEvent(hd, zmanim.tzeit(TZEIT_3MEDIUM_STARS), 'Fast ends', ev, timeFormat); return [null, end]; } const dawn = zmanim.alotHaShachar(); @@ -220,7 +230,7 @@ export function makeFastStartEnd(ev, hd, location, timeFormat) { if (dt.getDay() === 5 || (hd.getDate() === 14 && hd.getMonth() === months.NISAN)) { return [begin, null]; } - const end = makeTimedEvent(hd, zmanim.tzeit(7.083), 'Fast ends', ev, timeFormat); + const end = makeTimedEvent(hd, zmanim.tzeit(TZEIT_3MEDIUM_STARS), 'Fast ends', ev, timeFormat); return [begin, end]; } @@ -239,3 +249,20 @@ function makeTimedEvent(hd, time, desc, ev, timeFormat) { } return new TimedEvent(hd, desc, ev.getFlags(), time, formatTime(timeFormat, time), ev); } + + +/** + * Makes a candle-lighting event for Chankah (not on Friday/Saturday) + * @private + * @param {Event} ev + * @param {HDate} hd + * @param {Location} location + * @param {Intl.DateTimeFormat} timeFormat + * @return {TimedEvent} + */ +export function makeWeekdayChanukahCandleLighting(ev, hd, location, timeFormat) { + const zmanim = new Zmanim(hd.greg(), location.getLatitude(), location.getLongitude()); + const candleLightingTime = zmanim.tzeit(TZEIT_3MEDIUM_STARS); + // const candleLightingTime = zmanim.sunset(); + return makeTimedEvent(hd, candleLightingTime, ev.getDesc(), ev, timeFormat); +} diff --git a/src/candles.spec.js b/src/candles.spec.js index 1ae3f1f..63081c8 100644 --- a/src/candles.spec.js +++ b/src/candles.spec.js @@ -84,7 +84,7 @@ test('candles-only-diaspora', (t) => { candlelighting: true, }; const events = HebrewCalendar.calendar(options); - t.is(events.length, 126); + t.is(events.length, 120); t.is(events[0].getFlags(), flags.LIGHT_CANDLES); t.is(events[0].render(), 'Candle lighting: 16:10'); t.is(events[0].getDesc(), 'Candle lighting'); @@ -208,7 +208,7 @@ test('candles-only-israel', (t) => { candlelighting: true, }; const events = HebrewCalendar.calendar(options); - t.is(events.length, 123); + t.is(events.length, 117); t.is(events[0].getFlags(), flags.LIGHT_CANDLES, 'Candle lighting 0'); t.is(events[33].getFlags(), flags.CHAG | flags.YOM_TOV_ENDS | flags.IL_ONLY, 'Havdalah in Israel on Pesach VII'); }); @@ -338,3 +338,22 @@ test('fastStartEnd-9av', (t) => { ]; t.deepEqual(events.map(eventTitleDateTime), expected); }); + +test('no-chanukah-candles-when-noHolidays', (t) => { + const options = { + candlelighting: true, + noHolidays: true, + start: new Date(2020, 11, 9), + end: new Date(2020, 11, 19), + location: Location.lookup('Seattle'), + }; + const events = HebrewCalendar.calendar(options); + const expected = [ + {date: '2020-12-11', time: '15:59', desc: 'Candle lighting'}, + {date: '2020-12-12', time: '17:10', desc: 'Havdalah'}, + {date: '2020-12-18', time: '16:01', desc: 'Candle lighting'}, + {date: '2020-12-19', time: '17:12', desc: 'Havdalah'}, + ]; + const actual = events.map(eventTitleDateTime); + t.deepEqual(actual, expected); +}); diff --git a/src/hebcal.js b/src/hebcal.js index e0a12f1..ae425cb 100644 --- a/src/hebcal.js +++ b/src/hebcal.js @@ -257,7 +257,7 @@ function getMaskFromOptions(options) { LIGHT_CANDLES | LIGHT_CANDLES_TZEIS | CHANUKAH_CANDLES; } if (options.candlelighting) { - mask |= LIGHT_CANDLES | LIGHT_CANDLES_TZEIS | CHANUKAH_CANDLES; + mask |= LIGHT_CANDLES | LIGHT_CANDLES_TZEIS; } // suppression of defaults if (options.noRoshChodesh) {