Skip to content

Commit 92ab74d

Browse files
committed
Add start dates for Chofetz Chaim, Shemirat HaLashon, Daily Rambam
1 parent 4373c42 commit 92ab74d

6 files changed

+100
-20
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@hebcal/learning",
3-
"version": "1.3.0",
3+
"version": "1.3.1",
44
"description": "Daily learning schedules: Daf Yomi, Mishna Yomi, etc",
55
"main": "dist/index.js",
66
"module": "dist/index.mjs",

src/chofetzChaim.js

+8
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ const Adar = months.ADAR_I;
1515
const Adar1 = months.ADAR_I;
1616
const Adar2 = months.ADAR_II;
1717

18+
// Sefer Chofetz Chaim was published in 1873 CE
19+
const startDate = new HDate(1, Tishrei, 5634);
20+
export const chofetzChaimStart = startDate.abs();
21+
1822
const Hakdamah = 'Hakdamah';
1923
const Psichah = 'Psichah';
2024
const Lavin = 'Lavin';
@@ -299,6 +303,10 @@ export function chofetzChaim(hdate) {
299303
if (!HDate.isHDate(hdate)) {
300304
throw new TypeError(`Invalid date: ${hdate}`);
301305
}
306+
const cday = hdate.abs();
307+
if (cday < chofetzChaimStart) {
308+
throw new RangeError(`Date ${hdate} too early; Sefer Chofetz Chaim cycle began on ${startDate}`);
309+
}
302310

303311
const readings = hdate.isLeapYear() ? leap : simple;
304312
const day = hdate.getDate();

src/hebcal.spec.js

+52
Original file line numberDiff line numberDiff line change
@@ -158,3 +158,55 @@ test('yerushalmiYomi-Schottenstein', (t) => {
158158
];
159159
t.deepEqual(actual, expected);
160160
});
161+
162+
test('shemiratHaLashon', (t) => {
163+
const events = HebrewCalendar.calendar({
164+
start: new Date(1997, 3, 25),
165+
end: new Date(1997, 5, 2),
166+
noHolidays: true,
167+
dailyLearning: {shemiratHaLashon: true},
168+
});
169+
const actual = events.map((ev) => gregDtString(ev) + ' ' + ev.render('en'));
170+
const expected = [
171+
'4/25/1997 Book I, Shar Hatorah 9.15-9.17',
172+
'4/26/1997 Book I, Shar Hatorah 10.1-10.4',
173+
'4/27/1997 Book I, Shar Hatorah 10.5-10.7',
174+
'4/28/1997 Book I, Shar Hatorah 10.8-10.9',
175+
'4/29/1997 Book I, Shar Hatorah 10.10-10.11',
176+
'4/30/1997 Book I, Chasimas Hasefer 1.1-1.4',
177+
'5/1/1997 Book I, Chasimas Hasefer 1.5',
178+
'5/2/1997 Book I, Chasimas Hasefer 2.1-2.4',
179+
'5/3/1997 Book I, Chasimas Hasefer 2.5',
180+
'5/4/1997 Book I, Chasimas Hasefer 3.1-3.2',
181+
'5/5/1997 Book I, Chasimas Hasefer 3.3-3.4',
182+
'5/6/1997 Book I, Chasimas Hasefer 3.5',
183+
'5/7/1997 Book I, Chasimas Hasefer 3.6',
184+
'5/8/1997 Book I, Chasimas Hasefer 4.1-4.3',
185+
'5/9/1997 Book I, Chasimas Hasefer 4.4-4.5',
186+
'5/10/1997 Book I, Chasimas Hasefer 4.6-4.8',
187+
'5/11/1997 Book I, Chasimas Hasefer 5.1-5.3',
188+
'5/12/1997 Book I, Chasimas Hasefer 6.1-6.2',
189+
'5/13/1997 Book I, Chasimas Hasefer 6.3-6.4',
190+
'5/14/1997 Book I, Chasimas Hasefer 6.5-6.6',
191+
'5/15/1997 Book I, Chasimas Hasefer 6.7-6.9',
192+
'5/16/1997 Book I, Chasimas Hasefer 6.10-6.11',
193+
'5/17/1997 Book I, Chasimas Hasefer 7.1-7.5',
194+
'5/18/1997 Book I, Chasimas Hasefer 7.6',
195+
'5/19/1997 Book I, Chasimas Hasefer 7.7-7.8',
196+
'5/20/1997 Book I, Chasimas Hasefer 7.9',
197+
'5/21/1997 Book I, Chasimas Hasefer 7.10',
198+
'5/22/1997 Book I, Chasimas Hasefer 7.11',
199+
'5/23/1997 Book I, Chasimas Hasefer 7.12-7.13',
200+
'5/24/1997 Book II 1.1-1.2',
201+
'5/25/1997 Book II 1.3-1.5',
202+
'5/26/1997 Book II 1.6-1.7',
203+
'5/27/1997 Book II 1.8',
204+
'5/28/1997 Book II 2.1-2.4',
205+
'5/29/1997 Book II 2.5-2.6',
206+
'5/30/1997 Book II 2.7',
207+
'5/31/1997 Book II 2.8',
208+
'6/1/1997 Book II 2.9',
209+
'6/2/1997 Book II 2.10',
210+
];
211+
t.deepEqual(actual, expected);
212+
});

