Skip to content

Commit

Permalink
Further simplify specialReadings() by handing Pinchas after 17 Tamuz
Browse files Browse the repository at this point in the history
 and Masei / Matot-Masei on Shabbat Rosh Chodesh
 consistently with other special Shabbatot
  • Loading branch information
mjradwin committed Aug 26, 2022
1 parent e3b4f79 commit fd93e7e
Show file tree
Hide file tree
Showing 9 changed files with 67 additions and 89 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ e.g. <code>Genesis 21:1-34; Numbers 29:1-6</code>.</p>
<dt><a href="#getLeyningKeyForEvent">getLeyningKeyForEvent(ev, [il])</a> ⇒ <code>string</code></dt>
<dd><p>Based on the event date, type and title, finds the relevant leyning key</p>
</dd>
<dt><a href="#specialReadings">specialReadings(hd, il, aliyot, reason)</a> ⇒ <code><a href="#Aliyah">Aliyah</a></code> | <code><a href="#Aliyah">Array.&lt;Aliyah&gt;</a></code></dt>
<dt><a href="#specialReadings">specialReadings(hd, il, aliyot, reason, parsha)</a> ⇒ <code><a href="#Aliyah">Aliyah</a></code> | <code><a href="#Aliyah">Array.&lt;Aliyah&gt;</a></code></dt>
<dd><p>Determines if the regular parashat haShavua coincides with an event that requires
a special maftir or Haftara (for example Shabbat HaGadol, Shabbat Chanukah, Rosh
Chodesh or Machar Chodesh, etc.).</p>
Expand Down Expand Up @@ -298,7 +298,7 @@ Based on the event date, type and title, finds the relevant leyning key

<a name="specialReadings"></a>

## specialReadings(hd, il, aliyot, reason) ⇒ [<code>Aliyah</code>](#Aliyah) \| [<code>Array.&lt;Aliyah&gt;</code>](#Aliyah)
## specialReadings(hd, il, aliyot, reason, parsha) ⇒ [<code>Aliyah</code>](#Aliyah) \| [<code>Array.&lt;Aliyah&gt;</code>](#Aliyah)
Determines if the regular parashat haShavua coincides with an event that requires
a special maftir or Haftara (for example Shabbat HaGadol, Shabbat Chanukah, Rosh
Chodesh or Machar Chodesh, etc.).
Expand All @@ -317,6 +317,7 @@ If no special Haftarah, returns `undefined`
| il | <code>boolean</code> |
| aliyot | <code>Object.&lt;string, Aliyah&gt;</code> |
| reason | <code>Object.&lt;string, string&gt;</code> |
| parsha | <code>Array.&lt;string&gt;</code> |

<a name="getLeyningForHoliday"></a>

