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,647 @@
|
|
|
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 GeneralUtils_1 = require("../GeneralUtils");
|
|
7
|
+
const Utils_js_1 = __importDefault(require("./Utils.js"));
|
|
8
|
+
const Sedra_js_1 = __importDefault(require("./Sedra.js"));
|
|
9
|
+
const PirkeiAvos_js_1 = __importDefault(require("./PirkeiAvos.js"));
|
|
10
|
+
const Zmanim_js_1 = __importDefault(require("./Zmanim.js"));
|
|
11
|
+
const Dafyomi_1 = __importDefault(require("./Dafyomi"));
|
|
12
|
+
/** Keeps a "memcache" of years that have had their elapsed days previously calculated. Format: { year:5776, elapsed:2109283 } */
|
|
13
|
+
const _yearCache = [],
|
|
14
|
+
//The absolute date for the zero hour of all javascript date objects - 1/1/1970 0:00:00 UTC
|
|
15
|
+
JS_START_DATE_ABS = 719163,
|
|
16
|
+
//The number of milliseconds in everyday
|
|
17
|
+
MS_PER_DAY = 8.64e7,
|
|
18
|
+
//The time zone offset (in minutes) for 1/1/1970 0:00:00 UTC at the current users time zone
|
|
19
|
+
JS_START_OFFSET = new Date(0).getTimezoneOffset();
|
|
20
|
+
/* ****************************************************************************************************************
|
|
21
|
+
* Many of the date conversion algorithms in the jDate class are based on the C code which was translated from Lisp
|
|
22
|
+
* in "Calendrical Calculations" by Nachum Dershowitz and Edward M. Reingold
|
|
23
|
+
* in Software---Practice & Experience, vol. 20, no. 9 (September, 1990), pp. 899--928.
|
|
24
|
+
* ****************************************************************************************************************/
|
|
25
|
+
/** Represents a single day in the Jewish Calendar. */
|
|
26
|
+
class jDate {
|
|
27
|
+
/**
|
|
28
|
+
* Create a new Jdate.
|
|
29
|
+
* new jDate() - Sets the Jewish Date for the current system date
|
|
30
|
+
* new jDate(javascriptDateObject) - Sets to the Jewish date on the given Gregorian date
|
|
31
|
+
* new jDate("January 1 2045") - Accepts any valid javascript Date string (uses javascripts new Date(string))
|
|
32
|
+
* new jDate(jewishYear, jewishMonth, jewishDay) - Months start at 1. Nissan is month 1 Adar Sheini is 13.
|
|
33
|
+
* new jDate(jewishYear, jewishMonth) - Same as above, with Day defaulting to 1
|
|
34
|
+
* new jDate( { year: 5776, month: 4, day: 5 } ) - same as new jDate(jewishYear, jewishMonth, jewishDay)
|
|
35
|
+
* new jDate( { year: 5776, month: 4 } ) - same as new jDate(jewishYear, jewishMonth)
|
|
36
|
+
* new jDate( { year: 5776 } ) - sets to the first day of Rosh Hashana on the given year
|
|
37
|
+
* new jDate(absoluteDate) - The number of days elapsed since the theoretical date Sunday, December 31, 0001 BCE
|
|
38
|
+
* new jDate(jewishYear, jewishMonth, jewishDay, absoluteDate) - Most efficient constructor. Needs no calculations at all.
|
|
39
|
+
* new jDate( { year: 5776, month: 4, day: 5, abs: 122548708 } ) - same as new jDate(jewishYear, jewishMonth, jewishDay, absoluteDate)
|
|
40
|
+
* @param {number | Date | string | {year:number,month:number,day:number} | [number, number, number, number]} [arg] The full Jewish year number OR Javascript Date object or string OR object or array of year, month, day
|
|
41
|
+
* @param {number} [month] The month of the Jewish date. Nissan is 1.
|
|
42
|
+
* @param {number} [day] The day of the month
|
|
43
|
+
* @param {number} [abs] The number of days that have passed since 12/31/0001
|
|
44
|
+
*/
|
|
45
|
+
constructor(arg, month, day, abs) {
|
|
46
|
+
//The day of the Jewish Month
|
|
47
|
+
this.Day = NaN;
|
|
48
|
+
//The Jewish Month. As in the Torah, Nissan is 1 and Adara Sheini is 13
|
|
49
|
+
this.Month = NaN;
|
|
50
|
+
//The number of years since the creation of the world
|
|
51
|
+
this.Year = NaN;
|
|
52
|
+
//The number of days since the theoretical date: Dec. 31, 0001 BCE
|
|
53
|
+
this.Abs = NaN;
|
|
54
|
+
if (arguments.length === 0) {
|
|
55
|
+
this.fromAbs(jDate.absSd(new Date()));
|
|
56
|
+
}
|
|
57
|
+
else if (arg instanceof Date) {
|
|
58
|
+
if ((0, GeneralUtils_1.isValidDate)(arg)) {
|
|
59
|
+
this.fromAbs(jDate.absSd(arg));
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
throw 'jDate constructor: The given Date is not a valid javascript Date';
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
else if (Array.isArray(arg) && arg.length >= 3) {
|
|
66
|
+
this.Day = arg[0];
|
|
67
|
+
this.Month = arg[1];
|
|
68
|
+
this.Year = arg[2];
|
|
69
|
+
this.Abs =
|
|
70
|
+
(arg.length > 3 && arg[3]) ||
|
|
71
|
+
jDate.absJd(this.Year, this.Month, this.Day);
|
|
72
|
+
}
|
|
73
|
+
else if (arg && (0, GeneralUtils_1.isString)(arg)) {
|
|
74
|
+
const d = new Date(arg);
|
|
75
|
+
if ((0, GeneralUtils_1.isValidDate)(d)) {
|
|
76
|
+
this.fromAbs(jDate.absSd(d));
|
|
77
|
+
}
|
|
78
|
+
else {
|
|
79
|
+
throw ('jDate constructor: The given string "' +
|
|
80
|
+
arg +
|
|
81
|
+
'" cannot be parsed into a Date');
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
else if ((0, GeneralUtils_1.isNumber)(arg)) {
|
|
85
|
+
//if no other arguments were supplied, we assume that the supplied number is an absolute date
|
|
86
|
+
if (arguments.length === 1) {
|
|
87
|
+
this.fromAbs(arg);
|
|
88
|
+
}
|
|
89
|
+
//If the year and any other number is supplied, we set the year and create the date using either the supplied values or the defaults
|
|
90
|
+
else {
|
|
91
|
+
this.Year = arg;
|
|
92
|
+
this.Month = month || 7; //If no month was supplied, we take Tishrei
|
|
93
|
+
this.Day = day || 1; //If no day was supplied, we take the first day of the month
|
|
94
|
+
//If the absolute date was also supplied (very efficient), we use the supplied value, otherwise we calculate it.
|
|
95
|
+
this.Abs = abs || jDate.absJd(this.Year, this.Month, this.Day);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
//If arg is an object that has a "year" property that contains a valid value...
|
|
99
|
+
else if (typeof arg === 'object') {
|
|
100
|
+
const argObj = arg;
|
|
101
|
+
if ((0, GeneralUtils_1.isNumber)(argObj.year)) {
|
|
102
|
+
this.Day = argObj.day || 1;
|
|
103
|
+
this.Month = argObj.month || 7;
|
|
104
|
+
this.Year = argObj.year;
|
|
105
|
+
this.Abs = argObj.abs || jDate.absJd(this.Year, this.Month, this.Day);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
/**Sets the current Jewish date from the given absolute date*/
|
|
110
|
+
fromAbs(absolute) {
|
|
111
|
+
const ymd = jDate.fromAbs(absolute);
|
|
112
|
+
this.Year = ymd.year;
|
|
113
|
+
this.Month = ymd.month;
|
|
114
|
+
this.Day = ymd.day;
|
|
115
|
+
this.Abs = absolute;
|
|
116
|
+
}
|
|
117
|
+
/**Returns a valid javascript Date object that represents the Gregorian date
|
|
118
|
+
that starts at midnight of the current Jewish date.*/
|
|
119
|
+
getDate() {
|
|
120
|
+
return jDate.sdFromAbs(this.Abs);
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* @returns {number} The day of the week for the current Jewish date. Sunday is 0 and Shabbos is 6.
|
|
124
|
+
*/
|
|
125
|
+
getDayOfWeek() {
|
|
126
|
+
return Math.abs(this.Abs % 7);
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* @returns {number} The day of the week for the current Jewish date. Sunday is 0 and Shabbos is 6
|
|
130
|
+
*/
|
|
131
|
+
get DayOfWeek() {
|
|
132
|
+
return this.getDayOfWeek();
|
|
133
|
+
}
|
|
134
|
+
/**Returns a new Jewish date represented by adding the given number of days to the current Jewish date.*/
|
|
135
|
+
addDays(days) {
|
|
136
|
+
return new jDate(this.Abs + days);
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Returns a new Jewish date represented by adding the given number of
|
|
140
|
+
* Jewish Months to the current Jewish date.
|
|
141
|
+
* If the current Day is 30 and the new month only has 29 days,
|
|
142
|
+
* the 29th day of the month is returned.
|
|
143
|
+
* @param {number} months
|
|
144
|
+
*/
|
|
145
|
+
addMonths(months) {
|
|
146
|
+
let year = this.Year, month = this.Month, day = this.Day, miy = jDate.monthsJYear(year);
|
|
147
|
+
for (let i = 0; i < Math.abs(months); i++) {
|
|
148
|
+
if (months > 0) {
|
|
149
|
+
month += 1;
|
|
150
|
+
if (month > miy) {
|
|
151
|
+
month = 1;
|
|
152
|
+
}
|
|
153
|
+
if (month === 7) {
|
|
154
|
+
year += 1;
|
|
155
|
+
miy = jDate.monthsJYear(year);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
else if (months < 0) {
|
|
159
|
+
month -= 1;
|
|
160
|
+
if (month === 0) {
|
|
161
|
+
month = miy;
|
|
162
|
+
}
|
|
163
|
+
if (month === 6) {
|
|
164
|
+
year -= 1;
|
|
165
|
+
miy = jDate.monthsJYear(year);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
if (day === 30 && jDate.daysJMonth(year, month) === 29) {
|
|
170
|
+
day = 29;
|
|
171
|
+
}
|
|
172
|
+
return new jDate(year, month, day);
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Returns a new Jewish date represented by adding the
|
|
176
|
+
* given number of Jewish Years to the current Jewish date.
|
|
177
|
+
* If the current Day is 30 and the new dates month only has 29 days,
|
|
178
|
+
* the 29th day of the month is returned.
|
|
179
|
+
* @param {number} years
|
|
180
|
+
*/
|
|
181
|
+
addYears(years) {
|
|
182
|
+
let year = this.Year + years, month = this.Month, day = this.Day;
|
|
183
|
+
if (month === 13 && !jDate.isJdLeapY(year)) {
|
|
184
|
+
month = 12;
|
|
185
|
+
}
|
|
186
|
+
else if (month === 8 && day === 30 && !jDate.isLongCheshvan(year)) {
|
|
187
|
+
month = 9;
|
|
188
|
+
day = 1;
|
|
189
|
+
}
|
|
190
|
+
else if (month === 9 && day === 30 && jDate.isShortKislev(year)) {
|
|
191
|
+
month = 10;
|
|
192
|
+
day = 1;
|
|
193
|
+
}
|
|
194
|
+
if (day === 30 && jDate.daysJMonth(year, month) === 29) {
|
|
195
|
+
day = 29;
|
|
196
|
+
}
|
|
197
|
+
return new jDate(year, month, day);
|
|
198
|
+
}
|
|
199
|
+
addSecularMonths(months) {
|
|
200
|
+
const secDate = new Date(this.getDate().valueOf());
|
|
201
|
+
secDate.setMonth(secDate.getMonth() + months);
|
|
202
|
+
return new jDate(secDate);
|
|
203
|
+
}
|
|
204
|
+
addSecularYears(years) {
|
|
205
|
+
const secDate = new Date(this.getDate().valueOf());
|
|
206
|
+
secDate.setFullYear(secDate.getFullYear() + years);
|
|
207
|
+
return new jDate(secDate);
|
|
208
|
+
}
|
|
209
|
+
/**Gets the number of days separating this Jewish Date and the given one.
|
|
210
|
+
*
|
|
211
|
+
* If the given date is before this one, the number will be negative.
|
|
212
|
+
* @param {jDate} jd
|
|
213
|
+
* */
|
|
214
|
+
diffDays(jd) {
|
|
215
|
+
return jd.Abs - this.Abs;
|
|
216
|
+
}
|
|
217
|
+
/**Gets the number of months separating this Jewish Date and the given one.
|
|
218
|
+
*
|
|
219
|
+
* Ignores the Day property:
|
|
220
|
+
*
|
|
221
|
+
* jDate.toJDate(5777, 6, 29).diffMonths(jDate.toJDate(5778, 7, 1)) will return 1 even though they are a day apart.
|
|
222
|
+
*
|
|
223
|
+
* If the given date is before this one, the number will be negative.
|
|
224
|
+
* @param {jDate} jd
|
|
225
|
+
* */
|
|
226
|
+
diffMonths(jd) {
|
|
227
|
+
let month = jd.Month, year = jd.Year, months = 0;
|
|
228
|
+
while (!(year === this.Year && month === this.Month)) {
|
|
229
|
+
if (this.Abs > jd.Abs) {
|
|
230
|
+
months--;
|
|
231
|
+
month++;
|
|
232
|
+
if (month > jDate.monthsJYear(year)) {
|
|
233
|
+
month = 1;
|
|
234
|
+
}
|
|
235
|
+
else if (month === 7) {
|
|
236
|
+
year++;
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
else {
|
|
240
|
+
months++;
|
|
241
|
+
month--;
|
|
242
|
+
if (month < 1) {
|
|
243
|
+
month = jDate.monthsJYear(year);
|
|
244
|
+
}
|
|
245
|
+
else if (month === 6) {
|
|
246
|
+
year--;
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
return months;
|
|
251
|
+
}
|
|
252
|
+
/**Gets the number of years separating this Jewish Date and the given one.
|
|
253
|
+
*
|
|
254
|
+
* Ignores the Day and Month properties:
|
|
255
|
+
*
|
|
256
|
+
* jDate.toJDate(5777, 6, 29).diffYears(jDate.toJDate(5778, 7, 1)) will return 1 even though they are a day apart.
|
|
257
|
+
*
|
|
258
|
+
* If the given date is before this one, the number will be negative.
|
|
259
|
+
* @param {jDate} jd*/
|
|
260
|
+
diffYears(jd) {
|
|
261
|
+
return jd.Year - this.Year;
|
|
262
|
+
}
|
|
263
|
+
/**
|
|
264
|
+
* Returns the current Jewish date in the format: Thursday, the 3rd of Kislev 5776.
|
|
265
|
+
* @param {boolean} hideDayOfWeek
|
|
266
|
+
* @param {boolean} dontCapitalize
|
|
267
|
+
*/
|
|
268
|
+
toString(hideDayOfWeek, dontCapitalize) {
|
|
269
|
+
return ((hideDayOfWeek
|
|
270
|
+
? dontCapitalize
|
|
271
|
+
? 't'
|
|
272
|
+
: 'T'
|
|
273
|
+
: Utils_js_1.default.dowEng[this.getDayOfWeek()] + ', t') +
|
|
274
|
+
'he ' +
|
|
275
|
+
Utils_js_1.default.toSuffixed(this.Day) +
|
|
276
|
+
' of ' +
|
|
277
|
+
this.monthName());
|
|
278
|
+
}
|
|
279
|
+
/**
|
|
280
|
+
* Returns the current Jewish date in the format "[Tuesday] Nissan 3, 5778"
|
|
281
|
+
* @param {boolean} showDow - show day of week?
|
|
282
|
+
*/
|
|
283
|
+
toShortstring(showDow) {
|
|
284
|
+
return ((showDow ? Utils_js_1.default.dowEng[this.getDayOfWeek()] + ' ' : '') +
|
|
285
|
+
Utils_js_1.default.jMonthsEng[this.Month] +
|
|
286
|
+
' ' +
|
|
287
|
+
this.Day.toString() +
|
|
288
|
+
', ' +
|
|
289
|
+
this.Year.toString());
|
|
290
|
+
}
|
|
291
|
+
/**
|
|
292
|
+
* Returns the current Jewish date in the format "Nissan 5778"
|
|
293
|
+
* @param {boolean} showYear - show the year number?
|
|
294
|
+
*/
|
|
295
|
+
monthName(showYear = true) {
|
|
296
|
+
return (Utils_js_1.default.jMonthsEng[this.Month] +
|
|
297
|
+
(showYear ? ' ' + this.Year.toString() : ''));
|
|
298
|
+
}
|
|
299
|
+
/**Returns the current Jewish date in the format: יום חמישי כ"א כסלו תשע"ו.*/
|
|
300
|
+
toStringHeb() {
|
|
301
|
+
return (Utils_js_1.default.dowHeb[this.getDayOfWeek()] +
|
|
302
|
+
' ' +
|
|
303
|
+
Utils_js_1.default.toJNum(this.Day) +
|
|
304
|
+
' ' +
|
|
305
|
+
Utils_js_1.default.jMonthsHeb[this.Month] +
|
|
306
|
+
' ' +
|
|
307
|
+
Utils_js_1.default.toJNum(this.Year % 1000));
|
|
308
|
+
}
|
|
309
|
+
/**Gets the day of the omer for the current Jewish date. If the date is not during sefira, 0 is returned.*/
|
|
310
|
+
getDayOfOmer() {
|
|
311
|
+
let dayOfOmer = 0;
|
|
312
|
+
if ((this.Month === 1 && this.Day > 15) ||
|
|
313
|
+
this.Month === 2 ||
|
|
314
|
+
(this.Month === 3 && this.Day < 6)) {
|
|
315
|
+
const first = new jDate(this.Year, 1, 15);
|
|
316
|
+
dayOfOmer = first.diffDays(this);
|
|
317
|
+
}
|
|
318
|
+
return dayOfOmer;
|
|
319
|
+
}
|
|
320
|
+
/**
|
|
321
|
+
* Returns true if this day is yomtov or chol hamoed
|
|
322
|
+
* @param {boolean} israel
|
|
323
|
+
*/
|
|
324
|
+
isYomTovOrCholHamoed(israel) {
|
|
325
|
+
return (this.isYomTov(israel) ||
|
|
326
|
+
(this.Month === 1 && [16, 17, 18, 19, 20].includes(this.Day)) ||
|
|
327
|
+
(this.Month === 7 && [16, 17, 18, 19, 20, 21].includes(this.Day)));
|
|
328
|
+
}
|
|
329
|
+
/**
|
|
330
|
+
* Returns true if this day is yomtov
|
|
331
|
+
* @param {boolean} israel
|
|
332
|
+
*/
|
|
333
|
+
isYomTov(israel) {
|
|
334
|
+
const day = this.Day;
|
|
335
|
+
switch (this.Month) {
|
|
336
|
+
case 1:
|
|
337
|
+
if (day === 15 || day === 21)
|
|
338
|
+
return true;
|
|
339
|
+
if (!israel && (day === 16 || day === 22))
|
|
340
|
+
return true;
|
|
341
|
+
break;
|
|
342
|
+
case 3:
|
|
343
|
+
if (day === 6 || (!israel && day === 7))
|
|
344
|
+
return true;
|
|
345
|
+
break;
|
|
346
|
+
case 7:
|
|
347
|
+
if ([1, 2, 10, 15, 22].includes(day)) {
|
|
348
|
+
return true;
|
|
349
|
+
}
|
|
350
|
+
if (!israel && (day === 16 || day === 23))
|
|
351
|
+
return true;
|
|
352
|
+
break;
|
|
353
|
+
}
|
|
354
|
+
return false;
|
|
355
|
+
}
|
|
356
|
+
/**Is today Erev Yom Tov? (includes Erev second days of Sukkos and Pesach) */
|
|
357
|
+
isErevYomTov() {
|
|
358
|
+
return ((this.Month === 1 && (0, GeneralUtils_1.has)(this.Day, 14, 20)) ||
|
|
359
|
+
(this.Month === 3 && this.Day === 5) ||
|
|
360
|
+
(this.Month === 6 && this.Day === 29) ||
|
|
361
|
+
(this.Month === 7 && (0, GeneralUtils_1.has)(this.Day, 9, 14, 21)));
|
|
362
|
+
}
|
|
363
|
+
/**Does the current Jewish date have candle lighting before sunset?*/
|
|
364
|
+
hasCandleLighting() {
|
|
365
|
+
const dow = this.getDayOfWeek();
|
|
366
|
+
if (dow === 5) {
|
|
367
|
+
return true;
|
|
368
|
+
}
|
|
369
|
+
else if (dow === 6) {
|
|
370
|
+
//there is no "candle lighting time" - even if yom tov is on Motzai Shabbos
|
|
371
|
+
return false;
|
|
372
|
+
}
|
|
373
|
+
return this.isErevYomTov();
|
|
374
|
+
}
|
|
375
|
+
/**Is the current Jewish Date the day before a yomtov that contains a Friday?*/
|
|
376
|
+
hasEiruvTavshilin(israel) {
|
|
377
|
+
let dow = this.getDayOfWeek();
|
|
378
|
+
return (
|
|
379
|
+
//Eiruv Tavshilin is only on Wednesday or Thursday
|
|
380
|
+
[3, 4].includes(dow) &&
|
|
381
|
+
//today is Erev Yomtov
|
|
382
|
+
this.isErevYomTov() &&
|
|
383
|
+
//Thursday OR Wednesday when in Chu"l or Erev Rosh Hashana anywhere
|
|
384
|
+
(dow === 4 || (dow === 3 && (!israel || this.Month === 6))) &&
|
|
385
|
+
//No Eiruv Tavshilin on Erev yom kippur
|
|
386
|
+
this.Day !== 9);
|
|
387
|
+
}
|
|
388
|
+
/**Gets the candle lighting time for the current Jewish date for the given Location object.*/
|
|
389
|
+
getCandleLighting(location, nullIfNoCandles) {
|
|
390
|
+
if (!location) {
|
|
391
|
+
throw 'To get sunrise and sunset, the location needs to be supplied';
|
|
392
|
+
}
|
|
393
|
+
if (this.hasCandleLighting()) {
|
|
394
|
+
return Zmanim_js_1.default.getCandleLighting(this, location);
|
|
395
|
+
}
|
|
396
|
+
else if (nullIfNoCandles) {
|
|
397
|
+
return null;
|
|
398
|
+
}
|
|
399
|
+
else {
|
|
400
|
+
throw 'No candle lighting on ' + this.toString();
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
/**Get the sedra of the week for the current Jewish date.*/
|
|
404
|
+
getSedra(israel) {
|
|
405
|
+
return new Sedra_js_1.default(this, israel);
|
|
406
|
+
}
|
|
407
|
+
/**Get the prakim of Pirkei Avos for the current Jewish date.*/
|
|
408
|
+
getPirkeiAvos(israel) {
|
|
409
|
+
return PirkeiAvos_js_1.default.getPrakim(this, israel);
|
|
410
|
+
}
|
|
411
|
+
/**Gets sunrise and sunset time for the current Jewish date at the given Location.
|
|
412
|
+
*
|
|
413
|
+
* Return format: {sunrise: {hour: 6, minute: 18}, sunset: {hour: 19, minute: 41}}*/
|
|
414
|
+
getSunriseSunset(location, ignoreElevation) {
|
|
415
|
+
if (!location) {
|
|
416
|
+
throw 'To get sunrise and sunset, the location needs to be supplied';
|
|
417
|
+
}
|
|
418
|
+
return Zmanim_js_1.default.getSunTimes(this, location, !ignoreElevation);
|
|
419
|
+
}
|
|
420
|
+
/**Gets Chatzos for both the day and the night for the current Jewish date at the given Location.
|
|
421
|
+
*
|
|
422
|
+
*Return format: {hour: 11, minute: 48}*/
|
|
423
|
+
getChatzos(location) {
|
|
424
|
+
if (!location) {
|
|
425
|
+
throw 'To get Chatzos, the location needs to be supplied';
|
|
426
|
+
}
|
|
427
|
+
return Zmanim_js_1.default.getChatzos(this, location);
|
|
428
|
+
}
|
|
429
|
+
/**Gets the length of a single Sha'a Zmanis in minutes for the current Jewish date at the given Location.*/
|
|
430
|
+
getShaaZmanis(location, offset) {
|
|
431
|
+
if (!location) {
|
|
432
|
+
throw 'To get the Shaa Zmanis, the location needs to be supplied';
|
|
433
|
+
}
|
|
434
|
+
return Zmanim_js_1.default.getShaaZmanis(this, location, offset);
|
|
435
|
+
}
|
|
436
|
+
/**Returns the daily daf in English. For example: Sukkah, Daf 3.*/
|
|
437
|
+
getDafYomi() {
|
|
438
|
+
return Dafyomi_1.default.toString(this) || '';
|
|
439
|
+
}
|
|
440
|
+
/**Gets the daily daf in Hebrew. For example: 'סוכה דף כ.*/
|
|
441
|
+
getDafyomiHeb() {
|
|
442
|
+
return Dafyomi_1.default.toStringHeb(this) || '';
|
|
443
|
+
}
|
|
444
|
+
/**
|
|
445
|
+
* Converts its argument/s to a Jewish Date.
|
|
446
|
+
* Samples of use:
|
|
447
|
+
* To get the current Jewish Date: jDate.toJDate(new Date()).
|
|
448
|
+
* To print out the current date in English: jDate.toJDate(new Date()).toString()
|
|
449
|
+
* To print out the current date in Hebrew: jDate.toJDate(new Date()).toStringHeb()
|
|
450
|
+
*
|
|
451
|
+
* Arguments to the jDate.toJDate function can be one of the following:
|
|
452
|
+
* jDate.toJDate() - Sets the Jewish Date for the current system date
|
|
453
|
+
* jDate.toJDate(Date) - Sets to the Jewish date on the given Javascript Date object
|
|
454
|
+
* jDate.toJDate("January 1 2045") - Accepts any valid Javascript Date string (uses string constructor of Date object)
|
|
455
|
+
* jDate.toJDate(jewishYear, jewishMonth, jewishDay) - Months start at 1. Nissan is month 1 Adara Sheini is 13.
|
|
456
|
+
* jDate.toJDate(jewishYear, jewishMonth) - Same as above, with Day defaulting to 1
|
|
457
|
+
* jDate.toJDate(jewishYear) - sets to the first day of Rosh Hashana on the given year
|
|
458
|
+
* jDate.toJDate( { year: 5776, month: 4, day: 5 } ) - Months start at 1. Nissan is month 1 Adara Sheini is 13.
|
|
459
|
+
* jDate.toJDate( { year: 5776, month: 4 } ) - Same as above, with Day defaulting to 1
|
|
460
|
+
* jDate.toJDate( { year: 5776 } ) - sets to the first day of Rosh Hashana on the given year
|
|
461
|
+
* jDate.toJDate(jewishYear, jewishMonth, jewishDay, absoluteDate) - Most efficient. Needs no calculations at all. The absoluteDate is the number of days elapsed since the theoretical date Sunday, December 31, 0001 BCE.
|
|
462
|
+
* jDate.toJDate( { year: 5776, month: 4, day: 5, abs: 122548708 } ) - same as jDate.toJDate(jewishYear, jewishMonth, jewishDay, absoluteDate)
|
|
463
|
+
****************************************************************************************************************/
|
|
464
|
+
static toJDate(arg, month, day, abs) {
|
|
465
|
+
if (arguments.length === 0) {
|
|
466
|
+
return new jDate();
|
|
467
|
+
}
|
|
468
|
+
// If just the year is set, then the date is set to Rosh Hashana of that year.
|
|
469
|
+
// In the above scenario, we can't just pass the args along, as the constructor will treat it as an absolute date.
|
|
470
|
+
//...and that folks, is actually the whole point of this function...
|
|
471
|
+
else if ((0, GeneralUtils_1.isNumber)(arg) && arguments.length === 1) {
|
|
472
|
+
return new jDate(arg, 7, 1);
|
|
473
|
+
}
|
|
474
|
+
else {
|
|
475
|
+
return new jDate(arg, month, day, abs);
|
|
476
|
+
}
|
|
477
|
+
}
|
|
478
|
+
static now() {
|
|
479
|
+
return new jDate();
|
|
480
|
+
}
|
|
481
|
+
/**Calculate the Jewish year, month and day for the given absolute date.*/
|
|
482
|
+
static fromAbs(absDay) {
|
|
483
|
+
//To save on calculations, start with a few years before date
|
|
484
|
+
let year = 3761 + Utils_js_1.default.toInt(absDay / (absDay > 0 ? 366 : 300)), month, day;
|
|
485
|
+
// Search forward for year from the approximation year.
|
|
486
|
+
while (absDay >= jDate.absJd(year + 1, 7, 1)) {
|
|
487
|
+
year++;
|
|
488
|
+
}
|
|
489
|
+
// Search forward for month from either Tishrei or Nissan.
|
|
490
|
+
month = absDay < jDate.absJd(year, 1, 1) ? 7 : 1;
|
|
491
|
+
while (absDay > jDate.absJd(year, month, jDate.daysJMonth(year, month))) {
|
|
492
|
+
month++;
|
|
493
|
+
}
|
|
494
|
+
// Calculate the day by subtraction.
|
|
495
|
+
day = absDay - jDate.absJd(year, month, 1) + 1;
|
|
496
|
+
return { year, month, day };
|
|
497
|
+
}
|
|
498
|
+
/**
|
|
499
|
+
* Gets the absolute date of the given javascript Date object.
|
|
500
|
+
* @param {Date} date
|
|
501
|
+
*/
|
|
502
|
+
static absSd(date) {
|
|
503
|
+
//Get the correct number of milliseconds since 1/1/1970 00:00:00 UTC until current system time
|
|
504
|
+
const ms = date.valueOf() - date.getTimezoneOffset() * 60000,
|
|
505
|
+
//The number of full days since 1/1/1970.
|
|
506
|
+
numFullDays = Math.floor(ms / MS_PER_DAY);
|
|
507
|
+
//Add that to the number of days from 1/1/0001 until 1/1/1970 00:00:00 UTC
|
|
508
|
+
return JS_START_DATE_ABS + numFullDays;
|
|
509
|
+
}
|
|
510
|
+
/**Calculate the absolute date for the given Jewish Date.*/
|
|
511
|
+
static absJd(year, month, day) {
|
|
512
|
+
//The number of total days.
|
|
513
|
+
let dayInYear = day; // day is the number of days so far this month.
|
|
514
|
+
if (month < 7) {
|
|
515
|
+
// Before Tishrei, so add days in prior months this year before and after Nissan.
|
|
516
|
+
let m = 7;
|
|
517
|
+
while (m <= jDate.monthsJYear(year)) {
|
|
518
|
+
dayInYear += jDate.daysJMonth(year, m);
|
|
519
|
+
m++;
|
|
520
|
+
}
|
|
521
|
+
m = 1;
|
|
522
|
+
while (m < month) {
|
|
523
|
+
dayInYear += jDate.daysJMonth(year, m);
|
|
524
|
+
m++;
|
|
525
|
+
}
|
|
526
|
+
}
|
|
527
|
+
else {
|
|
528
|
+
// Add days in prior months this year
|
|
529
|
+
let m = 7;
|
|
530
|
+
while (m < month) {
|
|
531
|
+
dayInYear += jDate.daysJMonth(year, m);
|
|
532
|
+
m++;
|
|
533
|
+
}
|
|
534
|
+
}
|
|
535
|
+
// Days elapsed before absolute date 1. - Days in prior years.
|
|
536
|
+
return dayInYear + (jDate.tDays(year) + -1373429);
|
|
537
|
+
}
|
|
538
|
+
/**
|
|
539
|
+
* Gets a javascript date from an absolute date
|
|
540
|
+
*/
|
|
541
|
+
static sdFromAbs(abs) {
|
|
542
|
+
//The "zero hour" for Javascript is 1/1/1970 0:00:00 UTC.
|
|
543
|
+
//If the time zone offset was more than 0, the current time zone was earlier than UTC at the time.
|
|
544
|
+
//As the "zero hour" is at midnight, so if the current time was earlier than that, than it was during the previous date.
|
|
545
|
+
//So we will need to add another day to get the correct date.
|
|
546
|
+
const offset = JS_START_OFFSET > 0 ? 1 : 0,
|
|
547
|
+
//Get the number of days from the "zero hour" until the given date.
|
|
548
|
+
//This is done by taking the given absolute date and removing the
|
|
549
|
+
//number of days from absolute date 0 until the js "zero hour" - keeping into
|
|
550
|
+
//account the previously calculated possible day offset.
|
|
551
|
+
daysSinceStart = abs - JS_START_DATE_ABS + offset;
|
|
552
|
+
//Create a javascript date from the number of milliseconds since the "zero hour"
|
|
553
|
+
return new Date(daysSinceStart * MS_PER_DAY);
|
|
554
|
+
}
|
|
555
|
+
/**number of days in the given Jewish Month. Nissan is 1 and Adar Sheini is 13.*/
|
|
556
|
+
static daysJMonth(year, month) {
|
|
557
|
+
switch (month) {
|
|
558
|
+
//Nissan, Sivan, Av, Tishrei and Shvat always have 30 days
|
|
559
|
+
case 1:
|
|
560
|
+
case 3:
|
|
561
|
+
case 5:
|
|
562
|
+
case 7:
|
|
563
|
+
case 11:
|
|
564
|
+
return 30;
|
|
565
|
+
//Iyyar, Tammuz, Ellul, Teves and Adar Sheini always have 29 days.
|
|
566
|
+
case 2:
|
|
567
|
+
case 4:
|
|
568
|
+
case 6:
|
|
569
|
+
case 10:
|
|
570
|
+
case 13:
|
|
571
|
+
return 29;
|
|
572
|
+
//Cheshvan sometimes has 29 days and sometimes 30 days.
|
|
573
|
+
case 8:
|
|
574
|
+
return jDate.isLongCheshvan(year) ? 30 : 29;
|
|
575
|
+
//Kislev sometimes has 29 days and sometimes 30 days.
|
|
576
|
+
case 9:
|
|
577
|
+
return jDate.isShortKislev(year) ? 29 : 30;
|
|
578
|
+
//Adar has 29 days unless it is Adar Rishon.
|
|
579
|
+
case 12:
|
|
580
|
+
return jDate.isJdLeapY(year) ? 30 : 29;
|
|
581
|
+
}
|
|
582
|
+
return 0;
|
|
583
|
+
}
|
|
584
|
+
/**Elapsed days since creation of the world until Rosh Hashana of the given year*/
|
|
585
|
+
static tDays(year) {
|
|
586
|
+
/*As this function is called many times, often on the same year for all types of calculations,
|
|
587
|
+
we save a list of years with their elapsed values.*/
|
|
588
|
+
const cached = _yearCache.find(y => !!y && y.year === year);
|
|
589
|
+
//If this year was already calculated and cached, then we return the cached value.
|
|
590
|
+
if (cached) {
|
|
591
|
+
return cached.elapsed;
|
|
592
|
+
}
|
|
593
|
+
const months = Utils_js_1.default.toInt(235 * Utils_js_1.default.toInt((year - 1) / 19) + // Leap months this cycle
|
|
594
|
+
12 * ((year - 1) % 19) + // Regular months in this cycle.
|
|
595
|
+
(7 * ((year - 1) % 19) + 1) / 19), // Months in complete cycles so far.
|
|
596
|
+
parts = 204 + 793 * (months % 1080), hours = 5 +
|
|
597
|
+
12 * months +
|
|
598
|
+
793 * Utils_js_1.default.toInt(months / 1080) +
|
|
599
|
+
Utils_js_1.default.toInt(parts / 1080), conjDay = Utils_js_1.default.toInt(1 + 29 * months + hours / 24), conjParts = 1080 * (hours % 24) + (parts % 1080);
|
|
600
|
+
let altDay;
|
|
601
|
+
/* at the end of a leap year - 15 hours, 589 parts or later... -
|
|
602
|
+
... or is on a Monday at... - ...of a common year, -
|
|
603
|
+
at 9 hours, 204 parts or later... - ...or is on a Tuesday... -
|
|
604
|
+
If new moon is at or after midday,*/
|
|
605
|
+
if (conjParts >= 19440 ||
|
|
606
|
+
(conjDay % 7 === 2 &&
|
|
607
|
+
conjParts >= 9924 &&
|
|
608
|
+
!jDate.isJdLeapY(year)) ||
|
|
609
|
+
(conjDay % 7 === 1 &&
|
|
610
|
+
conjParts >= 16789 &&
|
|
611
|
+
jDate.isJdLeapY(year - 1))) {
|
|
612
|
+
// Then postpone Rosh HaShanah one day
|
|
613
|
+
altDay = conjDay + 1;
|
|
614
|
+
}
|
|
615
|
+
else {
|
|
616
|
+
altDay = conjDay;
|
|
617
|
+
}
|
|
618
|
+
// A day is added if Rosh HaShanah would occur on Sunday, Friday or Wednesday,
|
|
619
|
+
if ((0, GeneralUtils_1.has)(altDay % 7, 0, 3, 5)) {
|
|
620
|
+
altDay += 1;
|
|
621
|
+
}
|
|
622
|
+
//Add this year to the cache to save on calculations later on
|
|
623
|
+
_yearCache.push({ year: year, elapsed: altDay });
|
|
624
|
+
return altDay;
|
|
625
|
+
}
|
|
626
|
+
/**number of days in the given Jewish Year.*/
|
|
627
|
+
static daysJYear(year) {
|
|
628
|
+
return jDate.tDays(year + 1) - jDate.tDays(year);
|
|
629
|
+
}
|
|
630
|
+
/**Does Cheshvan for the given Jewish Year have 30 days?*/
|
|
631
|
+
static isLongCheshvan(year) {
|
|
632
|
+
return jDate.daysJYear(year) % 10 === 5;
|
|
633
|
+
}
|
|
634
|
+
/**Does Kislev for the given Jewish Year have 29 days?*/
|
|
635
|
+
static isShortKislev(year) {
|
|
636
|
+
return jDate.daysJYear(year) % 10 === 3;
|
|
637
|
+
}
|
|
638
|
+
/**Does the given Jewish Year have 13 months?*/
|
|
639
|
+
static isJdLeapY(year) {
|
|
640
|
+
return (7 * year + 1) % 19 < 7;
|
|
641
|
+
}
|
|
642
|
+
/**number of months in Jewish Year.*/
|
|
643
|
+
static monthsJYear(year) {
|
|
644
|
+
return jDate.isJdLeapY(year) ? 13 : 12;
|
|
645
|
+
}
|
|
646
|
+
}
|
|
647
|
+
exports.default = jDate;
|