Skip to content

Commit 6d99f3a

Browse files
committed
Add dafWeeklySunday
1 parent 05094ba commit 6d99f3a

9 files changed

+189
-88
lines changed

README.md

+134-36
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ Supports several learning schedules
1616
* 1 chapter a day cycle - `rambam1`
1717
* Chofetz Chaim - `chofetzChaim`
1818
* Sefer Shemirat HaLashon - `shemiratHaLashon`
19+
* Daf-a-Week
20+
* Daily - `dafWeekly`
21+
* Sundays only - `dafWeeklySunday`
1922

2023
## Installation
2124
```bash
@@ -25,9 +28,15 @@ $ npm install @hebcal/learning
2528
## Classes
2629

2730
<dl>
31+
<dt><a href="#DafPage">DafPage</a></dt>
32+
<dd><p>Represents a tractate and page number</p>
33+
</dd>
2834
<dt><a href="#DafYomi">DafYomi</a></dt>
2935
<dd><p>Returns the Daf Yomi for given date</p>
3036
</dd>
37+
<dt><a href="#DafPageEvent">DafPageEvent</a></dt>
38+
<dd><p>Event wrapper around a DafPage instance</p>
39+
</dd>
3140
<dt><a href="#DafYomiEvent">DafYomiEvent</a></dt>
3241
<dd><p>Event wrapper around a DafYomi instance</p>
3342
</dd>
@@ -60,6 +69,9 @@ and Ketuvim (Writings).</p>
6069
<dt><a href="#PsalmsEvent">PsalmsEvent</a></dt>
6170
<dd><p>Event wrapper around a daily Psalms / Tehillim</p>
6271
</dd>
72+
<dt><a href="#DafWeeklyEvent">DafWeeklyEvent</a></dt>
73+
<dd><p>Event wrapper around a daily weekly</p>
74+
</dd>
6375
</dl>
6476

6577
## Constants
@@ -101,6 +113,9 @@ cycle began (2 February 1980 for Vilna,
101113
<dt><a href="#dailyPsalms">dailyPsalms(date)</a> ⇒ <code>any</code></dt>
102114
<dd><p>Calculates Daily Psalms (Tehillim) for 30-day cycle.</p>
103115
</dd>
116+
<dt><a href="#dafWeekly">dafWeekly(date)</a> ⇒ <code><a href="#DafPage">DafPage</a></code></dt>
117+
<dd><p>Daf-a-Week</p>
118+
</dd>
104119
</dl>
105120

106121
## Typedefs
@@ -114,19 +129,55 @@ cycle began (2 February 1980 for Vilna,
114129
</dd>
115130
</dl>
116131

132+
<a name="DafPage"></a>
133+
134+
## DafPage
135+
Represents a tractate and page number
136+
137+
**Kind**: global class
138+
139+
* [DafPage](#DafPage)
140+
* [new DafPage(name, blatt)](#new_DafPage_new)
141+
* [.getBlatt()](#DafPage+getBlatt) ⇒ <code>number</code>
142+
* [.getName()](#DafPage+getName) ⇒ <code>string</code>
143+
* [.render([locale])](#DafPage+render) ⇒ <code>string</code>
144+
145+
<a name="new_DafPage_new"></a>
146+
147+
### new DafPage(name, blatt)
148+
Initializes a daf yomi instance
149+
150+
151+
| Param | Type |
152+
| --- | --- |
153+
| name | <code>string</code> |
154+
| blatt | <code>number</code> |
155+
156+
<a name="DafPage+getBlatt"></a>
157+
158+
### dafPage.getBlatt() ⇒ <code>number</code>
159+
**Kind**: instance method of [<code>DafPage</code>](#DafPage)
160+
<a name="DafPage+getName"></a>
161+
162+
### dafPage.getName() ⇒ <code>string</code>
163+
**Kind**: instance method of [<code>DafPage</code>](#DafPage)
164+
<a name="DafPage+render"></a>
165+
166+
### dafPage.render([locale]) ⇒ <code>string</code>
167+
Formats (with translation) the dafyomi result as a string like "Pesachim 34"
168+
169+
**Kind**: instance method of [<code>DafPage</code>](#DafPage)
170+
171+
| Param | Type | Description |
172+
| --- | --- | --- |
173+
| [locale] | <code>string</code> | Optional locale name (defaults to active locale). |
174+
117175
<a name="DafYomi"></a>
118176

119177
## DafYomi
120178
Returns the Daf Yomi for given date
121179

122180
**Kind**: global class
123-
124-
* [DafYomi](#DafYomi)
125-
* [new DafYomi(date)](#new_DafYomi_new)
126-
* [.getBlatt()](#DafYomi+getBlatt) ⇒ <code>number</code>
127-
* [.getName()](#DafYomi+getName) ⇒ <code>string</code>
128-
* [.render([locale])](#DafYomi+render) ⇒ <code>string</code>
129-
130181
<a name="new_DafYomi_new"></a>
131182

132183
### new DafYomi(date)
@@ -137,25 +188,56 @@ Initializes a daf yomi instance
137188
| --- | --- | --- |
138189
| date | <code>Date</code> \| <code>HDate</code> \| <code>number</code> | Gregorian or Hebrew date |
139190

140-
<a name="DafYomi+getBlatt"></a>
191+
<a name="DafPageEvent"></a>
141192

142-
### dafYomi.getBlatt() ⇒ <code>number</code>
143-
**Kind**: instance method of [<code>DafYomi</code>](#DafYomi)
144-
<a name="DafYomi+getName"></a>
193+
## DafPageEvent
194+
Event wrapper around a DafPage instance
145195

146-
### dafYomi.getName() ⇒ <code>string</code>
147-
**Kind**: instance method of [<code>DafYomi</code>](#DafYomi)
148-
<a name="DafYomi+render"></a>
196+
**Kind**: global class
149197

150-
### dafYomi.render([locale]) ⇒ <code>string</code>
151-
Formats (with translation) the dafyomi result as a string like "Pesachim 34"
198+
* [DafPageEvent](#DafPageEvent)
199+
* [new DafPageEvent(date, daf)](#new_DafPageEvent_new)
200+
* [.render([locale])](#DafPageEvent+render) ⇒ <code>string</code>
201+
* [.renderBrief([locale])](#DafPageEvent+renderBrief) ⇒ <code>string</code>
202+
* [.url()](#DafPageEvent+url) ⇒ <code>string</code>
152203

153-
**Kind**: instance method of [<code>DafYomi</code>](#DafYomi)
204+
<a name="new_DafPageEvent_new"></a>
205+
206+
### new DafPageEvent(date, daf)
207+
208+
| Param | Type |
209+
| --- | --- |
210+
| date | <code>HDate</code> |
211+
| daf | [<code>DafPage</code>](#DafPage) |
212+
213+
<a name="DafPageEvent+render"></a>
214+
215+
### dafPageEvent.render([locale]) ⇒ <code>string</code>
216+
Returns Daf Yomi name including the 'Daf Yomi: ' prefix (e.g. "Daf Yomi: Pesachim 107").
217+
218+
**Kind**: instance method of [<code>DafPageEvent</code>](#DafPageEvent)
154219

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

224+
<a name="DafPageEvent+renderBrief"></a>
225+
226+
### dafPageEvent.renderBrief([locale]) ⇒ <code>string</code>
227+
Returns Daf Yomi name without the 'Daf Yomi: ' prefix (e.g. "Pesachim 107").
228+
229+
**Kind**: instance method of [<code>DafPageEvent</code>](#DafPageEvent)
230+
231+
| Param | Type | Description |
232+
| --- | --- | --- |
233+
| [locale] | <code>string</code> | Optional locale name (defaults to active locale). |
234+
235+
<a name="DafPageEvent+url"></a>
236+
237+
### dafPageEvent.url() ⇒ <code>string</code>
238+
Returns a link to sefaria.org or dafyomi.org
239+
240+
**Kind**: instance method of [<code>DafPageEvent</code>](#DafPageEvent)
159241
<a name="DafYomiEvent"></a>
160242

161243
## DafYomiEvent
@@ -166,8 +248,6 @@ Event wrapper around a DafYomi instance
166248
* [DafYomiEvent](#DafYomiEvent)
167249
* [new DafYomiEvent(date)](#new_DafYomiEvent_new)
168250
* [.render([locale])](#DafYomiEvent+render) ⇒ <code>string</code>
169-
* [.renderBrief([locale])](#DafYomiEvent+renderBrief) ⇒ <code>string</code>
170-
* [.url()](#DafYomiEvent+url) ⇒ <code>string</code>
171251
* [.getCategories()](#DafYomiEvent+getCategories) ⇒ <code>Array.&lt;string&gt;</code>
172252

173253
<a name="new_DafYomiEvent_new"></a>
@@ -189,23 +269,6 @@ Returns Daf Yomi name including the 'Daf Yomi: ' prefix (e.g. "Daf Yomi: Pesachi
189269
| --- | --- | --- |
190270
| [locale] | <code>string</code> | Optional locale name (defaults to active locale). |
191271

192-
<a name="DafYomiEvent+renderBrief"></a>
193-
194-
### dafYomiEvent.renderBrief([locale]) ⇒ <code>string</code>
195-
Returns Daf Yomi name without the 'Daf Yomi: ' prefix (e.g. "Pesachim 107").
196-
197-
**Kind**: instance method of [<code>DafYomiEvent</code>](#DafYomiEvent)
198-
199-
| Param | Type | Description |
200-
| --- | --- | --- |
201-
| [locale] | <code>string</code> | Optional locale name (defaults to active locale). |
202-
203-
<a name="DafYomiEvent+url"></a>
204-
205-
### dafYomiEvent.url() ⇒ <code>string</code>
206-
Returns a link to sefaria.org or dafyomi.org
207-
208-
**Kind**: instance method of [<code>DafYomiEvent</code>](#DafYomiEvent)
209272
<a name="DafYomiEvent+getCategories"></a>
210273

211274
### dafYomiEvent.getCategories() ⇒ <code>Array.&lt;string&gt;</code>
@@ -587,6 +650,30 @@ Returns a link to sefaria.org
587650

588651
### psalmsEvent.getCategories() ⇒ <code>Array.&lt;string&gt;</code>
589652
**Kind**: instance method of [<code>PsalmsEvent</code>](#PsalmsEvent)
653+
<a name="DafWeeklyEvent"></a>
654+
655+
## DafWeeklyEvent
656+
Event wrapper around a daily weekly
657+
658+
**Kind**: global class
659+
660+
* [DafWeeklyEvent](#DafWeeklyEvent)
661+
* [new DafWeeklyEvent(date, daf)](#new_DafWeeklyEvent_new)
662+
* [.getCategories()](#DafWeeklyEvent+getCategories) ⇒ <code>Array.&lt;string&gt;</code>
663+
664+
<a name="new_DafWeeklyEvent_new"></a>
665+
666+
### new DafWeeklyEvent(date, daf)
667+
668+
| Param | Type |
669+
| --- | --- |
670+
| date | <code>HDate</code> |
671+
| daf | [<code>DafPage</code>](#DafPage) |
672+
673+
<a name="DafWeeklyEvent+getCategories"></a>
674+
675+
### dafWeeklyEvent.getCategories() ⇒ <code>Array.&lt;string&gt;</code>
676+
**Kind**: instance method of [<code>DafWeeklyEvent</code>](#DafWeeklyEvent)
590677
<a name="vilna"></a>
591678

592679
## vilna
@@ -669,6 +756,17 @@ Calculates Daily Psalms (Tehillim) for 30-day cycle.
669756
| --- | --- | --- |
670757
| date | <code>HDate</code> \| <code>Date</code> \| <code>number</code> | Hebrew or Gregorian date |
671758

759+
<a name="dafWeekly"></a>
760+
761+
## dafWeekly(date) ⇒ [<code>DafPage</code>](#DafPage)
762+
Daf-a-Week
763+
764+
**Kind**: global function
765+
766+
| Param | Type | Description |
767+
| --- | --- | --- |
768+
| date | <code>HDate</code> \| <code>Date</code> \| <code>number</code> | Hebrew or Gregorian date |
769+
672770
<a name="MishnaYomi"></a>
673771

674772
## MishnaYomi : <code>Object</code>

package-lock.json

+6-6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@hebcal/learning",
3-
"version": "1.5.0",
3+
"version": "1.5.1",
44
"description": "Daily learning schedules: Daf Yomi, Mishna Yomi, etc",
55
"main": "dist/index.js",
66
"module": "dist/index.mjs",
@@ -23,7 +23,7 @@
2323
},
2424
"homepage": "https://github.com/mjradwin/hebcal-learning#readme",
2525
"dependencies": {
26-
"@hebcal/core": "^4.3.0"
26+
"@hebcal/core": "^4.3.1"
2727
},
2828
"files": [
2929
"types.d.ts",

src/dafWeekly.js

+4-34
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import {greg} from '@hebcal/core';
2-
import {shas0 as shas, DafPage, DafPageEvent} from './dafyomi';
1+
import {flags, greg} from '@hebcal/core';
2+
import {shas0, findDaf, DafPageEvent} from './dafyomi';
33
import {getAbsDate, checkTooEarly} from './common';
44

55
const startDate = new Date(2005, 2, 6);
@@ -19,37 +19,7 @@ export function dafWeekly(date) {
1919
const dayNum = (abs - dafWeeklyStart) % numDays;
2020
const weekNum = Math.trunc(dayNum / 7);
2121

22-
// Find the daf
23-
let total = 0;
24-
let blatt = 0;
25-
let count = -1;
26-
let j = 0;
27-
const dafcnt = 40;
28-
while (j < dafcnt) {
29-
count++;
30-
total = total + shas[j].blatt - 1;
31-
if (weekNum < total) {
32-
blatt = (shas[j].blatt + 1) - (total - weekNum);
33-
// fiddle with the weird ones near the end
34-
switch (count) {
35-
case 36:
36-
blatt = blatt + 21;
37-
break;
38-
case 37:
39-
blatt = blatt + 24;
40-
break;
41-
case 38:
42-
blatt = blatt + 32;
43-
break;
44-
default:
45-
break;
46-
}
47-
// Bailout
48-
j = 1 + dafcnt;
49-
}
50-
j++;
51-
}
52-
return new DafPage(shas[count].name, blatt);
22+
return findDaf(shas0, weekNum);
5323
}
5424

5525
/**
@@ -61,7 +31,7 @@ export class DafWeeklyEvent extends DafPageEvent {
6131
* @param {DafPage} daf
6232
*/
6333
constructor(date, daf) {
64-
super(date, daf);
34+
super(date, daf, flags.USER_EVENT);
6535
this.alarm = false;
6636
this.category = 'Daf Weekly';
6737
}

src/dafWeekly.spec.js

-1
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,4 @@ test('dafWeekly-render', (t) => {
2323
t.is(ev.render('he'), 'שַׁבָּת דף ק״ד');
2424
t.is(ev.render('he-x-NoNikud'), 'שבת דף ק״ד');
2525
t.is(ev.url(), 'https://www.sefaria.org/Shabbat.104a?lang=bi');
26-
t.deepEqual(ev.getCategories(), ['dafWeekly']);
2726
});

0 commit comments

Comments
 (0)