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
package/src/AppUtils.ts
ADDED
|
@@ -0,0 +1,500 @@
|
|
|
1
|
+
import Utils from './JCal/Utils';
|
|
2
|
+
import Zmanim from './JCal/Zmanim';
|
|
3
|
+
import Location from './JCal/Location';
|
|
4
|
+
import Settings from './Settings';
|
|
5
|
+
import jDate from './JCal/jDate';
|
|
6
|
+
import { ZmanTypes, ZmanTypeIds, getZmanType } from './ZmanTypes';
|
|
7
|
+
import { SunTimes, Time, ZmanToShow } from './jcal-zmanim';
|
|
8
|
+
|
|
9
|
+
type ZmanTime = {
|
|
10
|
+
date: Date,
|
|
11
|
+
location: Location,
|
|
12
|
+
sunrise: Time | undefined,
|
|
13
|
+
sunset: Time | undefined,
|
|
14
|
+
suntimesMishor: SunTimes | undefined,
|
|
15
|
+
sunriseMishor: Time | undefined,
|
|
16
|
+
sunsetMishor: Time | undefined,
|
|
17
|
+
mishorNeg90: Time | undefined,
|
|
18
|
+
chatzos: Time | undefined,
|
|
19
|
+
shaaZmanis: number | undefined,
|
|
20
|
+
shaaZmanisMga: number | undefined,
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export const DaysOfWeek = Object.freeze({
|
|
24
|
+
SUNDAY: 0,
|
|
25
|
+
MONDAY: 1,
|
|
26
|
+
TUESDAY: 2,
|
|
27
|
+
WEDNESDAY: 3,
|
|
28
|
+
THURSDAY: 4,
|
|
29
|
+
FRIDAY: 5,
|
|
30
|
+
SHABBOS: 6,
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
export const WhichDaysFlags = Object.freeze({
|
|
34
|
+
SUNDAY: 1,
|
|
35
|
+
MONDAY: 2,
|
|
36
|
+
TUESDAY: 4,
|
|
37
|
+
WEDNESDAY: 8,
|
|
38
|
+
THURSDAY: 16,
|
|
39
|
+
FRIDAY: 32,
|
|
40
|
+
SHABBOS: 64,
|
|
41
|
+
YOMTOV: 128,
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
export default class AppUtils {
|
|
45
|
+
static zmanTimesCache: ZmanTime[] = [];
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Returns the date corrected time of the given zmanim on the given date at the given location
|
|
49
|
+
* If the zman is after or within 30 minutes of the given time, this days zman is returned, othwise tomorrows zman is returned.
|
|
50
|
+
* @param {Date} sdate
|
|
51
|
+
* @param {jDate} jdate
|
|
52
|
+
* @param {Time} time
|
|
53
|
+
* @param {Settings} settings
|
|
54
|
+
* @param {Time} sunset
|
|
55
|
+
* @returns {[{zmanType:ZmanToShow,time:Time, isTomorrow:boolean}]}
|
|
56
|
+
*/
|
|
57
|
+
static getCorrectZmanTimes(sdate: Date, jdate: jDate, time: Time, settings: Settings, sunset: Time) {
|
|
58
|
+
const correctedTimes = [],
|
|
59
|
+
zmanTypes = settings.zmanimToShow,
|
|
60
|
+
location = settings.location,
|
|
61
|
+
tomorrowJd = jdate.addDays(1),
|
|
62
|
+
tomorrowSd = Utils.addDaysToSdate(sdate, 1),
|
|
63
|
+
/* Candle lighting and chometz times are not shown after sunset.
|
|
64
|
+
This solves the issue of Candle lighting showing as having "passed 20 minutes ago"
|
|
65
|
+
Thursday evening after sunset - which shows as hasCandleLighting = true
|
|
66
|
+
as it is already Friday... */
|
|
67
|
+
zmanTimes = AppUtils.getZmanTimes(
|
|
68
|
+
zmanTypes.filter(
|
|
69
|
+
(zt) => ![21, 22, 23].includes(zt.id) || Utils.isTimeAfter(time, sunset),
|
|
70
|
+
),
|
|
71
|
+
sdate,
|
|
72
|
+
jdate,
|
|
73
|
+
location,
|
|
74
|
+
),
|
|
75
|
+
tomorrowTimes = AppUtils.getZmanTimes(
|
|
76
|
+
//Candle lighting tomorrow is never shown...
|
|
77
|
+
zmanTypes.filter((zt) => zt.id !== 21),
|
|
78
|
+
tomorrowSd,
|
|
79
|
+
tomorrowJd,
|
|
80
|
+
location,
|
|
81
|
+
);
|
|
82
|
+
|
|
83
|
+
for (let zt of zmanTimes) {
|
|
84
|
+
let oTime = zt.time as Time,
|
|
85
|
+
isTomorrow = false,
|
|
86
|
+
diff = Utils.timeDiff(time, oTime, true);
|
|
87
|
+
if (
|
|
88
|
+
diff.sign < 1 &&
|
|
89
|
+
Utils.totalMinutes(diff) >= settings.minToShowPassedZman
|
|
90
|
+
) {
|
|
91
|
+
const tom = tomorrowTimes.find(
|
|
92
|
+
(t) => t.zmanType === zt.zmanType,
|
|
93
|
+
);
|
|
94
|
+
if (tom && tom.time) {
|
|
95
|
+
oTime = tom.time;
|
|
96
|
+
isTomorrow = true;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
correctedTimes.push({
|
|
100
|
+
zmanType: zt.zmanType,
|
|
101
|
+
time: oTime,
|
|
102
|
+
isTomorrow,
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
return correctedTimes.sort(
|
|
106
|
+
(a, b) =>
|
|
107
|
+
(a.isTomorrow ? 1 : -1) - (b.isTomorrow ? 1 : -1) ||
|
|
108
|
+
Utils.totalSeconds(a.time) - Utils.totalSeconds(b.time),
|
|
109
|
+
);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Gets the zmanim for all the types in the given list.
|
|
114
|
+
* @param {[ZmanToShow]} zmanTypes An array of ZmanTypes to get the zman for.
|
|
115
|
+
* @param {Date} date The secular date to get the zmanim for
|
|
116
|
+
* @param {jDate} jdate The jewish date to get the zmanim for
|
|
117
|
+
* @param {Location} location The location for which to get the zmanim
|
|
118
|
+
* @returns{[{zmanType:{id:number,offset:?number,desc:string,eng:string,heb:string },time:Time}]}
|
|
119
|
+
*/
|
|
120
|
+
static getZmanTimes(zmanTypes: ZmanToShow[], date: Date, jdate: jDate, location: Location): { zmanType: ZmanToShow, time?: Time }[] {
|
|
121
|
+
const mem = AppUtils.zmanTimesCache.find(
|
|
122
|
+
(z) =>
|
|
123
|
+
Utils.isSameSdate(z.date, date) &&
|
|
124
|
+
z.location.Name === location.Name,
|
|
125
|
+
),
|
|
126
|
+
zmanTimes: { zmanType: ZmanToShow, time?: Time }[] = [],
|
|
127
|
+
whichDay = AppUtils.getWhichDays(date, jdate, location);
|
|
128
|
+
let sunrise: Time | undefined,
|
|
129
|
+
sunset: Time | undefined,
|
|
130
|
+
suntimesMishor: SunTimes | undefined,
|
|
131
|
+
sunriseMishor: Time | undefined,
|
|
132
|
+
sunsetMishor: Time | undefined,
|
|
133
|
+
mishorNeg90: Time | undefined,
|
|
134
|
+
chatzos: Time | undefined,
|
|
135
|
+
shaaZmanis: number | undefined,
|
|
136
|
+
shaaZmanisMga: number | undefined;
|
|
137
|
+
if (mem) {
|
|
138
|
+
sunrise = mem.sunrise;
|
|
139
|
+
sunset = mem.sunset;
|
|
140
|
+
suntimesMishor = mem.suntimesMishor;
|
|
141
|
+
sunriseMishor = mem.sunriseMishor;
|
|
142
|
+
sunsetMishor = mem.sunsetMishor;
|
|
143
|
+
mishorNeg90 = mem.mishorNeg90;
|
|
144
|
+
chatzos = mem.chatzos;
|
|
145
|
+
shaaZmanis = mem.shaaZmanis;
|
|
146
|
+
shaaZmanisMga = mem.shaaZmanisMga;
|
|
147
|
+
} else {
|
|
148
|
+
const suntimes = Zmanim.getSunTimes(date, location, true);
|
|
149
|
+
sunrise = suntimes.sunrise;
|
|
150
|
+
sunset = suntimes.sunset;
|
|
151
|
+
suntimesMishor = Zmanim.getSunTimes(date, location, false);
|
|
152
|
+
sunriseMishor = suntimesMishor.sunrise;
|
|
153
|
+
sunsetMishor = suntimesMishor.sunset;
|
|
154
|
+
mishorNeg90 = Utils.addMinutes(sunriseMishor, -90);
|
|
155
|
+
chatzos =
|
|
156
|
+
sunriseMishor &&
|
|
157
|
+
sunsetMishor &&
|
|
158
|
+
Zmanim.getChatzosFromSuntimes(suntimesMishor);
|
|
159
|
+
shaaZmanis =
|
|
160
|
+
sunriseMishor &&
|
|
161
|
+
sunsetMishor &&
|
|
162
|
+
Zmanim.getShaaZmanisFromSunTimes(suntimesMishor);
|
|
163
|
+
shaaZmanisMga =
|
|
164
|
+
sunriseMishor &&
|
|
165
|
+
sunsetMishor &&
|
|
166
|
+
Zmanim.getShaaZmanisMga(suntimesMishor, true);
|
|
167
|
+
|
|
168
|
+
AppUtils.zmanTimesCache.push({
|
|
169
|
+
date,
|
|
170
|
+
location,
|
|
171
|
+
sunrise,
|
|
172
|
+
sunset,
|
|
173
|
+
suntimesMishor,
|
|
174
|
+
sunriseMishor,
|
|
175
|
+
sunsetMishor,
|
|
176
|
+
mishorNeg90,
|
|
177
|
+
chatzos,
|
|
178
|
+
shaaZmanis,
|
|
179
|
+
shaaZmanisMga,
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
for (let zmanType of zmanTypes) {
|
|
183
|
+
const offset = zmanType.offset &&
|
|
184
|
+
(!zmanType.whichDaysFlags || zmanType.whichDaysFlags & whichDay)
|
|
185
|
+
? zmanType.offset
|
|
186
|
+
: 0;
|
|
187
|
+
switch (zmanType.id) {
|
|
188
|
+
case ZmanTypeIds.ChatzosLayla: // chatzosNight
|
|
189
|
+
zmanTimes.push({
|
|
190
|
+
zmanType,
|
|
191
|
+
time: Utils.addMinutes(chatzos, 720 + offset),
|
|
192
|
+
});
|
|
193
|
+
break;
|
|
194
|
+
case ZmanTypeIds.Alos90: // alos90
|
|
195
|
+
zmanTimes.push({
|
|
196
|
+
zmanType,
|
|
197
|
+
time: offset
|
|
198
|
+
? Utils.addMinutes(mishorNeg90, offset)
|
|
199
|
+
: mishorNeg90,
|
|
200
|
+
});
|
|
201
|
+
break;
|
|
202
|
+
case ZmanTypeIds.Alos72: // alos72
|
|
203
|
+
zmanTimes.push({
|
|
204
|
+
zmanType,
|
|
205
|
+
time: Utils.addMinutes(sunriseMishor, -72 + offset),
|
|
206
|
+
});
|
|
207
|
+
break;
|
|
208
|
+
case ZmanTypeIds.TalisTefillin: //talisTefillin
|
|
209
|
+
zmanTimes.push({
|
|
210
|
+
zmanType,
|
|
211
|
+
time: Utils.addMinutes(sunriseMishor, -36 + offset),
|
|
212
|
+
});
|
|
213
|
+
break;
|
|
214
|
+
case ZmanTypeIds.NetzAtElevation: //netzElevation
|
|
215
|
+
zmanTimes.push({
|
|
216
|
+
zmanType,
|
|
217
|
+
time: offset
|
|
218
|
+
? Utils.addMinutes(sunrise, offset)
|
|
219
|
+
: sunrise,
|
|
220
|
+
});
|
|
221
|
+
break;
|
|
222
|
+
case ZmanTypeIds.NetzMishor: // netzMishor:
|
|
223
|
+
zmanTimes.push({
|
|
224
|
+
zmanType,
|
|
225
|
+
time: offset
|
|
226
|
+
? Utils.addMinutes(sunriseMishor, offset)
|
|
227
|
+
: sunriseMishor,
|
|
228
|
+
});
|
|
229
|
+
break;
|
|
230
|
+
case ZmanTypeIds.szksMga: //szksMga
|
|
231
|
+
if (shaaZmanisMga)
|
|
232
|
+
zmanTimes.push({
|
|
233
|
+
zmanType,
|
|
234
|
+
time: Utils.addMinutes(
|
|
235
|
+
mishorNeg90,
|
|
236
|
+
Math.floor(shaaZmanisMga * 3) + offset,
|
|
237
|
+
),
|
|
238
|
+
});
|
|
239
|
+
break;
|
|
240
|
+
case ZmanTypeIds.szksGra: //szksGra
|
|
241
|
+
if (shaaZmanis)
|
|
242
|
+
zmanTimes.push({
|
|
243
|
+
zmanType,
|
|
244
|
+
time: Utils.addMinutes(
|
|
245
|
+
sunriseMishor,
|
|
246
|
+
Math.floor(shaaZmanis * 3) + offset,
|
|
247
|
+
),
|
|
248
|
+
});
|
|
249
|
+
break;
|
|
250
|
+
case ZmanTypeIds.sztMga: // sztMga
|
|
251
|
+
if (shaaZmanisMga)
|
|
252
|
+
zmanTimes.push({
|
|
253
|
+
zmanType,
|
|
254
|
+
time: Utils.addMinutes(
|
|
255
|
+
mishorNeg90,
|
|
256
|
+
Math.floor(shaaZmanisMga * 4) + offset,
|
|
257
|
+
),
|
|
258
|
+
});
|
|
259
|
+
break;
|
|
260
|
+
case ZmanTypeIds.sztGra: //sztGra
|
|
261
|
+
if (shaaZmanis)
|
|
262
|
+
zmanTimes.push({
|
|
263
|
+
zmanType,
|
|
264
|
+
time: Utils.addMinutes(
|
|
265
|
+
sunriseMishor,
|
|
266
|
+
Math.floor(shaaZmanis * 4) + offset,
|
|
267
|
+
),
|
|
268
|
+
});
|
|
269
|
+
break;
|
|
270
|
+
case ZmanTypeIds.chatzosDay: //chatzos
|
|
271
|
+
zmanTimes.push({
|
|
272
|
+
zmanType,
|
|
273
|
+
time: offset
|
|
274
|
+
? Utils.addMinutes(chatzos, offset)
|
|
275
|
+
: chatzos,
|
|
276
|
+
});
|
|
277
|
+
break;
|
|
278
|
+
case ZmanTypeIds.minGed: //minGed
|
|
279
|
+
if (shaaZmanis)
|
|
280
|
+
zmanTimes.push({
|
|
281
|
+
zmanType,
|
|
282
|
+
time: Utils.addMinutes(
|
|
283
|
+
chatzos,
|
|
284
|
+
shaaZmanis * 0.5 + offset,
|
|
285
|
+
),
|
|
286
|
+
});
|
|
287
|
+
break;
|
|
288
|
+
case ZmanTypeIds.minKet: //minKet
|
|
289
|
+
if (shaaZmanis)
|
|
290
|
+
zmanTimes.push({
|
|
291
|
+
zmanType,
|
|
292
|
+
time: Utils.addMinutes(
|
|
293
|
+
sunriseMishor,
|
|
294
|
+
shaaZmanis * 9.5 + offset,
|
|
295
|
+
),
|
|
296
|
+
});
|
|
297
|
+
break;
|
|
298
|
+
case ZmanTypeIds.plag: //plag
|
|
299
|
+
if (shaaZmanis)
|
|
300
|
+
zmanTimes.push({
|
|
301
|
+
zmanType,
|
|
302
|
+
time: Utils.addMinutes(
|
|
303
|
+
sunriseMishor,
|
|
304
|
+
shaaZmanis * 10.75 + offset,
|
|
305
|
+
),
|
|
306
|
+
});
|
|
307
|
+
break;
|
|
308
|
+
case ZmanTypeIds.shkiaAtSeaLevel: //shkiaMishor
|
|
309
|
+
zmanTimes.push({
|
|
310
|
+
zmanType,
|
|
311
|
+
time: offset
|
|
312
|
+
? Utils.addMinutes(sunsetMishor, offset)
|
|
313
|
+
: sunsetMishor,
|
|
314
|
+
});
|
|
315
|
+
break;
|
|
316
|
+
case ZmanTypeIds.shkiaElevation: //shkiaElevation
|
|
317
|
+
zmanTimes.push({
|
|
318
|
+
zmanType,
|
|
319
|
+
time: offset
|
|
320
|
+
? Utils.addMinutes(sunset, offset)
|
|
321
|
+
: sunset,
|
|
322
|
+
});
|
|
323
|
+
break;
|
|
324
|
+
case ZmanTypeIds.tzais45: // tzais45
|
|
325
|
+
zmanTimes.push({
|
|
326
|
+
zmanType,
|
|
327
|
+
time: Utils.addMinutes(sunset, 45 + offset),
|
|
328
|
+
});
|
|
329
|
+
break;
|
|
330
|
+
case ZmanTypeIds.tzais50: //tzais50
|
|
331
|
+
zmanTimes.push({
|
|
332
|
+
zmanType,
|
|
333
|
+
time: Utils.addMinutes(sunset, 50 + offset),
|
|
334
|
+
});
|
|
335
|
+
break;
|
|
336
|
+
case ZmanTypeIds.tzais72: //tzais72
|
|
337
|
+
zmanTimes.push({
|
|
338
|
+
zmanType,
|
|
339
|
+
time: Utils.addMinutes(sunset, 72 + offset),
|
|
340
|
+
});
|
|
341
|
+
break;
|
|
342
|
+
case ZmanTypeIds.rabbeinuTamZmanios: //tzais72Zmaniot
|
|
343
|
+
if (shaaZmanis)
|
|
344
|
+
zmanTimes.push({
|
|
345
|
+
zmanType,
|
|
346
|
+
time: Utils.addMinutes(
|
|
347
|
+
sunset,
|
|
348
|
+
shaaZmanis * 1.2 + offset,
|
|
349
|
+
),
|
|
350
|
+
});
|
|
351
|
+
break;
|
|
352
|
+
case ZmanTypeIds.rabbeinuTamZmaniosMga: //tzais72ZmaniotMA
|
|
353
|
+
if (shaaZmanisMga)
|
|
354
|
+
zmanTimes.push({
|
|
355
|
+
zmanType,
|
|
356
|
+
time: Utils.addMinutes(
|
|
357
|
+
sunset,
|
|
358
|
+
shaaZmanisMga * 1.2 + offset,
|
|
359
|
+
),
|
|
360
|
+
});
|
|
361
|
+
break;
|
|
362
|
+
case ZmanTypeIds.candleLighting: //candleLighting
|
|
363
|
+
if (sunset && jdate.hasCandleLighting()) {
|
|
364
|
+
zmanTimes.push({
|
|
365
|
+
zmanType,
|
|
366
|
+
time: Utils.addMinutes(
|
|
367
|
+
Zmanim.getCandleLightingFromSunset(
|
|
368
|
+
sunset,
|
|
369
|
+
location,
|
|
370
|
+
),
|
|
371
|
+
offset,
|
|
372
|
+
),
|
|
373
|
+
});
|
|
374
|
+
}
|
|
375
|
+
break;
|
|
376
|
+
case ZmanTypeIds.SofZmanEatingChometz: //Sof Zman Achilas Chometz
|
|
377
|
+
if (shaaZmanisMga && jdate.Month === 1 &&
|
|
378
|
+
jdate.Day === 14 &&
|
|
379
|
+
Utils.isTimeAfter(sunrise, Utils.timeFromDate(date))) {
|
|
380
|
+
zmanTimes.push({
|
|
381
|
+
zmanType,
|
|
382
|
+
time: Utils.addMinutes(
|
|
383
|
+
sunrise,
|
|
384
|
+
-90 + offset + shaaZmanisMga * 4,
|
|
385
|
+
),
|
|
386
|
+
});
|
|
387
|
+
}
|
|
388
|
+
break;
|
|
389
|
+
case ZmanTypeIds.SofZmanBurnChometz: //Sof Zman Biur Chometz
|
|
390
|
+
if (shaaZmanisMga &&
|
|
391
|
+
jdate.Month === 1 &&
|
|
392
|
+
(jdate.Day === 14 ||
|
|
393
|
+
(jdate.DayOfWeek === DaysOfWeek.FRIDAY &&
|
|
394
|
+
jdate.Day === 13)) &&
|
|
395
|
+
Utils.isTimeAfter(sunrise, Utils.timeFromDate(date))
|
|
396
|
+
) {
|
|
397
|
+
zmanTimes.push({
|
|
398
|
+
zmanType,
|
|
399
|
+
time: Utils.addMinutes(
|
|
400
|
+
sunrise,
|
|
401
|
+
-90 + offset + shaaZmanisMga * 5,
|
|
402
|
+
),
|
|
403
|
+
});
|
|
404
|
+
}
|
|
405
|
+
break;
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
return zmanTimes;
|
|
409
|
+
}
|
|
410
|
+
/**
|
|
411
|
+
* Get the WhichDaysFlags for the given secular date
|
|
412
|
+
* @param {Date} date
|
|
413
|
+
* @param {jDate} jdate
|
|
414
|
+
* @param {Location} location
|
|
415
|
+
*/
|
|
416
|
+
static getWhichDays(date: Date, jdate: jDate, location: Location) {
|
|
417
|
+
if (jdate.isYomTov(location.Israel)) {
|
|
418
|
+
return WhichDaysFlags.YOMTOV;
|
|
419
|
+
}
|
|
420
|
+
switch (date.getDay()) {
|
|
421
|
+
case DaysOfWeek.SUNDAY:
|
|
422
|
+
return WhichDaysFlags.SUNDAY;
|
|
423
|
+
case DaysOfWeek.MONDAY:
|
|
424
|
+
return WhichDaysFlags.MONDAY;
|
|
425
|
+
case DaysOfWeek.TUESDAY:
|
|
426
|
+
return WhichDaysFlags.TUESDAY;
|
|
427
|
+
case DaysOfWeek.WEDNESDAY:
|
|
428
|
+
return WhichDaysFlags.WEDNESDAY;
|
|
429
|
+
case DaysOfWeek.THURSDAY:
|
|
430
|
+
return WhichDaysFlags.THURSDAY;
|
|
431
|
+
case DaysOfWeek.FRIDAY:
|
|
432
|
+
return WhichDaysFlags.FRIDAY;
|
|
433
|
+
case DaysOfWeek.SHABBOS:
|
|
434
|
+
return WhichDaysFlags.SHABBOS;
|
|
435
|
+
}
|
|
436
|
+
return 0;
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
/**
|
|
440
|
+
* Returns the zmanim necessary for showing basic shul notifications: chatzosHayom, chatzosHalayla, alos
|
|
441
|
+
* @param {jDate} jdate
|
|
442
|
+
* @param {Date} sdate
|
|
443
|
+
* @param {Location} location
|
|
444
|
+
* @returns {{chatzosHayom:Time, chatzosHalayla:Time, alos:Time, shkia:Time }}
|
|
445
|
+
*/
|
|
446
|
+
static getBasicShulZmanim(jdate: jDate, sdate: Date,location: Location) {
|
|
447
|
+
const zmanim = AppUtils.getZmanTimes(
|
|
448
|
+
[
|
|
449
|
+
getZmanType(ZmanTypeIds.chatzosDay) as ZmanToShow, //Chatzos hayom
|
|
450
|
+
getZmanType(ZmanTypeIds.Alos90) as ZmanToShow, //alos90
|
|
451
|
+
getZmanType(ZmanTypeIds.shkiaElevation) as ZmanToShow, //shkiaElevation,
|
|
452
|
+
getZmanType(ZmanTypeIds.candleLighting) as ZmanToShow, //candleLighting,
|
|
453
|
+
],
|
|
454
|
+
sdate,
|
|
455
|
+
jdate,
|
|
456
|
+
location,
|
|
457
|
+
);
|
|
458
|
+
return {
|
|
459
|
+
chatzosHayom: zmanim[0].time,
|
|
460
|
+
chatzosHalayla: Utils.addMinutes(zmanim[0].time, 720),
|
|
461
|
+
alos: zmanim[1].time,
|
|
462
|
+
shkia: zmanim[2].time,
|
|
463
|
+
};
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
/**
|
|
467
|
+
* Returns all the zmanim for the given day
|
|
468
|
+
* @param {jDate} jdate
|
|
469
|
+
* @param {Date} sdate
|
|
470
|
+
* @param {Location} location
|
|
471
|
+
* @returns {{zmanType:ZmanToShow, time?:Time }[]}
|
|
472
|
+
*/
|
|
473
|
+
static getAllZmanim(jdate: jDate, sdate: Date, location: Location) {
|
|
474
|
+
return AppUtils.getZmanTimes(ZmanTypes, sdate, jdate, location,);
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
/**
|
|
478
|
+
* Compares two zmanim for showing to see if they are the same
|
|
479
|
+
* @param {{id:number,offset:?Number, whichDaysFlags:?Number, desc: String, eng: String, heb: String }} zman1
|
|
480
|
+
* @param {{id:number,offset:?Number, whichDaysFlags:?Number, desc: String, eng: String, heb: String }} zman2
|
|
481
|
+
*/
|
|
482
|
+
static IsSameZmanToShow(zman1: ZmanToShow, zman2: ZmanToShow) {
|
|
483
|
+
return (
|
|
484
|
+
zman1.id === zman2.id &&
|
|
485
|
+
zman1.desc === zman2.desc &&
|
|
486
|
+
zman1.eng === zman2.eng &&
|
|
487
|
+
zman1.heb === zman2.heb &&
|
|
488
|
+
(zman1.offset || 0) === (zman2.offset || 0) &&
|
|
489
|
+
(zman1.whichDaysFlags || 0) === (zman2.whichDaysFlags || 0)
|
|
490
|
+
);
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
/**
|
|
494
|
+
* Returns all available ZmanTypes - including baseTypes and custom added types
|
|
495
|
+
* @param {Settings} settings
|
|
496
|
+
*/
|
|
497
|
+
static AllZmanTypes(settings: Settings) {
|
|
498
|
+
return [...ZmanTypes]/*.concat(settings.customZmanim)*/;
|
|
499
|
+
}
|
|
500
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
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
|
+
}
|