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