@hebcal/core 3.45.3 → 3.45.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/README.md +1 -1
- package/dist/bundle.js +368 -1139
- package/dist/bundle.min.js +2 -2
- package/dist/greg0.mjs +1 -1
- package/dist/hdate-bundle.js +112 -292
- package/dist/hdate-bundle.min.js +2 -2
- package/dist/hdate.js +117 -337
- package/dist/hdate.mjs +2 -2
- package/dist/hdate0-bundle.js +38 -68
- package/dist/hdate0-bundle.min.js +1 -1
- package/dist/hdate0.mjs +1 -1
- package/dist/index.js +362 -1166
- package/dist/index.mjs +365 -1164
- package/package.json +7 -7
package/dist/hdate.js
CHANGED
|
@@ -1,120 +1,93 @@
|
|
|
1
|
-
/*! @hebcal/core v3.45.
|
|
1
|
+
/*! @hebcal/core v3.45.4 */
|
|
2
2
|
'use strict';
|
|
3
3
|
|
|
4
4
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
5
|
|
|
6
6
|
const GERESH = '׳';
|
|
7
7
|
const GERSHAYIM = '״';
|
|
8
|
+
|
|
8
9
|
/**
|
|
9
10
|
* @private
|
|
10
11
|
* @param {number} num
|
|
11
12
|
* @return {string}
|
|
12
13
|
*/
|
|
13
|
-
|
|
14
14
|
function num2heb(num) {
|
|
15
15
|
switch (num) {
|
|
16
16
|
case 1:
|
|
17
17
|
return 'א';
|
|
18
|
-
|
|
19
18
|
case 2:
|
|
20
19
|
return 'ב';
|
|
21
|
-
|
|
22
20
|
case 3:
|
|
23
21
|
return 'ג';
|
|
24
|
-
|
|
25
22
|
case 4:
|
|
26
23
|
return 'ד';
|
|
27
|
-
|
|
28
24
|
case 5:
|
|
29
25
|
return 'ה';
|
|
30
|
-
|
|
31
26
|
case 6:
|
|
32
27
|
return 'ו';
|
|
33
|
-
|
|
34
28
|
case 7:
|
|
35
29
|
return 'ז';
|
|
36
|
-
|
|
37
30
|
case 8:
|
|
38
31
|
return 'ח';
|
|
39
|
-
|
|
40
32
|
case 9:
|
|
41
33
|
return 'ט';
|
|
42
|
-
|
|
43
34
|
case 10:
|
|
44
35
|
return 'י';
|
|
45
|
-
|
|
46
36
|
case 20:
|
|
47
37
|
return 'כ';
|
|
48
|
-
|
|
49
38
|
case 30:
|
|
50
39
|
return 'ל';
|
|
51
|
-
|
|
52
40
|
case 40:
|
|
53
41
|
return 'מ';
|
|
54
|
-
|
|
55
42
|
case 50:
|
|
56
43
|
return 'נ';
|
|
57
|
-
|
|
58
44
|
case 60:
|
|
59
45
|
return 'ס';
|
|
60
|
-
|
|
61
46
|
case 70:
|
|
62
47
|
return 'ע';
|
|
63
|
-
|
|
64
48
|
case 80:
|
|
65
49
|
return 'פ';
|
|
66
|
-
|
|
67
50
|
case 90:
|
|
68
51
|
return 'צ';
|
|
69
|
-
|
|
70
52
|
case 100:
|
|
71
53
|
return 'ק';
|
|
72
|
-
|
|
73
54
|
case 200:
|
|
74
55
|
return 'ר';
|
|
75
|
-
|
|
76
56
|
case 300:
|
|
77
57
|
return 'ש';
|
|
78
|
-
|
|
79
58
|
case 400:
|
|
80
59
|
return 'ת';
|
|
81
|
-
|
|
82
60
|
default:
|
|
83
61
|
return '*INVALID*';
|
|
84
62
|
}
|
|
85
63
|
}
|
|
64
|
+
|
|
86
65
|
/**
|
|
87
66
|
* @private
|
|
88
67
|
* @param {number} num
|
|
89
68
|
* @return {number[]}
|
|
90
69
|
*/
|
|
91
|
-
|
|
92
|
-
|
|
93
70
|
function num2digits(num) {
|
|
94
71
|
const digits = [];
|
|
95
|
-
|
|
96
72
|
while (num > 0) {
|
|
97
73
|
if (num === 15 || num === 16) {
|
|
98
74
|
digits.push(9);
|
|
99
75
|
digits.push(num - 9);
|
|
100
76
|
break;
|
|
101
77
|
}
|
|
102
|
-
|
|
103
78
|
let incr = 100;
|
|
104
79
|
let i;
|
|
105
|
-
|
|
106
80
|
for (i = 400; i > num; i -= incr) {
|
|
107
81
|
if (i === incr) {
|
|
108
82
|
incr = incr / 10;
|
|
109
83
|
}
|
|
110
84
|
}
|
|
111
|
-
|
|
112
85
|
digits.push(i);
|
|
113
86
|
num -= i;
|
|
114
87
|
}
|
|
115
|
-
|
|
116
88
|
return digits;
|
|
117
89
|
}
|
|
90
|
+
|
|
118
91
|
/**
|
|
119
92
|
* Converts a numerical value to a string of Hebrew letters.
|
|
120
93
|
*
|
|
@@ -129,42 +102,30 @@ function num2digits(num) {
|
|
|
129
102
|
* @param {number} number
|
|
130
103
|
* @return {string}
|
|
131
104
|
*/
|
|
132
|
-
|
|
133
|
-
|
|
134
105
|
function gematriya(number) {
|
|
135
106
|
const num = parseInt(number, 10);
|
|
136
|
-
|
|
137
107
|
if (!num) {
|
|
138
108
|
throw new TypeError(`invalid parameter to gematriya ${number}`);
|
|
139
109
|
}
|
|
140
|
-
|
|
141
110
|
let str = '';
|
|
142
111
|
const thousands = Math.floor(num / 1000);
|
|
143
|
-
|
|
144
112
|
if (thousands > 0 && thousands !== 5) {
|
|
145
113
|
const tdigits = num2digits(thousands);
|
|
146
|
-
|
|
147
114
|
for (let i = 0; i < tdigits.length; i++) {
|
|
148
115
|
str += num2heb(tdigits[i]);
|
|
149
116
|
}
|
|
150
|
-
|
|
151
117
|
str += GERESH;
|
|
152
118
|
}
|
|
153
|
-
|
|
154
119
|
const digits = num2digits(num % 1000);
|
|
155
|
-
|
|
156
120
|
if (digits.length == 1) {
|
|
157
121
|
return str + num2heb(digits[0]) + GERESH;
|
|
158
122
|
}
|
|
159
|
-
|
|
160
123
|
for (let i = 0; i < digits.length; i++) {
|
|
161
124
|
if (i + 1 === digits.length) {
|
|
162
125
|
str += GERSHAYIM;
|
|
163
126
|
}
|
|
164
|
-
|
|
165
127
|
str += num2heb(digits[i]);
|
|
166
128
|
}
|
|
167
|
-
|
|
168
129
|
return str;
|
|
169
130
|
}
|
|
170
131
|
|
|
@@ -175,40 +136,39 @@ function gematriya(number) {
|
|
|
175
136
|
/** @private */
|
|
176
137
|
const lengths = [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
|
|
177
138
|
/** @private */
|
|
178
|
-
|
|
179
139
|
const monthLengths = [lengths, lengths.slice()];
|
|
180
140
|
monthLengths[1][2] = 29;
|
|
141
|
+
|
|
181
142
|
/**
|
|
182
143
|
* @private
|
|
183
144
|
* @param {number} x
|
|
184
145
|
* @param {number} y
|
|
185
146
|
* @return {number}
|
|
186
147
|
*/
|
|
187
|
-
|
|
188
148
|
function mod(x, y) {
|
|
189
149
|
return x - y * Math.floor(x / y);
|
|
190
150
|
}
|
|
151
|
+
|
|
191
152
|
/**
|
|
192
153
|
* @private
|
|
193
154
|
* @param {number} x
|
|
194
155
|
* @param {number} y
|
|
195
156
|
* @return {number}
|
|
196
157
|
*/
|
|
197
|
-
|
|
198
158
|
function quotient(x, y) {
|
|
199
159
|
return Math.floor(x / y);
|
|
200
160
|
}
|
|
161
|
+
|
|
201
162
|
/**
|
|
202
163
|
* Returns true if the Gregorian year is a leap year
|
|
203
164
|
* @private
|
|
204
165
|
* @param {number} year Gregorian year
|
|
205
166
|
* @return {boolean}
|
|
206
167
|
*/
|
|
207
|
-
|
|
208
|
-
|
|
209
168
|
function isLeapYear$1(year) {
|
|
210
169
|
return !(year % 4) && (!!(year % 100) || !(year % 400));
|
|
211
170
|
}
|
|
171
|
+
|
|
212
172
|
/**
|
|
213
173
|
* Number of days in the Gregorian month for given year
|
|
214
174
|
* @private
|
|
@@ -216,21 +176,21 @@ function isLeapYear$1(year) {
|
|
|
216
176
|
* @param {number} year Gregorian year
|
|
217
177
|
* @return {number}
|
|
218
178
|
*/
|
|
219
|
-
|
|
220
179
|
function daysInMonth$1(month, year) {
|
|
221
180
|
// 1 based months
|
|
222
181
|
return monthLengths[+isLeapYear$1(year)][month];
|
|
223
182
|
}
|
|
183
|
+
|
|
224
184
|
/**
|
|
225
185
|
* Returns true if the object is a Javascript Date
|
|
226
186
|
* @private
|
|
227
187
|
* @param {Object} obj
|
|
228
188
|
* @return {boolean}
|
|
229
189
|
*/
|
|
230
|
-
|
|
231
190
|
function isDate(obj) {
|
|
232
191
|
return typeof obj === 'object' && Date.prototype === obj.__proto__;
|
|
233
192
|
}
|
|
193
|
+
|
|
234
194
|
/*
|
|
235
195
|
const ABS_14SEP1752 = 639797;
|
|
236
196
|
const ABS_2SEP1752 = 639785;
|
|
@@ -242,27 +202,24 @@ const ABS_2SEP1752 = 639785;
|
|
|
242
202
|
* @param {Date} date Gregorian date
|
|
243
203
|
* @return {number}
|
|
244
204
|
*/
|
|
245
|
-
|
|
246
205
|
function greg2abs(date) {
|
|
247
206
|
if (!isDate(date)) {
|
|
248
207
|
throw new TypeError(`Argument not a Date: ${date}`);
|
|
249
208
|
}
|
|
250
|
-
|
|
251
209
|
const abs = toFixed(date.getFullYear(), date.getMonth() + 1, date.getDate());
|
|
252
210
|
/*
|
|
253
211
|
if (abs < ABS_14SEP1752 && abs > ABS_2SEP1752) {
|
|
254
212
|
throw new RangeError(`Invalid Date: ${date}`);
|
|
255
213
|
}
|
|
256
214
|
*/
|
|
257
|
-
|
|
258
215
|
return abs;
|
|
259
216
|
}
|
|
217
|
+
|
|
260
218
|
/**
|
|
261
219
|
* @private
|
|
262
220
|
* @param {number} abs - R.D. number of days
|
|
263
221
|
* @return {number}
|
|
264
222
|
*/
|
|
265
|
-
|
|
266
223
|
function yearFromFixed(abs) {
|
|
267
224
|
const l0 = abs - 1;
|
|
268
225
|
const n400 = quotient(l0, 146097);
|
|
@@ -275,6 +232,7 @@ function yearFromFixed(abs) {
|
|
|
275
232
|
const year = 400 * n400 + 100 * n100 + 4 * n4 + n1;
|
|
276
233
|
return n100 != 4 && n1 != 4 ? year + 1 : year;
|
|
277
234
|
}
|
|
235
|
+
|
|
278
236
|
/**
|
|
279
237
|
* @private
|
|
280
238
|
* @param {number} year
|
|
@@ -282,12 +240,11 @@ function yearFromFixed(abs) {
|
|
|
282
240
|
* @param {number} day (1-31)
|
|
283
241
|
* @return {number}
|
|
284
242
|
*/
|
|
285
|
-
|
|
286
|
-
|
|
287
243
|
function toFixed(year, month, day) {
|
|
288
244
|
const py = year - 1;
|
|
289
245
|
return 365 * py + quotient(py, 4) - quotient(py, 100) + quotient(py, 400) + quotient(367 * month - 362, 12) + (month <= 2 ? 0 : isLeapYear$1(year) ? -1 : -2) + day;
|
|
290
246
|
}
|
|
247
|
+
|
|
291
248
|
/**
|
|
292
249
|
* Converts from Rata Die (R.D. number) to Gregorian date.
|
|
293
250
|
* See the footnote on page 384 of ``Calendrical Calculations, Part II:
|
|
@@ -298,31 +255,25 @@ function toFixed(year, month, day) {
|
|
|
298
255
|
* @param {number} abs - R.D. number of days
|
|
299
256
|
* @return {Date}
|
|
300
257
|
*/
|
|
301
|
-
|
|
302
|
-
|
|
303
258
|
function abs2greg(abs) {
|
|
304
259
|
if (typeof abs !== 'number') {
|
|
305
260
|
throw new TypeError(`Argument not a Number: ${abs}`);
|
|
306
261
|
}
|
|
307
|
-
|
|
308
262
|
abs = Math.trunc(abs);
|
|
309
263
|
/*
|
|
310
264
|
if (abs < ABS_14SEP1752 && abs > ABS_2SEP1752) {
|
|
311
265
|
throw new RangeError(`Invalid Date: ${abs}`);
|
|
312
266
|
}
|
|
313
267
|
*/
|
|
314
|
-
|
|
315
268
|
const year = yearFromFixed(abs);
|
|
316
269
|
const priorDays = abs - toFixed(year, 1, 1);
|
|
317
270
|
const correction = abs < toFixed(year, 3, 1) ? 0 : isLeapYear$1(year) ? 1 : 2;
|
|
318
271
|
const month = quotient(12 * (priorDays + correction) + 373, 367);
|
|
319
272
|
const day = abs - toFixed(year, month, 1) + 1;
|
|
320
273
|
const dt = new Date(year, month - 1, day);
|
|
321
|
-
|
|
322
274
|
if (year < 100 && year >= 0) {
|
|
323
275
|
dt.setFullYear(year);
|
|
324
276
|
}
|
|
325
|
-
|
|
326
277
|
return dt;
|
|
327
278
|
}
|
|
328
279
|
|
|
@@ -346,10 +297,10 @@ function abs2greg(abs) {
|
|
|
346
297
|
You should have received a copy of the GNU General Public License
|
|
347
298
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
348
299
|
*/
|
|
300
|
+
|
|
349
301
|
/**
|
|
350
302
|
* Gregorian date helper functions.
|
|
351
303
|
*/
|
|
352
|
-
|
|
353
304
|
class greg {
|
|
354
305
|
/**
|
|
355
306
|
* Long names of the Gregorian months (1='January', 12='December')
|
|
@@ -357,73 +308,66 @@ class greg {
|
|
|
357
308
|
* @type {string[]}
|
|
358
309
|
*/
|
|
359
310
|
static monthNames = ['', 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
|
|
311
|
+
|
|
360
312
|
/**
|
|
361
313
|
* Returns true if the Gregorian year is a leap year
|
|
362
314
|
* @param {number} year Gregorian year
|
|
363
315
|
* @return {boolean}
|
|
364
316
|
*/
|
|
365
|
-
|
|
366
317
|
static isLeapYear(year) {
|
|
367
318
|
return isLeapYear$1(year);
|
|
368
319
|
}
|
|
320
|
+
|
|
369
321
|
/**
|
|
370
322
|
* Number of days in the Gregorian month for given year
|
|
371
323
|
* @param {number} month Gregorian month (1=January, 12=December)
|
|
372
324
|
* @param {number} year Gregorian year
|
|
373
325
|
* @return {number}
|
|
374
326
|
*/
|
|
375
|
-
|
|
376
|
-
|
|
377
327
|
static daysInMonth(month, year) {
|
|
378
328
|
return daysInMonth$1(month, year);
|
|
379
329
|
}
|
|
330
|
+
|
|
380
331
|
/**
|
|
381
332
|
* Returns true if the object is a Javascript Date
|
|
382
333
|
* @param {Object} obj
|
|
383
334
|
* @return {boolean}
|
|
384
335
|
*/
|
|
385
|
-
|
|
386
|
-
|
|
387
336
|
static isDate(obj) {
|
|
388
337
|
return isDate(obj);
|
|
389
338
|
}
|
|
339
|
+
|
|
390
340
|
/**
|
|
391
341
|
* Returns number of days since January 1 of that year
|
|
392
342
|
* @deprecated
|
|
393
343
|
* @param {Date} date Gregorian date
|
|
394
344
|
* @return {number}
|
|
395
345
|
*/
|
|
396
|
-
|
|
397
|
-
|
|
398
346
|
static dayOfYear(date) {
|
|
399
347
|
if (!isDate(date)) {
|
|
400
348
|
throw new TypeError(`Argument not a Date: ${date}`);
|
|
401
349
|
}
|
|
402
|
-
|
|
403
350
|
const month = date.getMonth();
|
|
404
351
|
let doy = date.getDate() + 31 * month;
|
|
405
|
-
|
|
406
352
|
if (month > 1) {
|
|
407
353
|
// FEB
|
|
408
354
|
doy -= Math.floor((4 * (month + 1) + 23) / 10);
|
|
409
|
-
|
|
410
355
|
if (isLeapYear$1(date.getFullYear())) {
|
|
411
356
|
doy++;
|
|
412
357
|
}
|
|
413
358
|
}
|
|
414
|
-
|
|
415
359
|
return doy;
|
|
416
360
|
}
|
|
361
|
+
|
|
417
362
|
/**
|
|
418
363
|
* Converts Gregorian date to absolute R.D. (Rata Die) days
|
|
419
364
|
* @param {Date} date Gregorian date
|
|
420
365
|
* @return {number}
|
|
421
366
|
*/
|
|
422
|
-
|
|
423
|
-
|
|
424
367
|
static greg2abs(date) {
|
|
425
368
|
return greg2abs(date);
|
|
426
369
|
}
|
|
370
|
+
|
|
427
371
|
/**
|
|
428
372
|
* Converts from Rata Die (R.D. number) to Gregorian date.
|
|
429
373
|
* See the footnote on page 384 of ``Calendrical Calculations, Part II:
|
|
@@ -433,12 +377,9 @@ class greg {
|
|
|
433
377
|
* @param {number} theDate - R.D. number of days
|
|
434
378
|
* @return {Date}
|
|
435
379
|
*/
|
|
436
|
-
|
|
437
|
-
|
|
438
380
|
static abs2greg(theDate) {
|
|
439
381
|
return abs2greg(theDate);
|
|
440
382
|
}
|
|
441
|
-
|
|
442
383
|
}
|
|
443
384
|
|
|
444
385
|
const noopLocale = {
|
|
@@ -455,6 +396,7 @@ const alias = {
|
|
|
455
396
|
's': 'en',
|
|
456
397
|
'': 'en'
|
|
457
398
|
};
|
|
399
|
+
|
|
458
400
|
/**
|
|
459
401
|
* A locale in Hebcal is used for translations/transliterations of
|
|
460
402
|
* holidays. `@hebcal/core` supports four locales by default
|
|
@@ -463,16 +405,14 @@ const alias = {
|
|
|
463
405
|
* * `he` - Hebrew (e.g. "שַׁבָּת")
|
|
464
406
|
* * `he-x-NoNikud` - Hebrew without nikud (e.g. "שבת")
|
|
465
407
|
*/
|
|
466
|
-
|
|
467
408
|
class Locale {
|
|
468
409
|
/** @private */
|
|
469
410
|
static locales = Object.create(null);
|
|
470
411
|
/** @private */
|
|
471
|
-
|
|
472
412
|
static activeLocale = null;
|
|
473
413
|
/** @private */
|
|
474
|
-
|
|
475
414
|
static activeName = null;
|
|
415
|
+
|
|
476
416
|
/**
|
|
477
417
|
* Returns translation only if `locale` offers a non-empty translation for `id`.
|
|
478
418
|
* Otherwise, returns `undefined`.
|
|
@@ -480,49 +420,42 @@ class Locale {
|
|
|
480
420
|
* @param {string} [locale] Optional locale name (i.e: `'he'`, `'fr'`). Defaults to active locale.
|
|
481
421
|
* @return {string}
|
|
482
422
|
*/
|
|
483
|
-
|
|
484
423
|
static lookupTranslation(id, locale) {
|
|
485
424
|
const locale0 = locale && locale.toLowerCase();
|
|
486
425
|
const loc = typeof locale == 'string' && this.locales[locale0] || this.activeLocale;
|
|
487
426
|
const array = loc[id];
|
|
488
|
-
|
|
489
427
|
if (array && array.length && array[0].length) {
|
|
490
428
|
return array[0];
|
|
491
429
|
}
|
|
492
|
-
|
|
493
430
|
return undefined;
|
|
494
431
|
}
|
|
432
|
+
|
|
495
433
|
/**
|
|
496
434
|
* By default, if no translation was found, returns `id`.
|
|
497
435
|
* @param {string} id Message ID to translate
|
|
498
436
|
* @param {string} [locale] Optional locale name (i.e: `'he'`, `'fr'`). Defaults to active locale.
|
|
499
437
|
* @return {string}
|
|
500
438
|
*/
|
|
501
|
-
|
|
502
|
-
|
|
503
439
|
static gettext(id, locale) {
|
|
504
440
|
const text = this.lookupTranslation(id, locale);
|
|
505
|
-
|
|
506
441
|
if (typeof text == 'undefined') {
|
|
507
442
|
return id;
|
|
508
443
|
}
|
|
509
|
-
|
|
510
444
|
return text;
|
|
511
445
|
}
|
|
446
|
+
|
|
512
447
|
/**
|
|
513
448
|
* Register locale translations.
|
|
514
449
|
* @param {string} locale Locale name (i.e.: `'he'`, `'fr'`)
|
|
515
450
|
* @param {LocaleDate} data parsed data from a `.po` file.
|
|
516
451
|
*/
|
|
517
|
-
|
|
518
|
-
|
|
519
452
|
static addLocale(locale, data) {
|
|
520
453
|
if (typeof data.contexts !== 'object' || typeof data.contexts[''] !== 'object') {
|
|
521
454
|
throw new TypeError(`Locale '${locale}' invalid compact format`);
|
|
522
455
|
}
|
|
523
|
-
|
|
524
456
|
this.locales[locale.toLowerCase()] = data.contexts[''];
|
|
525
457
|
}
|
|
458
|
+
|
|
526
459
|
/**
|
|
527
460
|
* Activates a locale. Throws an error if the locale has not been previously added.
|
|
528
461
|
* After setting the locale to be used, all strings marked for translations
|
|
@@ -530,53 +463,44 @@ class Locale {
|
|
|
530
463
|
* @param {string} locale Locale name (i.e: `'he'`, `'fr'`)
|
|
531
464
|
* @return {LocaleData}
|
|
532
465
|
*/
|
|
533
|
-
|
|
534
|
-
|
|
535
466
|
static useLocale(locale) {
|
|
536
467
|
const locale0 = locale.toLowerCase();
|
|
537
468
|
const obj = this.locales[locale0];
|
|
538
|
-
|
|
539
469
|
if (!obj) {
|
|
540
470
|
throw new RangeError(`Locale '${locale}' not found`);
|
|
541
471
|
}
|
|
542
|
-
|
|
543
472
|
this.activeName = alias[locale0] || locale0;
|
|
544
473
|
this.activeLocale = obj;
|
|
545
474
|
return this.activeLocale;
|
|
546
475
|
}
|
|
476
|
+
|
|
547
477
|
/**
|
|
548
478
|
* Returns the name of the active locale (i.e. 'he', 'ashkenazi', 'fr')
|
|
549
479
|
* @return {string}
|
|
550
480
|
*/
|
|
551
|
-
|
|
552
|
-
|
|
553
481
|
static getLocaleName() {
|
|
554
482
|
return this.activeName;
|
|
555
483
|
}
|
|
484
|
+
|
|
556
485
|
/**
|
|
557
486
|
* Returns the names of registered locales
|
|
558
487
|
* @return {string[]}
|
|
559
488
|
*/
|
|
560
|
-
|
|
561
|
-
|
|
562
489
|
static getLocaleNames() {
|
|
563
490
|
return Object.keys(this.locales).sort();
|
|
564
491
|
}
|
|
492
|
+
|
|
565
493
|
/**
|
|
566
494
|
* @param {number} n
|
|
567
495
|
* @param {string} [locale] Optional locale name (i.e: `'he'`, `'fr'`). Defaults to active locale.
|
|
568
496
|
* @return {string}
|
|
569
497
|
*/
|
|
570
|
-
|
|
571
|
-
|
|
572
498
|
static ordinal(n, locale) {
|
|
573
499
|
const locale1 = locale && locale.toLowerCase();
|
|
574
500
|
const locale0 = locale1 || this.activeName;
|
|
575
|
-
|
|
576
501
|
if (!locale0) {
|
|
577
502
|
return this.getEnOrdinal(n);
|
|
578
503
|
}
|
|
579
|
-
|
|
580
504
|
switch (locale0) {
|
|
581
505
|
case 'en':
|
|
582
506
|
case 's':
|
|
@@ -586,42 +510,36 @@ class Locale {
|
|
|
586
510
|
case 'ashkenazi_poylish':
|
|
587
511
|
case 'ashkenazi_standard':
|
|
588
512
|
return this.getEnOrdinal(n);
|
|
589
|
-
|
|
590
513
|
case 'es':
|
|
591
514
|
return n + 'º';
|
|
592
|
-
|
|
593
515
|
case 'h':
|
|
594
516
|
case 'he':
|
|
595
517
|
case 'he-x-nonikud':
|
|
596
518
|
return String(n);
|
|
597
|
-
|
|
598
519
|
default:
|
|
599
520
|
return n + '.';
|
|
600
521
|
}
|
|
601
522
|
}
|
|
523
|
+
|
|
602
524
|
/**
|
|
603
525
|
* @private
|
|
604
526
|
* @param {number} n
|
|
605
527
|
* @return {string}
|
|
606
528
|
*/
|
|
607
|
-
|
|
608
|
-
|
|
609
529
|
static getEnOrdinal(n) {
|
|
610
530
|
const s = ['th', 'st', 'nd', 'rd'];
|
|
611
531
|
const v = n % 100;
|
|
612
532
|
return n + (s[(v - 20) % 10] || s[v] || s[0]);
|
|
613
533
|
}
|
|
534
|
+
|
|
614
535
|
/**
|
|
615
536
|
* Removes nekudot from Hebrew string
|
|
616
537
|
* @param {string} str
|
|
617
538
|
* @return {string}
|
|
618
539
|
*/
|
|
619
|
-
|
|
620
|
-
|
|
621
540
|
static hebrewStripNikkud(str) {
|
|
622
541
|
return str.replace(/[\u0590-\u05bd]/g, '').replace(/[\u05bf-\u05c7]/g, '');
|
|
623
542
|
}
|
|
624
|
-
|
|
625
543
|
}
|
|
626
544
|
Locale.addLocale('en', noopLocale);
|
|
627
545
|
Locale.addLocale('s', noopLocale);
|
|
@@ -631,77 +549,67 @@ Locale.useLocale('en');
|
|
|
631
549
|
/*
|
|
632
550
|
* More minimal HDate
|
|
633
551
|
*/
|
|
634
|
-
const NISAN$1 = 1;
|
|
635
|
-
const IYYAR = 2; // const SIVAN = 3;
|
|
636
|
-
|
|
637
|
-
const TAMUZ = 4; // const AV = 5;
|
|
638
552
|
|
|
553
|
+
const NISAN$1 = 1;
|
|
554
|
+
const IYYAR = 2;
|
|
555
|
+
// const SIVAN = 3;
|
|
556
|
+
const TAMUZ = 4;
|
|
557
|
+
// const AV = 5;
|
|
639
558
|
const ELUL = 6;
|
|
640
559
|
const TISHREI = 7;
|
|
641
560
|
const CHESHVAN$1 = 8;
|
|
642
561
|
const KISLEV$1 = 9;
|
|
643
|
-
const TEVET$1 = 10;
|
|
644
|
-
|
|
562
|
+
const TEVET$1 = 10;
|
|
563
|
+
// const SHVAT = 11;
|
|
645
564
|
const ADAR_I$1 = 12;
|
|
646
565
|
const ADAR_II$1 = 13;
|
|
566
|
+
|
|
647
567
|
/**
|
|
648
568
|
* Hebrew months of the year (NISAN=1, TISHREI=7)
|
|
649
569
|
* @readonly
|
|
650
570
|
* @enum {number}
|
|
651
571
|
*/
|
|
652
|
-
|
|
653
572
|
const months = {
|
|
654
573
|
/** Nissan / ניסן */
|
|
655
574
|
NISAN: 1,
|
|
656
|
-
|
|
657
575
|
/** Iyyar / אייר */
|
|
658
576
|
IYYAR: 2,
|
|
659
|
-
|
|
660
577
|
/** Sivan / סיון */
|
|
661
578
|
SIVAN: 3,
|
|
662
|
-
|
|
663
579
|
/** Tamuz (sometimes Tammuz) / תמוז */
|
|
664
580
|
TAMUZ: 4,
|
|
665
|
-
|
|
666
581
|
/** Av / אב */
|
|
667
582
|
AV: 5,
|
|
668
|
-
|
|
669
583
|
/** Elul / אלול */
|
|
670
584
|
ELUL: 6,
|
|
671
|
-
|
|
672
585
|
/** Tishrei / תִשְׁרֵי */
|
|
673
586
|
TISHREI: 7,
|
|
674
|
-
|
|
675
587
|
/** Cheshvan / חשון */
|
|
676
588
|
CHESHVAN: 8,
|
|
677
|
-
|
|
678
589
|
/** Kislev / כסלו */
|
|
679
590
|
KISLEV: 9,
|
|
680
|
-
|
|
681
591
|
/** Tevet / טבת */
|
|
682
592
|
TEVET: 10,
|
|
683
|
-
|
|
684
593
|
/** Sh'vat / שבט */
|
|
685
594
|
SHVAT: 11,
|
|
686
|
-
|
|
687
595
|
/** Adar or Adar Rishon / אדר */
|
|
688
596
|
ADAR_I: 12,
|
|
689
|
-
|
|
690
597
|
/** Adar Sheini (only on leap years) / אדר ב׳ */
|
|
691
598
|
ADAR_II: 13
|
|
692
599
|
};
|
|
693
600
|
const monthNames0 = ['', 'Nisan', 'Iyyar', 'Sivan', 'Tamuz', 'Av', 'Elul', 'Tishrei', 'Cheshvan', 'Kislev', 'Tevet', 'Sh\'vat'];
|
|
601
|
+
|
|
694
602
|
/**
|
|
695
603
|
* Transliterations of Hebrew month names.
|
|
696
604
|
* Regular years are index 0 and leap years are index 1.
|
|
697
605
|
* @private
|
|
698
606
|
*/
|
|
699
|
-
|
|
700
607
|
const monthNames = [monthNames0.concat(['Adar', 'Nisan']), monthNames0.concat(['Adar I', 'Adar II', 'Nisan'])];
|
|
701
608
|
const edCache = Object.create(null);
|
|
702
|
-
const EPOCH = -1373428;
|
|
703
|
-
|
|
609
|
+
const EPOCH = -1373428;
|
|
610
|
+
// Avg year length in the cycle (19 solar years with 235 lunar months)
|
|
704
611
|
const AVG_HEBYEAR_DAYS = 365.24682220597794;
|
|
612
|
+
|
|
705
613
|
/**
|
|
706
614
|
* Converts Hebrew date to R.D. (Rata Die) fixed days.
|
|
707
615
|
* R.D. 1 is the imaginary date Monday, January 1, 1 on the Gregorian
|
|
@@ -712,15 +620,12 @@ const AVG_HEBYEAR_DAYS = 365.24682220597794;
|
|
|
712
620
|
* @param {number} day Hebrew date (1-30)
|
|
713
621
|
* @return {number}
|
|
714
622
|
*/
|
|
715
|
-
|
|
716
623
|
function hebrew2abs(year, month, day) {
|
|
717
624
|
let tempabs = day;
|
|
718
|
-
|
|
719
625
|
if (month < TISHREI) {
|
|
720
626
|
for (let m = TISHREI; m <= monthsInYear(year); m++) {
|
|
721
627
|
tempabs += daysInMonth(m, year);
|
|
722
628
|
}
|
|
723
|
-
|
|
724
629
|
for (let m = NISAN$1; m < month; m++) {
|
|
725
630
|
tempabs += daysInMonth(m, year);
|
|
726
631
|
}
|
|
@@ -729,46 +634,40 @@ function hebrew2abs(year, month, day) {
|
|
|
729
634
|
tempabs += daysInMonth(m, year);
|
|
730
635
|
}
|
|
731
636
|
}
|
|
732
|
-
|
|
733
637
|
return EPOCH + elapsedDays(year) + tempabs - 1;
|
|
734
638
|
}
|
|
639
|
+
|
|
735
640
|
/**
|
|
736
641
|
* @private
|
|
737
642
|
* @param {number} year
|
|
738
643
|
* @return {number}
|
|
739
644
|
*/
|
|
740
|
-
|
|
741
645
|
function newYear(year) {
|
|
742
646
|
return EPOCH + elapsedDays(year);
|
|
743
647
|
}
|
|
648
|
+
|
|
744
649
|
/**
|
|
745
650
|
* Converts absolute R.D. days to Hebrew date
|
|
746
651
|
* @private
|
|
747
652
|
* @param {number} abs absolute R.D. days
|
|
748
653
|
* @return {SimpleHebrewDate}
|
|
749
654
|
*/
|
|
750
|
-
|
|
751
|
-
|
|
752
655
|
function abs2hebrew(abs) {
|
|
753
656
|
if (typeof abs !== 'number' || isNaN(abs)) {
|
|
754
657
|
throw new TypeError(`invalid parameter to abs2hebrew ${abs}`);
|
|
755
658
|
}
|
|
659
|
+
abs = Math.trunc(abs);
|
|
756
660
|
|
|
757
|
-
|
|
758
|
-
|
|
661
|
+
// first, quickly approximate year
|
|
759
662
|
let year = Math.floor((abs - EPOCH) / AVG_HEBYEAR_DAYS);
|
|
760
|
-
|
|
761
663
|
while (newYear(year) <= abs) {
|
|
762
664
|
++year;
|
|
763
665
|
}
|
|
764
|
-
|
|
765
666
|
--year;
|
|
766
667
|
let month = abs < hebrew2abs(year, 1, 1) ? 7 : 1;
|
|
767
|
-
|
|
768
668
|
while (abs > hebrew2abs(year, month, daysInMonth(month, year))) {
|
|
769
669
|
++month;
|
|
770
670
|
}
|
|
771
|
-
|
|
772
671
|
const day = 1 + abs - hebrew2abs(year, month, 1);
|
|
773
672
|
return {
|
|
774
673
|
yy: year,
|
|
@@ -776,26 +675,27 @@ function abs2hebrew(abs) {
|
|
|
776
675
|
dd: day
|
|
777
676
|
};
|
|
778
677
|
}
|
|
678
|
+
|
|
779
679
|
/**
|
|
780
680
|
* Returns true if Hebrew year is a leap year
|
|
781
681
|
* @private
|
|
782
682
|
* @param {number} year Hebrew year
|
|
783
683
|
* @return {boolean}
|
|
784
684
|
*/
|
|
785
|
-
|
|
786
685
|
function isLeapYear(year) {
|
|
787
686
|
return (1 + year * 7) % 19 < 7;
|
|
788
687
|
}
|
|
688
|
+
|
|
789
689
|
/**
|
|
790
690
|
* Number of months in this Hebrew year (either 12 or 13 depending on leap year)
|
|
791
691
|
* @private
|
|
792
692
|
* @param {number} year Hebrew year
|
|
793
693
|
* @return {number}
|
|
794
694
|
*/
|
|
795
|
-
|
|
796
695
|
function monthsInYear(year) {
|
|
797
696
|
return 12 + isLeapYear(year); // boolean is cast to 1 or 0
|
|
798
697
|
}
|
|
698
|
+
|
|
799
699
|
/**
|
|
800
700
|
* Number of days in Hebrew month in a given year (29 or 30)
|
|
801
701
|
* @private
|
|
@@ -803,7 +703,6 @@ function monthsInYear(year) {
|
|
|
803
703
|
* @param {number} year Hebrew year
|
|
804
704
|
* @return {number}
|
|
805
705
|
*/
|
|
806
|
-
|
|
807
706
|
function daysInMonth(month, year) {
|
|
808
707
|
switch (month) {
|
|
809
708
|
case IYYAR:
|
|
@@ -813,13 +712,13 @@ function daysInMonth(month, year) {
|
|
|
813
712
|
case ADAR_II$1:
|
|
814
713
|
return 29;
|
|
815
714
|
}
|
|
816
|
-
|
|
817
715
|
if (month === ADAR_I$1 && !isLeapYear(year) || month === CHESHVAN$1 && !longCheshvan(year) || month === KISLEV$1 && shortKislev(year)) {
|
|
818
716
|
return 29;
|
|
819
717
|
} else {
|
|
820
718
|
return 30;
|
|
821
719
|
}
|
|
822
720
|
}
|
|
721
|
+
|
|
823
722
|
/**
|
|
824
723
|
* Returns a transliterated string name of Hebrew month in year,
|
|
825
724
|
* for example 'Elul' or 'Cheshvan'.
|
|
@@ -828,14 +727,13 @@ function daysInMonth(month, year) {
|
|
|
828
727
|
* @param {number} year Hebrew year
|
|
829
728
|
* @return {string}
|
|
830
729
|
*/
|
|
831
|
-
|
|
832
730
|
function getMonthName(month, year) {
|
|
833
731
|
if (typeof month !== 'number' || isNaN(month) || month < 1 || month > 14) {
|
|
834
732
|
throw new TypeError(`bad month argument ${month}`);
|
|
835
733
|
}
|
|
836
|
-
|
|
837
734
|
return monthNames[+isLeapYear(year)][month];
|
|
838
735
|
}
|
|
736
|
+
|
|
839
737
|
/**
|
|
840
738
|
* Days from sunday prior to start of Hebrew calendar to mean
|
|
841
739
|
* conjunction of Tishrei in Hebrew YEAR
|
|
@@ -843,11 +741,11 @@ function getMonthName(month, year) {
|
|
|
843
741
|
* @param {number} year Hebrew year
|
|
844
742
|
* @return {number}
|
|
845
743
|
*/
|
|
846
|
-
|
|
847
744
|
function elapsedDays(year) {
|
|
848
745
|
const elapsed = edCache[year] = edCache[year] || elapsedDays0(year);
|
|
849
746
|
return elapsed;
|
|
850
747
|
}
|
|
748
|
+
|
|
851
749
|
/**
|
|
852
750
|
* Days from sunday prior to start of Hebrew calendar to mean
|
|
853
751
|
* conjunction of Tishrei in Hebrew YEAR
|
|
@@ -855,11 +753,12 @@ function elapsedDays(year) {
|
|
|
855
753
|
* @param {number} year Hebrew year
|
|
856
754
|
* @return {number}
|
|
857
755
|
*/
|
|
858
|
-
|
|
859
756
|
function elapsedDays0(year) {
|
|
860
757
|
const prevYear = year - 1;
|
|
861
|
-
const mElapsed = 235 * Math.floor(prevYear / 19) +
|
|
862
|
-
|
|
758
|
+
const mElapsed = 235 * Math.floor(prevYear / 19) +
|
|
759
|
+
// Months in complete 19 year lunar (Metonic) cycles so far
|
|
760
|
+
12 * (prevYear % 19) +
|
|
761
|
+
// Regular months in this cycle
|
|
863
762
|
Math.floor((prevYear % 19 * 7 + 1) / 19); // Leap months this cycle
|
|
864
763
|
|
|
865
764
|
const pElapsed = 204 + 793 * (mElapsed % 1080);
|
|
@@ -869,6 +768,7 @@ function elapsedDays0(year) {
|
|
|
869
768
|
const altDay = day + (parts >= 19440 || 2 === day % 7 && parts >= 9924 && !isLeapYear(year) || 1 === day % 7 && parts >= 16789 && isLeapYear(prevYear));
|
|
870
769
|
return altDay + (altDay % 7 === 0 || altDay % 7 === 3 || altDay % 7 === 5);
|
|
871
770
|
}
|
|
771
|
+
|
|
872
772
|
/**
|
|
873
773
|
* Number of days in the hebrew YEAR.
|
|
874
774
|
* A common Hebrew calendar year can have a length of 353, 354 or 355 days
|
|
@@ -877,28 +777,26 @@ function elapsedDays0(year) {
|
|
|
877
777
|
* @param {number} year Hebrew year
|
|
878
778
|
* @return {number}
|
|
879
779
|
*/
|
|
880
|
-
|
|
881
|
-
|
|
882
780
|
function daysInYear(year) {
|
|
883
781
|
return elapsedDays(year + 1) - elapsedDays(year);
|
|
884
782
|
}
|
|
783
|
+
|
|
885
784
|
/**
|
|
886
785
|
* true if Cheshvan is long in Hebrew year
|
|
887
786
|
* @private
|
|
888
787
|
* @param {number} year Hebrew year
|
|
889
788
|
* @return {boolean}
|
|
890
789
|
*/
|
|
891
|
-
|
|
892
790
|
function longCheshvan(year) {
|
|
893
791
|
return daysInYear(year) % 10 === 5;
|
|
894
792
|
}
|
|
793
|
+
|
|
895
794
|
/**
|
|
896
795
|
* true if Kislev is short in Hebrew year
|
|
897
796
|
* @private
|
|
898
797
|
* @param {number} year Hebrew year
|
|
899
798
|
* @return {boolean}
|
|
900
799
|
*/
|
|
901
|
-
|
|
902
800
|
function shortKislev(year) {
|
|
903
801
|
return daysInYear(year) % 10 === 3;
|
|
904
802
|
}
|
|
@@ -924,10 +822,10 @@ function shortKislev(year) {
|
|
|
924
822
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
925
823
|
*/
|
|
926
824
|
|
|
825
|
+
// eslint-disable-next-line require-jsdoc
|
|
927
826
|
function throwTypeError(msg) {
|
|
928
827
|
throw new TypeError(msg);
|
|
929
828
|
}
|
|
930
|
-
|
|
931
829
|
const UNITS_DAY = 'day';
|
|
932
830
|
const UNITS_WEEK = 'week';
|
|
933
831
|
const UNITS_MONTH = 'month';
|
|
@@ -944,6 +842,7 @@ const UNITS_VALID = {
|
|
|
944
842
|
month: UNITS_MONTH,
|
|
945
843
|
year: UNITS_YEAR
|
|
946
844
|
};
|
|
845
|
+
|
|
947
846
|
/**
|
|
948
847
|
* A simple Hebrew date object with numeric fields `yy`, `mm`, and `dd`
|
|
949
848
|
* @typedef {Object} SimpleHebrewDate
|
|
@@ -954,7 +853,6 @@ const UNITS_VALID = {
|
|
|
954
853
|
*/
|
|
955
854
|
|
|
956
855
|
/** Represents a Hebrew date */
|
|
957
|
-
|
|
958
856
|
class HDate {
|
|
959
857
|
/**
|
|
960
858
|
* Create a Hebrew date. There are 3 basic forms for the `HDate()` constructor.
|
|
@@ -990,10 +888,8 @@ class HDate {
|
|
|
990
888
|
if (arguments.length == 2 || arguments.length > 3) {
|
|
991
889
|
throw new TypeError('HDate constructor requires 0, 1 or 3 arguments');
|
|
992
890
|
}
|
|
993
|
-
|
|
994
891
|
if (arguments.length == 3) {
|
|
995
892
|
// Hebrew day, Hebrew month, Hebrew year
|
|
996
|
-
|
|
997
893
|
/**
|
|
998
894
|
* @private
|
|
999
895
|
* @type {number}
|
|
@@ -1003,30 +899,23 @@ class HDate {
|
|
|
1003
899
|
* @private
|
|
1004
900
|
* @type {number}
|
|
1005
901
|
*/
|
|
1006
|
-
|
|
1007
902
|
year = parseInt(year, 10);
|
|
1008
|
-
|
|
1009
903
|
if (isNaN(year)) {
|
|
1010
904
|
throw new TypeError(`HDate called with bad year argument: ${year}`);
|
|
1011
905
|
}
|
|
1012
|
-
|
|
1013
906
|
this.year = year;
|
|
1014
907
|
this.setMonth(month); // will throw if we can't parse
|
|
1015
|
-
|
|
1016
908
|
day = parseInt(day, 10);
|
|
1017
|
-
|
|
1018
909
|
if (isNaN(day)) {
|
|
1019
910
|
throw new TypeError(`HDate called with bad day argument: ${day}`);
|
|
1020
911
|
}
|
|
1021
|
-
|
|
1022
912
|
this.setDate(day);
|
|
1023
913
|
} else {
|
|
1024
914
|
// 0 arguments
|
|
1025
915
|
if (typeof day === 'undefined') {
|
|
1026
916
|
day = new Date();
|
|
1027
|
-
}
|
|
1028
|
-
|
|
1029
|
-
|
|
917
|
+
}
|
|
918
|
+
// 1 argument
|
|
1030
919
|
const abs0 = typeof day === 'number' && !isNaN(day) ? day : isDate(day) ? greg2abs(day) : HDate.isHDate(day) ? {
|
|
1031
920
|
dd: day.day,
|
|
1032
921
|
mm: day.month,
|
|
@@ -1038,21 +927,17 @@ class HDate {
|
|
|
1038
927
|
* @private
|
|
1039
928
|
* @type {number}
|
|
1040
929
|
*/
|
|
1041
|
-
|
|
1042
930
|
this.day = d.dd;
|
|
1043
931
|
/**
|
|
1044
932
|
* @private
|
|
1045
933
|
* @type {number}
|
|
1046
934
|
*/
|
|
1047
|
-
|
|
1048
935
|
this.month = d.mm;
|
|
1049
936
|
/**
|
|
1050
937
|
* @private
|
|
1051
938
|
* @type {number}
|
|
1052
939
|
*/
|
|
1053
|
-
|
|
1054
940
|
this.year = d.yy;
|
|
1055
|
-
|
|
1056
941
|
if (isNumber) {
|
|
1057
942
|
/**
|
|
1058
943
|
* @private
|
|
@@ -1062,70 +947,64 @@ class HDate {
|
|
|
1062
947
|
}
|
|
1063
948
|
}
|
|
1064
949
|
}
|
|
950
|
+
|
|
1065
951
|
/**
|
|
1066
952
|
* Gets the Hebrew year of this Hebrew date
|
|
1067
953
|
* @return {number}
|
|
1068
954
|
*/
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
955
|
getFullYear() {
|
|
1072
956
|
return this.year;
|
|
1073
957
|
}
|
|
958
|
+
|
|
1074
959
|
/**
|
|
1075
960
|
* Tests if this date occurs during a leap year
|
|
1076
961
|
* @return {boolean}
|
|
1077
962
|
*/
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
963
|
isLeapYear() {
|
|
1081
964
|
return isLeapYear(this.year);
|
|
1082
965
|
}
|
|
966
|
+
|
|
1083
967
|
/**
|
|
1084
968
|
* Gets the Hebrew month (1=NISAN, 7=TISHREI) of this Hebrew date
|
|
1085
969
|
* @return {number}
|
|
1086
970
|
*/
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
971
|
getMonth() {
|
|
1090
972
|
return this.month;
|
|
1091
973
|
}
|
|
974
|
+
|
|
1092
975
|
/**
|
|
1093
976
|
* The Tishrei-based month of the date. 1 is Tishrei, 7 is Nisan, 13 is Elul in a leap year
|
|
1094
977
|
* @return {number}
|
|
1095
978
|
*/
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
979
|
getTishreiMonth() {
|
|
1099
980
|
const nummonths = monthsInYear(this.getFullYear());
|
|
1100
981
|
return (this.getMonth() + nummonths - 6) % nummonths || nummonths;
|
|
1101
982
|
}
|
|
983
|
+
|
|
1102
984
|
/**
|
|
1103
985
|
* Number of days in the month of this Hebrew date
|
|
1104
986
|
* @return {number}
|
|
1105
987
|
*/
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
988
|
daysInMonth() {
|
|
1109
989
|
return daysInMonth(this.getMonth(), this.getFullYear());
|
|
1110
990
|
}
|
|
991
|
+
|
|
1111
992
|
/**
|
|
1112
993
|
* Gets the day within the month (1-30)
|
|
1113
994
|
* @return {number}
|
|
1114
995
|
*/
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
996
|
getDate() {
|
|
1118
997
|
return this.day;
|
|
1119
998
|
}
|
|
999
|
+
|
|
1120
1000
|
/**
|
|
1121
1001
|
* Gets the day of the week. 0=Sunday, 6=Saturday
|
|
1122
1002
|
* @return {number}
|
|
1123
1003
|
*/
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
1004
|
getDay() {
|
|
1127
1005
|
return mod(this.abs(), 7);
|
|
1128
1006
|
}
|
|
1007
|
+
|
|
1129
1008
|
/**
|
|
1130
1009
|
* Sets the year of the date. Returns the object it was called upon.
|
|
1131
1010
|
* @private
|
|
@@ -1133,47 +1012,43 @@ class HDate {
|
|
|
1133
1012
|
* @param {number} year
|
|
1134
1013
|
* @return {HDate}
|
|
1135
1014
|
*/
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
1015
|
setFullYear(year) {
|
|
1139
1016
|
this.year = year;
|
|
1140
1017
|
fix(this);
|
|
1141
1018
|
return this;
|
|
1142
1019
|
}
|
|
1020
|
+
|
|
1143
1021
|
/**
|
|
1144
1022
|
* Sets the day of the month of the date. Returns the object it was called upon
|
|
1145
1023
|
* @private
|
|
1146
1024
|
* @param {number} month
|
|
1147
1025
|
* @return {HDate}
|
|
1148
1026
|
*/
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
1027
|
setMonth(month) {
|
|
1152
1028
|
this.month = HDate.monthNum(month);
|
|
1153
1029
|
fix(this);
|
|
1154
1030
|
return this;
|
|
1155
1031
|
}
|
|
1032
|
+
|
|
1156
1033
|
/**
|
|
1157
1034
|
* @private
|
|
1158
1035
|
* @param {number} date
|
|
1159
1036
|
* @return {HDate}
|
|
1160
1037
|
*/
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
1038
|
setDate(date) {
|
|
1164
1039
|
this.day = date;
|
|
1165
1040
|
fix(this);
|
|
1166
1041
|
return this;
|
|
1167
1042
|
}
|
|
1043
|
+
|
|
1168
1044
|
/**
|
|
1169
1045
|
* Converts to Gregorian date
|
|
1170
1046
|
* @return {Date}
|
|
1171
1047
|
*/
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
1048
|
greg() {
|
|
1175
1049
|
return abs2greg(this.abs());
|
|
1176
1050
|
}
|
|
1051
|
+
|
|
1177
1052
|
/**
|
|
1178
1053
|
* Returns R.D. (Rata Die) fixed days.
|
|
1179
1054
|
* R.D. 1 == Monday, January 1, 1 (Gregorian)
|
|
@@ -1181,15 +1056,13 @@ class HDate {
|
|
|
1181
1056
|
* https://en.wikipedia.org/wiki/Rata_Die#Dershowitz_and_Reingold
|
|
1182
1057
|
* @return {number}
|
|
1183
1058
|
*/
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
1059
|
abs() {
|
|
1187
1060
|
if (typeof this.abs0 !== 'number') {
|
|
1188
1061
|
this.abs0 = hebrew2abs(this.year, this.month, this.day);
|
|
1189
1062
|
}
|
|
1190
|
-
|
|
1191
1063
|
return this.abs0;
|
|
1192
1064
|
}
|
|
1065
|
+
|
|
1193
1066
|
/**
|
|
1194
1067
|
* Converts Hebrew date to R.D. (Rata Die) fixed days.
|
|
1195
1068
|
* R.D. 1 is the imaginary date Monday, January 1, 1 on the Gregorian
|
|
@@ -1199,31 +1072,28 @@ class HDate {
|
|
|
1199
1072
|
* @param {number} day Hebrew date (1-30)
|
|
1200
1073
|
* @return {number}
|
|
1201
1074
|
*/
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
1075
|
static hebrew2abs(year, month, day) {
|
|
1205
1076
|
return hebrew2abs(year, month, day);
|
|
1206
1077
|
}
|
|
1078
|
+
|
|
1207
1079
|
/**
|
|
1208
1080
|
* Converts absolute R.D. days to Hebrew date
|
|
1209
1081
|
* @private
|
|
1210
1082
|
* @param {number} abs absolute R.D. days
|
|
1211
1083
|
* @return {SimpleHebrewDate}
|
|
1212
1084
|
*/
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
1085
|
static abs2hebrew(abs) {
|
|
1216
1086
|
return abs2hebrew(abs);
|
|
1217
1087
|
}
|
|
1088
|
+
|
|
1218
1089
|
/**
|
|
1219
1090
|
* Returns a transliterated Hebrew month name, e.g. `'Elul'` or `'Cheshvan'`.
|
|
1220
1091
|
* @return {string}
|
|
1221
1092
|
*/
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
1093
|
getMonthName() {
|
|
1225
1094
|
return getMonthName(this.getMonth(), this.getFullYear());
|
|
1226
1095
|
}
|
|
1096
|
+
|
|
1227
1097
|
/**
|
|
1228
1098
|
* Renders this Hebrew date as a translated or transliterated string,
|
|
1229
1099
|
* including ordinal e.g. `'15th of Cheshvan, 5769'`.
|
|
@@ -1237,8 +1107,6 @@ class HDate {
|
|
|
1237
1107
|
* @param {boolean} [showYear=true] Display year (defaults to true).
|
|
1238
1108
|
* @return {string}
|
|
1239
1109
|
*/
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
1110
|
render(locale = null, showYear = true) {
|
|
1243
1111
|
const locale0 = locale || Locale.getLocaleName();
|
|
1244
1112
|
const day = this.getDate();
|
|
@@ -1246,7 +1114,6 @@ class HDate {
|
|
|
1246
1114
|
const nth = Locale.ordinal(day, locale0);
|
|
1247
1115
|
const dayOf = HDate.getDayOfTranslation(locale0);
|
|
1248
1116
|
const dateStr = `${nth}${dayOf} ${monthName}`;
|
|
1249
|
-
|
|
1250
1117
|
if (showYear) {
|
|
1251
1118
|
const fullYear = this.getFullYear();
|
|
1252
1119
|
return `${dateStr}, ${fullYear}`;
|
|
@@ -1254,13 +1121,12 @@ class HDate {
|
|
|
1254
1121
|
return dateStr;
|
|
1255
1122
|
}
|
|
1256
1123
|
}
|
|
1124
|
+
|
|
1257
1125
|
/**
|
|
1258
1126
|
* @private
|
|
1259
1127
|
* @param {string} locale
|
|
1260
1128
|
* @return {string}
|
|
1261
1129
|
*/
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
1130
|
static getDayOfTranslation(locale) {
|
|
1265
1131
|
switch (locale) {
|
|
1266
1132
|
case 'en':
|
|
@@ -1269,19 +1135,16 @@ class HDate {
|
|
|
1269
1135
|
case 'ashkenazi':
|
|
1270
1136
|
return ' of';
|
|
1271
1137
|
}
|
|
1272
|
-
|
|
1273
1138
|
const ofStr = Locale.lookupTranslation('of', locale);
|
|
1274
|
-
|
|
1275
1139
|
if (ofStr) {
|
|
1276
1140
|
return ' ' + ofStr;
|
|
1277
1141
|
}
|
|
1278
|
-
|
|
1279
1142
|
if ('ashkenazi' === locale.substring(0, 9)) {
|
|
1280
1143
|
return ' of';
|
|
1281
1144
|
}
|
|
1282
|
-
|
|
1283
1145
|
return '';
|
|
1284
1146
|
}
|
|
1147
|
+
|
|
1285
1148
|
/**
|
|
1286
1149
|
* Renders this Hebrew date in Hebrew gematriya, regardless of locale.
|
|
1287
1150
|
* @example
|
|
@@ -1290,14 +1153,13 @@ class HDate {
|
|
|
1290
1153
|
* console.log(hd.renderGematriya()); // 'ט״ו חֶשְׁוָן תשס״ט'
|
|
1291
1154
|
* @return {string}
|
|
1292
1155
|
*/
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
1156
|
renderGematriya() {
|
|
1296
1157
|
const d = this.getDate();
|
|
1297
1158
|
const m = Locale.gettext(this.getMonthName(), 'he');
|
|
1298
1159
|
const y = this.getFullYear();
|
|
1299
1160
|
return gematriya(d) + ' ' + m + ' ' + gematriya(y);
|
|
1300
1161
|
}
|
|
1162
|
+
|
|
1301
1163
|
/**
|
|
1302
1164
|
* Returns an `HDate` representing the a dayNumber before the current date.
|
|
1303
1165
|
* Sunday=0, Saturday=6
|
|
@@ -1306,11 +1168,10 @@ class HDate {
|
|
|
1306
1168
|
* @param {number} day day of week
|
|
1307
1169
|
* @return {HDate}
|
|
1308
1170
|
*/
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
1171
|
before(day) {
|
|
1312
1172
|
return onOrBefore(day, this, -1);
|
|
1313
1173
|
}
|
|
1174
|
+
|
|
1314
1175
|
/**
|
|
1315
1176
|
* Returns an `HDate` representing the a dayNumber on or before the current date.
|
|
1316
1177
|
* Sunday=0, Saturday=6
|
|
@@ -1321,11 +1182,10 @@ class HDate {
|
|
|
1321
1182
|
* @param {number} dow day of week
|
|
1322
1183
|
* @return {HDate}
|
|
1323
1184
|
*/
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
1185
|
onOrBefore(dow) {
|
|
1327
1186
|
return onOrBefore(dow, this, 0);
|
|
1328
1187
|
}
|
|
1188
|
+
|
|
1329
1189
|
/**
|
|
1330
1190
|
* Returns an `HDate` representing the nearest dayNumber to the current date
|
|
1331
1191
|
* Sunday=0, Saturday=6
|
|
@@ -1335,11 +1195,10 @@ class HDate {
|
|
|
1335
1195
|
* @param {number} dow day of week
|
|
1336
1196
|
* @return {HDate}
|
|
1337
1197
|
*/
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
1198
|
nearest(dow) {
|
|
1341
1199
|
return onOrBefore(dow, this, 3);
|
|
1342
1200
|
}
|
|
1201
|
+
|
|
1343
1202
|
/**
|
|
1344
1203
|
* Returns an `HDate` representing the a dayNumber on or after the current date.
|
|
1345
1204
|
* Sunday=0, Saturday=6
|
|
@@ -1350,11 +1209,10 @@ class HDate {
|
|
|
1350
1209
|
* @param {number} dow day of week
|
|
1351
1210
|
* @return {HDate}
|
|
1352
1211
|
*/
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
1212
|
onOrAfter(dow) {
|
|
1356
1213
|
return onOrBefore(dow, this, 6);
|
|
1357
1214
|
}
|
|
1215
|
+
|
|
1358
1216
|
/**
|
|
1359
1217
|
* Returns an `HDate` representing the a dayNumber after the current date.
|
|
1360
1218
|
* Sunday=0, Saturday=6
|
|
@@ -1365,29 +1223,26 @@ class HDate {
|
|
|
1365
1223
|
* @param {number} day day of week
|
|
1366
1224
|
* @return {HDate}
|
|
1367
1225
|
*/
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
1226
|
after(day) {
|
|
1371
1227
|
return onOrBefore(day, this, 7);
|
|
1372
1228
|
}
|
|
1229
|
+
|
|
1373
1230
|
/**
|
|
1374
1231
|
* Returns the next Hebrew date
|
|
1375
1232
|
* @return {HDate}
|
|
1376
1233
|
*/
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
1234
|
next() {
|
|
1380
1235
|
return new HDate(this.abs() + 1);
|
|
1381
1236
|
}
|
|
1237
|
+
|
|
1382
1238
|
/**
|
|
1383
1239
|
* Returns the previous Hebrew date
|
|
1384
1240
|
* @return {HDate}
|
|
1385
1241
|
*/
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
1242
|
prev() {
|
|
1389
1243
|
return new HDate(this.abs() - 1);
|
|
1390
1244
|
}
|
|
1245
|
+
|
|
1391
1246
|
/**
|
|
1392
1247
|
* Returns a cloned `HDate` object with a specified amount of time added
|
|
1393
1248
|
*
|
|
@@ -1404,17 +1259,12 @@ class HDate {
|
|
|
1404
1259
|
* @param {string} [units]
|
|
1405
1260
|
* @return {HDate}
|
|
1406
1261
|
*/
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
1262
|
add(number, units = 'd') {
|
|
1410
1263
|
number = parseInt(number, 10);
|
|
1411
|
-
|
|
1412
1264
|
if (!number) {
|
|
1413
1265
|
return new HDate(this);
|
|
1414
1266
|
}
|
|
1415
|
-
|
|
1416
1267
|
units = HDate.standardizeUnits(units);
|
|
1417
|
-
|
|
1418
1268
|
if (units === UNITS_DAY) {
|
|
1419
1269
|
return new HDate(this.abs() + number);
|
|
1420
1270
|
} else if (units === UNITS_WEEK) {
|
|
@@ -1425,25 +1275,23 @@ class HDate {
|
|
|
1425
1275
|
let hd = new HDate(this);
|
|
1426
1276
|
const sign = number > 0 ? 1 : -1;
|
|
1427
1277
|
number = Math.abs(number);
|
|
1428
|
-
|
|
1429
1278
|
for (let i = 0; i < number; i++) {
|
|
1430
1279
|
hd = new HDate(hd.abs() + sign * hd.daysInMonth());
|
|
1431
1280
|
}
|
|
1432
|
-
|
|
1433
1281
|
return hd;
|
|
1434
1282
|
}
|
|
1435
1283
|
}
|
|
1284
|
+
|
|
1436
1285
|
/**
|
|
1437
1286
|
* @private
|
|
1438
1287
|
* @param {string} units
|
|
1439
1288
|
* @return {string}
|
|
1440
1289
|
*/
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
1290
|
static standardizeUnits(units) {
|
|
1444
1291
|
const full = UNITS_SINGLE[units] || String(units || '').toLowerCase().replace(/s$/, '');
|
|
1445
1292
|
return UNITS_VALID[full] || throwTypeError(`Invalid units '${units}'`);
|
|
1446
1293
|
}
|
|
1294
|
+
|
|
1447
1295
|
/**
|
|
1448
1296
|
* Returns a cloned `HDate` object with a specified amount of time subracted
|
|
1449
1297
|
*
|
|
@@ -1466,11 +1314,10 @@ class HDate {
|
|
|
1466
1314
|
* @param {string} [units]
|
|
1467
1315
|
* @return {HDate}
|
|
1468
1316
|
*/
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
1317
|
subtract(number, units = 'd') {
|
|
1472
1318
|
return this.add(number * -1, units);
|
|
1473
1319
|
}
|
|
1320
|
+
|
|
1474
1321
|
/**
|
|
1475
1322
|
* Returns the difference in days between the two given HDates.
|
|
1476
1323
|
*
|
|
@@ -1488,69 +1335,61 @@ class HDate {
|
|
|
1488
1335
|
* @param {HDate} other Hebrew date to compare
|
|
1489
1336
|
* @return {number}
|
|
1490
1337
|
*/
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
1338
|
deltaDays(other) {
|
|
1494
1339
|
if (!HDate.isHDate(other)) {
|
|
1495
1340
|
throw new TypeError(`Bad argument: ${other}`);
|
|
1496
1341
|
}
|
|
1497
|
-
|
|
1498
1342
|
return this.abs() - other.abs();
|
|
1499
1343
|
}
|
|
1344
|
+
|
|
1500
1345
|
/**
|
|
1501
1346
|
* Compares this date to another date, returning `true` if the dates match.
|
|
1502
1347
|
* @param {HDate} other Hebrew date to compare
|
|
1503
1348
|
* @return {boolean}
|
|
1504
1349
|
*/
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
1350
|
isSameDate(other) {
|
|
1508
1351
|
if (HDate.isHDate(other)) {
|
|
1509
1352
|
return this.year == other.year && this.month == other.month && this.day == other.day;
|
|
1510
1353
|
}
|
|
1511
|
-
|
|
1512
1354
|
return false;
|
|
1513
1355
|
}
|
|
1514
|
-
/** @return {string} */
|
|
1515
|
-
|
|
1516
1356
|
|
|
1357
|
+
/** @return {string} */
|
|
1517
1358
|
toString() {
|
|
1518
1359
|
const day = this.getDate();
|
|
1519
1360
|
const fullYear = this.getFullYear();
|
|
1520
1361
|
const monthName = this.getMonthName();
|
|
1521
1362
|
return `${day} ${monthName} ${fullYear}`;
|
|
1522
1363
|
}
|
|
1364
|
+
|
|
1523
1365
|
/**
|
|
1524
1366
|
* Returns true if Hebrew year is a leap year
|
|
1525
1367
|
* @param {number} year Hebrew year
|
|
1526
1368
|
* @return {boolean}
|
|
1527
1369
|
*/
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
1370
|
static isLeapYear(year) {
|
|
1531
1371
|
return isLeapYear(year);
|
|
1532
1372
|
}
|
|
1373
|
+
|
|
1533
1374
|
/**
|
|
1534
1375
|
* Number of months in this Hebrew year (either 12 or 13 depending on leap year)
|
|
1535
1376
|
* @param {number} year Hebrew year
|
|
1536
1377
|
* @return {number}
|
|
1537
1378
|
*/
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
1379
|
static monthsInYear(year) {
|
|
1541
1380
|
return monthsInYear(year);
|
|
1542
1381
|
}
|
|
1382
|
+
|
|
1543
1383
|
/**
|
|
1544
1384
|
* Number of days in Hebrew month in a given year (29 or 30)
|
|
1545
1385
|
* @param {number} month Hebrew month (e.g. months.TISHREI)
|
|
1546
1386
|
* @param {number} year Hebrew year
|
|
1547
1387
|
* @return {number}
|
|
1548
1388
|
*/
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
1389
|
static daysInMonth(month, year) {
|
|
1552
1390
|
return daysInMonth(month, year);
|
|
1553
1391
|
}
|
|
1392
|
+
|
|
1554
1393
|
/**
|
|
1555
1394
|
* Returns a transliterated string name of Hebrew month in year,
|
|
1556
1395
|
* for example 'Elul' or 'Cheshvan'.
|
|
@@ -1558,77 +1397,65 @@ class HDate {
|
|
|
1558
1397
|
* @param {number} year Hebrew year
|
|
1559
1398
|
* @return {string}
|
|
1560
1399
|
*/
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
1400
|
static getMonthName(month, year) {
|
|
1564
1401
|
return getMonthName(month, year);
|
|
1565
1402
|
}
|
|
1403
|
+
|
|
1566
1404
|
/**
|
|
1567
1405
|
* Returns the Hebrew month number (NISAN=1, TISHREI=7)
|
|
1568
1406
|
* @param {number|string} month A number, or Hebrew month name string
|
|
1569
1407
|
* @return {number}
|
|
1570
1408
|
*/
|
|
1571
|
-
|
|
1572
|
-
|
|
1573
1409
|
static monthNum(month) {
|
|
1574
1410
|
if (typeof month === 'number') {
|
|
1575
1411
|
if (isNaN(month) || month > 14) {
|
|
1576
1412
|
throw new RangeError(`Invalid month number: ${month}`);
|
|
1577
1413
|
}
|
|
1578
|
-
|
|
1579
1414
|
return month;
|
|
1580
1415
|
}
|
|
1581
|
-
|
|
1582
|
-
return month.charCodeAt(0) >= 48 && month.charCodeAt(0) <= 57 ?
|
|
1583
|
-
/* number */
|
|
1416
|
+
return month.charCodeAt(0) >= 48 && month.charCodeAt(0) <= 57 ? /* number */
|
|
1584
1417
|
parseInt(month, 10) : HDate.monthFromName(month);
|
|
1585
1418
|
}
|
|
1419
|
+
|
|
1586
1420
|
/**
|
|
1587
1421
|
* Number of days in the hebrew YEAR
|
|
1588
1422
|
* @param {number} year Hebrew year
|
|
1589
1423
|
* @return {number}
|
|
1590
1424
|
*/
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
1425
|
static daysInYear(year) {
|
|
1594
1426
|
return daysInYear(year);
|
|
1595
1427
|
}
|
|
1428
|
+
|
|
1596
1429
|
/**
|
|
1597
1430
|
* true if Cheshvan is long in Hebrew year
|
|
1598
1431
|
* @param {number} year Hebrew year
|
|
1599
1432
|
* @return {boolean}
|
|
1600
1433
|
*/
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
1434
|
static longCheshvan(year) {
|
|
1604
1435
|
return longCheshvan(year);
|
|
1605
1436
|
}
|
|
1437
|
+
|
|
1606
1438
|
/**
|
|
1607
1439
|
* true if Kislev is short in Hebrew year
|
|
1608
1440
|
* @param {number} year Hebrew year
|
|
1609
1441
|
* @return {boolean}
|
|
1610
1442
|
*/
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
1443
|
static shortKislev(year) {
|
|
1614
1444
|
return shortKislev(year);
|
|
1615
1445
|
}
|
|
1446
|
+
|
|
1616
1447
|
/**
|
|
1617
1448
|
* Converts Hebrew month string name to numeric
|
|
1618
1449
|
* @param {string} monthName monthName
|
|
1619
1450
|
* @return {number}
|
|
1620
1451
|
*/
|
|
1621
|
-
|
|
1622
|
-
|
|
1623
1452
|
static monthFromName(monthName) {
|
|
1624
1453
|
if (typeof monthName === 'number') {
|
|
1625
1454
|
if (isNaN(monthName) || monthName < 1 || monthName > 14) {
|
|
1626
1455
|
throw new RangeError(`Invalid month name: ${monthName}`);
|
|
1627
1456
|
}
|
|
1628
|
-
|
|
1629
1457
|
return monthName;
|
|
1630
1458
|
}
|
|
1631
|
-
|
|
1632
1459
|
const c = monthName.toLowerCase();
|
|
1633
1460
|
/*
|
|
1634
1461
|
the Hebrew months are unique to their second letter
|
|
@@ -1651,115 +1478,88 @@ class HDate {
|
|
|
1651
1478
|
ש שבט
|
|
1652
1479
|
תמ תש תמוז תשרי
|
|
1653
1480
|
*/
|
|
1654
|
-
|
|
1655
1481
|
switch (c[0]) {
|
|
1656
1482
|
case 'n':
|
|
1657
1483
|
case 'נ':
|
|
1658
1484
|
if (c[1] == 'o') {
|
|
1659
|
-
break;
|
|
1660
|
-
/* this catches "november" */
|
|
1485
|
+
break; /* this catches "november" */
|
|
1661
1486
|
}
|
|
1662
1487
|
|
|
1663
1488
|
return months.NISAN;
|
|
1664
|
-
|
|
1665
1489
|
case 'i':
|
|
1666
1490
|
return months.IYYAR;
|
|
1667
|
-
|
|
1668
1491
|
case 'e':
|
|
1669
1492
|
return months.ELUL;
|
|
1670
|
-
|
|
1671
1493
|
case 'c':
|
|
1672
1494
|
case 'ח':
|
|
1673
1495
|
return months.CHESHVAN;
|
|
1674
|
-
|
|
1675
1496
|
case 'k':
|
|
1676
1497
|
case 'כ':
|
|
1677
1498
|
return months.KISLEV;
|
|
1678
|
-
|
|
1679
1499
|
case 's':
|
|
1680
1500
|
switch (c[1]) {
|
|
1681
1501
|
case 'i':
|
|
1682
1502
|
return months.SIVAN;
|
|
1683
|
-
|
|
1684
1503
|
case 'h':
|
|
1685
1504
|
return months.SHVAT;
|
|
1686
1505
|
}
|
|
1687
|
-
|
|
1688
1506
|
case 't':
|
|
1689
1507
|
switch (c[1]) {
|
|
1690
1508
|
case 'a':
|
|
1691
1509
|
return months.TAMUZ;
|
|
1692
|
-
|
|
1693
1510
|
case 'i':
|
|
1694
1511
|
return months.TISHREI;
|
|
1695
|
-
|
|
1696
1512
|
case 'e':
|
|
1697
1513
|
return months.TEVET;
|
|
1698
1514
|
}
|
|
1699
|
-
|
|
1700
1515
|
break;
|
|
1701
|
-
|
|
1702
1516
|
case 'a':
|
|
1703
1517
|
switch (c[1]) {
|
|
1704
1518
|
case 'v':
|
|
1705
1519
|
return months.AV;
|
|
1706
|
-
|
|
1707
1520
|
case 'd':
|
|
1708
1521
|
if (/(1|[^i]i|a|א)$/i.test(monthName)) {
|
|
1709
1522
|
return months.ADAR_I;
|
|
1710
1523
|
}
|
|
1711
|
-
|
|
1712
1524
|
return months.ADAR_II;
|
|
1713
1525
|
// else assume sheini
|
|
1714
1526
|
}
|
|
1715
1527
|
|
|
1716
1528
|
break;
|
|
1717
|
-
|
|
1718
1529
|
case 'ס':
|
|
1719
1530
|
return months.SIVAN;
|
|
1720
|
-
|
|
1721
1531
|
case 'ט':
|
|
1722
1532
|
return months.TEVET;
|
|
1723
|
-
|
|
1724
1533
|
case 'ש':
|
|
1725
1534
|
return months.SHVAT;
|
|
1726
|
-
|
|
1727
1535
|
case 'א':
|
|
1728
1536
|
switch (c[1]) {
|
|
1729
1537
|
case 'ב':
|
|
1730
1538
|
return months.AV;
|
|
1731
|
-
|
|
1732
1539
|
case 'ד':
|
|
1733
1540
|
if (/(1|[^i]i|a|א)$/i.test(monthName)) {
|
|
1734
1541
|
return months.ADAR_I;
|
|
1735
1542
|
}
|
|
1736
|
-
|
|
1737
1543
|
return months.ADAR_II;
|
|
1738
1544
|
// else assume sheini
|
|
1739
|
-
|
|
1740
1545
|
case 'י':
|
|
1741
1546
|
return months.IYYAR;
|
|
1742
|
-
|
|
1743
1547
|
case 'ל':
|
|
1744
1548
|
return months.ELUL;
|
|
1745
1549
|
}
|
|
1746
|
-
|
|
1747
1550
|
break;
|
|
1748
|
-
|
|
1749
1551
|
case 'ת':
|
|
1750
1552
|
switch (c[1]) {
|
|
1751
1553
|
case 'מ':
|
|
1752
1554
|
return months.TAMUZ;
|
|
1753
|
-
|
|
1754
1555
|
case 'ש':
|
|
1755
1556
|
return months.TISHREI;
|
|
1756
1557
|
}
|
|
1757
|
-
|
|
1758
1558
|
break;
|
|
1759
1559
|
}
|
|
1760
|
-
|
|
1761
1560
|
throw new RangeError(`Unable to parse month name: ${monthName}`);
|
|
1762
1561
|
}
|
|
1562
|
+
|
|
1763
1563
|
/**
|
|
1764
1564
|
* Note: Applying this function to d+6 gives us the DAYNAME on or after an
|
|
1765
1565
|
* absolute day d. Similarly, applying it to d+3 gives the DAYNAME nearest to
|
|
@@ -1769,71 +1569,60 @@ class HDate {
|
|
|
1769
1569
|
* @param {number} absdate
|
|
1770
1570
|
* @return {number}
|
|
1771
1571
|
*/
|
|
1772
|
-
|
|
1773
|
-
|
|
1774
1572
|
static dayOnOrBefore(dayOfWeek, absdate) {
|
|
1775
1573
|
return absdate - (absdate - dayOfWeek) % 7;
|
|
1776
1574
|
}
|
|
1575
|
+
|
|
1777
1576
|
/**
|
|
1778
1577
|
* Tests if the object is an instance of `HDate`
|
|
1779
1578
|
* @param {any} obj
|
|
1780
1579
|
* @return {boolean}
|
|
1781
1580
|
*/
|
|
1782
|
-
|
|
1783
|
-
|
|
1784
1581
|
static isHDate(obj) {
|
|
1785
1582
|
return obj !== null && typeof obj === 'object' && typeof obj.year === 'number' && typeof obj.month === 'number' && typeof obj.day === 'number' && typeof obj.greg === 'function' && typeof obj.abs === 'function';
|
|
1786
1583
|
}
|
|
1787
|
-
|
|
1788
1584
|
}
|
|
1585
|
+
|
|
1789
1586
|
/**
|
|
1790
1587
|
* @private
|
|
1791
1588
|
* @param {HDate} date
|
|
1792
1589
|
*/
|
|
1793
|
-
|
|
1794
1590
|
function fix(date) {
|
|
1795
1591
|
fixMonth(date);
|
|
1796
1592
|
fixDate(date);
|
|
1797
1593
|
}
|
|
1594
|
+
|
|
1798
1595
|
/**
|
|
1799
1596
|
* @private
|
|
1800
1597
|
* @param {HDate} date
|
|
1801
1598
|
*/
|
|
1802
|
-
|
|
1803
|
-
|
|
1804
1599
|
function fixDate(date) {
|
|
1805
1600
|
if (date.day < 1) {
|
|
1806
1601
|
if (date.month == months.TISHREI) {
|
|
1807
1602
|
date.year -= 1;
|
|
1808
1603
|
}
|
|
1809
|
-
|
|
1810
1604
|
date.day += daysInMonth(date.month, date.year);
|
|
1811
1605
|
date.month -= 1;
|
|
1812
1606
|
fix(date);
|
|
1813
1607
|
}
|
|
1814
|
-
|
|
1815
1608
|
if (date.day > daysInMonth(date.month, date.year)) {
|
|
1816
1609
|
if (date.month === months.ELUL) {
|
|
1817
1610
|
date.year += 1;
|
|
1818
1611
|
}
|
|
1819
|
-
|
|
1820
1612
|
date.day -= daysInMonth(date.month, date.year);
|
|
1821
1613
|
date.month += 1;
|
|
1822
1614
|
fix(date);
|
|
1823
1615
|
}
|
|
1824
|
-
|
|
1825
1616
|
fixMonth(date);
|
|
1826
1617
|
}
|
|
1618
|
+
|
|
1827
1619
|
/**
|
|
1828
1620
|
* @private
|
|
1829
1621
|
* @param {HDate} date
|
|
1830
1622
|
*/
|
|
1831
|
-
|
|
1832
|
-
|
|
1833
1623
|
function fixMonth(date) {
|
|
1834
1624
|
if (date.month === months.ADAR_II && !date.isLeapYear()) {
|
|
1835
1625
|
date.month -= 1; // to Adar I
|
|
1836
|
-
|
|
1837
1626
|
fix(date);
|
|
1838
1627
|
} else if (date.month < 1) {
|
|
1839
1628
|
date.month += monthsInYear(date.year);
|
|
@@ -1844,9 +1633,9 @@ function fixMonth(date) {
|
|
|
1844
1633
|
date.year += 1;
|
|
1845
1634
|
fix(date);
|
|
1846
1635
|
}
|
|
1847
|
-
|
|
1848
1636
|
delete date.abs0;
|
|
1849
1637
|
}
|
|
1638
|
+
|
|
1850
1639
|
/**
|
|
1851
1640
|
* @private
|
|
1852
1641
|
* @param {number} day
|
|
@@ -1854,8 +1643,6 @@ function fixMonth(date) {
|
|
|
1854
1643
|
* @param {number} offset
|
|
1855
1644
|
* @return {HDate}
|
|
1856
1645
|
*/
|
|
1857
|
-
|
|
1858
|
-
|
|
1859
1646
|
function onOrBefore(day, t, offset) {
|
|
1860
1647
|
return new HDate(HDate.dayOnOrBefore(day, t.abs() + offset));
|
|
1861
1648
|
}
|
|
@@ -1867,13 +1654,13 @@ const TEVET = months.TEVET;
|
|
|
1867
1654
|
const SHVAT = months.SHVAT;
|
|
1868
1655
|
const ADAR_I = months.ADAR_I;
|
|
1869
1656
|
const ADAR_II = months.ADAR_II;
|
|
1657
|
+
|
|
1870
1658
|
/**
|
|
1871
1659
|
* @private
|
|
1872
1660
|
* @param {number} hyear Hebrew year
|
|
1873
1661
|
* @param {Date|HDate} gdate Gregorian or Hebrew date of death
|
|
1874
1662
|
* @return {HDate} anniversary occurring in hyear
|
|
1875
1663
|
*/
|
|
1876
|
-
|
|
1877
1664
|
function getYahrzeit_(hyear, gdate) {
|
|
1878
1665
|
const orig = HDate.isHDate(gdate) ? gdate : new HDate(gdate);
|
|
1879
1666
|
let hDeath = {
|
|
@@ -1881,12 +1668,10 @@ function getYahrzeit_(hyear, gdate) {
|
|
|
1881
1668
|
mm: orig.getMonth(),
|
|
1882
1669
|
dd: orig.getDate()
|
|
1883
1670
|
};
|
|
1884
|
-
|
|
1885
1671
|
if (hyear <= hDeath.yy) {
|
|
1886
1672
|
// `Hebrew year ${hyear} occurs on or before original date in ${hDeath.yy}`
|
|
1887
1673
|
return undefined;
|
|
1888
1674
|
}
|
|
1889
|
-
|
|
1890
1675
|
if (hDeath.mm == CHESHVAN && hDeath.dd == 30 && !longCheshvan(hDeath.yy + 1)) {
|
|
1891
1676
|
// If it's Heshvan 30 it depends on the first anniversary;
|
|
1892
1677
|
// if that was not Heshvan 30, use the day before Kislev 1.
|
|
@@ -1903,10 +1688,10 @@ function getYahrzeit_(hyear, gdate) {
|
|
|
1903
1688
|
// (so Adar has only 29 days), use the last day in Shevat.
|
|
1904
1689
|
hDeath.dd = 30;
|
|
1905
1690
|
hDeath.mm = SHVAT;
|
|
1906
|
-
}
|
|
1907
|
-
//
|
|
1908
|
-
|
|
1691
|
+
}
|
|
1692
|
+
// In all other cases, use the normal anniversary of the date of death.
|
|
1909
1693
|
|
|
1694
|
+
// advance day to rosh chodesh if needed
|
|
1910
1695
|
if (hDeath.mm == CHESHVAN && hDeath.dd == 30 && !longCheshvan(hyear)) {
|
|
1911
1696
|
hDeath.mm = KISLEV;
|
|
1912
1697
|
hDeath.dd = 1;
|
|
@@ -1914,29 +1699,25 @@ function getYahrzeit_(hyear, gdate) {
|
|
|
1914
1699
|
hDeath.mm = TEVET;
|
|
1915
1700
|
hDeath.dd = 1;
|
|
1916
1701
|
}
|
|
1917
|
-
|
|
1918
1702
|
return new HDate(hDeath.dd, hDeath.mm, hyear);
|
|
1919
1703
|
}
|
|
1704
|
+
|
|
1920
1705
|
/**
|
|
1921
1706
|
* @private
|
|
1922
1707
|
* @param {number} hyear Hebrew year
|
|
1923
1708
|
* @param {Date|HDate} gdate Gregorian or Hebrew date of event
|
|
1924
1709
|
* @return {HDate} anniversary occurring in `hyear`
|
|
1925
1710
|
*/
|
|
1926
|
-
|
|
1927
1711
|
function getBirthdayOrAnniversary_(hyear, gdate) {
|
|
1928
1712
|
const orig = HDate.isHDate(gdate) ? gdate : new HDate(gdate);
|
|
1929
1713
|
const origYear = orig.getFullYear();
|
|
1930
|
-
|
|
1931
1714
|
if (hyear <= origYear) {
|
|
1932
1715
|
// `Hebrew year ${hyear} occurs on or before original date in ${origYear}`
|
|
1933
1716
|
return undefined;
|
|
1934
1717
|
}
|
|
1935
|
-
|
|
1936
1718
|
const isOrigLeap = isLeapYear(origYear);
|
|
1937
1719
|
let month = orig.getMonth();
|
|
1938
1720
|
let day = orig.getDate();
|
|
1939
|
-
|
|
1940
1721
|
if (month == ADAR_I && !isOrigLeap || month == ADAR_II && isOrigLeap) {
|
|
1941
1722
|
month = monthsInYear(hyear);
|
|
1942
1723
|
} else if (month == CHESHVAN && day == 30 && !longCheshvan(hyear)) {
|
|
@@ -1949,11 +1730,10 @@ function getBirthdayOrAnniversary_(hyear, gdate) {
|
|
|
1949
1730
|
month = NISAN;
|
|
1950
1731
|
day = 1;
|
|
1951
1732
|
}
|
|
1952
|
-
|
|
1953
1733
|
return new HDate(day, month, hyear);
|
|
1954
1734
|
}
|
|
1955
1735
|
|
|
1956
|
-
const version="3.45.
|
|
1736
|
+
const version="3.45.4";
|
|
1957
1737
|
|
|
1958
1738
|
const headers={"plural-forms":"nplurals=2; plural=(n > 1);"};const contexts={"":{Adar:["אַדָר"],"Adar I":["אַדָר א׳"],"Adar II":["אַדָר ב׳"],Av:["אָב"],Cheshvan:["חֶשְׁוָן"],Elul:["אֱלוּל"],Iyyar:["אִיָיר"],Kislev:["כִּסְלֵו"],Nisan:["נִיסָן"],"Sh'vat":["שְׁבָט"],Sivan:["סִיוָן"],Tamuz:["תַּמּוּז"],Tevet:["טֵבֵת"],Tishrei:["תִשְׁרֵי"]}};var poHeMin = {headers:headers,contexts:contexts};
|
|
1959
1739
|
|