jcal-zmanim 1.0.50 → 1.1.0

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 (83) hide show
  1. package/LICENSE +674 -674
  2. package/{build → dist}/JCal/Dafyomi.d.ts +4 -3
  3. package/dist/JCal/Dafyomi.d.ts.map +1 -0
  4. package/{build → dist}/JCal/Dafyomi.js +9 -8
  5. package/dist/JCal/Dafyomi.js.map +1 -0
  6. package/{build → dist}/JCal/Location.d.ts +4 -4
  7. package/dist/JCal/Location.d.ts.map +1 -0
  8. package/{build → dist}/JCal/Location.js +10 -12
  9. package/dist/JCal/Location.js.map +1 -0
  10. package/{build → dist}/JCal/Molad.d.ts +1 -2
  11. package/dist/JCal/Molad.d.ts.map +1 -0
  12. package/{build → dist}/JCal/Molad.js +16 -19
  13. package/dist/JCal/Molad.js.map +1 -0
  14. package/{build → dist}/JCal/PirkeiAvos.d.ts +1 -0
  15. package/dist/JCal/PirkeiAvos.d.ts.map +1 -0
  16. package/{build → dist}/JCal/PirkeiAvos.js +4 -3
  17. package/dist/JCal/PirkeiAvos.js.map +1 -0
  18. package/{build → dist}/JCal/Sedra.d.ts +2 -1
  19. package/dist/JCal/Sedra.d.ts.map +1 -0
  20. package/{build → dist}/JCal/Sedra.js +2 -1
  21. package/dist/JCal/Sedra.js.map +1 -0
  22. package/{build → dist}/JCal/Zmanim.d.ts +1 -0
  23. package/dist/JCal/Zmanim.d.ts.map +1 -0
  24. package/{build → dist}/JCal/Zmanim.js +16 -16
  25. package/dist/JCal/Zmanim.js.map +1 -0
  26. package/{build/AppUtils.d.ts → dist/JCal/ZmanimUtils.d.ts} +10 -47
  27. package/dist/JCal/ZmanimUtils.d.ts.map +1 -0
  28. package/{build/AppUtils.js → dist/JCal/ZmanimUtils.js} +56 -122
  29. package/dist/JCal/ZmanimUtils.js.map +1 -0
  30. package/{build → dist}/JCal/jDate.d.ts +4 -3
  31. package/dist/JCal/jDate.d.ts.map +1 -0
  32. package/{build → dist}/JCal/jDate.js +24 -24
  33. package/dist/JCal/jDate.js.map +1 -0
  34. package/dist/Locations.d.ts +31 -0
  35. package/dist/Locations.d.ts.map +1 -0
  36. package/dist/Locations.js +119 -0
  37. package/dist/Locations.js.map +1 -0
  38. package/dist/Notifications.d.ts +18 -0
  39. package/dist/Notifications.d.ts.map +1 -0
  40. package/{build → dist}/Notifications.js +111 -130
  41. package/dist/Notifications.js.map +1 -0
  42. package/dist/README.md +521 -0
  43. package/{build/JCal → dist}/Utils.d.ts +72 -10
  44. package/dist/Utils.d.ts.map +1 -0
  45. package/{build/JCal → dist}/Utils.js +176 -70
  46. package/dist/Utils.js.map +1 -0
  47. package/{build → dist}/ZmanTypes.d.ts +11 -4
  48. package/dist/ZmanTypes.d.ts.map +1 -0
  49. package/{build → dist}/ZmanTypes.js +12 -5
  50. package/dist/ZmanTypes.js.map +1 -0
  51. package/dist/index.d.ts +2 -0
  52. package/dist/index.d.ts.map +1 -0
  53. package/dist/index.js +43 -0
  54. package/dist/index.js.map +1 -0
  55. package/dist/locations.json +1 -0
  56. package/package.json +43 -33
  57. package/README.md +0 -2
  58. package/build/GeneralUtils.d.ts +0 -43
  59. package/build/GeneralUtils.js +0 -93
  60. package/build/Locations.d.ts +0 -7
  61. package/build/Locations.js +0 -1308
  62. package/build/Notifications.d.ts +0 -14
  63. package/build/Settings.d.ts +0 -25
  64. package/build/Settings.js +0 -75
  65. package/build/index.d.ts +0 -1
  66. package/build/index.js +0 -59
  67. package/src/AppUtils.ts +0 -500
  68. package/src/GeneralUtils.ts +0 -84
  69. package/src/JCal/Dafyomi.ts +0 -139
  70. package/src/JCal/Location.ts +0 -100
  71. package/src/JCal/Molad.ts +0 -105
  72. package/src/JCal/PirkeiAvos.ts +0 -180
  73. package/src/JCal/Sedra.ts +0 -215
  74. package/src/JCal/Utils.ts +0 -732
  75. package/src/JCal/Zmanim.ts +0 -270
  76. package/src/JCal/jDate.ts +0 -714
  77. package/src/Locations.ts +0 -1303
  78. package/src/Notifications.ts +0 -1243
  79. package/src/Settings.ts +0 -103
  80. package/src/ZmanTypes.ts +0 -184
  81. package/src/index.ts +0 -31
  82. package/src/jcal-zmanim.d.ts +0 -4
  83. package/tsconfig.json +0 -109
