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