Skip to content

Commit

Permalink
Fix special readings for Israel triennial.
Browse files Browse the repository at this point in the history
Make CSV export work for Israel triennial.
  • Loading branch information
mjradwin committed May 28, 2023
1 parent 0efbcaa commit 8faaf64
Show file tree
Hide file tree
Showing 8 changed files with 203 additions and 4,854 deletions.
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ for (const [num, aliyah] of Object.entries(triReading)) {
<dt><a href="#getTriennialForParshaHaShavua">getTriennialForParshaHaShavua(ev, [il])</a> ⇒ <code><a href="#TriennialAliyot">TriennialAliyot</a></code></dt>
<dd><p>Looks up the triennial leyning for this Parashat HaShavua</p>
</dd>
<dt><a href="#writeTriennialCsv">writeTriennialCsv(stream, hyear, [il])</a></dt>
<dd></dd>
</dl>

## Typedefs
Expand Down Expand Up @@ -179,6 +181,17 @@ Looks up the triennial leyning for this Parashat HaShavua
| ev | <code>Event</code> | | |
| [il] | <code>boolean</code> | <code>false</code> | Israel |

<a name="writeTriennialCsv"></a>

## writeTriennialCsv(stream, hyear, [il])
**Kind**: global function

| Param | Type | Default |
| --- | --- | --- |
| stream | <code>fs.WriteStream</code> | |
| hyear | <code>number</code> | |
| [il] | <code>boolean</code> | <code>false</code> |

<a name="TriennialAliyot"></a>

## TriennialAliyot : <code>Object</code>
Expand Down
4,970 changes: 133 additions & 4,837 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@hebcal/triennial",
"version": "1.3.0",
"version": "1.3.1",
"description": "Javascript Triennial Torah Readings",
"main": "./dist/index.js",
"module": "./dist/index.mjs",
Expand Down
25 changes: 13 additions & 12 deletions src/csv.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,24 @@ import {getTriennialForParshaHaShavua} from './parshaHaShavua';
import {getTriennialHaftaraForHoliday} from './haftara';

/**
* @private
* @param {fs.WriteStream} stream
* @param {number} hyear
* @param {boolean} [il]
*/
export function writeTriennialCsv(stream, hyear) {
export function writeTriennialCsv(stream, hyear, il=false) {
const events0 = HebrewCalendar.calendar({
year: hyear,
isHebrewYear: true,
numYears: 3,
sedrot: true,
il: false,
il: il,
});
const events = events0.filter((ev) => ev.getDesc() !== 'Rosh Chodesh Tevet');
const parshaDates = getParshaDates(events);
stream.write('"Date","Parashah","Aliyah","Triennial Reading","Verses"\r\n');
events.forEach((ev) => {
if (ev.getFlags() === flags.PARSHA_HASHAVUA || !parshaDates[ev.getDate().toString()]) {
writeTriennialEvent(stream, ev);
writeTriennialEvent(stream, ev, il);
}
});
}
Expand All @@ -33,25 +33,26 @@ export function writeTriennialCsv(stream, hyear) {
* @private
* @param {fs.WriteStream} stream
* @param {Event} ev
* @param {boolean} il
*/
export function writeTriennialEvent(stream, ev) {
export function writeTriennialEvent(stream, ev, il) {
if (ignore(ev)) {
return;
}
if (ev.getFlags() === flags.PARSHA_HASHAVUA) {
writeTriennialEventParsha(stream, ev);
writeTriennialEventParsha(stream, ev, il);
} else {
writeTriennialEventHoliday(stream, ev);
writeTriennialEventHoliday(stream, ev, il);
}
}

/**
* @private
* @param {fs.WriteStream} stream
* @param {Event} ev
* @param {boolean} il
*/
function writeTriennialEventHoliday(stream, ev) {
const il = false;
function writeTriennialEventHoliday(stream, ev, il) {
const reading = getLeyningForHoliday(ev, il);
if (reading) {
const key = getLeyningKeyForEvent(ev, il);
Expand All @@ -71,11 +72,11 @@ function writeTriennialEventHoliday(stream, ev) {
* @private
* @param {fs.WriteStream} stream
* @param {Event} ev
* @param {boolean} il
*/
function writeTriennialEventParsha(stream, ev) {
const triReading = getTriennialForParshaHaShavua(ev, true);
function writeTriennialEventParsha(stream, ev, il) {
const triReading = getTriennialForParshaHaShavua(ev, il);
if (triReading) {
const il = false;
const reading = getLeyningForParshaHaShavua(ev, il);
reading.fullkriyah = triReading.aliyot;
reading.triHaftara = triReading.haftara;
Expand Down
23 changes: 22 additions & 1 deletion src/csv.spec.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable require-jsdoc */
import test from 'ava';
import {Writable} from 'stream';
import {HDate, HolidayEvent, RoshChodeshEvent, ParshaEvent, months, flags} from '@hebcal/core';
import {HDate, HolidayEvent, ParshaEvent, months, flags} from '@hebcal/core';
import {writeTriennialEvent} from './csv';

class StringWritable extends Writable {
Expand Down Expand Up @@ -94,3 +94,24 @@ test('writeTriennialEvent-holiday-alt-haftara', (t) => {
'', ''];
t.deepEqual(lines, expected);
});

test('writeTriennialEvent-il', (t) => {
const hd = new HDate(7, 'Sivan', 5783);
const ev = new ParshaEvent(hd, ['Nasso'], true);
const stream = new StringWritable();
writeTriennialEvent(stream, ev, true);
const lines = stream.toString().split('\r\n');
const expected = [
'27-May-2023,"Nasso",1,"Numbers 4:21-4:24",4',
'27-May-2023,"Nasso",2,"Numbers 4:25-4:28",4',
'27-May-2023,"Nasso",3,"Numbers 4:29-4:33",5',
'27-May-2023,"Nasso",4,"Numbers 4:34-4:37",4',
'27-May-2023,"Nasso",5,"Numbers 4:38-4:49",12',
'27-May-2023,"Nasso",6,"Numbers 5:1-5:4",4',
'27-May-2023,"Nasso",7,"Numbers 5:5-5:10",6',
'27-May-2023,"Nasso","maf","Numbers 5:8-5:10",3',
'27-May-2023,"Nasso","Haftara","Judges 13:2-25",24',
'27-May-2023,"Nasso","Alternate Haftara","Joshua 6:5-14; 6:12",11',
'', ''];
t.deepEqual(lines, expected);
});
20 changes: 19 additions & 1 deletion src/israel.spec.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import test from 'ava';
import {HDate} from '@hebcal/core';
import {HDate, ParshaEvent} from '@hebcal/core';
import {makeLeyningParts, makeSummaryFromParts} from '@hebcal/leyning';
import {Triennial} from './triennial';
import {getTriennialForParshaHaShavua} from './parshaHaShavua';

test('debug', (t) => {
const tri5774 = new Triennial(5774, true);
Expand Down Expand Up @@ -128,3 +129,20 @@ test('multi', (t) => {
}
t.pass();
});

test('getTriennialForParshaHaShavua', (t) => {
const hd = new HDate(7, 'Sivan', 5783);
const pe = new ParshaEvent(hd, ['Nasso'], true);
const reading = getTriennialForParshaHaShavua(pe, true);
const expected = {
'1': {k: 'Numbers', b: '4:21', e: '4:24', v: 4},
'2': {k: 'Numbers', b: '4:25', e: '4:28', v: 4},
'3': {k: 'Numbers', b: '4:29', e: '4:33', v: 5},
'4': {k: 'Numbers', b: '4:34', e: '4:37', v: 4},
'5': {k: 'Numbers', b: '4:38', e: '4:49', v: 12},
'6': {k: 'Numbers', b: '5:1', e: '5:4', v: 4},
'7': {k: 'Numbers', b: '5:5', e: '5:10', v: 6},
'M': {k: 'Numbers', b: '5:8', e: '5:10', v: 3},
};
t.deepEqual(reading.aliyot, expected);
});
2 changes: 1 addition & 1 deletion src/parshaHaShavua.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export function getTriennialForParshaHaShavua(ev, il = false) {
throw new ReferenceError(`Can't load reading for ${name} in ${hyear} (year number ${yearNum})`);
}
// possibly replace 7th aliyah and/or maftir
const special = specialReadings2(parsha, hd, false, reading.aliyot);
const special = specialReadings2(parsha, hd, il, reading.aliyot);
const reason = special.reason;
const aliyotMap = special.aliyot;
Object.keys(reason).forEach((num) => {
Expand Down
2 changes: 1 addition & 1 deletion types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,5 +64,5 @@ declare module '@hebcal/triennial' {

export function getTriennialHaftaraForHoliday(holiday: string, yearNum: number): any;

export function writeTriennialCsv(stream: WriteStream, hyear: number): void;
export function writeTriennialCsv(stream: WriteStream, hyear: number, il?: boolean): void;
}

0 comments on commit 8faaf64

Please sign in to comment.