@@ -1,84 +0,0 @@
1
- const __DEV__ = process.env.NODE_ENV === 'development';
2
-
3
- /** Returns true if "thing" is either a string primitive or String object.*/
4
- export function isString(thing: unknown) {
5
- return typeof thing === 'string' || thing instanceof String;
6
- }
7
- /** Returns true if "thing" is either a number primitive or a Number object.*/
8
- export function isNumber(thing: unknown) {
9
- return typeof thing === 'number' || thing instanceof Number;
10
- }
11
- /** Returns true if "thing" is a Date object containing a valid date.*/
12
- export function isValidDate(thing: unknown) {
13
- return thing instanceof Date && !isNaN(thing.valueOf());
14
- }
15
- /** Returns whether or not the given, array, string, or argument list contains the given item or substring.
16
- *
17
- * This function is awfully similar to Array.includes, but has the added plus of accepting any number or type of arguments.*/
18
- export function has(o: unknown, ...arr: unknown[]) {
19
- if (arr.length === 1 && (Array.isArray(arr[0]) || isString(arr[0]))) {
20
- return (arr[0] as unknown[]).includes(o);
21
- } else {
22
- return arr.includes(o);
23
- }
24
- }
25
- /** Returns the first value unless it is undefined, null or NaN.
26
- *
27
- * This is very useful for boolean, string and integer parameters
28
- * where we want to keep false, "" and 0 if they were supplied.
29
- *
30
- * Similar purpose to default parameters with the difference being that this function will return
31
- * the second value if the first is NaN or null, while default params will give give you the NaN or the null.
32
- */
33
- export function setDefault(paramValue: unknown, defValue: unknown) {
34
- if (
35
- typeof paramValue === 'undefined' ||
36
- paramValue === null ||
37
- isNaN(paramValue as number)
38
- ) {
39
- return defValue;
40
- } else {
41
- return paramValue;
42
- }
43
- }
44
- /**
45
- * Returns an array containing a range of integers.
46
- * @param {Number} [start] The number to start at. The start number is included in the results.
47
- * If only one argument is supplied, start will be set to 1.
48
- * @param {Number} end The top end of the range.
49
- * Unlike Pythons range function, The end number is included in the results.
50
- * @returns {[Number]}
51
- */
52
- export function range(start: number, end?: number) {
53
- const startNumber = typeof (end) === 'undefined' ? 1 : start,
54
- endNumber = typeof (end) === 'undefined' ? start : end;
55
-
56
- return Array.from({ length: endNumber - startNumber + 1 }, (v, i) => startNumber + i);
57
- }
58
- /**
59
- * Log message to console
60
- * @param {string} txt
61
- */
62
- export function log(txt: string, ...optionalItems: any[]) {
63
- if (__DEV__) {
64
- console.log(txt, ...optionalItems);
65
- }
66
- }
67
- /**
68
- * Warn message to console
69
- * @param {string} txt
70
- */
71
- export function warn(txt: string, ...optionalItems: any[]) {
72
- if (__DEV__) {
73
- console.warn(txt, ...optionalItems);
74
- }
75
- }
76
- /**
77
- * Error message to console
78
- * @param {*} txt
79
- */
80
- export function error(txt: string, ...optionalItems: any[]) {
81
- if (__DEV__) {
82
- console.error(txt, ...optionalItems);
83
- }
84
- }
@@ -1,139 +0,0 @@
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
- }
@@ -1,100 +0,0 @@
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
- }
package/src/JCal/Molad.ts DELETED
@@ -1,105 +0,0 @@
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
- }
@@ -1,180 +0,0 @@
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
- }