jcal-zmanim 1.2.0 → 1.2.2

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 (59) hide show
  1. package/LICENSE +674 -674
  2. package/dist/README.md +596 -566
  3. package/dist/index.cjs +13325 -0
  4. package/dist/index.cjs.map +1 -0
  5. package/dist/index.d.cts +922 -0
  6. package/dist/index.d.ts +922 -2
  7. package/dist/index.js +3564 -35
  8. package/dist/index.js.map +1 -1
  9. package/package.json +48 -46
  10. package/dist/JCal/Dafyomi.d.ts +0 -28
  11. package/dist/JCal/Dafyomi.d.ts.map +0 -1
  12. package/dist/JCal/Dafyomi.js +0 -130
  13. package/dist/JCal/Dafyomi.js.map +0 -1
  14. package/dist/JCal/Location.d.ts +0 -33
  15. package/dist/JCal/Location.d.ts.map +0 -1
  16. package/dist/JCal/Location.js +0 -77
  17. package/dist/JCal/Location.js.map +0 -1
  18. package/dist/JCal/Molad.d.ts +0 -38
  19. package/dist/JCal/Molad.d.ts.map +0 -1
  20. package/dist/JCal/Molad.js +0 -90
  21. package/dist/JCal/Molad.js.map +0 -1
  22. package/dist/JCal/PirkeiAvos.d.ts +0 -14
  23. package/dist/JCal/PirkeiAvos.d.ts.map +0 -1
  24. package/dist/JCal/PirkeiAvos.js +0 -171
  25. package/dist/JCal/PirkeiAvos.js.map +0 -1
  26. package/dist/JCal/Sedra.d.ts +0 -64
  27. package/dist/JCal/Sedra.d.ts.map +0 -1
  28. package/dist/JCal/Sedra.js +0 -183
  29. package/dist/JCal/Sedra.js.map +0 -1
  30. package/dist/JCal/Zmanim.d.ts +0 -96
  31. package/dist/JCal/Zmanim.d.ts.map +0 -1
  32. package/dist/JCal/Zmanim.js +0 -223
  33. package/dist/JCal/Zmanim.js.map +0 -1
  34. package/dist/JCal/ZmanimUtils.d.ts +0 -72
  35. package/dist/JCal/ZmanimUtils.d.ts.map +0 -1
  36. package/dist/JCal/ZmanimUtils.js +0 -349
  37. package/dist/JCal/ZmanimUtils.js.map +0 -1
  38. package/dist/JCal/jDate.d.ts +0 -204
  39. package/dist/JCal/jDate.d.ts.map +0 -1
  40. package/dist/JCal/jDate.js +0 -648
  41. package/dist/JCal/jDate.js.map +0 -1
  42. package/dist/Locations.d.ts +0 -31
  43. package/dist/Locations.d.ts.map +0 -1
  44. package/dist/Locations.js +0 -153
  45. package/dist/Locations.js.map +0 -1
  46. package/dist/Notifications.d.ts +0 -18
  47. package/dist/Notifications.d.ts.map +0 -1
  48. package/dist/Notifications.js +0 -1039
  49. package/dist/Notifications.js.map +0 -1
  50. package/dist/Utils.d.ts +0 -287
  51. package/dist/Utils.d.ts.map +0 -1
  52. package/dist/Utils.js +0 -822
  53. package/dist/Utils.js.map +0 -1
  54. package/dist/ZmanTypes.d.ts +0 -41
  55. package/dist/ZmanTypes.d.ts.map +0 -1
  56. package/dist/ZmanTypes.js +0 -187
  57. package/dist/ZmanTypes.js.map +0 -1
  58. package/dist/index.d.ts.map +0 -1
  59. package/dist/locations.json +0 -1
