@hebcal/core 3.45.3 → 3.45.5

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/hdate.js CHANGED
@@ -1,120 +1,93 @@
1
- /*! @hebcal/core v3.45.3 */
1
+ /*! @hebcal/core v3.45.5 */
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; // const SHVAT = 11;
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; // Avg year length in the cycle (19 solar years with 235 lunar months)
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,15 @@ 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) {
624
+ if (year < 1) {
625
+ throw new RangeError(`hebrew2abs: invalid year ${year}`);
626
+ }
717
627
  let tempabs = day;
718
-
719
628
  if (month < TISHREI) {
720
629
  for (let m = TISHREI; m <= monthsInYear(year); m++) {
721
630
  tempabs += daysInMonth(m, year);
722
631
  }
723
-
724
632
  for (let m = NISAN$1; m < month; m++) {
725
633
  tempabs += daysInMonth(m, year);
726
634
  }
@@ -729,46 +637,42 @@ function hebrew2abs(year, month, day) {
729
637
  tempabs += daysInMonth(m, year);
730
638
  }
731
639
  }
732
-
733
640
  return EPOCH + elapsedDays(year) + tempabs - 1;
734
641
  }
642
+
735
643
  /**
736
644
  * @private
737
645
  * @param {number} year
738
646
  * @return {number}
739
647
  */
740
-
741
648
  function newYear(year) {
742
649
  return EPOCH + elapsedDays(year);
743
650
  }
651
+
744
652
  /**
745
653
  * Converts absolute R.D. days to Hebrew date
746
654
  * @private
747
655
  * @param {number} abs absolute R.D. days
748
656
  * @return {SimpleHebrewDate}
749
657
  */
