@hebcal/core 3.37.2 → 3.38.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/hdate.js CHANGED
@@ -1,4 +1,4 @@
1
- /*! @hebcal/core v3.37.2 */
1
+ /*! @hebcal/core v3.38.2 */
2
2
  'use strict';
3
3
 
4
4
  Object.defineProperty(exports, '__esModule', { value: true });
@@ -169,26 +169,15 @@ function gematriya(number) {
169
169
  }
170
170
 
171
171
  /*
172
- Hebcal - A Jewish Calendar Generator
173
- Copyright (c) 1994-2020 Danny Sadinoff
174
- Portions copyright Eyal Schachter and Michael J. Radwin
175
-
176
- https://github.com/hebcal/hebcal-es6
177
-
178
- This program is free software; you can redistribute it and/or
179
- modify it under the terms of the GNU General Public License
180
- as published by the Free Software Foundation; either version 2
181
- of the License, or (at your option) any later version.
172
+ * More minimal greg routines
173
+ */
182
174
 
183
- This program is distributed in the hope that it will be useful,
184
- but WITHOUT ANY WARRANTY; without even the implied warranty of
185
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
186
- GNU General Public License for more details.
175
+ /** @private */
176
+ const lengths = [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
177
+ /** @private */
187
178
 
188
- You should have received a copy of the GNU General Public License
189
- along with this program. If not, see <http://www.gnu.org/licenses/>.
190
- */
191
- const monthLengths = [[0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31], [0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]];
179
+ const monthLengths = [lengths, lengths.slice()];
180
+ monthLengths[1][2] = 29;
192
181
  /**
193
182
  * @private
194
183
  * @param {number} x
@@ -210,9 +199,168 @@ function quotient(x, y) {
210
199
  return Math.floor(x / y);
211
200
  }
212
201
  /**
213
- * Gregorian date helper functions.
202
+ * Returns true if the Gregorian year is a leap year
203
+ * @private
204
+ * @param {number} year Gregorian year
205
+ * @return {boolean}
206
+ */
207
+
208
+
209
+ function isLeapYear$1(year) {
210
+ return !(year % 4) && (!!(year % 100) || !(year % 400));
211
+ }
212
+ /**
213
+ * Number of days in the Gregorian month for given year
214
+ * @private
215
+ * @param {number} month Gregorian month (1=January, 12=December)
216
+ * @param {number} year Gregorian year
217
+ * @return {number}
218
+ */
219
+
220
+ function daysInMonth$1(month, year) {
221
+ // 1 based months
222
+ return monthLengths[+isLeapYear$1(year)][month];
223
+ }
224
+ /**
225
+ * Returns true if the object is a Javascript Date
226
+ * @private
227
+ * @param {Object} obj
228
+ * @return {boolean}
229
+ */
230
+
231
+ function isDate(obj) {
232
+ return typeof obj === 'object' && Date.prototype === obj.__proto__;
233
+ }
234
+ /**
235
+ * Returns number of days since January 1 of that year
236
+ * @private
237
+ * @param {Date} date Gregorian date
238
+ * @return {number}
239
+ */
240
+
241
+ function dayOfYear(date) {
242
+ if (!isDate(date)) {
243
+ throw new TypeError(`Argument not a Date: ${date}`);
244
+ }
245
+
246
+ let doy = date.getDate() + 31 * date.getMonth();
247
+
248
+ if (date.getMonth() > 1) {
249
+ // FEB
250
+ doy -= Math.floor((4 * (date.getMonth() + 1) + 23) / 10);
251
+
252
+ if (isLeapYear$1(date.getFullYear())) {
253
+ doy++;
254
+ }
255
+ }
256
+
257
+ return doy;
258
+ }
259
+ /**
260
+ * Converts Gregorian date to absolute R.D. (Rata Die) days
261
+ * @private
262
+ * @param {Date} date Gregorian date
263
+ * @return {number}
264
+ */
265
+
266
+ function greg2abs(date) {
267
+ if (!isDate(date)) {
268
+ throw new TypeError(`Argument not a Date: ${date}`);
269
+ }
270
+
271
+ const year = date.getFullYear() - 1;
272
+ return dayOfYear(date) + // days this year
273
+ 365 * year + ( // + days in prior years
274
+ Math.floor(year / 4) - // + Julian Leap years
275
+ Math.floor(year / 100) + // - century years
276
+ Math.floor(year / 400)); // + Gregorian leap years
277
+ }
278
+ /**
279
+ * @private
280
+ * @param {number} abs - R.D. number of days
281
+ * @return {number}
214
282
  */
215
283
 
284
+ function yearFromFixed(abs) {
285
+ const l0 = abs - 1;
286
+ const n400 = quotient(l0, 146097);
287
+ const d1 = mod(l0, 146097);
288
+ const n100 = quotient(d1, 36524);
289
+ const d2 = mod(d1, 36524);
290
+ const n4 = quotient(d2, 1461);
291
+ const d3 = mod(d2, 1461);
292
+ const n1 = quotient(d3, 365);
293
+ const year = 400 * n400 + 100 * n100 + 4 * n4 + n1;
294
+ return n100 != 4 && n1 != 4 ? year + 1 : year;
295
+ }
296
+ /**
297
+ * @private
298
+ * @param {number} year
299
+ * @param {number} month
300
+ * @param {number} day
301
+ * @return {number}
302
+ */
303
+
304
+
305
+ function toFixed(year, month, day) {
306
+ const py = year - 1;
307
+ return 0 + 365 * py + quotient(py, 4) - quotient(py, 100) + quotient(py, 400) + quotient(367 * month - 362, 12) + Math.floor(month <= 2 ? 0 : isLeapYear$1(year) ? -1 : -2) + day;
308
+ }
309
+ /**
310
+ * Converts from Rata Die (R.D. number) to Gregorian date.
311
+ * See the footnote on page 384 of ``Calendrical Calculations, Part II:
312
+ * Three Historical Calendars'' by E. M. Reingold, N. Dershowitz, and S. M.
313
+ * Clamen, Software--Practice and Experience, Volume 23, Number 4
314
+ * (April, 1993), pages 383-404 for an explanation.
315
+ * @private
316
+ * @param {number} abs - R.D. number of days
317
+ * @return {Date}
318
+ */
319
+
320
+
321
+ function abs2greg(abs) {
322
+ if (typeof abs !== 'number') {
323
+ throw new TypeError(`Argument not a Number: ${abs}`);
324
+ }
325
+
326
+ abs = Math.trunc(abs);
327
+ const year = yearFromFixed(abs);
328
+ const priorDays = abs - toFixed(year, 1, 1);
329
+ const correction = abs < toFixed(year, 3, 1) ? 0 : isLeapYear$1(year) ? 1 : 2;
330
+ const month = quotient(12 * (priorDays + correction) + 373, 367);
331
+ const day = abs - toFixed(year, month, 1) + 1;
332
+ const dt = new Date(year, month - 1, day);
333
+
334
+ if (year < 100 && year >= 0) {
335
+ dt.setFullYear(year);
336
+ }
337
+
338
+ return dt;
339
+ }
340
+
341
+ /*
342
+ Hebcal - A Jewish Calendar Generator
343
+ Copyright (c) 1994-2020 Danny Sadinoff
344
+ Portions copyright Eyal Schachter and Michael J. Radwin
345
+
346
+ https://github.com/hebcal/hebcal-es6
347
+
348
+ This program is free software; you can redistribute it and/or
349
+ modify it under the terms of the GNU General Public License
350
+ as published by the Free Software Foundation; either version 2
351
+ of the License, or (at your option) any later version.
352
+
353
+ This program is distributed in the hope that it will be useful,
354
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
355
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
356
+ GNU General Public License for more details.
357
+
358
+ You should have received a copy of the GNU General Public License
359
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
360
+ */
361
+ /**
362
+ * Gregorian date helper functions.
363
+ */
216
364
 
217
365
  class greg {
218
366
  /**
@@ -228,7 +376,7 @@ class greg {
228
376
  */
229
377
 
230
378
  static isLeapYear(year) {
231
- return !(year % 4) && (!!(year % 100) || !(year % 400));
379
+ return isLeapYear$1(year);
232
380
  }
233
381
  /**
234
382
  * Number of days in the Gregorian month for given year
@@ -239,8 +387,7 @@ class greg {
239
387
 
240
388
 
241
389
  static daysInMonth(month, year) {
242
- // 1 based months
243
- return monthLengths[+this.isLeapYear(year)][month];
390
+ return daysInMonth$1(month, year);
244
391
  }
245
392
  /**
246
393
  * Returns true if the object is a Javascript Date
@@ -250,7 +397,7 @@ class greg {
250
397
 
251
398
 
252
399
  static isDate(obj) {
253
- return typeof obj === 'object' && Date.prototype === obj.__proto__;
400
+ return isDate(obj);
254
401
  }
255
402
  /**
256
403
  * Returns number of days since January 1 of that year
@@ -260,22 +407,7 @@ class greg {
260
407
 
261
408
 
262
409
  static dayOfYear(date) {
263
- if (!this.isDate(date)) {
264
- throw new TypeError('Argument to greg.dayOfYear not a Date');
265
- }
266
-
267
- let doy = date.getDate() + 31 * date.getMonth();
268
-
269
- if (date.getMonth() > 1) {
270
- // FEB
271
- doy -= Math.floor((4 * (date.getMonth() + 1) + 23) / 10);
272
-
273
- if (this.isLeapYear(date.getFullYear())) {
274
- doy++;
275
- }
276
- }
277
-
278
- return doy;
410
+ return dayOfYear(date);
279
411
  }
280
412
  /**
281
413
  * Converts Gregorian date to absolute R.D. (Rata Die) days
@@ -285,48 +417,7 @@ class greg {
285
417
 
286
418
 
287
419
  static greg2abs(date) {
288
- if (!this.isDate(date)) {
289
- throw new TypeError('Argument to greg.greg2abs not a Date');
290
- }
291
-
292
- const year = date.getFullYear() - 1;
293
- return this.dayOfYear(date) + // days this year
294
- 365 * year + ( // + days in prior years
295
- Math.floor(year / 4) - // + Julian Leap years
296
- Math.floor(year / 100) + // - century years
297
- Math.floor(year / 400)); // + Gregorian leap years
298
- }
299
- /**
300
- * @private
301
- * @param {number} theDate - R.D. number of days
302
- * @return {number}
303
- */
304
-
305
-
306
- static yearFromFixed(theDate) {
307
- const l0 = theDate - 1;
308
- const n400 = quotient(l0, 146097);
309
- const d1 = mod(l0, 146097);
310
- const n100 = quotient(d1, 36524);
311
- const d2 = mod(d1, 36524);
312
- const n4 = quotient(d2, 1461);
313
- const d3 = mod(d2, 1461);
314
- const n1 = quotient(d3, 365);
315
- const year = 400 * n400 + 100 * n100 + 4 * n4 + n1;
316
- return n100 != 4 && n1 != 4 ? year + 1 : year;
317
- }
318
- /**
319
- * @private
320
- * @param {number} year
321
- * @param {number} month
322
- * @param {number} day
323
- * @return {number}
324
- */
325
-
326
-
327
- static toFixed(year, month, day) {
328
- const py = year - 1;
329
- return 0 + 365 * py + quotient(py, 4) - quotient(py, 100) + quotient(py, 400) + quotient(367 * month - 362, 12) + Math.floor(month <= 2 ? 0 : this.isLeapYear(year) ? -1 : -2) + day;
420
+ return greg2abs(date);
330
421
  }
331
422
  /**
332
423
  * Converts from Rata Die (R.D. number) to Gregorian date.
@@ -340,23 +431,7 @@ class greg {
340
431
 
341
432
 
342
433
  static abs2greg(theDate) {
343
- if (typeof theDate !== 'number') {
344
- throw new TypeError('Argument to greg.abs2greg not a Number');
345
- }
346
-
347
- theDate = Math.trunc(theDate);
348
- const year = this.yearFromFixed(theDate);
349
- const priorDays = theDate - this.toFixed(year, 1, 1);
350
- const correction = theDate < this.toFixed(year, 3, 1) ? 0 : this.isLeapYear(year) ? 1 : 2;
351
- const month = quotient(12 * (priorDays + correction) + 373, 367);
352
- const day = theDate - this.toFixed(year, month, 1) + 1;
353
- const dt = new Date(year, month - 1, day);
354
-
355
- if (year < 100 && year >= 0) {
356
- dt.setFullYear(year);
357
- }
358
-
359
- return dt;
434
+ return abs2greg(theDate);
360
435
  }
361
436
 
362
437
  }
@@ -549,36 +624,19 @@ Locale.addLocale('', noopLocale);
549
624
  Locale.useLocale('en');
550
625
 
551
626
  /*
552
- Hebcal - A Jewish Calendar Generator
553
- Copyright (c) 1994-2020 Danny Sadinoff
554
- Portions copyright Eyal Schachter and Michael J. Radwin
555
-
556
- https://github.com/hebcal/hebcal-es6
557
-
558
- This program is free software; you can redistribute it and/or
559
- modify it under the terms of the GNU General Public License
560
- as published by the Free Software Foundation; either version 2
561
- of the License, or (at your option) any later version.
562
-
563
- This program is distributed in the hope that it will be useful,
564
- but WITHOUT ANY WARRANTY; without even the implied warranty of
565
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
566
- GNU General Public License for more details.
567
-
568
- You should have received a copy of the GNU General Public License
569
- along with this program. If not, see <http://www.gnu.org/licenses/>.
627
+ * More minimal HDate
570
628
  */
571
629
  const NISAN$1 = 1;
572
- const IYYAR = 2;
573
- const SIVAN = 3;
574
- const TAMUZ = 4;
575
- const AV = 5;
630
+ const IYYAR = 2; // const SIVAN = 3;
631
+
632
+ const TAMUZ = 4; // const AV = 5;
633
+
576
634
  const ELUL = 6;
577
635
  const TISHREI = 7;
578
636
  const CHESHVAN$1 = 8;
579
637
  const KISLEV$1 = 9;
580
- const TEVET$1 = 10;
581
- const SHVAT$1 = 11;
638
+ const TEVET$1 = 10; // const SHVAT = 11;
639
+
582
640
  const ADAR_I$1 = 12;
583
641
  const ADAR_II$1 = 13;
584
642
  /**
@@ -634,16 +692,237 @@ const monthNames0 = ['', 'Nisan', 'Iyyar', 'Sivan', 'Tamuz', 'Av', 'Elul', 'Tish
634
692
  * @private
635
693
  */
636
694
 
637
- const monthNames = [monthNames0.concat(['Adar', 'Nisan']), monthNames0.concat(['Adar I', 'Adar II', 'Nisan'])]; // eslint-disable-next-line require-jsdoc
695
+ const monthNames = [monthNames0.concat(['Adar', 'Nisan']), monthNames0.concat(['Adar I', 'Adar II', 'Nisan'])];
696
+ const edCache = Object.create(null);
697
+ const EPOCH = -1373428; // Avg year length in the cycle (19 solar years with 235 lunar months)
698
+
699
+ const AVG_HEBYEAR_DAYS = 365.24682220597794;
700
+ /**
701
+ * Converts Hebrew date to R.D. (Rata Die) fixed days.
702
+ * R.D. 1 is the imaginary date Monday, January 1, 1 on the Gregorian
703
+ * Calendar.
704
+ * @private
705
+ * @param {number} year Hebrew year
706
+ * @param {number} month Hebrew month
707
+ * @param {number} day Hebrew date (1-30)
708
+ * @return {number}
709
+ */
710
+
711
+ function hebrew2abs(year, month, day) {
712
+ let tempabs = day;
713
+
714
+ if (month < TISHREI) {
715
+ for (let m = TISHREI; m <= monthsInYear(year); m++) {
716
+ tempabs += daysInMonth(m, year);
717
+ }
718
+
719
+ for (let m = NISAN$1; m < month; m++) {
720
+ tempabs += daysInMonth(m, year);
721
+ }
722
+ } else {
723
+ for (let m = TISHREI; m < month; m++) {
724
+ tempabs += daysInMonth(m, year);
725
+ }
726
+ }
727
+
728
+ return EPOCH + elapsedDays(year) + tempabs - 1;
729
+ }
730
+ /**
731
+ * @private
732
+ * @param {number} year
733
+ * @return {number}
734
+ */
735
+
736
+ function newYear(year) {
737
+ return EPOCH + elapsedDays(year);
738
+ }
739
+ /**
740
+ * Converts absolute R.D. days to Hebrew date
741
+ * @private
742
+ * @param {number} abs absolute R.D. days
743
+ * @return {SimpleHebrewDate}
744
+ */
745
+
746
+
747
+ function abs2hebrew(abs) {
748
+ if (typeof abs !== 'number' || isNaN(abs)) {
749
+ throw new TypeError(`invalid parameter to abs2hebrew ${abs}`);
750
+ }
751
+
752
+ abs = Math.trunc(abs); // first, quickly approximate year
753
+
754
+ let year = Math.floor((abs - EPOCH) / AVG_HEBYEAR_DAYS);
755
+
756
+ while (newYear(year) <= abs) {
757
+ ++year;
758
+ }
759
+
760
+ --year;
761
+ let month = abs < hebrew2abs(year, 1, 1) ? 7 : 1;
762
+
763
+ while (abs > hebrew2abs(year, month, daysInMonth(month, year))) {
764
+ ++month;
765
+ }
766
+
767
+ const day = 1 + abs - hebrew2abs(year, month, 1);
768
+ return {
769
+ yy: year,
770
+ mm: month,
771
+ dd: day
772
+ };
773
+ }
774
+ /**
775
+ * Returns true if Hebrew year is a leap year
776
+ * @private
777
+ * @param {number} year Hebrew year
778
+ * @return {boolean}
779
+ */
780
+
781
+ function isLeapYear(year) {
782
+ return (1 + year * 7) % 19 < 7;
783
+ }
784
+ /**
785
+ * Number of months in this Hebrew year (either 12 or 13 depending on leap year)
786
+ * @private
787
+ * @param {number} year Hebrew year
788
+ * @return {number}
789
+ */
790
+
791
+ function monthsInYear(year) {
792
+ return 12 + isLeapYear(year); // boolean is cast to 1 or 0
793
+ }
794
+ /**
795
+ * Number of days in Hebrew month in a given year (29 or 30)
796
+ * @private
797
+ * @param {number} month Hebrew month (e.g. months.TISHREI)
798
+ * @param {number} year Hebrew year
799
+ * @return {number}
800
+ */
801
+
802
+ function daysInMonth(month, year) {
803
+ switch (month) {
804
+ case IYYAR:
805
+ case TAMUZ:
806
+ case ELUL:
807
+ case TEVET$1:
808
+ case ADAR_II$1:
809
+ return 29;
810
+ }
811
+
812
+ if (month === ADAR_I$1 && !isLeapYear(year) || month === CHESHVAN$1 && !longCheshvan(year) || month === KISLEV$1 && shortKislev(year)) {
813
+ return 29;
814
+ } else {
815
+ return 30;
816
+ }
817
+ }
818
+ /**
819
+ * Returns a transliterated string name of Hebrew month in year,
820
+ * for example 'Elul' or 'Cheshvan'.
821
+ * @private
822
+ * @param {number} month Hebrew month (e.g. months.TISHREI)
823
+ * @param {number} year Hebrew year
824
+ * @return {string}
825
+ */
826
+
827
+ function getMonthName(month, year) {
828
+ if (typeof month !== 'number' || isNaN(month) || month < 1 || month > 14) {
829
+ throw new TypeError(`bad month argument ${month}`);
830
+ }
831
+
832
+ return monthNames[+isLeapYear(year)][month];
833
+ }
834
+ /**
835
+ * Days from sunday prior to start of Hebrew calendar to mean
836
+ * conjunction of Tishrei in Hebrew YEAR
837
+ * @private
838
+ * @param {number} year Hebrew year
839
+ * @return {number}
840
+ */
841
+
842
+ function elapsedDays(year) {
843
+ const elapsed = edCache[year] = edCache[year] || elapsedDays0(year);
844
+ return elapsed;
845
+ }
846
+ /**
847
+ * Days from sunday prior to start of Hebrew calendar to mean
848
+ * conjunction of Tishrei in Hebrew YEAR
849
+ * @private
850
+ * @param {number} year Hebrew year
851
+ * @return {number}
852
+ */
853
+
854
+ function elapsedDays0(year) {
855
+ const prevYear = year - 1;
856
+ const mElapsed = 235 * Math.floor(prevYear / 19) + // Months in complete 19 year lunar (Metonic) cycles so far
857
+ 12 * (prevYear % 19) + // Regular months in this cycle
858
+ Math.floor((prevYear % 19 * 7 + 1) / 19); // Leap months this cycle
859
+
860
+ const pElapsed = 204 + 793 * (mElapsed % 1080);
861
+ const hElapsed = 5 + 12 * mElapsed + 793 * Math.floor(mElapsed / 1080) + Math.floor(pElapsed / 1080);
862
+ const parts = pElapsed % 1080 + 1080 * (hElapsed % 24);
863
+ const day = 1 + 29 * mElapsed + Math.floor(hElapsed / 24);
864
+ const altDay = day + (parts >= 19440 || 2 === day % 7 && parts >= 9924 && !isLeapYear(year) || 1 === day % 7 && parts >= 16789 && isLeapYear(prevYear));
865
+ return altDay + (altDay % 7 === 0 || altDay % 7 === 3 || altDay % 7 === 5);
866
+ }
867
+ /**
868
+ * Number of days in the hebrew YEAR.
869
+ * A common Hebrew calendar year can have a length of 353, 354 or 355 days
870
+ * A leap Hebrew calendar year can have a length of 383, 384 or 385 days
871
+ * @private
872
+ * @param {number} year Hebrew year
873
+ * @return {number}
874
+ */
875
+
876
+
877
+ function daysInYear(year) {
878
+ return elapsedDays(year + 1) - elapsedDays(year);
879
+ }
880
+ /**
881
+ * true if Cheshvan is long in Hebrew year
882
+ * @private
883
+ * @param {number} year Hebrew year
884
+ * @return {boolean}
885
+ */
886
+
887
+ function longCheshvan(year) {
888
+ return daysInYear(year) % 10 === 5;
889
+ }
890
+ /**
891
+ * true if Kislev is short in Hebrew year
892
+ * @private
893
+ * @param {number} year Hebrew year
894
+ * @return {boolean}
895
+ */
896
+
897
+ function shortKislev(year) {
898
+ return daysInYear(year) % 10 === 3;
899
+ }
900
+
901
+ /*
902
+ Hebcal - A Jewish Calendar Generator
903
+ Copyright (c) 1994-2020 Danny Sadinoff
904
+ Portions copyright Eyal Schachter and Michael J. Radwin
905
+
906
+ https://github.com/hebcal/hebcal-es6
907
+
908
+ This program is free software; you can redistribute it and/or
909
+ modify it under the terms of the GNU General Public License
910
+ as published by the Free Software Foundation; either version 2
911
+ of the License, or (at your option) any later version.
912
+
913
+ This program is distributed in the hope that it will be useful,
914
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
915
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
916
+ GNU General Public License for more details.
917
+
918
+ You should have received a copy of the GNU General Public License
919
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
920
+ */
638
921
 
639
922
  function throwTypeError(msg) {
640
923
  throw new TypeError(msg);
641
924
  }
642
925
 
643
- const edCache = Object.create(null);
644
- const EPOCH = -1373428; // Avg year length in the cycle (19 solar years with 235 lunar months)
645
-
646
- const AVG_HEBYEAR_DAYS = 365.24682220597794;
647
926
  const UNITS_DAY = 'day';
648
927
  const UNITS_WEEK = 'week';
649
928
  const UNITS_MONTH = 'month';
@@ -720,19 +999,22 @@ class HDate {
720
999
  * @type {number}
721
1000
  */
722
1001
 
723
- this.year = +year;
1002
+ year = parseInt(year, 10);
724
1003
 
725
- if (isNaN(this.year)) {
1004
+ if (isNaN(year)) {
726
1005
  throw new TypeError(`HDate called with bad year argument: ${year}`);
727
1006
  }
728
1007
 
1008
+ this.year = year;
729
1009
  this.setMonth(month); // will throw if we can't parse
730
1010
 
731
- this.setDate(+day);
1011
+ day = parseInt(day, 10);
732
1012
 
733
- if (isNaN(this.day)) {
1013
+ if (isNaN(day)) {
734
1014
  throw new TypeError(`HDate called with bad day argument: ${day}`);
735
1015
  }
1016
+
1017
+ this.setDate(day);
736
1018
  } else {
737
1019
  // 0 arguments
738
1020
  if (typeof day === 'undefined') {
@@ -740,13 +1022,13 @@ class HDate {
740
1022
  } // 1 argument
741
1023
 
742
1024
 
743
- const abs0 = typeof day === 'number' && !isNaN(day) ? day : greg.isDate(day) ? greg.greg2abs(day) : HDate.isHDate(day) ? {
1025
+ const abs0 = typeof day === 'number' && !isNaN(day) ? day : isDate(day) ? greg2abs(day) : HDate.isHDate(day) ? {
744
1026
  dd: day.day,
745
1027
  mm: day.month,
746
1028
  yy: day.year
747
1029
  } : throwTypeError(`HDate called with bad argument: ${day}`);
748
1030
  const isNumber = typeof abs0 === 'number';
749
- const d = isNumber ? HDate.abs2hebrew(abs0) : abs0;
1031
+ const d = isNumber ? abs2hebrew(abs0) : abs0;
750
1032
  /**
751
1033
  * @private
752
1034
  * @type {number}
@@ -791,7 +1073,7 @@ class HDate {
791
1073
 
792
1074
 
793
1075
  isLeapYear() {
794
- return HDate.isLeapYear(this.year);
1076
+ return isLeapYear(this.year);
795
1077
  }
796
1078
  /**
797
1079
  * Gets the Hebrew month (1=NISAN, 7=TISHREI) of this Hebrew date
@@ -809,7 +1091,7 @@ class HDate {
809
1091
 
810
1092
 
811
1093
  getTishreiMonth() {
812
- const nummonths = HDate.monthsInYear(this.getFullYear());
1094
+ const nummonths = monthsInYear(this.getFullYear());
813
1095
  return (this.getMonth() + nummonths - 6) % nummonths || nummonths;
814
1096
  }
815
1097
  /**
@@ -819,7 +1101,7 @@ class HDate {
819
1101
 
820
1102
 
821
1103
  daysInMonth() {
822
- return HDate.daysInMonth(this.getMonth(), this.getFullYear());
1104
+ return daysInMonth(this.getMonth(), this.getFullYear());
823
1105
  }
824
1106
  /**
825
1107
  * Gets the day within the month (1-30)
@@ -885,7 +1167,7 @@ class HDate {
885
1167
 
886
1168
 
887
1169
  greg() {
888
- return greg.abs2greg(this.abs());
1170
+ return abs2greg(this.abs());
889
1171
  }
890
1172
  /**
891
1173
  * Returns R.D. (Rata Die) fixed days.
@@ -898,7 +1180,7 @@ class HDate {
898
1180
 
899
1181
  abs() {
900
1182
  if (typeof this.abs0 !== 'number') {
901
- this.abs0 = HDate.hebrew2abs(this.year, this.month, this.day);
1183
+ this.abs0 = hebrew2abs(this.year, this.month, this.day);
902
1184
  }
903
1185
 
904
1186
  return this.abs0;
@@ -915,51 +1197,7 @@ class HDate {
915
1197
 
916
1198
 
917
1199
  static hebrew2abs(year, month, day) {
918
- let tempabs = day;
919
-
920
- if (month < TISHREI) {
921
- for (let m = TISHREI; m <= HDate.monthsInYear(year); m++) {
922
- tempabs += HDate.daysInMonth(m, year);
923
- }
924
-
925
- for (let m = NISAN$1; m < month; m++) {
926
- tempabs += HDate.daysInMonth(m, year);
927
- }
928
- } else {
929
- for (let m = TISHREI; m < month; m++) {
930
- tempabs += HDate.daysInMonth(m, year);
931
- }
932
- }
933
-
934
- return EPOCH + HDate.elapsedDays(year) + tempabs - 1;
935
- }
936
- /**
937
- * @private
938
- * @param {number} year
939
- * @return {number}
940
- */
941
-
942
-
943
- static newYear(year) {
944
- return EPOCH + HDate.elapsedDays(year) + HDate.newYearDelay(year);
945
- }
946
- /**
947
- * @private
948
- * @param {number} year
949
- * @return {number}
950
- */
951
-
952
-
953
- static newYearDelay(year) {
954
- const ny1 = HDate.elapsedDays(year);
955
- const ny2 = HDate.elapsedDays(year + 1);
956
-
957
- if (ny2 - ny1 === 356) {
958
- return 2;
959
- } else {
960
- const ny0 = HDate.elapsedDays(year - 1);
961
- return ny1 - ny0 === 382 ? 1 : 0;
962
- }
1200
+ return hebrew2abs(year, month, day);
963
1201
  }
964
1202
  /**
965
1203
  * Converts absolute R.D. days to Hebrew date
@@ -970,31 +1208,7 @@ class HDate {
970
1208
 
971
1209
 
972
1210
  static abs2hebrew(abs) {
973
- if (typeof abs !== 'number' || isNaN(abs)) {
974
- throw new TypeError(`invalid parameter to abs2hebrew ${abs}`);
975
- }
976
-
977
- abs = Math.trunc(abs); // first, quickly approximate year
978
-
979
- let year = Math.floor((abs - EPOCH) / AVG_HEBYEAR_DAYS);
980
-
981
- while (HDate.newYear(year) <= abs) {
982
- ++year;
983
- }
984
-
985
- --year;
986
- let month = abs < HDate.hebrew2abs(year, 1, 1) ? 7 : 1;
987
-
988
- while (abs > HDate.hebrew2abs(year, month, HDate.daysInMonth(month, year))) {
989
- ++month;
990
- }
991
-
992
- const day = 1 + abs - HDate.hebrew2abs(year, month, 1);
993
- return {
994
- yy: year,
995
- mm: month,
996
- dd: day
997
- };
1211
+ return abs2hebrew(abs);
998
1212
  }
999
1213
  /**
1000
1214
  * Returns a transliterated Hebrew month name, e.g. `'Elul'` or `'Cheshvan'`.
@@ -1003,7 +1217,7 @@ class HDate {
1003
1217
 
1004
1218
 
1005
1219
  getMonthName() {
1006
- return HDate.getMonthName(this.getMonth(), this.getFullYear());
1220
+ return getMonthName(this.getMonth(), this.getFullYear());
1007
1221
  }
1008
1222
  /**
1009
1223
  * Renders this Hebrew date as a translated or transliterated string,
@@ -1309,7 +1523,7 @@ class HDate {
1309
1523
 
1310
1524
 
1311
1525
  static isLeapYear(year) {
1312
- return (1 + year * 7) % 19 < 7;
1526
+ return isLeapYear(year);
1313
1527
  }
1314
1528
  /**
1315
1529
  * Number of months in this Hebrew year (either 12 or 13 depending on leap year)
@@ -1319,7 +1533,7 @@ class HDate {
1319
1533
 
1320
1534
 
1321
1535
  static monthsInYear(year) {
1322
- return 12 + HDate.isLeapYear(year); // boolean is cast to 1 or 0
1536
+ return monthsInYear(year);
1323
1537
  }
1324
1538
  /**
1325
1539
  * Number of days in Hebrew month in a given year (29 or 30)
@@ -1330,11 +1544,7 @@ class HDate {
1330
1544
 
1331
1545
 
1332
1546
  static daysInMonth(month, year) {
1333
- if (month == IYYAR || month == TAMUZ || month == ELUL || month == TEVET$1 || month == ADAR_II$1 || month == ADAR_I$1 && !HDate.isLeapYear(year) || month == CHESHVAN$1 && !HDate.longCheshvan(year) || month == KISLEV$1 && HDate.shortKislev(year)) {
1334
- return 29;
1335
- } else {
1336
- return 30;
1337
- }
1547
+ return daysInMonth(month, year);
1338
1548
  }
1339
1549
  /**
1340
1550
  * Returns a transliterated string name of Hebrew month in year,
@@ -1346,11 +1556,7 @@ class HDate {
1346
1556
 
1347
1557
 
1348
1558
  static getMonthName(month, year) {
1349
- if (typeof month !== 'number' || month < 1 || month > 14) {
1350
- throw new TypeError(`bad month argument ${month}`);
1351
- }
1352
-
1353
- return monthNames[+HDate.isLeapYear(year)][month];
1559
+ return getMonthName(month, year);
1354
1560
  }
1355
1561
  /**
1356
1562
  * Returns the Hebrew month number (NISAN=1, TISHREI=7)
@@ -1360,43 +1566,17 @@ class HDate {
1360
1566
 
1361
1567
 
1362
1568
  static monthNum(month) {
1363
- return typeof month === 'number' ? month : month.charCodeAt(0) >= 48 && month.charCodeAt(0) <= 57 ?
1364
- /* number */
1365
- parseInt(month, 10) : HDate.monthFromName(month);
1366
- }
1367
- /**
1368
- * Days from sunday prior to start of Hebrew calendar to mean
1369
- * conjunction of Tishrei in Hebrew YEAR
1370
- * @param {number} year Hebrew year
1371
- * @return {number}
1372
- */
1373
-
1374
-
1375
- static elapsedDays(year) {
1376
- const elapsed = edCache[year] = edCache[year] || HDate.elapsedDays0(year);
1377
- return elapsed;
1378
- }
1379
- /**
1380
- * Days from sunday prior to start of Hebrew calendar to mean
1381
- * conjunction of Tishrei in Hebrew YEAR
1382
- * @private
1383
- * @param {number} year Hebrew year
1384
- * @return {number}
1385
- */
1386
-
1569
+ if (typeof month === 'number') {
1570
+ if (isNaN(month) || month > 14) {
1571
+ throw new RangeError(`Invalid month number: ${month}`);
1572
+ }
1387
1573
 
1388
- static elapsedDays0(year) {
1389
- const prevYear = year - 1;
1390
- const mElapsed = 235 * Math.floor(prevYear / 19) + // Months in complete 19 year lunar (Metonic) cycles so far
1391
- 12 * (prevYear % 19) + // Regular months in this cycle
1392
- Math.floor((prevYear % 19 * 7 + 1) / 19); // Leap months this cycle
1574
+ return month;
1575
+ }
1393
1576
 
1394
- const pElapsed = 204 + 793 * (mElapsed % 1080);
1395
- const hElapsed = 5 + 12 * mElapsed + 793 * Math.floor(mElapsed / 1080) + Math.floor(pElapsed / 1080);
1396
- const parts = pElapsed % 1080 + 1080 * (hElapsed % 24);
1397
- const day = 1 + 29 * mElapsed + Math.floor(hElapsed / 24);
1398
- const altDay = day + (parts >= 19440 || 2 == day % 7 && parts >= 9924 && !HDate.isLeapYear(year) || 1 == day % 7 && parts >= 16789 && HDate.isLeapYear(prevYear));
1399
- return altDay + (altDay % 7 === 0 || altDay % 7 == 3 || altDay % 7 == 5);
1577
+ return month.charCodeAt(0) >= 48 && month.charCodeAt(0) <= 57 ?
1578
+ /* number */
1579
+ parseInt(month, 10) : HDate.monthFromName(month);
1400
1580
  }
1401
1581
  /**
1402
1582
  * Number of days in the hebrew YEAR
@@ -1406,7 +1586,7 @@ class HDate {
1406
1586
 
1407
1587
 
1408
1588
  static daysInYear(year) {
1409
- return HDate.elapsedDays(year + 1) - HDate.elapsedDays(year);
1589
+ return daysInYear(year);
1410
1590
  }
1411
1591
  /**
1412
1592
  * true if Cheshvan is long in Hebrew year
@@ -1416,7 +1596,7 @@ class HDate {
1416
1596
 
1417
1597
 
1418
1598
  static longCheshvan(year) {
1419
- return HDate.daysInYear(year) % 10 == 5;
1599
+ return longCheshvan(year);
1420
1600
  }
1421
1601
  /**
1422
1602
  * true if Kislev is short in Hebrew year
@@ -1426,7 +1606,7 @@ class HDate {
1426
1606
 
1427
1607
 
1428
1608
  static shortKislev(year) {
1429
- return HDate.daysInYear(year) % 10 == 3;
1609
+ return shortKislev(year);
1430
1610
  }
1431
1611
  /**
1432
1612
  * Converts Hebrew month string name to numeric
@@ -1436,7 +1616,14 @@ class HDate {
1436
1616
 
1437
1617
 
1438
1618
  static monthFromName(monthName) {
1439
- if (typeof monthName === 'number') return monthName;
1619
+ if (typeof monthName === 'number') {
1620
+ if (isNaN(monthName) || monthName < 1 || monthName > 14) {
1621
+ throw new RangeError(`Invalid month name: ${monthName}`);
1622
+ }
1623
+
1624
+ return monthName;
1625
+ }
1626
+
1440
1627
  const c = monthName.toLowerCase();
1441
1628
  /*
1442
1629
  the Hebrew months are unique to their second letter
@@ -1468,41 +1655,41 @@ class HDate {
1468
1655
  /* this catches "november" */
1469
1656
  }
1470
1657
 
1471
- return NISAN$1;
1658
+ return months.NISAN;
1472
1659
 
1473
1660
  case 'i':
1474
- return IYYAR;
1661
+ return months.IYYAR;
1475
1662
 
1476
1663
  case 'e':
1477
- return ELUL;
1664
+ return months.ELUL;
1478
1665
 
1479
1666
  case 'c':
1480
1667
  case 'ח':
1481
- return CHESHVAN$1;
1668
+ return months.CHESHVAN;
1482
1669
 
1483
1670
  case 'k':
1484
1671
  case 'כ':
1485
- return KISLEV$1;
1672
+ return months.KISLEV;
1486
1673
 
1487
1674
  case 's':
1488
1675
  switch (c[1]) {
1489
1676
  case 'i':
1490
- return SIVAN;
1677
+ return months.SIVAN;
1491
1678
 
1492
1679
  case 'h':
1493
- return SHVAT$1;
1680
+ return months.SHVAT;
1494
1681
  }
1495
1682
 
1496
1683
  case 't':
1497
1684
  switch (c[1]) {
1498
1685
  case 'a':
1499
- return TAMUZ;
1686
+ return months.TAMUZ;
1500
1687
 
1501
1688
  case 'i':
1502
- return TISHREI;
1689
+ return months.TISHREI;
1503
1690
 
1504
1691
  case 'e':
1505
- return TEVET$1;
1692
+ return months.TEVET;
1506
1693
  }
1507
1694
 
1508
1695
  break;
@@ -1510,46 +1697,46 @@ class HDate {
1510
1697
  case 'a':
1511
1698
  switch (c[1]) {
1512
1699
  case 'v':
1513
- return AV;
1700
+ return months.AV;
1514
1701
 
1515
1702
  case 'd':
1516
1703
  if (/(1|[^i]i|a|א)$/i.test(monthName)) {
1517
- return ADAR_I$1;
1704
+ return months.ADAR_I;
1518
1705
  }
1519
1706
 
1520
- return ADAR_II$1;
1707
+ return months.ADAR_II;
1521
1708
  // else assume sheini
1522
1709
  }
1523
1710
 
1524
1711
  break;
1525
1712
 
1526
1713
  case 'ס':
1527
- return SIVAN;
1714
+ return months.SIVAN;
1528
1715
 
1529
1716
  case 'ט':
1530
- return TEVET$1;
1717
+ return months.TEVET;
1531
1718
 
1532
1719
  case 'ש':
1533
- return SHVAT$1;
1720
+ return months.SHVAT;
1534
1721
 
1535
1722
  case 'א':
1536
1723
  switch (c[1]) {
1537
1724
  case 'ב':
1538
- return AV;
1725
+ return months.AV;
1539
1726
 
1540
1727
  case 'ד':
1541
1728
  if (/(1|[^i]i|a|א)$/i.test(monthName)) {
1542
- return ADAR_I$1;
1729
+ return months.ADAR_I;
1543
1730
  }
1544
1731
 
1545
- return ADAR_II$1;
1732
+ return months.ADAR_II;
1546
1733
  // else assume sheini
1547
1734
 
1548
1735
  case 'י':
1549
- return IYYAR;
1736
+ return months.IYYAR;
1550
1737
 
1551
1738
  case 'ל':
1552
- return ELUL;
1739
+ return months.ELUL;
1553
1740
  }
1554
1741
 
1555
1742
  break;
@@ -1557,10 +1744,10 @@ class HDate {
1557
1744
  case 'ת':
1558
1745
  switch (c[1]) {
1559
1746
  case 'מ':
1560
- return TAMUZ;
1747
+ return months.TAMUZ;
1561
1748
 
1562
1749
  case 'ש':
1563
- return TISHREI;
1750
+ return months.TISHREI;
1564
1751
  }
1565
1752
 
1566
1753
  break;
@@ -1611,21 +1798,21 @@ function fix(date) {
1611
1798
 
1612
1799
  function fixDate(date) {
1613
1800
  if (date.day < 1) {
1614
- if (date.month == TISHREI) {
1801
+ if (date.month == months.TISHREI) {
1615
1802
  date.year -= 1;
1616
1803
  }
1617
1804
 
1618
- date.day += HDate.daysInMonth(date.month, date.year);
1805
+ date.day += daysInMonth(date.month, date.year);
1619
1806
  date.month -= 1;
1620
1807
  fix(date);
1621
1808
  }
1622
1809
 
1623
- if (date.day > HDate.daysInMonth(date.month, date.year)) {
1624
- if (date.month == ELUL) {
1810
+ if (date.day > daysInMonth(date.month, date.year)) {
1811
+ if (date.month === months.ELUL) {
1625
1812
  date.year += 1;
1626
1813
  }
1627
1814
 
1628
- date.day -= HDate.daysInMonth(date.month, date.year);
1815
+ date.day -= daysInMonth(date.month, date.year);
1629
1816
  date.month += 1;
1630
1817
  fix(date);
1631
1818
  }
@@ -1639,16 +1826,16 @@ function fixDate(date) {
1639
1826
 
1640
1827
 
1641
1828
  function fixMonth(date) {
1642
- if (date.month == ADAR_II$1 && !date.isLeapYear()) {
1829
+ if (date.month === months.ADAR_II && !date.isLeapYear()) {
1643
1830
  date.month -= 1; // to Adar I
1644
1831
 
1645
1832
  fix(date);
1646
1833
  } else if (date.month < 1) {
1647
- date.month += HDate.monthsInYear(date.year);
1834
+ date.month += monthsInYear(date.year);
1648
1835
  date.year -= 1;
1649
1836
  fix(date);
1650
- } else if (date.month > HDate.monthsInYear(date.year)) {
1651
- date.month -= HDate.monthsInYear(date.year);
1837
+ } else if (date.month > monthsInYear(date.year)) {
1838
+ date.month -= monthsInYear(date.year);
1652
1839
  date.year += 1;
1653
1840
  fix(date);
1654
1841
  }
@@ -1695,18 +1882,18 @@ function getYahrzeit_(hyear, gdate) {
1695
1882
  return undefined;
1696
1883
  }
1697
1884
 
1698
- if (hDeath.mm == CHESHVAN && hDeath.dd == 30 && !HDate.longCheshvan(hDeath.yy + 1)) {
1885
+ if (hDeath.mm == CHESHVAN && hDeath.dd == 30 && !longCheshvan(hDeath.yy + 1)) {
1699
1886
  // If it's Heshvan 30 it depends on the first anniversary;
1700
1887
  // if that was not Heshvan 30, use the day before Kislev 1.
1701
- hDeath = HDate.abs2hebrew(HDate.hebrew2abs(hyear, KISLEV, 1) - 1);
1702
- } else if (hDeath.mm == KISLEV && hDeath.dd == 30 && HDate.shortKislev(hDeath.yy + 1)) {
1888
+ hDeath = abs2hebrew(hebrew2abs(hyear, KISLEV, 1) - 1);
1889
+ } else if (hDeath.mm == KISLEV && hDeath.dd == 30 && shortKislev(hDeath.yy + 1)) {
1703
1890
  // If it's Kislev 30 it depends on the first anniversary;
1704
1891
  // if that was not Kislev 30, use the day before Teveth 1.
1705
- hDeath = HDate.abs2hebrew(HDate.hebrew2abs(hyear, TEVET, 1) - 1);
1892
+ hDeath = abs2hebrew(hebrew2abs(hyear, TEVET, 1) - 1);
1706
1893
  } else if (hDeath.mm == ADAR_II) {
1707
1894
  // If it's Adar II, use the same day in last month of year (Adar or Adar II).
1708
- hDeath.mm = HDate.monthsInYear(hyear);
1709
- } else if (hDeath.mm == ADAR_I && hDeath.dd == 30 && !HDate.isLeapYear(hyear)) {
1895
+ hDeath.mm = monthsInYear(hyear);
1896
+ } else if (hDeath.mm == ADAR_I && hDeath.dd == 30 && !isLeapYear(hyear)) {
1710
1897
  // If it's the 30th in Adar I and year is not a leap year
1711
1898
  // (so Adar has only 29 days), use the last day in Shevat.
1712
1899
  hDeath.dd = 30;
@@ -1715,10 +1902,10 @@ function getYahrzeit_(hyear, gdate) {
1715
1902
  // advance day to rosh chodesh if needed
1716
1903
 
1717
1904
 
1718
- if (hDeath.mm == CHESHVAN && hDeath.dd == 30 && !HDate.longCheshvan(hyear)) {
1905
+ if (hDeath.mm == CHESHVAN && hDeath.dd == 30 && !longCheshvan(hyear)) {
1719
1906
  hDeath.mm = KISLEV;
1720
1907
  hDeath.dd = 1;
1721
- } else if (hDeath.mm == KISLEV && hDeath.dd == 30 && HDate.shortKislev(hyear)) {
1908
+ } else if (hDeath.mm == KISLEV && hDeath.dd == 30 && shortKislev(hyear)) {
1722
1909
  hDeath.mm = TEVET;
1723
1910
  hDeath.dd = 1;
1724
1911
  }
@@ -1741,19 +1928,19 @@ function getBirthdayOrAnniversary_(hyear, gdate) {
1741
1928
  return undefined;
1742
1929
  }
1743
1930
 
1744
- const isOrigLeap = HDate.isLeapYear(origYear);
1931
+ const isOrigLeap = isLeapYear(origYear);
1745
1932
  let month = orig.getMonth();
1746
1933
  let day = orig.getDate();
1747
1934
 
1748
1935
  if (month == ADAR_I && !isOrigLeap || month == ADAR_II && isOrigLeap) {
1749
- month = HDate.monthsInYear(hyear);
1750
- } else if (month == CHESHVAN && day == 30 && !HDate.longCheshvan(hyear)) {
1936
+ month = monthsInYear(hyear);
1937
+ } else if (month == CHESHVAN && day == 30 && !longCheshvan(hyear)) {
1751
1938
  month = KISLEV;
1752
1939
  day = 1;
1753
- } else if (month == KISLEV && day == 30 && HDate.shortKislev(hyear)) {
1940
+ } else if (month == KISLEV && day == 30 && shortKislev(hyear)) {
1754
1941
  month = TEVET;
1755
1942
  day = 1;
1756
- } else if (month == ADAR_I && day == 30 && isOrigLeap && !HDate.isLeapYear(hyear)) {
1943
+ } else if (month == ADAR_I && day == 30 && isOrigLeap && !isLeapYear(hyear)) {
1757
1944
  month = NISAN;
1758
1945
  day = 1;
1759
1946
  }
@@ -1761,7 +1948,7 @@ function getBirthdayOrAnniversary_(hyear, gdate) {
1761
1948
  return new HDate(day, month, hyear);
1762
1949
  }
1763
1950
 
1764
- const version="3.37.2";
1951
+ const version="3.38.2";
1765
1952
 
1766
1953
  const headers={"plural-forms":"nplurals=2; plural=(n > 1);",language:"he"};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};
1767
1954