-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Psalms (30-day schedule) to daily learning
- Loading branch information
Showing
11 changed files
with
247 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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']; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters