Skip to content

Commit

Permalink
Enable checking for a holiday reading specifically for Israel or Dias…
Browse files Browse the repository at this point in the history
…pora
  • Loading branch information
mjradwin committed May 17, 2023
1 parent ee11254 commit 71dceba
Show file tree
Hide file tree
Showing 10 changed files with 73 additions and 37 deletions.
33 changes: 17 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ with <code>aliyot[&#39;M&#39;]</code> replaced and sets <code>reason.M</code>
<p>If a special Haftarah applies, the result will have a <code>haft</code> property
pointing to Haftarah object and sets <code>reason.haftara</code>.</p>
</dd>
<dt><a href="#getLeyningForHolidayKey">getLeyningForHolidayKey(key, [cholHaMoedDay])</a> ⇒ <code><a href="#Leyning">Leyning</a></code></dt>
<dt><a href="#getLeyningForHolidayKey">getLeyningForHolidayKey(key, [cholHaMoedDay], [il])</a> ⇒ <code><a href="#Leyning">Leyning</a></code></dt>
<dd><p>Looks up leyning for a given holiday key. Key should be an
(untranslated) string used in holiday-readings.json. Returns some
of full kriyah aliyot, special Maftir, special Haftarah</p>
Expand All @@ -118,6 +118,9 @@ of full kriyah aliyot, special Maftir, special Haftarah</p>
<dd><p>Looks up leyning for a regular Shabbat parsha, including any special
maftir or Haftara.</p>
</dd>
<dt><a href="#lookupParsha">lookupParsha(parsha)</a> ⇒ <code><a href="#ParshaMeta">ParshaMeta</a></code></dt>
<dd><p>Returns the parsha metadata</p>
</dd>
<dt><a href="#getLeyningOnDate">getLeyningOnDate(hdate, il, [wantarray])</a> ⇒ <code><a href="#Leyning">Leyning</a></code> | <code><a href="#Leyning">Array.&lt;Leyning&gt;</a></code></dt>
<dd><p>Looks up leyning for a regular Shabbat, Monday/Thursday weekday or holiday.</p>
<p>If <code>hdate</code> coincides with a holiday that has Torah reading, returns the
Expand All @@ -127,9 +130,6 @@ reading for that day (see <a href="#getLeyningForHoliday">getLeyningForHoliday</
Parashat haShavua, containing only the <code>weekday</code> aliyot (no <code>fullkriyah</code>).</p>
<p>Otherwise, returns <code>undefined</code>.</p>
</dd>
<dt><a href="#lookupParsha">lookupParsha(parsha)</a> ⇒ <code><a href="#ParshaMeta">ParshaMeta</a></code></dt>
<dd><p>Returns the parsha metadata</p>
</dd>
<dt><a href="#writeCsvLines">writeCsvLines(stream, ev, reading, il, isParsha)</a></dt>
<dd><p>Formats reading for CSV</p>
</dd>
Expand Down Expand Up @@ -329,7 +329,7 @@ pointing to Haftarah object and sets `reason.haftara`.

<a name="getLeyningForHolidayKey"></a>

## getLeyningForHolidayKey(key, [cholHaMoedDay]) ⇒ [<code>Leyning</code>](#Leyning)
## getLeyningForHolidayKey(key, [cholHaMoedDay], [il]) ⇒ [<code>Leyning</code>](#Leyning)
Looks up leyning for a given holiday key. Key should be an
(untranslated) string used in holiday-readings.json. Returns some
of full kriyah aliyot, special Maftir, special Haftarah
Expand All @@ -341,6 +341,7 @@ of full kriyah aliyot, special Maftir, special Haftarah
| --- | --- | --- |
| key | <code>string</code> | name from `holiday-readings.json` to find |
| [cholHaMoedDay] | <code>number</code> | |
| [il] | <code>boolean</code> | |

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

Expand Down Expand Up @@ -394,6 +395,17 @@ maftir or Haftara.
| ev | <code>Event</code> | | the Hebcal event associated with this leyning |
| [il] | <code>boolean</code> | <code>false</code> | in Israel |

<a name="lookupParsha"></a>

## lookupParsha(parsha) ⇒ [<code>ParshaMeta</code>](#ParshaMeta)
Returns the parsha metadata

**Kind**: global function

| Param | Type | Description |
| --- | --- | --- |
| parsha | <code>string</code> \| <code>Array.&lt;string&gt;</code> | untranslated name like 'Pinchas' or ['Pinchas'] or ['Matot','Masei'] |

<a name="getLeyningOnDate"></a>

## getLeyningOnDate(hdate, il, [wantarray]) ⇒ [<code>Leyning</code>](#Leyning) \| [<code>Array.&lt;Leyning&gt;</code>](#Leyning)
Expand All @@ -418,17 +430,6 @@ Otherwise, returns `undefined`.
| il | <code>boolean</code> | | in Israel |
| [wantarray] | <code>boolean</code> | <code>false</code> | to return an array of 0 or more readings |

<a name="lookupParsha"></a>

## lookupParsha(parsha) ⇒ [<code>ParshaMeta</code>](#ParshaMeta)
Returns the parsha metadata

**Kind**: global function

| Param | Type | Description |
| --- | --- | --- |
| parsha | <code>string</code> \| <code>Array.&lt;string&gt;</code> | untranslated name like 'Pinchas' or ['Pinchas'] or ['Matot','Masei'] |

<a name="writeCsvLines"></a>

## writeCsvLines(stream, ev, reading, il, isParsha)
Expand Down
4 changes: 3 additions & 1 deletion leyning.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,11 @@ declare module '@hebcal/leyning' {
* (untranslated) string used in holiday-readings.json. Returns some
* of full kriyah aliyot, special Maftir, special Haftarah
* @param key - name from `holiday-readings.json` to find
* @param [cholHaMoedDay] - `ev.cholHaMoedDay` or `undefined`
* @param [il] - true if Israel holiday scheme
* @returns map of aliyot
*/
export function getLeyningForHolidayKey(key: string): Leyning;
export function getLeyningForHolidayKey(key: string, cholHaMoedDay?: number, il?: boolean): Leyning;

/**
* Looks up leyning for a regular Shabbat parsha, including any special
Expand Down
10 changes: 5 additions & 5 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@hebcal/leyning",
"version": "7.3.3",
"version": "7.4.0",
"author": "Michael J. Radwin (https://github.com/mjradwin)",
"keywords": [
"hebcal",
Expand Down
4 changes: 2 additions & 2 deletions src/csv.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,9 @@ export function writeFullKriyahEvent(stream, ev, il) {
export function writeHolidayMincha(stream, ev, il) {
const desc = ev.getDesc();
const minchaDesc1 = desc + ' (Mincha)';
const readingMincha1 = getLeyningForHolidayKey(minchaDesc1);
const readingMincha1 = getLeyningForHolidayKey(minchaDesc1, ev.cholHaMoedDay, il);
const readingMincha = readingMincha1 ||
getLeyningForHolidayKey(getLeyningKeyForEvent(ev, il) + ' (Mincha)');
getLeyningForHolidayKey(getLeyningKeyForEvent(ev, il) + ' (Mincha)', ev.cholHaMoedDay, il);
if (readingMincha) {
const minchaEv = new Event(ev.getDate(), minchaDesc1, flags.USER_EVENT);
writeCsvLines(stream, minchaEv, readingMincha, il, false);
Expand Down
8 changes: 6 additions & 2 deletions src/getLeyningForHoliday.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,20 @@ import numverses from './numverses.json';
* of full kriyah aliyot, special Maftir, special Haftarah
* @param {string} key name from `holiday-readings.json` to find
* @param {number} [cholHaMoedDay]
* @param {boolean} [il]
* @return {Leyning} map of aliyot
*/
export function getLeyningForHolidayKey(key, cholHaMoedDay) {
export function getLeyningForHolidayKey(key, cholHaMoedDay, il) {
if (typeof key !== 'string') {
return undefined;
}
const src = lookupFestival(key);
if (typeof src === 'undefined') {
return undefined;
}
if (typeof src.il === 'boolean' && typeof il === 'boolean' && il !== src.il) {
return undefined;
}
const leyning = {
name: {
en: key,
Expand Down Expand Up @@ -86,6 +90,6 @@ export function getLeyningForHoliday(ev, il = false) {
return undefined;
}
const key = getLeyningKeyForEvent(ev, il);
const leyning = getLeyningForHolidayKey(key, ev.cholHaMoedDay);
const leyning = getLeyningForHolidayKey(key, ev.cholHaMoedDay, il);
return leyning;
}
4 changes: 2 additions & 2 deletions src/getLeyningOnDate.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,13 @@ const minchaSuffix = ' (Mincha)';
*/
function getMincha(ev, il) {
const desc = ev.getDesc() + minchaSuffix;
const reading1 = getLeyningForHolidayKey(desc);
const reading1 = getLeyningForHolidayKey(desc, ev.cholHaMoedDay, il);
if (reading1) {
return reading1;
}
const desc2 = getLeyningKeyForEvent(ev, il);
if (desc2) {
const reading2 = getLeyningForHolidayKey(desc2 + minchaSuffix);
const reading2 = getLeyningForHolidayKey(desc2 + minchaSuffix, ev.cholHaMoedDay, il);
if (reading2) {
return reading2;
}
Expand Down
4 changes: 4 additions & 0 deletions src/holiday-readings.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"M":{"p":41,"k":4,"b":"28:16","e":"28:25"}}},
"Pesach II (CH''M)":{
"note":"Israel only - according to Vaani T'fillati Siddur Yisraeli",
"il":true,
"fullkriyah":
{"1":{"p":31,"k":3,"b":"22:26","e":"23:8"},
"2":{"p":31,"k":3,"b":"23:9","e":"23:14"},
Expand Down Expand Up @@ -119,6 +120,7 @@
"Pesach Chol ha-Moed Day 3 on Monday":{"alias":true,"il":false,"key":"Pesach Chol ha-Moed Day 2"},
"Shavuot":{
"note":"Israel only",
"il":true,
"megillah":"Ruth",
"haft":[{"k":"Ezekiel","b":"1:1","e":"1:28"},
{"k":"Ezekiel","b":"3:12","e":"3:12"}],
Expand Down Expand Up @@ -472,12 +474,14 @@
"3":{"p":16,"k":2,"b":"17:14","e":"17:16"}}},
"Shushan Purim":{
"note":"Jerusalem & walled cities only",
"il":true,
"megillah":"Esther",
"fullkriyah":
{"1":{"p":16,"k":2,"b":"17:8","e":"17:10"},
"2":{"p":16,"k":2,"b":"17:11","e":"17:13"},
"3":{"p":16,"k":2,"b":"17:14","e":"17:16"}}},
"Shushan Purim (on Shabbat)":{
"il":true,
"note":"Jerusalem & walled cities only: special maftir Exodus 17:8-16, same Haftara as Shabbat Zachor"},
"Shabbat HaChodesh":{
"haft":{"k":"Ezekiel","b":"45:16","e":"46:18"},
Expand Down
38 changes: 30 additions & 8 deletions src/holiday.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ function formatAliyah(aliyot, num) {
return formatAliyahWithBook(aliyot.fullkriyah[num]);
}

test('getLeyningForHoliday', (t) => {
test('getLeyningForHoliday-il', (t) => {
const options = {year: 5757, isHebrewYear: true, il: true};
const events = HebrewCalendar.calendar(options);

Expand All @@ -110,19 +110,41 @@ test('getLeyningForHoliday', (t) => {
t.is(sukkot1a.fullkriyah['7'].p, 31);
t.is(sukkot1a.summary, 'Leviticus 22:26-23:44; Numbers 29:12-16');
const sukkot2 = events.find((e) => e.getDesc() == 'Sukkot II (CH\'\'M)');
t.is(getLeyningForHoliday(sukkot2).fullkriyah['4'].p, 41);
t.is(getLeyningForHoliday(sukkot2, true).fullkriyah['4'].p, 41);
const shminiAtzeret = events.find((e) => e.getDesc() == 'Shmini Atzeret');
t.is(getLeyningForHoliday(shminiAtzeret).fullkriyah['7'].p, 47);
t.is(getLeyningForHoliday(shminiAtzeret, true).fullkriyah['7'].p, 1);
const tevet17 = events.find((e) => e.getDesc() == 'Asara B\'Tevet');
t.is(getLeyningForHoliday(tevet17).fullkriyah['3'].e, '34:10');
t.is(getLeyningForHoliday(tevet17, true).fullkriyah['3'].e, '34:10');
const pesach5 = events.find((e) => e.getDesc() == 'Pesach V (CH\'\'M)');
t.is(getLeyningForHoliday(pesach5).fullkriyah['4'].p, 21);
t.is(getLeyningForHoliday(pesach5, true).fullkriyah['4'].p, 21);
const shavuot = events.find((e) => e.getDesc() == 'Shavuot');
t.is(getLeyningForHoliday(shavuot).fullkriyah['4'].p, 17);
t.is(getLeyningForHoliday(shavuot, true).fullkriyah['4'].p, 17);
const av9 = events.find((e) => e.getDesc() == 'Tish\'a B\'Av');
t.is(getLeyningForHoliday(av9).haftara, 'Jeremiah 8:13-9:23');
t.is(getLeyningForHoliday(av9, true).haftara, 'Jeremiah 8:13-9:23');
});

test('getLeyningForHoliday-diaspora', (t) => {
const events = HebrewCalendar.calendar({year: 5757, isHebrewYear: true, il: false});

const sukkot1 = events.find((e) => e.getDesc() == 'Sukkot I');
const sukkot1a = getLeyningForHoliday(sukkot1);
t.is(sukkot1a.fullkriyah['7'].p, 31);
t.is(sukkot1a.summary, 'Leviticus 22:26-23:44; Numbers 29:12-16');
const sukkot3 = events.find((e) => e.getDesc() == 'Sukkot III (CH\'\'M)');
t.is(getLeyningForHoliday(sukkot3, false).fullkriyah['4'].p, 41);
const shminiAtzeret = events.find((e) => e.getDesc() == 'Shmini Atzeret');
t.is(getLeyningForHoliday(shminiAtzeret, false).fullkriyah['7'].p, 47);
const tevet17 = events.find((e) => e.getDesc() == 'Asara B\'Tevet');
t.is(getLeyningForHoliday(tevet17, false).fullkriyah['3'].e, '34:10');
const pesach5 = events.find((e) => e.getDesc() == 'Pesach V (CH\'\'M)');
t.is(getLeyningForHoliday(pesach5, false).fullkriyah['4'].p, 21);
const shavuot = events.find((e) => e.getDesc() == 'Shavuot I');
t.is(getLeyningForHoliday(shavuot, false).fullkriyah['4'].p, 17);
const av9 = events.find((e) => e.getDesc() == 'Tish\'a B\'Av');
t.is(getLeyningForHoliday(av9, false).haftara, 'Jeremiah 8:13-9:23');
});


test('getLeyningForHoliday-Chanukah', (t) => {
const options = {year: 5757, isHebrewYear: true, il: true};
const events = HebrewCalendar.calendar(options);
Expand Down Expand Up @@ -555,7 +577,7 @@ test('pesach-diaspora-chm-day2-sunday', (t) => {
test('Shavuot Israel', (t) => {
const events0 = HebrewCalendar.calendar({year: 5783, isHebrewYear: true, il: true});
const events = events0.filter((ev) => ev.getDesc() === 'Shavuot');
const actual = getLeyningForHoliday(events[0]);
const actual = getLeyningForHoliday(events[0], true);
const expected = {
'1': {k: 'Ruth', b: '1:1', e: '1:22', v: 22},
'2': {k: 'Ruth', b: '2:1', e: '2:23', v: 23},
Expand Down
3 changes: 3 additions & 0 deletions src/specialReadings.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ export function specialReadings2(parsha, hd, il, aliyot) {
if (!special) {
return;
}
if (typeof special.il === 'boolean' && il !== special.il) {
return;
}
if (special.haft && !specialHaft) {
haft = cloneHaftara(special.haft);
reason.haftara = key;
Expand Down

0 comments on commit 71dceba

Please sign in to comment.