Skip to content

Commit

Permalink
Add Psalms (30-day schedule) to daily learning
Browse files Browse the repository at this point in the history
  • Loading branch information
mjradwin committed Jun 7, 2023
1 parent c5f2090 commit f6b8c84
Show file tree
Hide file tree
Showing 11 changed files with 247 additions and 21 deletions.
62 changes: 62 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Supports several learning schedules
* Daf Yomi (Babylonian Talmud / Bavli) - `dafYomi`
* Mishna Yomi - `mishnaYomi`
* Nach Yomi - `nachYomi`
* Psalms / Tehillim (30 day cycle) - `psalms`
* Yerushalmi Yomi (Jerusalem Talmud)
* Vilna edition - `yerushalmi-vilna`
* Schottenstein edition - `yerushalmi-schottenstein`
Expand Down Expand Up @@ -56,6 +57,9 @@ and Ketuvim (Writings).</p>
<dt><a href="#ShemiratHaLashonEvent">ShemiratHaLashonEvent</a></dt>
<dd><p>Event wrapper around a Sefer Shemirat HaLashon instance</p>
</dd>
<dt><a href="#PsalmsEvent">PsalmsEvent</a></dt>
<dd><p>Event wrapper around a daily Psalms / Tehillim</p>
</dd>
</dl>

