jcal-zmanim 1.0.4 → 1.0.9

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