jcal-zmanim 1.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +674 -0
- package/README.md +2 -0
- package/build/AppUtils.d.ts +109 -0
- package/build/AppUtils.js +394 -0
- package/build/GeneralUtils.d.ts +43 -0
- package/build/GeneralUtils.js +93 -0
- package/build/JCal/Dafyomi.d.ts +27 -0
- package/build/JCal/Dafyomi.js +131 -0
- package/build/JCal/Location.d.ts +33 -0
- package/build/JCal/Location.js +80 -0
- package/build/JCal/Molad.d.ts +39 -0
- package/build/JCal/Molad.js +95 -0
- package/build/JCal/PirkeiAvos.d.ts +13 -0
- package/build/JCal/PirkeiAvos.js +172 -0
- package/build/JCal/Sedra.d.ts +63 -0
- package/build/JCal/Sedra.js +186 -0
- package/build/JCal/Utils.d.ts +225 -0
- package/build/JCal/Utils.js +666 -0
- package/build/JCal/Zmanim.d.ts +95 -0
- package/build/JCal/Zmanim.js +224 -0
- package/build/JCal/jDate.d.ts +203 -0
- package/build/JCal/jDate.js +647 -0
- package/build/Locations.d.ts +7 -0
- package/build/Locations.js +1308 -0
- package/build/Notifications.d.ts +14 -0
- package/build/Notifications.js +1040 -0
- package/build/Settings.d.ts +25 -0
- package/build/Settings.js +75 -0
- package/build/ZmanTypes.d.ts +34 -0
- package/build/ZmanTypes.js +184 -0
- package/build/index.d.ts +1 -0
- package/build/index.js +59 -0
- package/package.json +33 -0
- package/src/AppUtils.ts +500 -0
- package/src/GeneralUtils.ts +84 -0
- package/src/JCal/Dafyomi.ts +139 -0
- package/src/JCal/Location.ts +100 -0
- package/src/JCal/Molad.ts +105 -0
- package/src/JCal/PirkeiAvos.ts +180 -0
- package/src/JCal/Sedra.ts +215 -0
- package/src/JCal/Utils.ts +732 -0
- package/src/JCal/Zmanim.ts +270 -0
- package/src/JCal/jDate.ts +714 -0
- package/src/Locations.ts +1303 -0
- package/src/Notifications.ts +1243 -0
- package/src/Settings.ts +103 -0
- package/src/ZmanTypes.ts +184 -0
- package/src/index.ts +31 -0
- package/src/jcal-zmanim.d.ts +4 -0
- package/tsconfig.json +109 -0
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import Utils from './Utils.js';
|
|
2
|
+
import jDate from './jDate.js';
|
|
3
|
+
|
|
4
|
+
'use strict';
|
|
5
|
+
/** *********************************************************************************************************
|
|
6
|
+
* Computes the Day Yomi for the given day.
|
|
7
|
+
* Sample of use - to get todays daf:
|
|
8
|
+
* const dafEng = Dafyomi.toString(new jDate(new Date()));
|
|
9
|
+
* const dafHeb = Dafyomi.toStringHeb(new jDate(new Date()));
|
|
10
|
+
* The code was converted to javascript and tweaked by CBS.
|
|
11
|
+
* It is directly based on the C code in Danny Sadinoff's HebCal - Copyright (C) 1994.
|
|
12
|
+
* The HebCal code for dafyomi was adapted by Aaron Peromsik from Bob Newell's public domain daf.el.
|
|
13
|
+
***********************************************************************************************************/
|
|
14
|
+
export default class Dafyomi {
|
|
15
|
+
static masechtaList = [
|
|
16
|
+
{ eng: 'Berachos', heb: 'ברכות', daf: 64 },
|
|
17
|
+
{ eng: 'Shabbos', heb: 'שבת', daf: 157 },
|
|
18
|
+
{ eng: 'Eruvin', heb: 'ערובין', daf: 105 },
|
|
19
|
+
{ eng: 'Pesachim', heb: 'פסחים', daf: 121 },
|
|
20
|
+
{ eng: 'Shekalim', heb: 'שקלים', daf: 22 },
|
|
21
|
+
{ eng: 'Yoma', heb: 'יומא', daf: 88 },
|
|
22
|
+
{ eng: 'Sukkah', heb: 'סוכה', daf: 56 },
|
|
23
|
+
{ eng: 'Beitzah', heb: 'ביצה', daf: 40 },
|
|
24
|
+
{ eng: 'Rosh Hashana', heb: 'ראש השנה', daf: 35 },
|
|
25
|
+
{ eng: 'Taanis', heb: 'תענית', daf: 31 },
|
|
26
|
+
{ eng: 'Megillah', heb: 'מגילה', daf: 32 },
|
|
27
|
+
{ eng: 'Moed Katan', heb: 'מועד קטן', daf: 29 },
|
|
28
|
+
{ eng: 'Chagigah', heb: 'חגיגה', daf: 27 },
|
|
29
|
+
{ eng: 'Yevamos', heb: 'יבמות', daf: 122 },
|
|
30
|
+
{ eng: 'Kesubos', heb: 'כתובות', daf: 112 },
|
|
31
|
+
{ eng: 'Nedarim', heb: 'נדרים', daf: 91 },
|
|
32
|
+
{ eng: 'Nazir', heb: 'נזיר', daf: 66 },
|
|
33
|
+
{ eng: 'Sotah', heb: 'סוטה', daf: 49 },
|
|
34
|
+
{ eng: 'Gitin', heb: 'גיטין', daf: 90 },
|
|
35
|
+
{ eng: 'Kiddushin', heb: 'קדושין', daf: 82 },
|
|
36
|
+
{ eng: 'Baba Kamma', heb: 'בבא קמא', daf: 119 },
|
|
37
|
+
{ eng: 'Baba Metzia', heb: 'בבא מציעא', daf: 119 },
|
|
38
|
+
{ eng: 'Baba Basra', heb: 'בבא בתרא', daf: 176 },
|
|
39
|
+
{ eng: 'Sanhedrin', heb: 'סנהדרין', daf: 113 },
|
|
40
|
+
{ eng: 'Makkot', heb: 'מכות', daf: 24 },
|
|
41
|
+
{ eng: 'Shevuot', heb: 'שבועות', daf: 49 },
|
|
42
|
+
{ eng: 'Avodah Zarah', heb: 'עבודה זרה', daf: 76 },
|
|
43
|
+
{ eng: 'Horayot', heb: 'הוריות', daf: 14 },
|
|
44
|
+
{ eng: 'Zevachim', heb: 'זבחים', daf: 120 },
|
|
45
|
+
{ eng: 'Menachos', heb: 'מנחות', daf: 110 },
|
|
46
|
+
{ eng: 'Chullin', heb: 'חולין', daf: 142 },
|
|
47
|
+
{ eng: 'Bechoros', heb: 'בכורות', daf: 61 },
|
|
48
|
+
{ eng: 'Arachin', heb: 'ערכין', daf: 34 },
|
|
49
|
+
{ eng: 'Temurah', heb: 'תמורה', daf: 34 },
|
|
50
|
+
{ eng: 'Kerisos', heb: 'כריתות', daf: 28 },
|
|
51
|
+
{ eng: 'Meilah', heb: 'מעילה', daf: 22 },
|
|
52
|
+
{ eng: 'Kinnim', heb: 'קנים', daf: 4 },
|
|
53
|
+
{ eng: 'Tamid', heb: 'תמיד', daf: 10 },
|
|
54
|
+
{ eng: 'Midos', heb: 'מדות', daf: 4 },
|
|
55
|
+
{ eng: 'Niddah', heb: 'נדה', daf: 73 }];
|
|
56
|
+
|
|
57
|
+
static getDaf(jdate:jDate) : {
|
|
58
|
+
masechet: { eng: string, heb: string, daf: number },
|
|
59
|
+
daf: number
|
|
60
|
+
} | null{
|
|
61
|
+
const absoluteDate = jdate.Abs;
|
|
62
|
+
let dafcnt = 40, cno:number, dno:number, osday:number, nsday:number, total:number, count:number, j:number, blatt:number;
|
|
63
|
+
|
|
64
|
+
osday = jDate.absSd(new Date(1923, 8, 11));
|
|
65
|
+
nsday = jDate.absSd(new Date(1975, 5, 24));
|
|
66
|
+
|
|
67
|
+
/* No cycle, new cycle, old cycle */
|
|
68
|
+
if (absoluteDate < osday)
|
|
69
|
+
return null; /* daf yomi hadn't started yet */
|
|
70
|
+
if (absoluteDate >= nsday) {
|
|
71
|
+
cno = 8 + Utils.toInt(((absoluteDate - nsday) / 2711));
|
|
72
|
+
dno = (absoluteDate - nsday) % 2711;
|
|
73
|
+
}
|
|
74
|
+
else {
|
|
75
|
+
cno = 1 + Utils.toInt((absoluteDate - osday) / 2702);
|
|
76
|
+
dno = Utils.toInt((absoluteDate - osday) / 2702);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/* Find the daf taking note that the cycle changed slightly after cycle 7. */
|
|
80
|
+
total = blatt = 0;
|
|
81
|
+
count = -1;
|
|
82
|
+
|
|
83
|
+
/* Fix Shekalim for old cycles */
|
|
84
|
+
if (cno <= 7)
|
|
85
|
+
Dafyomi.masechtaList[4].daf = 13;
|
|
86
|
+
else
|
|
87
|
+
Dafyomi.masechtaList[4].daf = 22;
|
|
88
|
+
|
|
89
|
+
/* Find the daf */
|
|
90
|
+
j = 0;
|
|
91
|
+
while (j < dafcnt) {
|
|
92
|
+
count++;
|
|
93
|
+
total = total + Dafyomi.masechtaList[j].daf - 1;
|
|
94
|
+
if (dno < total) {
|
|
95
|
+
blatt = (Dafyomi.masechtaList[j].daf + 1) - (total - dno);
|
|
96
|
+
/* fiddle with the weird ones near the end */
|
|
97
|
+
switch (count) {
|
|
98
|
+
case 36:
|
|
99
|
+
blatt = blatt + 21;
|
|
100
|
+
break;
|
|
101
|
+
case 37:
|
|
102
|
+
blatt = blatt + 24;
|
|
103
|
+
break;
|
|
104
|
+
case 38:
|
|
105
|
+
blatt = blatt + 33;
|
|
106
|
+
break;
|
|
107
|
+
default:
|
|
108
|
+
break;
|
|
109
|
+
}
|
|
110
|
+
/* Bailout */
|
|
111
|
+
j = 1 + dafcnt;
|
|
112
|
+
}
|
|
113
|
+
j++;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
return {
|
|
117
|
+
masechet: Dafyomi.masechtaList[count],
|
|
118
|
+
daf: blatt
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
// Returns the name of the Masechta and daf number in English, For example: Sukkah, Daf 3
|
|
123
|
+
static toString(jd:jDate):string|undefined {
|
|
124
|
+
const d = Dafyomi.getDaf(jd);
|
|
125
|
+
if(d!==null)
|
|
126
|
+
{
|
|
127
|
+
return d.masechet.eng + ', Daf ' + d.daf.toString();
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
//Returns the name of the Masechta and daf number in Hebrew. For example: 'סוכה דף כ.
|
|
132
|
+
static toStringHeb(jd:jDate):string |undefined{
|
|
133
|
+
const d = Dafyomi.getDaf(jd);
|
|
134
|
+
if(d!==null)
|
|
135
|
+
{
|
|
136
|
+
return d.masechet.heb + ' דף ' + Utils.toJNum(d.daf);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
/** Represents a geographic Location. Needed for calculating Zmanim.
|
|
2
|
+
If Israel is undefined, if the given coordinates are near the vicinity of Israel it will be assumed that it is in Israel.
|
|
3
|
+
UTCOffset is the time zone. Israel is always 2 and the US East coast is -5. England is 0 of course.
|
|
4
|
+
If UTCOffset is not specifically supplied, the longitude will be used to get a quasi-educated guess.*/
|
|
5
|
+
export default class Location {
|
|
6
|
+
Name: string;
|
|
7
|
+
Israel: boolean;
|
|
8
|
+
Latitude: number;
|
|
9
|
+
Longitude: number;
|
|
10
|
+
UTCOffset: number;
|
|
11
|
+
Elevation: number;
|
|
12
|
+
CandleLighting?: number;
|
|
13
|
+
locationId?: number;
|
|
14
|
+
/**
|
|
15
|
+
* Describe a new Location.
|
|
16
|
+
* @param {String} name The name of the Location
|
|
17
|
+
* @param {Boolean} israel Is this Location in Israel?
|
|
18
|
+
* @param {Number} latitude
|
|
19
|
+
* @param {Number} longitude
|
|
20
|
+
* @param {Number} utcOffset The time zone. Israel is 2 and New York is -5.
|
|
21
|
+
* @param {Number} elevation Elevation in meters
|
|
22
|
+
* @param {Number} [candleLighting] Number of minutes before sunset the candles are lit on Friday
|
|
23
|
+
* @param {Number} [locationId] If this location is in a database, keeps track of the id
|
|
24
|
+
*/
|
|
25
|
+
constructor(name:string, israel:boolean, latitude:number, longitude:number, utcOffset:number, elevation:number, candleLighting?:number, locationId?:number) {
|
|
26
|
+
//If the israel argument was not set at all.
|
|
27
|
+
if (typeof israel === 'undefined' || israel === null) {
|
|
28
|
+
//If the user is within Israels general coordinates,
|
|
29
|
+
//we feel pretty safe assuming they are in Israel.
|
|
30
|
+
//Where else on the map is the user? (Note, the probablity of our users Jewishness: 99.99%)
|
|
31
|
+
//Sinai, Lebanon, Syria, Jordan, in a submarine under the Mediterannian ...
|
|
32
|
+
israel = (latitude > 29.45 && latitude < 33 && longitude < -34.23 && longitude > -35.9);
|
|
33
|
+
}
|
|
34
|
+
if (israel) {
|
|
35
|
+
//Israel has only one immutable time zone
|
|
36
|
+
utcOffset = 2;
|
|
37
|
+
}
|
|
38
|
+
//If the utcOffset argument was not set at all.
|
|
39
|
+
else if (typeof utcOffset === 'undefined' || utcOffset === null) {
|
|
40
|
+
//Try to determine the "correct" time zone using the simple fact that Greenwich is both TZ 0 and longitude 0.
|
|
41
|
+
//Even though technically this is the way it should be,
|
|
42
|
+
//it will be often incorrect as time zones are almost always tweaked to accomadate the closest border.
|
|
43
|
+
utcOffset = -Math.round(longitude / 15);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
this.Name = (name || 'Unknown Location');
|
|
47
|
+
this.Israel = !!israel;
|
|
48
|
+
this.Latitude = latitude;
|
|
49
|
+
this.Longitude = longitude;
|
|
50
|
+
this.UTCOffset = utcOffset || 0;
|
|
51
|
+
this.Elevation = elevation || 0;
|
|
52
|
+
this.CandleLighting = candleLighting || Location.getCandles(this);
|
|
53
|
+
this.locationId = locationId;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
hasId() {
|
|
57
|
+
return !!this.locationId;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
static clone(location:Location) {
|
|
61
|
+
return new Location(
|
|
62
|
+
location.Name,
|
|
63
|
+
location.Israel,
|
|
64
|
+
location.Latitude,
|
|
65
|
+
location.Longitude,
|
|
66
|
+
location.UTCOffset,
|
|
67
|
+
location.Elevation,
|
|
68
|
+
location.CandleLighting || 0,
|
|
69
|
+
location.locationId||0);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
static getCandles(location:Location) {
|
|
73
|
+
if (location.CandleLighting) {
|
|
74
|
+
return location.CandleLighting;
|
|
75
|
+
}
|
|
76
|
+
else if (!location.Israel) {
|
|
77
|
+
return 18;
|
|
78
|
+
}
|
|
79
|
+
else {
|
|
80
|
+
const special = [{ names: ['jerusalem', 'yerush', 'petach', 'petah', 'petak', 'beit shemesh', 'ירושלים', 'פתח תקוה', 'בית שמש'], min: 40 },
|
|
81
|
+
{ names: ['haifa', 'chaifa', 'be\'er sheva', 'beersheba', 'חיפה', 'באר שבע'], min: 22 }],
|
|
82
|
+
loclc = location.Name.toLowerCase(),
|
|
83
|
+
city = special.find(sp => {
|
|
84
|
+
return sp.names.find(spi => {
|
|
85
|
+
return loclc.indexOf(spi) > -1;
|
|
86
|
+
});
|
|
87
|
+
});
|
|
88
|
+
return city ? city.min : 30;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**Gets the Location for Jerusalem.*/
|
|
93
|
+
static getJerusalem() {
|
|
94
|
+
return new Location('Jerusalem', true, 31.78, -35.22, 2, 800, 40, 28);
|
|
95
|
+
}
|
|
96
|
+
/**Gets the Location for Lakewood NJ*/
|
|
97
|
+
static getLakewood() {
|
|
98
|
+
return new Location('Lakewood NJ', false, 40.1, 74.23, -5, 0, 18, 185);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import Utils from './Utils.js';
|
|
2
|
+
import jDate from './jDate.js';
|
|
3
|
+
import Location from './Location.js';
|
|
4
|
+
import { Time } from '../jcal-zmanim.js';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Gets the molad for the given jewish month and year.
|
|
8
|
+
* Algorithm was adapted from Hebcal by Danny Sadinoff
|
|
9
|
+
*
|
|
10
|
+
* Example of use:
|
|
11
|
+
* const moladString = Molad.getString(5776, 10);
|
|
12
|
+
*/
|
|
13
|
+
export default class Molad {
|
|
14
|
+
/**
|
|
15
|
+
*
|
|
16
|
+
* @param {Number} month
|
|
17
|
+
* @param {Number} year
|
|
18
|
+
* @returns {{jDate:jDate,time:Time,chalakim:number}}
|
|
19
|
+
*/
|
|
20
|
+
static getMolad(month:number, year:number) :{jDate:jDate,time:Time,chalakim:number} {
|
|
21
|
+
let totalMonths, partsElapsed, hoursElapsed, parts, monthAdj = month - 7;
|
|
22
|
+
|
|
23
|
+
if (monthAdj < 0) {
|
|
24
|
+
monthAdj += jDate.monthsJYear(year);
|
|
25
|
+
}
|
|
26
|
+
totalMonths = Utils.toInt(monthAdj + 235 * Utils.toInt((year - 1) / 19) + 12 * ((year - 1) % 19) +
|
|
27
|
+
((((year - 1) % 19) * 7) + 1) / 19);
|
|
28
|
+
partsElapsed = 204 + (793 * (totalMonths % 1080));
|
|
29
|
+
hoursElapsed = 5 + (12 * totalMonths) + 793 * Utils.toInt(totalMonths / 1080) +
|
|
30
|
+
Utils.toInt(partsElapsed / 1080) - 6;
|
|
31
|
+
parts = Utils.toInt((partsElapsed % 1080) + 1080 * (hoursElapsed % 24));
|
|
32
|
+
|
|
33
|
+
return {
|
|
34
|
+
jDate: new jDate((1 + (29 * Utils.toInt(totalMonths))) + Utils.toInt((hoursElapsed / 24))),
|
|
35
|
+
time: { hour: Utils.toInt(hoursElapsed) % 24, minute: Utils.toInt((parts % 1080) / 18), second: 0 },
|
|
36
|
+
chalakim: parts % 18
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Returns the time of the molad as a string in the format: Monday Night, 8:33 PM and 12 Chalakim
|
|
42
|
+
* The molad is always in Jerusalem so we use the Jerusalem sunset times
|
|
43
|
+
* to determine whether to display "Night" or "Motzai Shabbos" etc. (check this...)
|
|
44
|
+
* @param {Number} year
|
|
45
|
+
* @param {Number} month
|
|
46
|
+
*/
|
|
47
|
+
static getString(year:number, month:number):string {
|
|
48
|
+
const molad = Molad.getMolad(month, year),
|
|
49
|
+
zmanim = molad.jDate.getSunriseSunset(Location.getJerusalem()),
|
|
50
|
+
isNight = Utils.isTimeAfter(zmanim.sunset, molad.time),
|
|
51
|
+
dow = molad.jDate.getDayOfWeek();
|
|
52
|
+
let str = '';
|
|
53
|
+
|
|
54
|
+
if (!zmanim.sunset || isNaN(zmanim.sunset.hour)) {
|
|
55
|
+
str += Utils.dowEng[dow];
|
|
56
|
+
}
|
|
57
|
+
else if (dow === 6 && isNight) {
|
|
58
|
+
str += 'Motzai Shabbos,';
|
|
59
|
+
}
|
|
60
|
+
else if (dow === 5 && isNight) {
|
|
61
|
+
str += 'Shabbos Night,';
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
str += Utils.dowEng[dow] + (isNight ? ' Night' : '');
|
|
65
|
+
}
|
|
66
|
+
str += ' ' + Utils.getTimeString(molad.time) + ' and ' +
|
|
67
|
+
molad.chalakim.toString() + ' Chalakim';
|
|
68
|
+
|
|
69
|
+
return str;
|
|
70
|
+
}
|
|
71
|
+
time(sunset: any, time: any) {
|
|
72
|
+
throw new Error('Method not implemented.');
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Returns the time of the molad as a string in the format: ליל שני 20:33 12 חלקים
|
|
77
|
+
* The molad is always in Jerusalem so we use the Jerusalem sunset times
|
|
78
|
+
* to determine whether to display "ליל/יום" or "מוצאי שב"ק" etc.
|
|
79
|
+
* @param {Number} year
|
|
80
|
+
* @param {Number} month
|
|
81
|
+
*/
|
|
82
|
+
static getStringHeb(year:number, month:number):string {
|
|
83
|
+
const molad = Molad.getMolad(month, year),
|
|
84
|
+
zmanim = molad.jDate.getSunriseSunset(Location.getJerusalem()),
|
|
85
|
+
isNight = Utils.isTimeAfter(zmanim.sunset, molad.time) &&
|
|
86
|
+
Utils.isTimeAfter(molad.time, zmanim.sunrise),
|
|
87
|
+
dow = molad.jDate.getDayOfWeek();
|
|
88
|
+
let str = '';
|
|
89
|
+
|
|
90
|
+
if (dow === 6) {
|
|
91
|
+
str += (isNight ? 'מוצאי שב"ק' : 'יום שב"ק');
|
|
92
|
+
}
|
|
93
|
+
else if (dow === 5) {
|
|
94
|
+
str += (isNight ? 'ליל שב"ק' : 'ערב שב"ק');
|
|
95
|
+
}
|
|
96
|
+
else {
|
|
97
|
+
str += (isNight ? 'ליל' : 'יום') +
|
|
98
|
+
Utils.dowHeb[dow].replace('יום', '');
|
|
99
|
+
}
|
|
100
|
+
str += ' ' + Utils.getTimeString(molad.time,1, true) + ' ' +
|
|
101
|
+
molad.chalakim.toString() + ' חלקים';
|
|
102
|
+
|
|
103
|
+
return str;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
import jDate from './jDate.js';
|
|
2
|
+
import Utils from './Utils.js';
|
|
3
|
+
|
|
4
|
+
'use strict';
|
|
5
|
+
|
|
6
|
+
/****************************************************************************************************************
|
|
7
|
+
* Computes the Perek/Prakim of the week for the given Shabbos.
|
|
8
|
+
* Returns an array of prakim (integers) (either one or two) for the given Jewish Date
|
|
9
|
+
* Sample of use to get todays sedra in Israel:
|
|
10
|
+
* const prakim = PirkeiAvos.getPrakim(new jDate(), true);
|
|
11
|
+
* const str = 'Pirkei Avos: ' + prakim.map(s => `${Utils.toSuffixed(s)} Perek`).join(' and ');
|
|
12
|
+
* ***************************************************************************************************************/
|
|
13
|
+
export default class PirkeiAvos {
|
|
14
|
+
static getPrakim(jd:jDate, israel:boolean) {
|
|
15
|
+
if (jd.getDayOfWeek() !== 6) {
|
|
16
|
+
return [];
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const jMonth = jd.Month,
|
|
20
|
+
jDay = jd.Day;
|
|
21
|
+
|
|
22
|
+
//Pirkei Avos is from after Pesach until Rosh Hashana
|
|
23
|
+
if ((jMonth === 1 && jDay > (israel ? 21 : 22)) ||
|
|
24
|
+
//All Shabbosim through Iyar, Sivan, Tamuz, Av - besides for the day/s of Shavuos and Tisha B'Av
|
|
25
|
+
((jMonth > 1 && jMonth < 6 &&
|
|
26
|
+
(!((jMonth === 3 && jDay === 6) || (!israel && jMonth === 3 && jDay === 7))) &&
|
|
27
|
+
(!(jMonth === 5 && jDay === 9))))) {
|
|
28
|
+
return [PirkeiAvos._get1stPerek(jd, israel)];
|
|
29
|
+
}
|
|
30
|
+
//Ellul can have multiple prakim
|
|
31
|
+
else if (jMonth === 6) {
|
|
32
|
+
return PirkeiAvos._ellul(jd, israel);
|
|
33
|
+
}
|
|
34
|
+
//No Pirkei Avos
|
|
35
|
+
else {
|
|
36
|
+
return [];
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
static _get1stPerek = function (jd:jDate, israel:boolean) {
|
|
40
|
+
const jYear = jd.Year,
|
|
41
|
+
jMonth = jd.Month,
|
|
42
|
+
jDay = jd.Day,
|
|
43
|
+
pes1 = new jDate(jYear, 1, 15),
|
|
44
|
+
//How many days after the first day of pesach was the first shabbos after pesach
|
|
45
|
+
shb1 = (israel ? 7 : 8) + (6 - pes1.getDayOfWeek()),
|
|
46
|
+
//What number shabbos after pesach is the current date
|
|
47
|
+
cShb = ((jMonth === 1 && jDay === (shb1 + 15)) ? 1 :
|
|
48
|
+
Utils.toInt((jd.Abs - (pes1.Abs + shb1)) / 7) + 1);
|
|
49
|
+
let prk = cShb % 6;
|
|
50
|
+
if (prk === 0) prk = 6;
|
|
51
|
+
//If the second day of Shavuos was on Shabbos, we missed a week.
|
|
52
|
+
//The second day of Pesach is always the same day as the first day of Shavuos.
|
|
53
|
+
//So if Pesach was on Thursday, Shavuos will be on Friday and Shabbos in Chu"l.
|
|
54
|
+
//Pesach can never come out on Friday, so in E. Yisroel Shavuos is never on Shabbos.
|
|
55
|
+
if ((!israel) && pes1.getDayOfWeek() === 4 && (jMonth > 3 || (jMonth === 3 && jDay > 6))) {
|
|
56
|
+
prk = prk === 1 ? 6 : prk - 1;
|
|
57
|
+
}
|
|
58
|
+
//If Tisha B'Av was on Shabbos, we missed a week. The first day of Pesach is always the same day of the week as Tisha b'av.
|
|
59
|
+
if (pes1.getDayOfWeek() === 6 && (jMonth > 5 || (jMonth === 5 && jDay > 9))) {
|
|
60
|
+
prk = prk === 1 ? 6 : prk - 1;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
return prk;
|
|
64
|
+
}
|
|
65
|
+
static _ellul = function (jd:jDate, israel:boolean) {
|
|
66
|
+
let prakim;
|
|
67
|
+
const jYear = jd.Year,
|
|
68
|
+
jDay = jd.Day,
|
|
69
|
+
//The fist day of Ellul.
|
|
70
|
+
//The year/month/day/absoluteDay constructor for JDate is used for efficiency.
|
|
71
|
+
day1 = new jDate(jYear, 6, 1, jd.Abs - jd.Day + 1),
|
|
72
|
+
day1DOW = day1.getDayOfWeek(),
|
|
73
|
+
shabbos1Day = day1DOW === 6 ? 1 : ((6 - (day1DOW + 6) % 6) + 1),
|
|
74
|
+
shabbos1Date = new jDate(jYear, 6, shabbos1Day, day1.Abs + shabbos1Day - 1),
|
|
75
|
+
//Which shabbos in Ellul are we working out now?
|
|
76
|
+
cShb = jDay === shabbos1Day ? 1 : Utils.toInt((jDay - shabbos1Day) / 7) + 1;
|
|
77
|
+
|
|
78
|
+
switch (PirkeiAvos._get1stPerek(shabbos1Date, israel)) {
|
|
79
|
+
case 1:
|
|
80
|
+
switch (cShb) {
|
|
81
|
+
case 1:
|
|
82
|
+
prakim = [1];
|
|
83
|
+
break;
|
|
84
|
+
case 2:
|
|
85
|
+
prakim = [2];
|
|
86
|
+
break;
|
|
87
|
+
case 3:
|
|
88
|
+
prakim = [3, 4];
|
|
89
|
+
break;
|
|
90
|
+
case 4:
|
|
91
|
+
prakim = [5, 6];
|
|
92
|
+
break;
|
|
93
|
+
}
|
|
94
|
+
break;
|
|
95
|
+
case 2:
|
|
96
|
+
switch (cShb) {
|
|
97
|
+
case 1:
|
|
98
|
+
prakim = [2];
|
|
99
|
+
break;
|
|
100
|
+
case 2:
|
|
101
|
+
prakim = [3];
|
|
102
|
+
break;
|
|
103
|
+
case 3:
|
|
104
|
+
prakim = [4];
|
|
105
|
+
break;
|
|
106
|
+
case 4:
|
|
107
|
+
prakim = [5, 6];
|
|
108
|
+
break;
|
|
109
|
+
}
|
|
110
|
+
break;
|
|
111
|
+
case 3:
|
|
112
|
+
switch (cShb) {
|
|
113
|
+
case 1:
|
|
114
|
+
prakim = [3];
|
|
115
|
+
break;
|
|
116
|
+
case 2:
|
|
117
|
+
prakim = [4];
|
|
118
|
+
break;
|
|
119
|
+
case 3:
|
|
120
|
+
prakim = [5];
|
|
121
|
+
break;
|
|
122
|
+
case 4:
|
|
123
|
+
prakim = [6];
|
|
124
|
+
break;
|
|
125
|
+
}
|
|
126
|
+
break;
|
|
127
|
+
case 4:
|
|
128
|
+
//This can only happen in Chutz La'aretz
|
|
129
|
+
switch (cShb) {
|
|
130
|
+
case 1:
|
|
131
|
+
prakim = [4, 5];
|
|
132
|
+
break;
|
|
133
|
+
case 2:
|
|
134
|
+
prakim = [6, 1];
|
|
135
|
+
break;
|
|
136
|
+
case 3:
|
|
137
|
+
prakim = [2, 3];
|
|
138
|
+
break;
|
|
139
|
+
case 4:
|
|
140
|
+
prakim = [4, 5, 6];
|
|
141
|
+
break;
|
|
142
|
+
}
|
|
143
|
+
break;
|
|
144
|
+
case 5:
|
|
145
|
+
switch (cShb) {
|
|
146
|
+
case 1:
|
|
147
|
+
prakim = [5, 6];
|
|
148
|
+
break;
|
|
149
|
+
case 2:
|
|
150
|
+
prakim = [1, 2];
|
|
151
|
+
break;
|
|
152
|
+
case 3:
|
|
153
|
+
prakim = [3, 4];
|
|
154
|
+
break;
|
|
155
|
+
case 4:
|
|
156
|
+
prakim = [5, 6];
|
|
157
|
+
break;
|
|
158
|
+
}
|
|
159
|
+
break;
|
|
160
|
+
case 6:
|
|
161
|
+
switch (cShb) {
|
|
162
|
+
case 1:
|
|
163
|
+
prakim = [6];
|
|
164
|
+
break;
|
|
165
|
+
case 2:
|
|
166
|
+
prakim = [1, 2];
|
|
167
|
+
break;
|
|
168
|
+
case 3:
|
|
169
|
+
prakim = [3, 4];
|
|
170
|
+
break;
|
|
171
|
+
case 4:
|
|
172
|
+
prakim = [5, 6];
|
|
173
|
+
break;
|
|
174
|
+
}
|
|
175
|
+
break;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
return prakim || [];
|
|
179
|
+
}
|
|
180
|
+
}
|