Expand Down
2 changes: 1 addition & 1 deletion leyning.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ declare module '@hebcal/leyning' {
* If a special Haftarah applies, returns the Haftarah object and sets `reason.haftara`.
* If no special Haftarah, returns `undefined`
*/
export function specialReadings(hd: HDate, il: boolean, aliyot: AliyotMap, reason: StringMap): Aliyah | Aliyah[];
export function specialReadings(hd: HDate, il: boolean, aliyot: AliyotMap, reason: StringMap, parsha: string[]): Aliyah | Aliyah[];
/**
* Looks up leyning for a regular Shabbat, Monday/Thursday weekday or holiday.
*
Expand Down
32 changes: 16 additions & 16 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@hebcal/leyning",
"version": "6.0.1",
"version": "6.0.2",
"author": "Michael J. Radwin (https://github.com/mjradwin)",
"keywords": [
"hebcal",
Expand Down Expand Up @@ -31,7 +31,7 @@
"leyning-csv": "bin/leyning-csv"
},
"dependencies": {
"@hebcal/core": "^3.42.2"
"@hebcal/core": "^3.42.3"
},
"scripts": {
"build": "rollup -c",
Expand Down Expand Up @@ -59,7 +59,7 @@
"@rollup/plugin-commonjs": "^22.0.2",
"@rollup/plugin-json": "^4.1.0",
"@rollup/plugin-node-resolve": "^13.3.0",
"ava": "^4.3.1",
"ava": "^4.3.3",
"core-js": "^3.25.0",
"eslint": "^8.22.0",
"eslint-config-google": "^0.14.0",
Expand Down
16 changes: 16 additions & 0 deletions src/getLeyningForParshaHaShavua.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,22 @@ test('pinchas17Tamuz', (t) => {
a = getLeyningForParshaHaShavua(ev);
t.is(a.haftara, 'Jeremiah 1:1-2:3');
t.is(a.reason.haftara, 'Pinchas occurring after 17 Tammuz');

options.year = 2022;
options.il = true;
events = HebrewCalendar.calendar(options);
ev = events.find((e) => e.getDesc() == 'Parashat Pinchas');
a = getLeyningForParshaHaShavua(ev);
t.is(a.reason, undefined);
t.is(a.haftara, 'I Kings 18:46-19:21');

options.year = 2023;
options.il = true;
events = HebrewCalendar.calendar(options);
ev = events.find((e) => e.getDesc() == 'Parashat Pinchas');
a = getLeyningForParshaHaShavua(ev);
t.is(a.haftara, 'Jeremiah 1:1-2:3');
t.is(a.reason.haftara, 'Pinchas occurring after 17 Tammuz');
});

// eslint-disable-next-line require-jsdoc
Expand Down
9 changes: 9 additions & 0 deletions src/holiday-readings.json
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,15 @@
"haft":{"k":"I Samuel","b":"15:2","e":"15:34"},
"fullkriyah":
{"M":{"p":49,"k":5,"b":"25:17","e":"25:19"}}},
"Pinchas occurring after 17 Tammuz":{
"haft": {"k": "Jeremiah", "b": "1:1", "e": "2:3"}},
"Masei on Shabbat Rosh Chodesh":{
"haft":[
{"k":"Jeremiah","b":"2:4","e":"2:28"},
{"k":"Jeremiah","b":"3:4","e":"3:4"},
{"k":"Isaiah","b":"66:1","e":"66:1"},
{"k":"Isaiah","b":"66:23","e":"66:23"}]},
"Matot-Masei on Shabbat Rosh Chodesh":{"alias":true,"key":"Masei on Shabbat Rosh Chodesh"},
"Rosh Chodesh":{
"fullkriyah":
{"1":{"p":41,"k":4,"b":"28:1","e":"28:3"},
Expand Down
2 changes: 1 addition & 1 deletion src/holiday.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ test('getLeyningForHoliday-Chanukah', (t) => {
const chanukah3 = events.find((e) => e.getDesc() == 'Chanukah: 3 Candles');
const reading = getLeyningForHoliday(chanukah3);
const expected = {
name: {en: 'Chanukah Day 2 (on Shabbat)', he: undefined},
name: {en: 'Chanukah Day 2 (on Shabbat)', he: 'חֲנוּכָּה יוֹם ב׳ (בְּשַׁבָּת)'},
fullkriyah: {M: {p: 35, k: 'Numbers', b: '7:18', e: '7:23', v: 6}},
haft: {k: 'Zechariah', b: '2:14', e: '4:7', v: 21},
haftara: 'Zechariah 2:14-4:7',
Expand Down
50 changes: 4 additions & 46 deletions src/leyning.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,37 +130,6 @@ function getHaftaraKey(parsha) {
}
}

/**
* @private
* @param {string[]} parsha
* @param {HDate} hd
* @return {Object|boolean}
*/
function getSpecialHaftara(parsha, hd) {
const name = parshaToString(parsha); // untranslated
const day = hd.getDate();
if (name === 'Pinchas') {
const month = hd.getMonth();
if (month > months.TAMUZ || (month === months.TAMUZ && day > 17)) {
return {
haft: {k: 'Jeremiah', b: '1:1', e: '2:3'},
reason: 'Pinchas occurring after 17 Tammuz',
};
}
} else if ((day === 30 || day === 1) && (name === 'Masei' || name === 'Matot-Masei')) {
return {
haft: [
{k: 'Jeremiah', b: '2:4', e: '2:28'},
{k: 'Jeremiah', b: '3:4', e: '3:4'},
{k: 'Isaiah', b: '66:1', e: '66:1'},
{k: 'Isaiah', b: '66:23', e: '66:23'},
],
reason: `${name} on Shabbat Rosh Chodesh`,
};
}
return false;
}

/**
* Looks up regular leyning for a weekly parsha with no special readings
* @param {string|string[]} parsha untranslated name like 'Pinchas' or ['Pinchas'] or ['Matot','Masei']
Expand Down Expand Up @@ -243,23 +212,17 @@ export function getLeyningForParshaHaShavua(ev, il=false) {
const reason = {};
const hd = ev.getDate();
// Now, check for special maftir or haftara on same date
const specialHaftara = specialReadings(hd, il, result.fullkriyah, reason);
let updateHaftaraSummary = false;
const specialHaftara = specialReadings(hd, il, result.fullkriyah, reason, parsha);
if (specialHaftara) {
result.haft = cloneHaftara(specialHaftara);
updateHaftaraSummary = true;
const haft = result.haft = cloneHaftara(specialHaftara);
result.haftara = makeSummaryFromParts(haft);
result.haftaraNumV = sumVerses(haft);
}
if (reason['7'] || reason['M']) {
const parts = makeLeyningParts(result.fullkriyah);
result.summary = makeSummaryFromParts(parts);
result.summaryParts = parts;
}
const specialHaftara2 = getSpecialHaftara(parsha, hd);
if (specialHaftara2) {
result.haft = cloneHaftara(specialHaftara2.haft);
updateHaftaraSummary = true;
reason.haftara = specialHaftara2.reason;
}
const reasons = Object.keys(reason);
if (reasons.length !== 0) {
result.reason = reason;
Expand All @@ -274,11 +237,6 @@ export function getLeyningForParshaHaShavua(ev, il=false) {
}
});
}
if (updateHaftaraSummary) {
const haft = result.haft;
result.haftara = makeSummaryFromParts(haft);
result.haftaraNumV = sumVerses(haft);
}
return result;
}

Expand Down
34 changes: 14 additions & 20 deletions src/specialReadings.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {HebrewCalendar, flags} from '@hebcal/core';
import {calculateNumVerses, clone, cloneHaftara} from './common';
import {calculateNumVerses, clone, cloneHaftara, parshaToString} from './common';
import {lookupFestival} from './festival';
import {getLeyningKeyForEvent} from './getLeyningKeyForEvent';

Expand Down Expand Up @@ -41,22 +41,6 @@ function mergeAliyotWithSpecial(aliyot, special) {
}
}

/**
* @private
* @param {Event} ev
* @param {string} key
* @return {string}
*/
function getChanukahShabbatKey(ev, key) {
if (key == 'Shabbat Rosh Chodesh Chanukah') {
return undefined;
}
if (ev.chanukahDay) {
return (ev.chanukahDay == 8) ? 'Shabbat Chanukah II' : 'Shabbat Chanukah';
}
return undefined;
}

/**
* Determines if the regular parashat haShavua coincides with an event that requires
* a special maftir or Haftara (for example Shabbat HaGadol, Shabbat Chanukah, Rosh
Expand All @@ -71,9 +55,10 @@ function getChanukahShabbatKey(ev, key) {
* @param {boolean} il
* @param {Object<string,Aliyah>} aliyot
* @param {Object<string,string>} reason
* @param {string[]} parsha
* @return {Aliyah | Aliyah[]}
*/
export function specialReadings(hd, il, aliyot, reason) {
export function specialReadings(hd, il, aliyot, reason, parsha) {
let haft;
let specialHaft = false;

Expand Down Expand Up @@ -101,9 +86,18 @@ export function specialReadings(hd, il, aliyot, reason) {
}
});
if (!haft) {
const parshaName = parsha ? parshaToString(parsha) : null;
const day = hd.getDate();
if (day === 30 || day === 1) {
const key = 'Shabbat Rosh Chodesh';
if (parshaName === 'Pinchas' && day > 17) {
// Pinchas is always read in Tamuz (never another month)
// either on the 14, 16, 17 (in Israel), 19, 21, 23, 24
const key = 'Pinchas occurring after 17 Tammuz';
const special = lookupFestival(key);
handleSpecial(special, key);
} else if (day === 30 || day === 1) {
const key = (parshaName === 'Masei' || parshaName === 'Matot-Masei') ?
`${parshaName} on Shabbat Rosh Chodesh` :
'Shabbat Rosh Chodesh';
const special = lookupFestival(key);
handleSpecial(special, key);
} else {
Expand Down

0 comments on commit fd93e7e

Please sign in to comment.