Skip to content

Commit

Permalink
Correctly generate leyning summary for Shabbat Chol Hamoed Sukkot
Browse files Browse the repository at this point in the history
  • Loading branch information
mjradwin committed Apr 27, 2022
1 parent 8e85854 commit ba9f6dd
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 21 deletions.
14 changes: 7 additions & 7 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
Expand Up @@ -31,7 +31,7 @@
"leyning-csv": "bin/leyning-csv"
},
"dependencies": {
"@hebcal/core": "^3.35.0"
"@hebcal/core": "^3.36.2"
},
"scripts": {
"build": "rollup -c",
Expand Down
27 changes: 14 additions & 13 deletions src/leyning.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,21 +150,15 @@ const HOLIDAY_IGNORE_MASK = flags.DAF_YOMI | flags.OMER_COUNT | flags.SHABBAT_ME
* @return {Leyning} map of aliyot
*/
export function getLeyningForHoliday(e, il=false) {
if (!e instanceof Event) {
if (typeof e !== 'object' || !(e instanceof Event)) {
throw new TypeError(`Bad event argument: ${e}`);
} else if (e.getFlags() & flags.PARSHA_HASHAVUA) {
throw new TypeError(`Event should be a holiday: ${e.getDesc()}`);
} else if (e.getFlags() & HOLIDAY_IGNORE_MASK) {
return undefined;
}
const key = getLeyningKeyForEvent(e, il);
const leyning = getLeyningForHolidayKey(key);
if (key === 'Sukkot Shabbat Chol ha-Moed') {
leyning.fullkriyah['M'] = leyning.fullkriyah[`M-day${e.cholHaMoedDay}`];
for (let day = 1; day <= 5; day++) {
delete leyning.fullkriyah[`M-day${day}`];
}
}
const leyning = getLeyningForHolidayKey(key, e.cholHaMoedDay);
return leyning;
}

Expand Down Expand Up @@ -232,7 +226,7 @@ function makeHaftaraSummary(haft) {
* @return {Aliyah[]}
*/
export function makeLeyningParts(aliyot) {
const nums = Object.keys(aliyot);
const nums = Object.keys(aliyot).filter((x) => x.length === 1);
let start = aliyot[nums[0]];
let end = start;
const parts = [];
Expand Down Expand Up @@ -289,9 +283,10 @@ function calculateHaftaraNumV(haft) {
* (untranslated) string used in holiday-readings.json. Returns some
* of full kriyah aliyot, special Maftir, special Haftarah
* @param {string} key name from `holiday-readings.json` to find
* @param {number} [cholHaMoedDay]
* @return {Leyning} map of aliyot
*/
export function getLeyningForHolidayKey(key) {
export function getLeyningForHolidayKey(key, cholHaMoedDay) {
if (typeof key !== 'string') {
return undefined;
}
Expand All @@ -310,14 +305,20 @@ export function getLeyningForHolidayKey(key) {
}
const leyning = Object.create(null);
if (src.fullkriyah) {
if (typeof src.fullkriyah['1'] === 'object') {
const parts = makeLeyningParts(src.fullkriyah);
leyning.fullkriyah = clone(src.fullkriyah);
if (key === 'Sukkot Shabbat Chol ha-Moed' && cholHaMoedDay) {
leyning.fullkriyah['M'] = leyning.fullkriyah[`M-day${cholHaMoedDay}`];
for (let day = 1; day <= 5; day++) {
delete leyning.fullkriyah[`M-day${day}`];
}
}
if (typeof leyning.fullkriyah['1'] === 'object') {
const parts = makeLeyningParts(leyning.fullkriyah);
leyning.summary = makeSummaryFromParts(parts);
if (parts.length > 1) {
leyning.summaryParts = parts;
}
}
leyning.fullkriyah = clone(src.fullkriyah);
Object.values(leyning.fullkriyah).map((aliyah) => calculateNumVerses(aliyah));
}
if (src.haft) {
Expand Down
31 changes: 31 additions & 0 deletions src/leyning.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import test from 'ava';
import {HDate, HebrewCalendar, Event, months, flags, ParshaEvent, parshiot} from '@hebcal/core';
import {
getLeyningForHoliday,
getLeyningForHolidayKey,
getLeyningForParsha,
getLeyningForParshaHaShavua,
getLeyningKeyForEvent,
Expand Down Expand Up @@ -890,3 +891,33 @@ test('makeLeyningSummary Tzom Gedaliah', (t) => {
const summary = makeLeyningSummary(fullkriyah, true);
t.is(summary, 'Exodus 32:11-14, 34:1-10');
});

test('Sukkot Shabbat Chol ha-Moed', (t) => {
const hd = new HDate(20, 'Tishrei', 5783);
const events = HebrewCalendar.calendar({
start: hd,
end: hd,
});
const reading = getLeyningForHoliday(events[0]);
const expected = {
fullkriyah: {
'1': {p: 21, k: 'Exodus', b: '33:12', e: '33:16', v: 5},
'2': {p: 21, k: 'Exodus', b: '33:17', e: '33:19', v: 3},
'3': {p: 21, k: 'Exodus', b: '33:20', e: '33:23', v: 4},
'4': {p: 21, k: 'Exodus', b: '34:1', e: '34:3', v: 3},
'5': {p: 21, k: 'Exodus', b: '34:4', e: '34:10', v: 7},
'6': {p: 21, k: 'Exodus', b: '34:11', e: '34:17', v: 7},
'7': {p: 21, k: 'Exodus', b: '34:18', e: '34:26', v: 9},
'M': {p: 41, k: 'Numbers', b: '29:26', e: '29:31', v: 6},
},
summary: 'Exodus 33:12-34:26; Numbers 29:26-31',
summaryParts: [
{k: 'Exodus', b: '33:12', e: '34:26'},
{k: 'Numbers', b: '29:26', e: '29:31'},
],
haft: {k: 'Ezekiel', b: '38:18', e: '39:16', v: 22},
haftara: 'Ezekiel 38:18-39:16',
haftaraNumV: 22,
};
t.deepEqual(reading, expected);
});

0 comments on commit ba9f6dd

Please sign in to comment.