## Constants
Expand Down Expand Up @@ -94,6 +98,9 @@ cycle began (2 February 1980 for Vilna,
<dt><a href="#shemiratHaLashon">shemiratHaLashon(hdate)</a> ⇒ <code>any</code></dt>
<dd><p>Looks up Sefer Shemirat HaLashon Calendar for date</p>
</dd>
<dt><a href="#dailyPsalms">dailyPsalms(date)</a> ⇒ <code>any</code></dt>
<dd><p>Calculates Daily Psalms (Tehillim) for 30-day cycle.</p>
</dd>
</dl>

## Typedefs
Expand Down Expand Up @@ -536,6 +543,50 @@ Returns a link to sefaria.org

### shemiratHaLashonEvent.getCategories() ⇒ <code>Array.&lt;string&gt;</code>
**Kind**: instance method of [<code>ShemiratHaLashonEvent</code>](#ShemiratHaLashonEvent)
<a name="PsalmsEvent"></a>

## PsalmsEvent
Event wrapper around a daily Psalms / Tehillim

**Kind**: global class

* [PsalmsEvent](#PsalmsEvent)
* [new PsalmsEvent(date, reading)](#new_PsalmsEvent_new)
* [.render([locale])](#PsalmsEvent+render) ⇒ <code>string</code>
* [.url()](#PsalmsEvent+url) ⇒ <code>string</code>
* [.getCategories()](#PsalmsEvent+getCategories) ⇒ <code>Array.&lt;string&gt;</code>

<a name="new_PsalmsEvent_new"></a>

### new PsalmsEvent(date, reading)

| Param | Type |
| --- | --- |
| date | <code>HDate</code> |
| reading | <code>Array.&lt;number&gt;</code> \| <code>Array.&lt;string&gt;</code> |

<a name="PsalmsEvent+render"></a>

### psalmsEvent.render([locale]) ⇒ <code>string</code>
Returns name of reading

**Kind**: instance method of [<code>PsalmsEvent</code>](#PsalmsEvent)

| Param | Type | Description |
| --- | --- | --- |
| [locale] | <code>string</code> | Optional locale name (defaults to active locale). |

<a name="PsalmsEvent+url"></a>

### psalmsEvent.url() ⇒ <code>string</code>
Returns a link to sefaria.org
e.g. https://www.sefaria.org/Psalms.1-9?lang=b

**Kind**: instance method of [<code>PsalmsEvent</code>](#PsalmsEvent)
<a name="PsalmsEvent+getCategories"></a>

### psalmsEvent.getCategories() ⇒ <code>Array.&lt;string&gt;</code>
**Kind**: instance method of [<code>PsalmsEvent</code>](#PsalmsEvent)
<a name="vilna"></a>

## vilna
Expand Down Expand Up @@ -607,6 +658,17 @@ Looks up Sefer Shemirat HaLashon Calendar for date
| --- | --- |
| hdate | <code>HDate</code> |

<a name="dailyPsalms"></a>

## dailyPsalms(date) ⇒ <code>any</code>
Calculates Daily Psalms (Tehillim) for 30-day cycle.

**Kind**: global function

| Param | Type | Description |
| --- | --- | --- |
| date | <code>HDate</code> \| <code>Date</code> \| <code>number</code> | Hebrew or Gregorian date |

<a name="MishnaYomi"></a>

## MishnaYomi : <code>Object</code>
Expand Down
20 changes: 10 additions & 10 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/learning",
"version": "1.3.4",
"version": "1.4.0",
"description": "Daily learning schedules: Daf Yomi, Mishna Yomi, etc",
"main": "dist/index.js",
"module": "dist/index.mjs",
Expand All @@ -23,7 +23,7 @@
},
"homepage": "https://github.com/mjradwin/hebcal-learning#readme",
"dependencies": {
"@hebcal/core": "^4.1.0"
"@hebcal/core": "^4.1.1"
},
"files": [
"types.d.ts",
Expand Down Expand Up @@ -56,7 +56,7 @@
"eslint-config-google": "^0.14.0",
"jsdoc": "^4.0.2",
"jsdoc-to-markdown": "^8.0.0",
"rollup": "^3.23.1",
"rollup": "^3.24.0",
"ttag-cli": "^1.10.5"
}
}
9 changes: 8 additions & 1 deletion src/MishnaYomiEvent.spec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
import test from 'ava';
import {MishnaYomiEvent} from './MishnaYomiEvent';
import {HDate} from '@hebcal/core';
import {HDate, Locale} from '@hebcal/core';
import poAshkenazi from './ashkenazi.po.json';
import poHe from './he.po.json';

Locale.addTranslations('ashkenazi', poAshkenazi);
Locale.addTranslations('a', poAshkenazi);
Locale.addTranslations('he', poHe);
Locale.addTranslations('h', poHe);

test('MishnaYomiEvent-url', (t) => {
const my = [{k: 'Berakhot', v: '3:6'}, {k: 'Berakhot', v: '4:1'}];
Expand Down
1 change: 1 addition & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ export {yerushalmiYomi, YerushalmiYomiEvent, vilna, schottenstein} from './yerus
export {chofetzChaim, ChofetzChaimEvent} from './chofetzChaim';
export {dailyRambam1, DailyRambamEvent} from './rambam';
export {shemiratHaLashon, ShemiratHaLashonEvent} from './shemiratHaLashon';
export {dailyPsalms, PsalmsEvent} from './psalms';
95 changes: 95 additions & 0 deletions src/psalms.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
import {HDate, Event, flags, Locale, gematriya} from '@hebcal/core';

const schedule = [
[],
[1, 9],
[10, 17],
[18, 22],
[23, 28],
[29, 34],
[35, 38],
[39, 43],
[44, 48],
[49, 54],
[55, 59],
[60, 65],
[66, 68],
[69, 71],
[72, 76],
[77, 78],
[79, 82],
[83, 87],
[88, 89],
[90, 96],
[97, 103],
[104, 105],
[106, 107],
[108, 112],
[113, 118],
['119:1', '119:96'],
['119:97', '119:176'],
[120, 134],
[135, 139],
[140, 144],
[145, 150],
];

/**
* Calculates Daily Psalms (Tehillim) for 30-day cycle.
* @param {HDate|Date|number} date - Hebrew or Gregorian date
* @return {any}
*/
export function dailyPsalms(date) {
const hd = new HDate(date);
const dd = hd.getDate();
if (dd === 29 && hd.daysInMonth() === 29) {
return [140, 150]; // read both 29th and 30th
}
return schedule[dd];
}

/**
* Event wrapper around a daily Psalms / Tehillim
*/
export class PsalmsEvent extends Event {
/**
* @param {HDate} date
* @param {number[]|string[]} reading
*/
constructor(date, reading) {
super(date, `Psalms ${reading[0]}-${reading[1]}`, flags.USER_EVENT);
this.reading = reading;
this.alarm = false;
this.category = 'Psalms';
}
/**
* Returns name of reading
* @param {string} [locale] Optional locale name (defaults to active locale).
* @return {string}
*/
render(locale) {
locale = locale || Locale.getLocaleName();
if (typeof locale === 'string') {
locale = locale.toLowerCase();
}
const book = Locale.gettext('Psalms', locale);
const reading = this.reading;
if ((locale === 'he' || locale === 'he-x-nonikud') && typeof reading[0] === 'number') {
return book + ' ' + gematriya(reading[0]) + '-' + gematriya(reading[1]);
}
return book + ' ' + reading[0] + '-' + reading[1];
}
/**
* Returns a link to sefaria.org
* e.g. https://www.sefaria.org/Psalms.1-9?lang=b
* @return {string}
*/
url() {
const str = this.getDesc().replace(' ', '.').replace(/:/g, '.');
return `https://www.sefaria.org/${str}?lang=bi`;
}
/** @return {string[]} */
getCategories() {
return ['dailyPsalms'];
}
}
25 changes: 25 additions & 0 deletions src/psalms.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import test from 'ava';
import {dailyPsalms, PsalmsEvent} from './psalms';
import {HDate} from '@hebcal/core';

test('dailyPsalms', (t) => {
t.deepEqual(dailyPsalms(new HDate(1, 'Av', 5783)), [1, 9]);
t.deepEqual(dailyPsalms(new HDate(18, 'Sivan', 5783)), [88, 89]);
t.deepEqual(dailyPsalms(new HDate(29, 'Sivan', 5783)), [140, 144]);
t.deepEqual(dailyPsalms(new HDate(30, 'Sivan', 5783)), [145, 150]);
t.deepEqual(dailyPsalms(new HDate(29, 'Tamuz', 5783)), [140, 150]);
});

test('PsalmsEvent.url', (t) => {
const hd = new HDate(2, 'Av', 5783);
const reading = dailyPsalms(hd);
const ev = new PsalmsEvent(hd, reading);
t.is(ev.url(), 'https://www.sefaria.org/Psalms.10-17?lang=bi');
});

test('PsalmsEvent.render', (t) => {
const hd = new HDate(3, 'Av', 5783);
const reading = dailyPsalms(hd);
const ev = new PsalmsEvent(hd, reading);
t.is(ev.render('en'), 'Psalms 18-22');
});
18 changes: 12 additions & 6 deletions src/register.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ import {yerushalmiYomi, YerushalmiYomiEvent, vilna, schottenstein} from './yerus
import {chofetzChaim, ChofetzChaimEvent, chofetzChaimStart} from './chofetzChaim';
import {dailyRambam1, DailyRambamEvent, rambam1Start} from './rambam';
import {shemiratHaLashon, ShemiratHaLashonEvent, shemiratHaLashonStart} from './shemiratHaLashon';
import po_he from './he.po.json';
import po_ashkenazi from './ashkenazi.po.json';
import {dailyPsalms, PsalmsEvent} from './psalms';
import poHe from './he.po.json';
import poAshkenazi from './ashkenazi.po.json';

DailyLearning.addCalendar('dafYomi', function(hd) {
const abs = hd.abs();
Expand Down Expand Up @@ -87,7 +88,12 @@ DailyLearning.addCalendar('shemiratHaLashon', function(hd) {
return new ShemiratHaLashonEvent(hd, reading);
});

Locale.addTranslations('he', po_he);
Locale.addTranslations('h', po_he);
Locale.addTranslations('ashkenazi', po_ashkenazi);
Locale.addTranslations('a', po_ashkenazi);
DailyLearning.addCalendar('psalms', function(hd) {
const reading = dailyPsalms(hd);
return new PsalmsEvent(hd, reading);
});

Locale.addTranslations('he', poHe);
Locale.addTranslations('h', poHe);
Locale.addTranslations('ashkenazi', poAshkenazi);
Locale.addTranslations('a', poAshkenazi);
10 changes: 10 additions & 0 deletions src/register.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import test from 'ava';
import './register';
import {DailyLearning, HDate} from '@hebcal/core';

test('lookup', (t) => {
const hd = new HDate(17, 'Sivan', 5783);
const ev = DailyLearning.lookup('psalms', hd);
t.is(typeof ev, 'object');
t.is(ev.getDesc(), 'Psalms 83-87');
});
9 changes: 8 additions & 1 deletion src/yerushalmi.spec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
import test from 'ava';
import {yerushalmiYomi, YerushalmiYomiEvent, vilna, schottenstein} from './yerushalmi';
import {HDate, greg} from '@hebcal/core';
import {HDate, greg, Locale} from '@hebcal/core';
import poAshkenazi from './ashkenazi.po.json';
import poHe from './he.po.json';

Locale.addTranslations('ashkenazi', poAshkenazi);
Locale.addTranslations('a', poAshkenazi);
Locale.addTranslations('he', poHe);
Locale.addTranslations('h', poHe);

test('yerushalmiYomi-small', (t) => {
const toTest = [
Expand Down
13 changes: 13 additions & 0 deletions types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,4 +169,17 @@ declare module '@hebcal/learning' {
url(): string;
getCategories(): string[];
}

/**
* Calculates Daily Psalms (Tehillim) for 30-day cycle.
* @param date - Hebrew or Gregorian date
*/
export function dailyPsalms(date: Date | HDate | number): any;

export class PsalmsEvent extends Event {
constructor(date: HDate, reading: any);
render(locale?: string): string;
url(): string;
getCategories(): string[];
}
}

0 comments on commit f6b8c84

Please sign in to comment.