750
-
751
-
752
658
  function abs2hebrew(abs) {
753
659
  if (typeof abs !== 'number' || isNaN(abs)) {
754
660
  throw new TypeError(`invalid parameter to abs2hebrew ${abs}`);
755
661
  }
756
-
757
- abs = Math.trunc(abs); // first, quickly approximate year
758
-
662
+ abs = Math.trunc(abs);
663
+ if (abs <= EPOCH) {
664
+ throw new RangeError(`abs2hebrew: ${abs} is before epoch`);
665
+ }
666
+ // first, quickly approximate year
759
667
  let year = Math.floor((abs - EPOCH) / AVG_HEBYEAR_DAYS);
760
-
761
668
  while (newYear(year) <= abs) {
762
669
  ++year;
763
670
  }
764
-
765
671
  --year;
766
672
  let month = abs < hebrew2abs(year, 1, 1) ? 7 : 1;
767
-
768
673
  while (abs > hebrew2abs(year, month, daysInMonth(month, year))) {
769
674
  ++month;
770
675
  }
771
-
772
676
  const day = 1 + abs - hebrew2abs(year, month, 1);
773
677
  return {
774
678
  yy: year,
@@ -776,26 +680,27 @@ function abs2hebrew(abs) {
776
680
  dd: day
777
681
  };
778
682
  }
683
+
779
684
  /**
780
685
  * Returns true if Hebrew year is a leap year
781
686
  * @private
782
687
  * @param {number} year Hebrew year
783
688
  * @return {boolean}
784
689
  */
785
-
786
690
  function isLeapYear(year) {
787
691
  return (1 + year * 7) % 19 < 7;
788
692
  }
693
+
789
694
  /**
790
695
  * Number of months in this Hebrew year (either 12 or 13 depending on leap year)
791
696
  * @private
792
697
  * @param {number} year Hebrew year
793
698
  * @return {number}
794
699
  */
795
-
796
700
  function monthsInYear(year) {
797
701
  return 12 + isLeapYear(year); // boolean is cast to 1 or 0
798
702
  }
703
+
799
704
  /**
800
705
  * Number of days in Hebrew month in a given year (29 or 30)
801
706
  * @private
@@ -803,7 +708,6 @@ function monthsInYear(year) {
803
708
  * @param {number} year Hebrew year
804
709
  * @return {number}
805
710
  */
806
-
807
711
  function daysInMonth(month, year) {
808
712
  switch (month) {
809
713
  case IYYAR:
@@ -813,13 +717,13 @@ function daysInMonth(month, year) {
813
717
  case ADAR_II$1:
814
718
  return 29;
815
719
  }
816
-
817
720
  if (month === ADAR_I$1 && !isLeapYear(year) || month === CHESHVAN$1 && !longCheshvan(year) || month === KISLEV$1 && shortKislev(year)) {
818
721
  return 29;
819
722
  } else {
820
723
  return 30;
821
724
  }
822
725
  }
726
+
823
727
  /**
824
728
  * Returns a transliterated string name of Hebrew month in year,
825
729
  * for example 'Elul' or 'Cheshvan'.
@@ -828,14 +732,13 @@ function daysInMonth(month, year) {
828
732
  * @param {number} year Hebrew year
829
733
  * @return {string}
830
734
  */
831
-
832
735
  function getMonthName(month, year) {
833
736
  if (typeof month !== 'number' || isNaN(month) || month < 1 || month > 14) {
834
737
  throw new TypeError(`bad month argument ${month}`);
835
738
  }
836
-
837
739
  return monthNames[+isLeapYear(year)][month];
838
740
  }
741
+
839
742
  /**
840
743
  * Days from sunday prior to start of Hebrew calendar to mean
841
744
  * conjunction of Tishrei in Hebrew YEAR
@@ -843,11 +746,11 @@ function getMonthName(month, year) {
843
746
  * @param {number} year Hebrew year
844
747
  * @return {number}
845
748
  */
846
-
847
749
  function elapsedDays(year) {
848
750
  const elapsed = edCache[year] = edCache[year] || elapsedDays0(year);
849
751
  return elapsed;
850
752
  }
753
+
851
754
  /**
852
755
  * Days from sunday prior to start of Hebrew calendar to mean
853
756
  * conjunction of Tishrei in Hebrew YEAR
@@ -855,11 +758,12 @@ function elapsedDays(year) {
855
758
  * @param {number} year Hebrew year
856
759
  * @return {number}
857
760
  */
858
-
859
761
  function elapsedDays0(year) {
860
762
  const prevYear = year - 1;
861
- const mElapsed = 235 * Math.floor(prevYear / 19) + // Months in complete 19 year lunar (Metonic) cycles so far
862
- 12 * (prevYear % 19) + // Regular months in this cycle
763
+ const mElapsed = 235 * Math.floor(prevYear / 19) +
764
+ // Months in complete 19 year lunar (Metonic) cycles so far
765
+ 12 * (prevYear % 19) +
766
+ // Regular months in this cycle
863
767
  Math.floor((prevYear % 19 * 7 + 1) / 19); // Leap months this cycle
864
768
 
865
769
  const pElapsed = 204 + 793 * (mElapsed % 1080);
@@ -869,6 +773,7 @@ function elapsedDays0(year) {
869
773
  const altDay = day + (parts >= 19440 || 2 === day % 7 && parts >= 9924 && !isLeapYear(year) || 1 === day % 7 && parts >= 16789 && isLeapYear(prevYear));
870
774
  return altDay + (altDay % 7 === 0 || altDay % 7 === 3 || altDay % 7 === 5);
871
775
  }
776
+
872
777
  /**
873
778
  * Number of days in the hebrew YEAR.
874
779
  * A common Hebrew calendar year can have a length of 353, 354 or 355 days
@@ -877,28 +782,26 @@ function elapsedDays0(year) {
877
782
  * @param {number} year Hebrew year
878
783
  * @return {number}
879
784
  */
880
-
881
-
882
785
  function daysInYear(year) {
883
786
  return elapsedDays(year + 1) - elapsedDays(year);
884
787
  }
788
+
885
789
  /**
886
790
  * true if Cheshvan is long in Hebrew year
887
791
  * @private
888
792
  * @param {number} year Hebrew year
889
793
  * @return {boolean}
890
794
  */
891
-
892
795
  function longCheshvan(year) {
893
796
  return daysInYear(year) % 10 === 5;
894
797
  }
798
+
895
799
  /**
896
800
  * true if Kislev is short in Hebrew year
897
801
  * @private
898
802
  * @param {number} year Hebrew year
899
803
  * @return {boolean}
900
804
  */
901
-
902
805
  function shortKislev(year) {
903
806
  return daysInYear(year) % 10 === 3;
904
807
  }
@@ -924,10 +827,10 @@ function shortKislev(year) {
924
827
  along with this program. If not, see <http://www.gnu.org/licenses/>.
925
828
  */
926
829
 
830
+ // eslint-disable-next-line require-jsdoc
927
831
  function throwTypeError(msg) {
928
832
  throw new TypeError(msg);
929
833
  }
930
-
931
834
  const UNITS_DAY = 'day';
932
835
  const UNITS_WEEK = 'week';
933
836
  const UNITS_MONTH = 'month';
@@ -944,6 +847,7 @@ const UNITS_VALID = {
944
847
  month: UNITS_MONTH,
945
848
  year: UNITS_YEAR
946
849
  };
850
+
947
851
  /**
948
852
  * A simple Hebrew date object with numeric fields `yy`, `mm`, and `dd`
949
853
  * @typedef {Object} SimpleHebrewDate
@@ -954,7 +858,6 @@ const UNITS_VALID = {
954
858
  */
955
859
 
956
860
  /** Represents a Hebrew date */
957
-
958
861
  class HDate {
959
862
  /**
960
863
  * Create a Hebrew date. There are 3 basic forms for the `HDate()` constructor.
@@ -990,10 +893,8 @@ class HDate {
990
893
  if (arguments.length == 2 || arguments.length > 3) {
991
894
  throw new TypeError('HDate constructor requires 0, 1 or 3 arguments');
992
895
  }
993
-
994
896
  if (arguments.length == 3) {
995
897
  // Hebrew day, Hebrew month, Hebrew year
996
-
997
898
  /**
998
899
  * @private
999
900
  * @type {number}
@@ -1003,30 +904,23 @@ class HDate {
1003
904
  * @private
1004
905
  * @type {number}
1005
906
  */
1006
-
1007
907
  year = parseInt(year, 10);
1008
-
1009
908
  if (isNaN(year)) {
1010
909
  throw new TypeError(`HDate called with bad year argument: ${year}`);
1011
910
  }
1012
-
1013
911
  this.year = year;
1014
912
  this.setMonth(month); // will throw if we can't parse
1015
-
1016
913
  day = parseInt(day, 10);
1017
-
1018
914
  if (isNaN(day)) {
1019
915
  throw new TypeError(`HDate called with bad day argument: ${day}`);
1020
916
  }
1021
-
1022
917
  this.setDate(day);
1023
918
  } else {
1024
919
  // 0 arguments
1025
920
  if (typeof day === 'undefined') {
1026
921
  day = new Date();
1027
- } // 1 argument
1028
-
1029
-
922
+ }
923
+ // 1 argument
1030
924
  const abs0 = typeof day === 'number' && !isNaN(day) ? day : isDate(day) ? greg2abs(day) : HDate.isHDate(day) ? {
1031
925
  dd: day.day,
1032
926
  mm: day.month,
@@ -1038,21 +932,17 @@ class HDate {
1038
932
  * @private
1039
933
  * @type {number}
1040
934
  */
1041
-
1042
935
  this.day = d.dd;
1043
936
  /**
1044
937
  * @private
1045
938
  * @type {number}
1046
939
  */
1047
-
1048
940
  this.month = d.mm;
1049
941
  /**
1050
942
  * @private
1051
943
  * @type {number}
1052
944
  */
1053
-
1054
945
  this.year = d.yy;
1055
-
1056
946
  if (isNumber) {
1057
947
  /**
1058
948
  * @private
@@ -1062,70 +952,64 @@ class HDate {
1062
952
  }
1063
953
  }
1064
954
  }
955
+
1065
956
  /**
1066
957
  * Gets the Hebrew year of this Hebrew date
1067
958
  * @return {number}
1068
959
  */
1069
-
1070
-
1071
960
  getFullYear() {
1072
961
  return this.year;
1073
962
  }
963
+
1074
964
  /**
1075
965
  * Tests if this date occurs during a leap year
1076
966
  * @return {boolean}
1077
967
  */
1078
-
1079
-
1080
968
  isLeapYear() {
1081
969
  return isLeapYear(this.year);
1082
970
  }
971
+
1083
972
  /**
1084
973
  * Gets the Hebrew month (1=NISAN, 7=TISHREI) of this Hebrew date
1085
974
  * @return {number}
1086
975
  */
1087
-
1088
-
1089
976
  getMonth() {
1090
977
  return this.month;
1091
978
  }
979
+
1092
980
  /**
1093
981
  * The Tishrei-based month of the date. 1 is Tishrei, 7 is Nisan, 13 is Elul in a leap year
1094
982
  * @return {number}
1095
983
  */
1096
-
1097
-
1098
984
  getTishreiMonth() {
1099
985
  const nummonths = monthsInYear(this.getFullYear());
1100
986
  return (this.getMonth() + nummonths - 6) % nummonths || nummonths;
1101
987
  }
988
+
1102
989
  /**
1103
990
  * Number of days in the month of this Hebrew date
1104
991
  * @return {number}
1105
992
  */
1106
-
1107
-
1108
993
  daysInMonth() {
1109
994
  return daysInMonth(this.getMonth(), this.getFullYear());
1110
995
  }
996
+
1111
997
  /**
1112
998
  * Gets the day within the month (1-30)
1113
999
  * @return {number}
1114
1000
  */
1115
-
1116
-
1117
1001
  getDate() {
1118
1002
  return this.day;
1119
1003
  }
1004
+
1120
1005
  /**
1121
1006
  * Gets the day of the week. 0=Sunday, 6=Saturday
1122
1007
  * @return {number}
1123
1008
  */
1124
-
1125
-
1126
1009
  getDay() {
1127
1010
  return mod(this.abs(), 7);
1128
1011
  }
1012
+
1129
1013
  /**
1130
1014
  * Sets the year of the date. Returns the object it was called upon.
1131
1015
  * @private
@@ -1133,47 +1017,43 @@ class HDate {
1133
1017
  * @param {number} year
1134
1018
  * @return {HDate}
1135
1019
  */
1136
-
1137
-
1138
1020
  setFullYear(year) {
1139
1021
  this.year = year;
1140
1022
  fix(this);
1141
1023
  return this;
1142
1024
  }
1025
+
1143
1026
  /**
1144
1027
  * Sets the day of the month of the date. Returns the object it was called upon
1145
1028
  * @private
1146
1029
  * @param {number} month
1147
1030
  * @return {HDate}
1148
1031
  */
1149
-
1150
-
1151
1032
  setMonth(month) {
1152
1033
  this.month = HDate.monthNum(month);
1153
1034
  fix(this);
1154
1035
  return this;
1155
1036
  }
1037
+
1156
1038
  /**
1157
1039
  * @private
1158
1040
  * @param {number} date
1159
1041
  * @return {HDate}
1160
1042
  */
1161
-
1162
-
1163
1043
  setDate(date) {
1164
1044
  this.day = date;
1165
1045
  fix(this);
1166
1046
  return this;
1167
1047
  }
1048
+
1168
1049
  /**
1169
1050
  * Converts to Gregorian date
1170
1051
  * @return {Date}
1171
1052
  */
1172
-
1173
-
1174
1053
  greg() {
1175
1054
  return abs2greg(this.abs());
1176
1055
  }
1056
+
1177
1057
  /**
1178
1058
  * Returns R.D. (Rata Die) fixed days.
1179
1059
  * R.D. 1 == Monday, January 1, 1 (Gregorian)
@@ -1181,15 +1061,13 @@ class HDate {
1181
1061
  * https://en.wikipedia.org/wiki/Rata_Die#Dershowitz_and_Reingold
1182
1062
  * @return {number}
1183
1063
  */
1184
-
1185
-
1186
1064
  abs() {
1187
1065
  if (typeof this.abs0 !== 'number') {
1188
1066
  this.abs0 = hebrew2abs(this.year, this.month, this.day);
1189
1067
  }
1190
-
1191
1068
  return this.abs0;
1192
1069
  }
1070
+
1193
1071
  /**
1194
1072
  * Converts Hebrew date to R.D. (Rata Die) fixed days.
1195
1073
  * R.D. 1 is the imaginary date Monday, January 1, 1 on the Gregorian
@@ -1199,31 +1077,28 @@ class HDate {
1199
1077
  * @param {number} day Hebrew date (1-30)
1200
1078
  * @return {number}
1201
1079
  */
1202
-
1203
-
1204
1080
  static hebrew2abs(year, month, day) {
1205
1081
  return hebrew2abs(year, month, day);
1206
1082
  }
1083
+
1207
1084
  /**
1208
1085
  * Converts absolute R.D. days to Hebrew date
1209
1086
  * @private
1210
1087
  * @param {number} abs absolute R.D. days
1211
1088
  * @return {SimpleHebrewDate}
1212
1089
  */
1213
-
1214
-
1215
1090
  static abs2hebrew(abs) {
1216
1091
  return abs2hebrew(abs);
1217
1092
  }
1093
+
1218
1094
  /**
1219
1095
  * Returns a transliterated Hebrew month name, e.g. `'Elul'` or `'Cheshvan'`.
1220
1096
  * @return {string}
1221
1097
  */
1222
-
1223
-
1224
1098
  getMonthName() {
1225
1099
  return getMonthName(this.getMonth(), this.getFullYear());
1226
1100
  }
1101
+
1227
1102
  /**
1228
1103
  * Renders this Hebrew date as a translated or transliterated string,
1229
1104
  * including ordinal e.g. `'15th of Cheshvan, 5769'`.
@@ -1237,8 +1112,6 @@ class HDate {
1237
1112
  * @param {boolean} [showYear=true] Display year (defaults to true).
1238
1113
  * @return {string}
1239
1114
  */
1240
-
1241
-
1242
1115
  render(locale = null, showYear = true) {
1243
1116
  const locale0 = locale || Locale.getLocaleName();
1244
1117
  const day = this.getDate();
@@ -1246,7 +1119,6 @@ class HDate {
1246
1119
  const nth = Locale.ordinal(day, locale0);
1247
1120
  const dayOf = HDate.getDayOfTranslation(locale0);
1248
1121
  const dateStr = `${nth}${dayOf} ${monthName}`;
1249
-
1250
1122
  if (showYear) {
1251
1123
  const fullYear = this.getFullYear();
1252
1124
  return `${dateStr}, ${fullYear}`;
@@ -1254,13 +1126,12 @@ class HDate {
1254
1126
  return dateStr;
1255
1127
  }
1256
1128
  }
1129
+
1257
1130
  /**
1258
1131
  * @private
1259
1132
  * @param {string} locale
1260
1133
  * @return {string}
1261
1134
  */
1262
-
1263
-
1264
1135
  static getDayOfTranslation(locale) {
1265
1136
  switch (locale) {
1266
1137
  case 'en':
@@ -1269,19 +1140,16 @@ class HDate {
1269
1140
  case 'ashkenazi':
1270
1141
  return ' of';
1271
1142
  }
1272
-
1273
1143
  const ofStr = Locale.lookupTranslation('of', locale);
1274
-
1275
1144
  if (ofStr) {
1276
1145
  return ' ' + ofStr;
1277
1146
  }
1278
-
1279
1147
  if ('ashkenazi' === locale.substring(0, 9)) {
1280
1148
  return ' of';
1281
1149
  }
1282
-
1283
1150
  return '';
1284
1151
  }
1152
+
1285
1153
  /**
1286
1154
  * Renders this Hebrew date in Hebrew gematriya, regardless of locale.
1287
1155
  * @example
@@ -1290,14 +1158,13 @@ class HDate {
1290
1158
  * console.log(hd.renderGematriya()); // 'ט״ו חֶשְׁוָן תשס״ט'
1291
1159
  * @return {string}
1292
1160
  */
1293
-
1294
-
1295
1161
  renderGematriya() {
1296
1162
  const d = this.getDate();
1297
1163
  const m = Locale.gettext(this.getMonthName(), 'he');
1298
1164
  const y = this.getFullYear();
1299
1165
  return gematriya(d) + ' ' + m + ' ' + gematriya(y);
1300
1166
  }
1167
+
1301
1168
  /**
1302
1169
  * Returns an `HDate` representing the a dayNumber before the current date.
1303
1170
  * Sunday=0, Saturday=6
@@ -1306,11 +1173,10 @@ class HDate {
1306
1173
  * @param {number} day day of week
1307
1174
  * @return {HDate}
1308
1175
  */
1309
-
1310
-
1311
1176
  before(day) {
1312
1177
  return onOrBefore(day, this, -1);
1313
1178
  }
1179
+
1314
1180
  /**
1315
1181
  * Returns an `HDate` representing the a dayNumber on or before the current date.
1316
1182
  * Sunday=0, Saturday=6
@@ -1321,11 +1187,10 @@ class HDate {
1321
1187
  * @param {number} dow day of week
1322
1188
  * @return {HDate}
1323
1189
  */
1324
-
1325
-
1326
1190
  onOrBefore(dow) {
1327
1191
  return onOrBefore(dow, this, 0);
1328
1192
  }
1193
+
1329
1194
  /**
1330
1195
  * Returns an `HDate` representing the nearest dayNumber to the current date
1331
1196
  * Sunday=0, Saturday=6
@@ -1335,11 +1200,10 @@ class HDate {
1335
1200
  * @param {number} dow day of week
1336
1201
  * @return {HDate}
1337
1202
  */
1338
-
1339
-
1340
1203
  nearest(dow) {
1341
1204
  return onOrBefore(dow, this, 3);
1342
1205
  }
1206
+
1343
1207
  /**
1344
1208
  * Returns an `HDate` representing the a dayNumber on or after the current date.
1345
1209
  * Sunday=0, Saturday=6
@@ -1350,11 +1214,10 @@ class HDate {
1350
1214
  * @param {number} dow day of week
1351
1215
  * @return {HDate}
1352
1216
  */
1353
-
1354
-
1355
1217
  onOrAfter(dow) {
1356
1218
  return onOrBefore(dow, this, 6);
1357
1219
  }
1220
+
1358
1221
  /**
1359
1222
  * Returns an `HDate` representing the a dayNumber after the current date.
1360
1223
  * Sunday=0, Saturday=6
@@ -1365,29 +1228,26 @@ class HDate {
1365
1228
  * @param {number} day day of week
1366
1229
  * @return {HDate}
1367
1230
  */
1368
-
1369
-
1370
1231
  after(day) {
1371
1232
  return onOrBefore(day, this, 7);
1372
1233
  }
1234
+
1373
1235
  /**
1374
1236
  * Returns the next Hebrew date
1375
1237
  * @return {HDate}
1376
1238
  */
1377
-
1378
-
1379
1239
  next() {
1380
1240
  return new HDate(this.abs() + 1);
1381
1241
  }
1242
+
1382
1243
  /**
1383
1244
  * Returns the previous Hebrew date
1384
1245
  * @return {HDate}
1385
1246
  */
1386
-
1387
-
1388
1247
  prev() {
1389
1248
  return new HDate(this.abs() - 1);
1390
1249
  }
1250
+
1391
1251
  /**
1392
1252
  * Returns a cloned `HDate` object with a specified amount of time added
1393
1253
  *
@@ -1404,17 +1264,12 @@ class HDate {
1404
1264
  * @param {string} [units]
1405
1265
  * @return {HDate}
1406
1266
  */
1407
-
1408
-
1409
1267
  add(number, units = 'd') {
1410
1268
  number = parseInt(number, 10);
1411
-
1412
1269
  if (!number) {
1413
1270
  return new HDate(this);
1414
1271
  }
1415
-
1416
1272
  units = HDate.standardizeUnits(units);
1417
-
1418
1273
  if (units === UNITS_DAY) {
1419
1274
  return new HDate(this.abs() + number);
1420
1275
  } else if (units === UNITS_WEEK) {
@@ -1425,25 +1280,23 @@ class HDate {
1425
1280
  let hd = new HDate(this);
1426
1281
  const sign = number > 0 ? 1 : -1;
1427
1282
  number = Math.abs(number);
1428
-
1429
1283
  for (let i = 0; i < number; i++) {
1430
1284
  hd = new HDate(hd.abs() + sign * hd.daysInMonth());
1431
1285
  }
1432
-
1433
1286
  return hd;
1434
1287
  }
1435
1288
  }
1289
+
1436
1290
  /**
1437
1291
  * @private
1438
1292
  * @param {string} units
1439
1293
  * @return {string}
1440
1294
  */
1441
-
1442
-
1443
1295
  static standardizeUnits(units) {
1444
1296
  const full = UNITS_SINGLE[units] || String(units || '').toLowerCase().replace(/s$/, '');
1445
1297
  return UNITS_VALID[full] || throwTypeError(`Invalid units '${units}'`);
1446
1298
  }
1299
+
1447
1300
  /**
1448
1301
  * Returns a cloned `HDate` object with a specified amount of time subracted
1449
1302
  *
@@ -1466,11 +1319,10 @@ class HDate {
1466
1319
  * @param {string} [units]
1467
1320
  * @return {HDate}
1468
1321
  */
1469
-
1470
-
1471
1322
  subtract(number, units = 'd') {
1472
1323
  return this.add(number * -1, units);
1473
1324
  }
1325
+
1474
1326
  /**
1475
1327
  * Returns the difference in days between the two given HDates.
1476
1328
  *
@@ -1488,69 +1340,61 @@ class HDate {
1488
1340
  * @param {HDate} other Hebrew date to compare
1489
1341
  * @return {number}
1490
1342
  */
1491
-
1492
-
1493
1343
  deltaDays(other) {
1494
1344
  if (!HDate.isHDate(other)) {
1495
1345
  throw new TypeError(`Bad argument: ${other}`);
1496
1346
  }
1497
-
1498
1347
  return this.abs() - other.abs();
1499
1348
  }
1349
+
1500
1350
  /**
1501
1351
  * Compares this date to another date, returning `true` if the dates match.
1502
1352
  * @param {HDate} other Hebrew date to compare
1503
1353
  * @return {boolean}
1504
1354
  */
1505
-
1506
-
1507
1355
  isSameDate(other) {
1508
1356
  if (HDate.isHDate(other)) {
1509
1357
  return this.year == other.year && this.month == other.month && this.day == other.day;
1510
1358
  }
1511
-
1512
1359
  return false;
1513
1360
  }
1514
- /** @return {string} */
1515
-
1516
1361
 
1362
+ /** @return {string} */
1517
1363
  toString() {
1518
1364
  const day = this.getDate();
1519
1365
  const fullYear = this.getFullYear();
1520
1366
  const monthName = this.getMonthName();
1521
1367
  return `${day} ${monthName} ${fullYear}`;
1522
1368
  }
1369
+
1523
1370
  /**
1524
1371
  * Returns true if Hebrew year is a leap year
1525
1372
  * @param {number} year Hebrew year
1526
1373
  * @return {boolean}
1527
1374
  */
1528
-
1529
-
1530
1375
  static isLeapYear(year) {
1531
1376
  return isLeapYear(year);
1532
1377
  }
1378
+
1533
1379
  /**
1534
1380
  * Number of months in this Hebrew year (either 12 or 13 depending on leap year)
1535
1381
  * @param {number} year Hebrew year
1536
1382
  * @return {number}
1537
1383
  */
1538
-
1539
-
1540
1384
  static monthsInYear(year) {
1541
1385
  return monthsInYear(year);
1542
1386
  }
1387
+
1543
1388
  /**
1544
1389
  * Number of days in Hebrew month in a given year (29 or 30)
1545
1390
  * @param {number} month Hebrew month (e.g. months.TISHREI)
1546
1391
  * @param {number} year Hebrew year
1547
1392
  * @return {number}
1548
1393
  */
1549
-
1550
-
1551
1394
  static daysInMonth(month, year) {
1552
1395
  return daysInMonth(month, year);
1553
1396
  }
1397
+
1554
1398
  /**
1555
1399
  * Returns a transliterated string name of Hebrew month in year,
1556
1400
  * for example 'Elul' or 'Cheshvan'.
@@ -1558,77 +1402,65 @@ class HDate {
1558
1402
  * @param {number} year Hebrew year
1559
1403
  * @return {string}
1560
1404
  */
1561
-
1562
-
1563
1405
  static getMonthName(month, year) {
1564
1406
  return getMonthName(month, year);
1565
1407
  }
1408
+
1566
1409
  /**
1567
1410
  * Returns the Hebrew month number (NISAN=1, TISHREI=7)
1568
1411
  * @param {number|string} month A number, or Hebrew month name string
1569
1412
  * @return {number}
1570
1413
  */
1571
-
1572
-
1573
1414
  static monthNum(month) {
1574
1415
  if (typeof month === 'number') {
1575
1416
  if (isNaN(month) || month > 14) {
1576
1417
  throw new RangeError(`Invalid month number: ${month}`);
1577
1418
  }
1578
-
1579
1419
  return month;
1580
1420
  }
1581
-
1582
- return month.charCodeAt(0) >= 48 && month.charCodeAt(0) <= 57 ?
1583
- /* number */
1421
+ return month.charCodeAt(0) >= 48 && month.charCodeAt(0) <= 57 ? /* number */
1584
1422
  parseInt(month, 10) : HDate.monthFromName(month);
1585
1423
  }
1424
+
1586
1425
  /**
1587
1426
  * Number of days in the hebrew YEAR
1588
1427
  * @param {number} year Hebrew year
1589
1428
  * @return {number}
1590
1429
  */
1591
-
1592
-
1593
1430
  static daysInYear(year) {
1594
1431
  return daysInYear(year);
1595
1432
  }
1433
+
1596
1434
  /**
1597
1435
  * true if Cheshvan is long in Hebrew year
1598
1436
  * @param {number} year Hebrew year
1599
1437
  * @return {boolean}
1600
1438
  */
1601
-
1602
-
1603
1439
  static longCheshvan(year) {
1604
1440
  return longCheshvan(year);
1605
1441
  }
1442
+
1606
1443
  /**
1607
1444
  * true if Kislev is short in Hebrew year
1608
1445
  * @param {number} year Hebrew year
1609
1446
  * @return {boolean}
1610
1447
  */
1611
-
1612
-
1613
1448
  static shortKislev(year) {
1614
1449
  return shortKislev(year);
1615
1450
  }
1451
+
1616
1452
  /**
1617
1453
  * Converts Hebrew month string name to numeric
1618
1454
  * @param {string} monthName monthName
1619
1455
  * @return {number}
1620
1456
  */
1621
-
1622
-
1623
1457
  static monthFromName(monthName) {
1624
1458
  if (typeof monthName === 'number') {
1625
1459
  if (isNaN(monthName) || monthName < 1 || monthName > 14) {
1626
1460
  throw new RangeError(`Invalid month name: ${monthName}`);
1627
1461
  }
1628
-
1629
1462
  return monthName;
1630
1463
  }
1631
-
1632
1464
  const c = monthName.toLowerCase();
1633
1465
  /*
1634
1466
  the Hebrew months are unique to their second letter
@@ -1651,115 +1483,88 @@ class HDate {
1651
1483
  ש שבט
1652
1484
  תמ תש תמוז תשרי
1653
1485
  */
1654
-
1655
1486
  switch (c[0]) {
1656
1487
  case 'n':
1657
1488
  case 'נ':
1658
1489
  if (c[1] == 'o') {
1659
- break;
1660
- /* this catches "november" */
1490
+ break; /* this catches "november" */
1661
1491
  }
1662
1492
 
1663
1493
  return months.NISAN;
1664
-
1665
1494
  case 'i':
1666
1495
  return months.IYYAR;
1667
-
1668
1496
  case 'e':
1669
1497
  return months.ELUL;
1670
-
1671
1498
  case 'c':
1672
1499
  case 'ח':
1673
1500
  return months.CHESHVAN;
1674
-
1675
1501
  case 'k':
1676
1502
  case 'כ':
1677
1503
  return months.KISLEV;
1678
-
1679
1504
  case 's':
1680
1505
  switch (c[1]) {
1681
1506
  case 'i':
1682
1507
  return months.SIVAN;
1683
-
1684
1508
  case 'h':
1685
1509
  return months.SHVAT;
1686
1510
  }
1687
-
1688
1511
  case 't':
1689
1512
  switch (c[1]) {
1690
1513
  case 'a':
1691
1514
  return months.TAMUZ;
1692
-
1693
1515
  case 'i':
1694
1516
  return months.TISHREI;
1695
-
1696
1517
  case 'e':
1697
1518
  return months.TEVET;
1698
1519
  }
1699
-
1700
1520
  break;
1701
-
1702
1521
  case 'a':
1703
1522
  switch (c[1]) {
1704
1523
  case 'v':
1705
1524
  return months.AV;
1706
-
1707
1525
  case 'd':
1708
1526
  if (/(1|[^i]i|a|א)$/i.test(monthName)) {
1709
1527
  return months.ADAR_I;
1710
1528
  }
1711
-
1712
1529
  return months.ADAR_II;
1713
1530
  // else assume sheini
1714
1531
  }
1715
1532
 
1716
1533
  break;
1717
-
1718
1534
  case 'ס':
1719
1535
  return months.SIVAN;
1720
-
1721
1536
  case 'ט':
1722
1537
  return months.TEVET;
1723
-
1724
1538
  case 'ש':
1725
1539
  return months.SHVAT;
1726
-
1727
1540
  case 'א':
1728
1541
  switch (c[1]) {
1729
1542
  case 'ב':
1730
1543
  return months.AV;
1731
-
1732
1544
  case 'ד':
1733
1545
  if (/(1|[^i]i|a|א)$/i.test(monthName)) {
1734
1546
  return months.ADAR_I;
1735
1547
  }
1736
-
1737
1548
  return months.ADAR_II;
1738
1549
  // else assume sheini
1739
-
1740
1550
  case 'י':
1741
1551
  return months.IYYAR;
1742
-
1743
1552
  case 'ל':
1744
1553
  return months.ELUL;
1745
1554
  }
1746
-
1747
1555
  break;
1748
-
1749
1556
  case 'ת':
1750
1557
  switch (c[1]) {
1751
1558
  case 'מ':
1752
1559
  return months.TAMUZ;
1753
-
1754
1560
  case 'ש':
1755
1561
  return months.TISHREI;
1756
1562
  }
1757
-
1758
1563
  break;
1759
1564
  }
1760
-
1761
1565
  throw new RangeError(`Unable to parse month name: ${monthName}`);
1762
1566
  }
1567
+
1763
1568
  /**
1764
1569
  * Note: Applying this function to d+6 gives us the DAYNAME on or after an
1765
1570
  * absolute day d. Similarly, applying it to d+3 gives the DAYNAME nearest to
@@ -1769,71 +1574,60 @@ class HDate {
1769
1574
  * @param {number} absdate
1770
1575
  * @return {number}
1771
1576
  */
1772
-
1773
-
1774
1577
  static dayOnOrBefore(dayOfWeek, absdate) {
1775
1578
  return absdate - (absdate - dayOfWeek) % 7;
1776
1579
  }
1580
+
1777
1581
  /**
1778
1582
  * Tests if the object is an instance of `HDate`
1779
1583
  * @param {any} obj
1780
1584
  * @return {boolean}
1781
1585
  */
1782
-
1783
-
1784
1586
  static isHDate(obj) {
1785
1587
  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
1588
  }
1787
-
1788
1589
  }
1590
+
1789
1591
  /**
1790
1592
  * @private
1791
1593
  * @param {HDate} date
1792
1594
  */
1793
-
1794
1595
  function fix(date) {
1795
1596
  fixMonth(date);
1796
1597
  fixDate(date);
1797
1598
  }
1599
+
1798
1600
  /**
1799
1601
  * @private
1800
1602
  * @param {HDate} date
1801
1603
  */
1802
-
1803
-
1804
1604
  function fixDate(date) {
1805
1605
  if (date.day < 1) {
1806
1606
  if (date.month == months.TISHREI) {
1807
1607
  date.year -= 1;
1808
1608
  }
1809
-
1810
1609
  date.day += daysInMonth(date.month, date.year);
1811
1610
  date.month -= 1;
1812
1611
  fix(date);
1813
1612
  }
1814
-
1815
1613
  if (date.day > daysInMonth(date.month, date.year)) {
1816
1614
  if (date.month === months.ELUL) {
1817
1615
  date.year += 1;
1818
1616
  }
1819
-
1820
1617
  date.day -= daysInMonth(date.month, date.year);
1821
1618
  date.month += 1;
1822
1619
  fix(date);
1823
1620
  }
1824
-
1825
1621
  fixMonth(date);
1826
1622
  }
1623
+
1827
1624
  /**
1828
1625
  * @private
1829
1626
  * @param {HDate} date
1830
1627
  */
1831
-
1832
-
1833
1628
  function fixMonth(date) {
1834
1629
  if (date.month === months.ADAR_II && !date.isLeapYear()) {
1835
1630
  date.month -= 1; // to Adar I
1836
-
1837
1631
  fix(date);
1838
1632
  } else if (date.month < 1) {
1839
1633
  date.month += monthsInYear(date.year);
@@ -1844,9 +1638,9 @@ function fixMonth(date) {
1844
1638
  date.year += 1;
1845
1639
  fix(date);
1846
1640
  }
1847
-
1848
1641
  delete date.abs0;
1849
1642
  }
1643
+
1850
1644
  /**
1851
1645
  * @private
1852
1646
  * @param {number} day
@@ -1854,8 +1648,6 @@ function fixMonth(date) {
1854
1648
  * @param {number} offset
1855
1649
  * @return {HDate}
1856
1650
  */
1857
-
1858
-
1859
1651
  function onOrBefore(day, t, offset) {
1860
1652
  return new HDate(HDate.dayOnOrBefore(day, t.abs() + offset));
1861
1653
  }
@@ -1867,13 +1659,13 @@ const TEVET = months.TEVET;
1867
1659
  const SHVAT = months.SHVAT;
1868
1660
  const ADAR_I = months.ADAR_I;
1869
1661
  const ADAR_II = months.ADAR_II;
1662
+
1870
1663
  /**
1871
1664
  * @private
1872
1665
  * @param {number} hyear Hebrew year
1873
1666
  * @param {Date|HDate} gdate Gregorian or Hebrew date of death
1874
1667
  * @return {HDate} anniversary occurring in hyear
1875
1668
  */
1876
-
1877
1669
  function getYahrzeit_(hyear, gdate) {
1878
1670
  const orig = HDate.isHDate(gdate) ? gdate : new HDate(gdate);
1879
1671
  let hDeath = {
@@ -1881,12 +1673,10 @@ function getYahrzeit_(hyear, gdate) {
1881
1673
  mm: orig.getMonth(),
1882
1674
  dd: orig.getDate()
1883
1675
  };
1884
-
1885
1676
  if (hyear <= hDeath.yy) {
1886
1677
  // `Hebrew year ${hyear} occurs on or before original date in ${hDeath.yy}`
1887
1678
  return undefined;
1888
1679
  }
1889
-
1890
1680
  if (hDeath.mm == CHESHVAN && hDeath.dd == 30 && !longCheshvan(hDeath.yy + 1)) {
1891
1681
  // If it's Heshvan 30 it depends on the first anniversary;
1892
1682
  // if that was not Heshvan 30, use the day before Kislev 1.
@@ -1903,10 +1693,10 @@ function getYahrzeit_(hyear, gdate) {
1903
1693
  // (so Adar has only 29 days), use the last day in Shevat.
1904
1694
  hDeath.dd = 30;
1905
1695
  hDeath.mm = SHVAT;
1906
- } // In all other cases, use the normal anniversary of the date of death.
1907
- // advance day to rosh chodesh if needed
1908
-
1696
+ }
1697
+ // In all other cases, use the normal anniversary of the date of death.
1909
1698
 
1699
+ // advance day to rosh chodesh if needed
1910
1700
  if (hDeath.mm == CHESHVAN && hDeath.dd == 30 && !longCheshvan(hyear)) {
1911
1701
  hDeath.mm = KISLEV;
1912
1702
  hDeath.dd = 1;
@@ -1914,29 +1704,25 @@ function getYahrzeit_(hyear, gdate) {
1914
1704
  hDeath.mm = TEVET;
1915
1705
  hDeath.dd = 1;
1916
1706
  }
1917
-
1918
1707
  return new HDate(hDeath.dd, hDeath.mm, hyear);
1919
1708
  }
1709
+
1920
1710
  /**
1921
1711
  * @private
1922
1712
  * @param {number} hyear Hebrew year
1923
1713
  * @param {Date|HDate} gdate Gregorian or Hebrew date of event
1924
1714
  * @return {HDate} anniversary occurring in `hyear`
1925
1715
  */
1926
-
1927
1716
  function getBirthdayOrAnniversary_(hyear, gdate) {
1928
1717
  const orig = HDate.isHDate(gdate) ? gdate : new HDate(gdate);
1929
1718
  const origYear = orig.getFullYear();
1930
-
1931
1719
  if (hyear <= origYear) {
1932
1720
  // `Hebrew year ${hyear} occurs on or before original date in ${origYear}`
1933
1721
  return undefined;
1934
1722
  }
1935
-
1936
1723
  const isOrigLeap = isLeapYear(origYear);
1937
1724
  let month = orig.getMonth();
1938
1725
  let day = orig.getDate();
1939
-
1940
1726
  if (month == ADAR_I && !isOrigLeap || month == ADAR_II && isOrigLeap) {
1941
1727
  month = monthsInYear(hyear);
1942
1728
  } else if (month == CHESHVAN && day == 30 && !longCheshvan(hyear)) {
@@ -1949,11 +1735,10 @@ function getBirthdayOrAnniversary_(hyear, gdate) {
1949
1735
  month = NISAN;
1950
1736
  day = 1;
1951
1737
  }
1952
-
1953
1738
  return new HDate(day, month, hyear);
1954
1739
  }
1955
1740
 
1956
- const version="3.45.3";
1741
+ const version="3.45.5";
1957
1742
 
1958
1743
  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
1744