src/rambam.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const cycleLen = 1017;
1111

1212
// The cycle of Rambam began on Sunday, 27 Nissan, 5744 - Apr. 29, 1984.
1313
const startDate = new Date(1984, 3, 29);
14-
export const rambam1StartAbs = greg.greg2abs(startDate);
14+
export const rambam1Start = greg.greg2abs(startDate);
1515

1616
const mishnehTorah = [
1717
['Transmission of the Oral Law', 3],
@@ -123,10 +123,10 @@ export function dailyRambam1(date) {
123123
greg.isDate(date) ? greg.greg2abs(date) :
124124
HDate.isHDate(date) ? date.abs() :
125125
throwTypeError(`non-date given to dailyRambam: ${date}`);
126-
if (cday < rambam1StartAbs) {
126+
if (cday < rambam1Start) {
127127
throw new RangeError(`Date ${date} too early; Daily Rambam cycle began on ${startDate}`);
128128
}
129-
const dno = (cday - rambam1StartAbs) % cycleLen;
129+
const dno = (cday - rambam1Start) % cycleLen;
130130
let total = dno;
131131
for (let j = 0; j < mishnehTorah.length; j++) {
132132
if (total < mishnehTorah[j].ch) {

src/register.js

+12-3
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ import {MishnaYomiIndex, mishnaYomiStart} from './mishnaYomi';
55
import {NachYomiEvent} from './NachYomiEvent';
66
import {NachYomiIndex, nachYomiStart} from './nachYomi';
77
import {yerushalmiYomi, YerushalmiYomiEvent, vilna, schottenstein} from './yerushalmi';
8-
import {chofetzChaim, ChofetzChaimEvent} from './chofetzChaim';
9-
import {dailyRambam1, DailyRambamEvent} from './rambam';
10-
import {shemiratHaLashon, ShemiratHaLashonEvent} from './shemiratHaLashon';
8+
import {chofetzChaim, ChofetzChaimEvent, chofetzChaimStart} from './chofetzChaim';
9+
import {dailyRambam1, DailyRambamEvent, rambam1Start} from './rambam';
10+
import {shemiratHaLashon, ShemiratHaLashonEvent, shemiratHaLashonStart} from './shemiratHaLashon';
1111

1212
DailyLearning.addCalendar('dafYomi', function(hd) {
1313
const abs = hd.abs();
@@ -62,16 +62,25 @@ DailyLearning.addCalendar('yerushalmi-schottenstein', function(hd) {
6262
});
6363

6464
DailyLearning.addCalendar('chofetzChaim', function(hd) {
65+
if (hd.abs() < chofetzChaimStart) {
66+
return null;
67+
}
6568
const reading = chofetzChaim(hd);
6669
return new ChofetzChaimEvent(hd, reading);
6770
});
6871

6972
DailyLearning.addCalendar('rambam1', function(hd) {
73+
if (hd.abs() < rambam1Start) {
74+
return null;
75+
}
7076
const reading = dailyRambam1(hd);
7177
return new DailyRambamEvent(hd, reading);
7278
});
7379

7480
DailyLearning.addCalendar('shemiratHaLashon', function(hd) {
81+
if (hd.abs() < shemiratHaLashonStart) {
82+
return null;
83+
}
7584
const reading = shemiratHaLashon(hd);
7685
return new ShemiratHaLashonEvent(hd, reading);
7786
});

src/shemiratHaLashon.js

+24-13
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ const Adar = months.ADAR_I;
1717
const Adar1 = months.ADAR_I;
1818
const Adar2 = months.ADAR_II;
1919

20+
// Sefer Shemirat HaLashon was written 1865-1875 CE
21+
// יום ד׳ כ״א ימים לחודש שבט שנת תרל״ו לפ״ק
22+
const startDate = new HDate(21, Shvat, 5636);
23+
export const shemiratHaLashonStart = startDate.abs();
24+
2025
const Book1 = 1;
2126
const Book2 = 2;
2227
const Hakdamah = 'Hakdamah';
@@ -434,6 +439,10 @@ export function shemiratHaLashon(hdate) {
434439
if (!HDate.isHDate(hdate)) {
435440
throw new TypeError(`Invalid date: ${hdate}`);
436441
}
442+
const cday = hdate.abs();
443+
if (cday < shemiratHaLashonStart) {
444+
throw new RangeError(`Date ${hdate} too early; Sefer Shemirat HaLashon cycle began on ${startDate}`);
445+
}
437446

438447
const day = hdate.getDate();
439448
const month = hdate.getMonth();
@@ -504,29 +513,31 @@ export class ShemiratHaLashonEvent extends Event {
504513
if (typeof locale === 'string') {
505514
locale = locale.toLowerCase();
506515
}
516+
const prefix = this.renderPrefix(locale);
517+
return prefix + formatReadingPages(this.reading);
518+
}
519+
520+
/**
521+
* @private
522+
* @param {string} locale
523+
* @return {string}
524+
*/
525+
renderPrefix(locale) {
507526
const reading = this.reading;
508527
const book = reading.bk === 1 ? 'Book I' : 'Book II';
509528
const section0 = reading.k.replace(/ /g, '_');
510-
const section = locale === 'memo' ? englishNames[section0] : Locale.gettext(section0, locale);
511-
let name = section ? `${book}, ${section}` : book;
512-
name += formatReadingPages(reading);
513-
return name;
529+
const section = locale === 'memo' ? englishNames[section0] :
530+
reading.k === Chapters ? null : Locale.gettext(reading.k, locale);
531+
return section ? `${book}, ${section}` : book;
514532
}
533+
515534
/**
516535
* Returns a link to sefaria.org
517536
* e.g. https://www.sefaria.org/Shemirat_HaLashon%2C_Book_I%2C_The_Gate_of_Torah.4.2?lang=b
518537
* @return {string}
519538
*/
520539
url() {
521-
const reading = this.reading;
522-
const book = reading.bk === 1 ? 'Book I' : 'Book II';
523-
const section0 = reading.k.replace(/ /g, '_');
524-
const section = englishNames[section0];
525-
let name = 'Shemirat HaLashon, ' + book;
526-
if (section) {
527-
name += ', ' + section;
528-
}
529-
name += '.' + reading.b;
540+
const name = 'Shemirat HaLashon, ' + this.renderPrefix('memo') + '.' + this.reading.b;
530541
const urlName = encodeURIComponent(name.replace(/ /g, '_'));
531542
return `https://www.sefaria.org/${urlName}?lang=bi`;
532543
}

0 commit comments

Comments
 (0)