package/dist/Utils.js DELETED
@@ -1,822 +0,0 @@
1
- var __assign = (this && this.__assign) || function () {
2
- __assign = Object.assign || function(t) {
3
- for (var s, i = 1, n = arguments.length; i < n; i++) {
4
- s = arguments[i];
5
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
6
- t[p] = s[p];
7
- }
8
- return t;
9
- };
10
- return __assign.apply(this, arguments);
11
- };
12
- var __read = (this && this.__read) || function (o, n) {
13
- var m = typeof Symbol === "function" && o[Symbol.iterator];
14
- if (!m) return o;
15
- var i = m.call(o), r, ar = [], e;
16
- try {
17
- while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
18
- }
19
- catch (error) { e = { error: error }; }
20
- finally {
21
- try {
22
- if (r && !r.done && (m = i["return"])) m.call(i);
23
- }
24
- finally { if (e) throw e.error; }
25
- }
26
- return ar;
27
- };
28
- var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
29
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
30
- if (ar || !(i in from)) {
31
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
32
- ar[i] = from[i];
33
- }
34
- }
35
- return to.concat(ar || Array.prototype.slice.call(from));
36
- };
37
- import Zmanim from './JCal/Zmanim.js';
38
- import jDate from './JCal/jDate.js';
39
- var __DEV__ = process.env.NODE_ENV === 'development';
40
- export var DaysOfWeek = Object.freeze({
41
- SUNDAY: 0,
42
- MONDAY: 1,
43
- TUESDAY: 2,
44
- WEDNESDAY: 3,
45
- THURSDAY: 4,
46
- FRIDAY: 5,
47
- SHABBOS: 6,
48
- });
49
- export var JewishMonthsEng = [
50
- '',
51
- 'Nissan',
52
- 'Iyar',
53
- 'Sivan',
54
- 'Tamuz',
55
- 'Av',
56
- 'Ellul',
57
- 'Tishrei',
58
- 'Cheshvan',
59
- 'Kislev',
60
- 'Teves',
61
- 'Shvat',
62
- 'Adar',
63
- 'Adar Sheini',
64
- ];
65
- export var JewishMonthsHeb = [
66
- '',
67
- 'ניסן',
68
- 'אייר',
69
- 'סיון',
70
- 'תמוז',
71
- 'אב',
72
- 'אלול',
73
- 'תשרי',
74
- 'חשון',
75
- 'כסלו',
76
- 'טבת',
77
- 'שבט',
78
- 'אדר',
79
- 'אדר שני',
80
- ];
81
- export var SecularMonthsEng = [
82
- 'January',
83
- 'February',
84
- 'March',
85
- 'April',
86
- 'May',
87
- 'June',
88
- 'July',
89
- 'August',
90
- 'September',
91
- 'October',
92
- 'November',
93
- 'December',
94
- ];
95
- export var DaysOfWeekEng = [
96
- 'Sunday',
97
- 'Monday',
98
- 'Tuesday',
99
- 'Wednesday',
100
- 'Thursday',
101
- 'Erev Shabbos',
102
- 'Shabbos Kodesh',
103
- ];
104
- export var DaysOfWeekHeb = [
105
- 'יום ראשון',
106
- 'יום שני',
107
- 'יום שלישי',
108
- 'יום רביעי',
109
- 'יום חמישי',
110
- 'ערב שבת קודש',
111
- 'שבת קודש',
112
- ];
113
- var Utils = /** @class */ (function () {
114
- function Utils() {
115
- }
116
- /**
117
- * Gets the Jewish representation of a number (365 = שס"ה)
118
- * Minimum number is 1 and maximum is 9999.
119
- * @param {Number} number
120
- */
121
- Utils.toJewishNumber = function (number) {
122
- if (number < 1) {
123
- throw 'Min value is 1';
124
- }
125
- if (number > 9999) {
126
- throw 'Max value is 9999';
127
- }
128
- var n = number, retval = '';
129
- if (n >= 1000) {
130
- retval += Utils.jsd[Utils.toInt((n - (n % 1000)) / 1000) - 1] + "'";
131
- n = n % 1000;
132
- }
133
- while (n >= 400) {
134
- retval += 'ת';
135
- n -= 400;
136
- }
137
- if (n >= 100) {
138
- retval += Utils.jhd[Utils.toInt((n - (n % 100)) / 100) - 1];
139
- n = n % 100;
140
- }
141
- if (n == 15) {
142
- retval += 'טו';
143
- }
144
- else if (n == 16) {
145
- retval += 'טז';
146
- }
147
- else {
148
- if (n > 9) {
149
- retval += Utils.jtd[Utils.toInt((n - (n % 10)) / 10) - 1];
150
- }
151
- if (n % 10 > 0) {
152
- retval += Utils.jsd[(n % 10) - 1];
153
- }
154
- }
155
- if (number > 999 && number % 1000 < 10) {
156
- retval = "'" + retval;
157
- }
158
- else if (retval.length > 1) {
159
- retval = retval.slice(0, -1) + '"' + retval[retval.length - 1];
160
- }
161
- return retval;
162
- };
163
- /**
164
- * Returns the javascript date in the format: Thursday, the 3rd of January 2018.
165
- * @param {Date} date
166
- * @param {Boolean} hideDayOfWeek
167
- * @param {Boolean} dontCapitalize
168
- */
169
- Utils.toStringDate = function (date, hideDayOfWeek, dontCapitalize) {
170
- if (!date)
171
- return;
172
- return ((hideDayOfWeek
173
- ? dontCapitalize
174
- ? 't'
175
- : 'T'
176
- : DaysOfWeekEng[date.getDay()] + ', t') +
177
- 'he ' +
178
- Utils.toSuffixed(date.getDate()) +
179
- ' of ' +
180
- SecularMonthsEng[date.getMonth()] +
181
- ' ' +
182
- date.getFullYear().toString());
183
- };
184
- /**
185
- * Returns the javascript date in the format: 1/3/2020.
186
- * @param {Date} date
187
- * @param {Boolean} monthFirst
188
- */
189
- Utils.toShortStringDate = function (date, monthFirst) {
190
- if (!date)
191
- return;
192
- var dayNum = date.getDate(), monthNum = date.getMonth() + 1;
193
- return ((monthFirst
194
- ? "".concat(monthNum, "/").concat(dayNum)
195
- : "".concat(dayNum < 10 ? '0' : '').concat(dayNum, "/").concat(monthNum < 10 ? '0' : '').concat(monthNum)) +
196
- '/' +
197
- date.getFullYear().toString());
198
- };
199
- /**
200
- * Add two character suffix to number. e.g. 21st, 102nd, 93rd, 500th
201
- * @param {Number} num
202
- */
203
- Utils.toSuffixed = function (num) {
204
- var t = num.toString();
205
- var suffix = 'th';
206
- if (t.length === 1 || t[t.length - 2] !== '1') {
207
- switch (t[t.length - 1]) {
208
- case '1':
209
- suffix = 'st';
210
- break;
211
- case '2':
212
- suffix = 'nd';
213
- break;
214
- case '3':
215
- suffix = 'rd';
216
- break;
217
- }
218
- }
219
- return t + suffix;
220
- };
221
- /**
222
- * Returns if the given full secular year has a February 29th
223
- * @param {Number} year
224
- */
225
- Utils.isSecularLeapYear = function (year) {
226
- return !(year % 400) || (!!(year % 100) && !(year % 4));
227
- };
228
- /**
229
- * Get day of week using Javascripts getDay function.
230
- * Important note: months starts at 1 not 0 like javascript
231
- * The DOW returned has Sunday = 0
232
- * @param {Number} year
233
- * @param {Number} month
234
- * @param {Number} day
235
- */
236
- Utils.getSdDOW = function (year, month, day) {
237
- return new Date(year, month - 1, day).getDay();
238
- };
239
- /**
240
- * Makes sure hour is between 0 and 23 and minute is between 0 and 59.
241
- * Overlaps get added/subtracted.
242
- * The argument needs to be an object in the format {hour : 12, minute : 42, second : 18}
243
- * @param {Time} time
244
- */
245
- Utils.fixTime = function (time) {
246
- //make a copy - javascript sends object parameters by reference
247
- var result = {
248
- hour: time.hour,
249
- minute: time.minute,
250
- second: time.second || 0,
251
- };
252
- while (result.second >= 60) {
253
- result.minute += 1;
254
- result.second -= 60;
255
- }
256
- while (result.second < 0) {
257
- result.minute -= 1;
258
- result.second += 60;
259
- }
260
- while (result.minute < 0) {
261
- result.minute += 60;
262
- result.hour--;
263
- }
264
- while (result.minute >= 60) {
265
- result.minute -= 60;
266
- result.hour++;
267
- }
268
- if (result.hour < 0) {
269
- result.hour = 24 + (result.hour % 24);
270
- }
271
- if (result.hour > 23) {
272
- result.hour = result.hour % 24;
273
- }
274
- return result;
275
- };
276
- /**
277
- * Add the given number of minutes to the given time.
278
- * The argument needs to be an object in the format {hour : 12, minute : 42, second : 18 }
279
- *
280
- * @param {Time} time
281
- * @param {Number} minutes
282
- */
283
- Utils.addMinutes = function (time, minutes) {
284
- if (!time)
285
- return time;
286
- return (time &&
287
- Utils.fixTime({
288
- hour: time.hour,
289
- minute: time.minute + (minutes || 0),
290
- second: time.second,
291
- }));
292
- };
293
- /**
294
- * Add the given number of seconds to the given time.
295
- * The argument needs to be an object in the format {hour : 12, minute :42, second : 18}
296
- *
297
- * @param {Time} time
298
- * @param {Number} seconds
299
- */
300
- Utils.addSeconds = function (time, seconds) {
301
- return Utils.fixTime({
302
- hour: time.hour,
303
- minute: time.minute,
304
- second: (time.second || 0) + seconds,
305
- });
306
- };
307
- /**
308
- * Gets the time difference between two times of day.
309
- * If showNegative is falsey, assumes that the earlier time is always before the later time.
310
- * So, if laterTime is less than earlierTime, the returned diff is until the next day.
311
- * Both arguments need to be an object in the format {hour : 12, minute : 42, second : 18 }
312
- * @param {Time} earlierTime
313
- * @param {Time} laterTime
314
- * @param {Boolean} [showNegative] show negative values or assume second value is next day?
315
- * @returns{{hour:number, minute:number, second:number, sign:1|-1}}
316
- */
317
- Utils.timeDiff = function (earlierTime, laterTime, showNegative) {
318
- if (showNegative === void 0) { showNegative = false; }
319
- var earlySec = Utils.totalSeconds(earlierTime), laterSec = Utils.totalSeconds(laterTime), time = Utils.fixTime({
320
- hour: 0,
321
- minute: 0,
322
- second: earlySec <= laterSec
323
- ? laterSec - earlySec
324
- : showNegative
325
- ? earlySec - laterSec
326
- : 86400 - earlySec + laterSec,
327
- });
328
- return __assign(__assign({}, time), { sign: earlySec <= laterSec || !showNegative ? 1 : -1 });
329
- };
330
- /**
331
- * Gets the total number of minutes in the given time.
332
- * @param {Time} time An object in the format {hour : 12, minute :42, second : 18}
333
- */
334
- Utils.totalMinutes = function (time) {
335
- return time ? time.hour * 60 + time.minute : 0;
336
- };
337
- /**
338
- * Gets the total number of seconds in the given time.
339
- * @param {Time} time An object in the format {hour : 12, minute :42, second : 18}
340
- */
341
- Utils.totalSeconds = function (time) {
342
- return time ? Utils.totalMinutes(time) * 60 + (time.second || 0) : 0;
343
- };
344
- /**
345
- * Returns the time of the given javascript date as an object in the format of {hour : 23, minute :42, second: 18 }
346
- * @param {Date} sdate
347
- * @returns {{hour :number, minute :number, second:number }}
348
- */
349
- Utils.timeFromDate = function (sdate) {
350
- return {
351
- hour: sdate.getHours(),
352
- minute: sdate.getMinutes(),
353
- second: sdate.getSeconds(),
354
- };
355
- };
356
- /**
357
- * Determines if the second given time is after (or at) the first given time
358
- * @param {{hour :number, minute :number, second:number }} beforeTime
359
- * @param {{hour :number, minute :number, second:number }} afterTime
360
- */
361
- Utils.isTimeAfter = function (beforeTime, afterTime) {
362
- if (!beforeTime || !afterTime)
363
- return false;
364
- return Utils.totalSeconds(afterTime) >= Utils.totalSeconds(beforeTime);
365
- };
366
- /**
367
- * Returns the given time interval in a formatted string.
368
- * @param {{hour:number, minute:number,second:number,sign?: 1 | -1}} time An object in the format {hour : 23, minute :42, second: 18 }
369
- */
370
- Utils.getTimeIntervalTextStringHeb = function (time) {
371
- var t = '';
372
- if (time.hour > 0) {
373
- t += "".concat(time.hour.toString(), " ").concat(time.hour === 1 ? 'שעה' : 'שעות');
374
- }
375
- if (time.minute > 0) {
376
- if (t.length) {
377
- t += ' ';
378
- }
379
- t += "".concat(time.minute.toString(), " ").concat(time.minute === 1 ? 'דקה' : 'דקות');
380
- }
381
- if ((time.second || 0) > 0) {
382
- if (t.length) {
383
- t += ' ';
384
- }
385
- t += "".concat(Math.trunc(time.second || 0).toString(), " ").concat(time.second === 1 ? 'שנייה' : 'שניות');
386
- }
387
- return t;
388
- };
389
- /**
390
- * Returns the given time interval in a formatted string.
391
- * @param {{hour:number, minute:number,second:number,sign?: 1 | -1}} time An object in the format {hour : 23, minute :42, second: 18 }
392
- */
393
- Utils.getTimeIntervalTextString = function (time) {
394
- var t = '';
395
- if (time.hour > 0) {
396
- t += "".concat(time.hour.toString(), " ").concat(time.hour === 1 ? 'hour' : 'hours');
397
- }
398
- if (time.minute > 0) {
399
- if (t.length) {
400
- t += ' ';
401
- }
402
- t += "".concat(time.minute.toString(), " ").concat(time.minute === 1 ? 'minute' : 'minutes');
403
- }
404
- if ((time.second || 0) > 0) {
405
- if (t.length) {
406
- t += ' ';
407
- }
408
- t += "".concat(Math.trunc(time.second || 0).toString(), " ").concat(time.second === 1 ? 'second' : 'seconds');
409
- }
410
- return t;
411
- };
412
- /**
413
- * Returns the nusach for Sefiras Ha'omer for the given day and minhag
414
- * @param {number} dayOfOmer The day of the Omer for which to get the nusach for
415
- * @param {'ashkenaz'|'sefard'|'sefardi'} nusach Should it be La'Omer ("sefard") or Ba'Omer ("ashkenaz") or "sefardi" (Eidot Hamizrach)?
416
- */
417
- Utils.getOmerNusach = function (dayOfOmer, nusach) {
418
- var weeks = Utils.toInt(dayOfOmer / 7), days = dayOfOmer % 7;
419
- var txt = 'היום ';
420
- if (dayOfOmer === 1) {
421
- txt += 'יום אחד ';
422
- }
423
- else {
424
- if (dayOfOmer === 2) {
425
- txt += 'שני ';
426
- }
427
- else {
428
- if (dayOfOmer === 10) {
429
- txt += 'עשרה ';
430
- }
431
- else {
432
- txt += Utils.jsnum[Utils.toInt(dayOfOmer % 10)] + ' ';
433
- if (dayOfOmer > 10) {
434
- if (dayOfOmer > 20 && dayOfOmer % 10 > 0) {
435
- txt += 'ו';
436
- }
437
- txt += Utils.jtnum[Utils.toInt(dayOfOmer / 10)] + ' ';
438
- }
439
- }
440
- }
441
- txt += (dayOfOmer >= 11 ? 'יום' : 'ימים') + ' ';
442
- if (nusach === 'sefardi') {
443
- txt += 'לעומר' + ' ';
444
- }
445
- if (dayOfOmer >= 7) {
446
- txt += 'שהם ';
447
- if (weeks === 1) {
448
- txt += 'שבוע אחד ';
449
- }
450
- else if (weeks === 2) {
451
- txt += 'שני שבועות ';
452
- }
453
- else if (weeks > 0) {
454
- txt += Utils.jsnum[Utils.toInt(weeks)] + ' שבועות ';
455
- }
456
- if (days === 1) {
457
- txt += 'ויום אחד ';
458
- }
459
- else if (days === 2) {
460
- txt += 'ושני ימים ';
461
- }
462
- else if (days > 0) {
463
- txt += 'ו' + Utils.jsnum[days] + ' ימים ';
464
- }
465
- }
466
- }
467
- if (nusach === 'sefard') {
468
- txt += 'לעומר';
469
- }
470
- else if (nusach === 'ashkenaz') {
471
- txt += 'בעומר';
472
- }
473
- return txt;
474
- };
475
- /**
476
- * Returns the given time in a formatted string.
477
- * @param {Time} time An object in the format {hour : 23, minute :42, second: 18 }
478
- * @param {1 | -1} [sign]
479
- * @param {Boolean} [army] If falsey, the returned string will be: 11:42:18 PM otherwise it will be 23:42:18
480
- * @param {Boolean} [roundUp] If falsey, the numbers will converted to a whole number by rounding down, otherwise, up.
481
- */
482
- Utils.getTimeString = function (time, sign, army, roundUp) {
483
- var round = roundUp ? Math.ceil : Math.floor;
484
- time = {
485
- hour: round(time.hour),
486
- minute: round(time.minute),
487
- second: round(time.second || 0),
488
- };
489
- if (army) {
490
- return ((sign && sign < 0 ? '-' : '') +
491
- (time.hour.toString() +
492
- ':' +
493
- (time.minute < 10
494
- ? '0' + time.minute.toString()
495
- : time.minute.toString()) +
496
- ':' +
497
- ((time.second || 0) < 10
498
- ? '0' + (time.second || 0).toString()
499
- : (time.second || 0).toString())));
500
- }
501
- else {
502
- return ((sign && sign < 0 ? '-' : '') +
503
- (time.hour <= 12
504
- ? time.hour == 0
505
- ? 12
506
- : time.hour
507
- : time.hour - 12).toString() +
508
- ':' +
509
- (time.minute < 10
510
- ? '0' + time.minute.toString()
511
- : time.minute.toString()) +
512
- ':' +
513
- ((time.second || 0) < 10
514
- ? '0' + (time.second || 0).toString()
515
- : (time.second || 0).toString()) +
516
- (time.hour < 12 ? ' AM' : ' PM'));
517
- }
518
- };
519
- /**
520
- * Gets the UTC offset in whole hours for the users time zone.
521
- * Note: this is not affected by DST - unlike javascripts getTimezoneOffset() function which gives you the current offset.
522
- */
523
- Utils.currUtcOffset = function () {
524
- var date = new Date(), jan = new Date(date.getFullYear(), 0, 1), jul = new Date(date.getFullYear(), 6, 1);
525
- return -Utils.toInt(Math.max(jan.getTimezoneOffset(), jul.getTimezoneOffset()) / 60);
526
- };
527
- /** Determines if the given date is within DST on the users system */
528
- Utils.isDateDST = function (date) {
529
- return (-Utils.toInt(date.getTimezoneOffset() / 60) !==
530
- Utils.currUtcOffset());
531
- };
532
- /**
533
- * Determines if the given date is within DST in the given location
534
- * Note: This may not be correct if the user has set the Location to a
535
- * time zone outside Israel or the USA which is not the current system time zone.
536
- */
537
- Utils.isDST = function (location, date) {
538
- //If the current system time zone is the same as the given locations time zone
539
- if (location.UTCOffset === Utils.currUtcOffset()) {
540
- //We can use the system data to determine if the given date is within DST
541
- return Utils.isDateDST(date);
542
- }
543
- else if (location.Israel) {
544
- return Utils.isIsrael_DST(date);
545
- }
546
- else {
547
- return Utils.isUSA_DST(date);
548
- }
549
- };
550
- /**
551
- * Determines if the given javascript date is during DST according to the USA rules
552
- * @param {Date} date A javascript Date object
553
- */
554
- Utils.isUSA_DST = function (date) {
555
- var year = date.getFullYear(), month = date.getMonth() + 1, day = date.getDate(), hour = date.getHours();
556
- if (month < 3 || month == 12) {
557
- return false;
558
- }
559
- else if (month > 3 && month < 11) {
560
- return true;
561
- }
562
- //DST starts at 2 AM on the second Sunday in March
563
- else if (month === 3) {
564
- //March
565
- //Gets day of week on March 1st
566
- var firstDOW = Utils.getSdDOW(year, 3, 1),
567
- //Gets date of second Sunday
568
- targetDate = firstDOW == 0 ? 8 : 7 - ((firstDOW + 7) % 7) + 8;
569
- return day > targetDate || (day === targetDate && hour >= 2);
570
- }
571
- //DST ends at 2 AM on the first Sunday in November //dt.Month == 11 / November
572
- else {
573
- //Gets day of week on November 1st
574
- var firstDOW = Utils.getSdDOW(year, 11, 1),
575
- //Gets date of first Sunday
576
- targetDate = firstDOW === 0 ? 1 : 7 - ((firstDOW + 7) % 7) + 1;
577
- return day < targetDate || (day === targetDate && hour < 2);
578
- }
579
- };
580
- //
581
- /**
582
- * Determines if the given Javascript date is during DST according to the current (5776) Israeli rules
583
- * @param {Date} date A Javascript Date object
584
- */
585
- Utils.isIsrael_DST = function (date) {
586
- var year = date.getFullYear(), month = date.getMonth() + 1, day = date.getDate(), hour = date.getHours();
587
- if (month > 10 || month < 3) {
588
- return false;
589
- }
590
- else if (month > 3 && month < 10) {
591
- return true;
592
- }
593
- //DST starts at 2 AM on the Friday before the last Sunday in March
594
- else if (month === 3) {
595
- //March
596
- //Gets date of the Friday before the last Sunday
597
- var lastFriday = 31 - Utils.getSdDOW(year, 3, 31) - 2;
598
- return day > lastFriday || (day === lastFriday && hour >= 2);
599
- }
600
- //DST ends at 2 AM on the last Sunday in October //dt.Month === 10 / October
601
- else {
602
- //Gets date of last Sunday in October
603
- var lastSunday = 31 - Utils.getSdDOW(year, 10, 31);
604
- return day < lastSunday || (day === lastSunday && hour < 2);
605
- }
606
- };
607
- /** The current time in Israel - determined by the current users system time and time zone offset*/
608
- Utils.getSdNowInIsrael = function () {
609
- var now = new Date(),
610
- //first determine the hour differential between this user and Israel time
611
- israelTimeOffset = 2 + -Utils.currUtcOffset();
612
- //This will give us the current correct date and time in Israel
613
- now.setHours(now.getHours() + israelTimeOffset);
614
- return now;
615
- };
616
- /**
617
- * Adds the given number of days to the given javascript date and returns the new date
618
- * @param {Date} sdate
619
- * @param {Number} days
620
- */
621
- Utils.addDaysToSdate = function (sdate, days) {
622
- return new Date(sdate.valueOf() + 8.64e7 * days);
623
- };
624
- /**
625
- * Compares two js dates to se if they both refer to the same day - time is ignored.
626
- * @param {Date} sdate1
627
- * @param {Date} sdate2
628
- */
629
- Utils.isSameSdate = function (sdate1, sdate2) {
630
- return (sdate1 && sdate2 && sdate1.toDateString() === sdate2.toDateString());
631
- };
632
- /**
633
- * Compares two jDates to se if they both refer to the same day - time is ignored.
634
- * @param {jDate} jdate1
635
- * @param {jDate} jdate2
636
- */
637
- Utils.isSameJdate = function (jdate1, jdate2) {
638
- return (jdate1 &&
639
- jdate2 &&
640
- jdate1.Abs &&
641
- jdate2.Abs &&
642
- jdate1.Abs === jdate2.Abs);
643
- };
644
- /**
645
- * Compares two jDates to see if they both refer to the same Jewish Month.
646
- * @param {jDate} jdate1
647
- * @param {jDate} jdate2
648
- */
649
- Utils.isSameJMonth = function (jdate1, jdate2) {
650
- return jdate1.Month === jdate2.Month && jdate1.Year === jdate2.Year;
651
- };
652
- /**
653
- * Compares two dates to se if they both refer to the same Secular Month.
654
- * @param {Date} sdate1
655
- * @param {Date} sdate2
656
- */
657
- Utils.isSameSMonth = function (sdate1, sdate2) {
658
- return (sdate1.getMonth() === sdate2.getMonth() &&
659
- sdate1.getFullYear() === sdate2.getFullYear());
660
- };
661
- /**
662
- * Determines if the time of the given Date() is after sunset at the given Location
663
- * @param {Date} sdate
664
- * @param {Location} location
665
- */
666
- Utils.isAfterSunset = function (sdate, location) {
667
- var shkia = Zmanim.getSunTimes(sdate, location).sunset, now = Utils.timeFromDate(sdate);
668
- return shkia && Utils.isTimeAfter(shkia, now);
669
- };
670
- /**
671
- * Gets the current Jewish Date at the given Location
672
- * @param {Location} location
673
- */
674
- Utils.nowAtLocation = function (location) {
675
- var sdate = new Date();
676
- //if isAfterSunset a day is added.
677
- if (Utils.isAfterSunset(sdate, location)) {
678
- sdate.setDate(sdate.getDate() + 1);
679
- }
680
- return new jDate(sdate);
681
- };
682
- /**
683
- * Converts the given complex number to an integer by removing the decimal part.
684
- * Returns same results as Math.floor for positive numbers and Math.ceil for negative ones.
685
- * Almost identical functionality to Math.trunc and parseInt.
686
- * The difference is if the argument is NaN. Math.trunc returns NaN while ths fuction returns 0.
687
- * In performance tests, this function was found to be quicker than the alternatives.
688
- * @param {Number} float The complex number to convert to an integer
689
- */
690
- Utils.toInt = function (float) {
691
- return float | 0;
692
- };
693
- /***
694
- * Takes either a jDate or a Date and returns both
695
- * @param date {Date |jDate}
696
- * @returns {{ sdate:Date, jdate:jDate }}
697
- */
698
- Utils.bothDates = function (date) {
699
- var jdate = date instanceof Date
700
- ? new jDate(date)
701
- : date;
702
- var sdate = date instanceof Date
703
- ? date
704
- : jdate.getDate();
705
- return { sdate: sdate, jdate: jdate };
706
- };
707
- /** Returns true if "thing" is either a string primitive or String object.*/
708
- Utils.isString = function (thing) {
709
- return typeof thing === 'string' || thing instanceof String;
710
- };
711
- /** Returns true if "thing" is either a number primitive or a Number object.*/
712
- Utils.isNumber = function (thing) {
713
- return typeof thing === 'number' || thing instanceof Number;
714
- };
715
- /** Returns true if "thing" is a Date object containing a valid date.*/
716
- Utils.isValidDate = function (thing) {
717
- return thing instanceof Date && !isNaN(thing.valueOf());
718
- };
719
- /** Returns whether or not the given, array, string, or argument list contains the given item or substring.
720
- *
721
- * This function is awfully similar to Array.includes, but has the added plus of accepting any number or type of arguments.*/
722
- Utils.has = function (o) {
723
- var arr = [];
724
- for (var _i = 1; _i < arguments.length; _i++) {
725
- arr[_i - 1] = arguments[_i];
726
- }
727
- if (arr.length === 1 && (Array.isArray(arr[0]) || Utils.isString(arr[0]))) {
728
- return arr[0].includes(o);
729
- }
730
- else {
731
- return arr.includes(o);
732
- }
733
- };
734
- /** Returns the first value unless it is undefined, null or NaN.
735
- *
736
- * This is very useful for boolean, string and integer parameters
737
- * where we want to keep false, "" and 0 if they were supplied.
738
- *
739
- * Similar purpose to default parameters with the difference being that this function will return
740
- * the second value if the first is NaN or null, while default params will give give you the NaN or the null.
741
- */
742
- Utils.setDefault = function (paramValue, defValue) {
743
- if (typeof paramValue === 'undefined' ||
744
- paramValue === null ||
745
- isNaN(paramValue)) {
746
- return defValue;
747
- }
748
- else {
749
- return paramValue;
750
- }
751
- };
752
- /**
753
- * Returns an array containing a range of integers.
754
- * @param {Number} [start] The number to start at. The start number is included in the results.
755
- * If only one argument is supplied, start will be set to 1.
756
- * @param {Number} end The top end of the range.
757
- * Unlike Pythons range function, The end number is included in the results.
758
- * @returns {[Number]}
759
- */
760
- Utils.range = function (start, end) {
761
- var startNumber = typeof (end) === 'undefined' ? 1 : start, endNumber = typeof (end) === 'undefined' ? start : end;
762
- return Array.from({ length: endNumber - startNumber + 1 }, function (v, i) { return startNumber + i; });
763
- };
764
- /**
765
- * Log message to console
766
- * @param {string} txt
767
- */
768
- Utils.log = function (txt) {
769
- var optionalItems = [];
770
- for (var _i = 1; _i < arguments.length; _i++) {
771
- optionalItems[_i - 1] = arguments[_i];
772
- }
773
- if (__DEV__) {
774
- console.log.apply(console, __spreadArray([txt], __read(optionalItems), false));
775
- }
776
- };
777
- /**
778
- * Warn message to console
779
- * @param {string} txt
780
- */
781
- Utils.warn = function (txt) {
782
- var optionalItems = [];
783
- for (var _i = 1; _i < arguments.length; _i++) {
784
- optionalItems[_i - 1] = arguments[_i];
785
- }
786
- if (__DEV__) {
787
- console.warn.apply(console, __spreadArray([txt], __read(optionalItems), false));
788
- }
789
- };
790
- /**
791
- * Error message to console
792
- * @param {*} txt
793
- */
794
- Utils.error = function (txt) {
795
- var optionalItems = [];
796
- for (var _i = 1; _i < arguments.length; _i++) {
797
- optionalItems[_i - 1] = arguments[_i];
798
- }
799
- if (__DEV__) {
800
- console.error.apply(console, __spreadArray([txt], __read(optionalItems), false));
801
- }
802
- };
803
- Utils.jsd = ['א', 'ב', 'ג', 'ד', 'ה', 'ו', 'ז', 'ח', 'ט'];
804
- Utils.jtd = ['י', 'כ', 'ל', 'מ', 'נ', 'ס', 'ע', 'פ', 'צ'];
805
- Utils.jhd = ['ק', 'ר', 'ש', 'ת'];
806
- Utils.jsnum = [
807
- '',
808
- 'אחד',
809
- 'שנים',
810
- 'שלשה',
811
- 'ארבעה',
812
- 'חמשה',
813
- 'ששה',
814
- 'שבעה',
815
- 'שמונה',
816
- 'תשעה',
817
- ];
818
- Utils.jtnum = ['', 'עשר', 'עשרים', 'שלושים', 'ארבעים'];
819
- return Utils;
820
- }());
821
- export { Utils };
822
- //# sourceMappingURL=Utils.js.map