@hebcal/core 3.37.0 → 3.38.0

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.mjs CHANGED
@@ -1,4 +1,4 @@
1
- /*! @hebcal/core v3.37.0 */
1
+ /*! @hebcal/core v3.38.0 */
2
2
  const GERESH = '׳';
3
3
  const GERSHAYIM = '״';
4
4
  /**
@@ -164,27 +164,12 @@ function gematriya(number) {
164
164
  return str;
165
165
  }
166
166
 
167
- /*
168
- Hebcal - A Jewish Calendar Generator
169
- Copyright (c) 1994-2020 Danny Sadinoff
170
- Portions copyright Eyal Schachter and Michael J. Radwin
171
-
172
- https://github.com/hebcal/hebcal-es6
173
-
174
- This program is free software; you can redistribute it and/or
175
- modify it under the terms of the GNU General Public License
176
- as published by the Free Software Foundation; either version 2
177
- of the License, or (at your option) any later version.
178
-
179
- This program is distributed in the hope that it will be useful,
180
- but WITHOUT ANY WARRANTY; without even the implied warranty of
181
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
182
- GNU General Public License for more details.
183
-
184
- You should have received a copy of the GNU General Public License
185
- along with this program. If not, see <http://www.gnu.org/licenses/>.
167
+ /**
168
+ * More minimal greg routines
186
169
  */
187
- 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]];
170
+ const lengths = [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
171
+ const monthLengths = [lengths, lengths.slice()];
172
+ monthLengths[1][2] = 29;
188
173
  /**
189
174
  * @private
190
175
  * @param {number} x
@@ -206,10 +191,169 @@ function quotient(x, y) {
206
191
  return Math.floor(x / y);
207
192
  }
208
193
  /**
209
- * Gregorian date helper functions.
194
+ * Returns true if the Gregorian year is a leap year
195
+ * @private
196
+ * @param {number} year Gregorian year
197
+ * @return {boolean}
210
198
  */
211
199
 
212
200
 
201
+ function isLeapYear$1(year) {
202
+ return !(year % 4) && (!!(year % 100) || !(year % 400));
203
+ }
204
+ /**
205
+ * Number of days in the Gregorian month for given year
206
+ * @private
207
+ * @param {number} month Gregorian month (1=January, 12=December)
208
+ * @param {number} year Gregorian year
209
+ * @return {number}
210
+ */
211
+
212
+ function daysInMonth$1(month, year) {
213
+ // 1 based months
214
+ return monthLengths[+isLeapYear$1(year)][month];
215
+ }
216
+ /**
217
+ * Returns true if the object is a Javascript Date
218
+ * @private
219
+ * @param {Object} obj
220
+ * @return {boolean}
221
+ */
222
+
223
+ function isDate(obj) {
224
+ return typeof obj === 'object' && Date.prototype === obj.__proto__;
225
+ }
226
+ /**
227
+ * Returns number of days since January 1 of that year
228
+ * @private
229
+ * @param {Date} date Gregorian date
230
+ * @return {number}
231
+ */
232
+
233
+ function dayOfYear(date) {
234
+ if (!isDate(date)) {
235
+ throw new TypeError('Argument to greg.dayOfYear not a Date');
236
+ }
237
+
238
+ let doy = date.getDate() + 31 * date.getMonth();
239
+
240
+ if (date.getMonth() > 1) {
241
+ // FEB
242
+ doy -= Math.floor((4 * (date.getMonth() + 1) + 23) / 10);
243
+
244
+ if (isLeapYear$1(date.getFullYear())) {
245
+ doy++;
246
+ }
247
+ }
248
+
249
+ return doy;
250
+ }
251
+ /**
252
+ * Converts Gregorian date to absolute R.D. (Rata Die) days
253
+ * @private
254
+ * @param {Date} date Gregorian date
255
+ * @return {number}
256
+ */
257
+
258
+ function greg2abs(date) {
259
+ if (!isDate(date)) {
260
+ throw new TypeError('Argument to greg.greg2abs not a Date');
261
+ }
262
+
263
+ const year = date.getFullYear() - 1;
264
+ return dayOfYear(date) + // days this year
265
+ 365 * year + ( // + days in prior years
266
+ Math.floor(year / 4) - // + Julian Leap years
267
+ Math.floor(year / 100) + // - century years
268
+ Math.floor(year / 400)); // + Gregorian leap years
269
+ }
270
+ /**
271
+ * @private
272
+ * @param {number} abs - R.D. number of days
273
+ * @return {number}
274
+ */
275
+
276
+ function yearFromFixed(abs) {
277
+ const l0 = abs - 1;
278
+ const n400 = quotient(l0, 146097);
279
+ const d1 = mod(l0, 146097);
280
+ const n100 = quotient(d1, 36524);
281
+ const d2 = mod(d1, 36524);
282
+ const n4 = quotient(d2, 1461);
283
+ const d3 = mod(d2, 1461);
284
+ const n1 = quotient(d3, 365);
285
+ const year = 400 * n400 + 100 * n100 + 4 * n4 + n1;
286
+ return n100 != 4 && n1 != 4 ? year + 1 : year;
287
+ }
288
+ /**
289
+ * @private
290
+ * @param {number} year
291
+ * @param {number} month
292
+ * @param {number} day
293
+ * @return {number}
294
+ */
295
+
296
+
297
+ function toFixed(year, month, day) {
298
+ const py = year - 1;
299
+ 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;
300
+ }
301
+ /**
302
+ * Converts from Rata Die (R.D. number) to Gregorian date.
303
+ * See the footnote on page 384 of ``Calendrical Calculations, Part II:
304
+ * Three Historical Calendars'' by E. M. Reingold, N. Dershowitz, and S. M.
305
+ * Clamen, Software--Practice and Experience, Volume 23, Number 4
306
+ * (April, 1993), pages 383-404 for an explanation.
307
+ * @private
308
+ * @param {number} abs - R.D. number of days
309
+ * @return {Date}
310
+ */
311
+
312
+
313
+ function abs2greg(abs) {
314
+ if (typeof abs !== 'number') {
315
+ throw new TypeError('Argument to greg.abs2greg not a Number');
316
+ }
317
+
318
+ abs = Math.trunc(abs);
319
+ const year = yearFromFixed(abs);
320
+ const priorDays = abs - toFixed(year, 1, 1);
321
+ const correction = abs < toFixed(year, 3, 1) ? 0 : isLeapYear$1(year) ? 1 : 2;
322
+ const month = quotient(12 * (priorDays + correction) + 373, 367);
323
+ const day = abs - toFixed(year, month, 1) + 1;
324
+ const dt = new Date(year, month - 1, day);
325
+
326
+ if (year < 100 && year >= 0) {
327
+ dt.setFullYear(year);
328
+ }
329
+
330
+ return dt;
331
+ }
332
+
333
+ /*
334
+ Hebcal - A Jewish Calendar Generator
335
+ Copyright (c) 1994-2020 Danny Sadinoff
336
+ Portions copyright Eyal Schachter and Michael J. Radwin
337
+
338
+ https://github.com/hebcal/hebcal-es6
339
+
340
+ This program is free software; you can redistribute it and/or
341
+ modify it under the terms of the GNU General Public License
342
+ as published by the Free Software Foundation; either version 2
343
+ of the License, or (at your option) any later version.
344
+
345
+ This program is distributed in the hope that it will be useful,
346
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
347
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
348
+ GNU General Public License for more details.
349
+
350
+ You should have received a copy of the GNU General Public License
351
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
352
+ */
353
+ /**
354
+ * Gregorian date helper functions.
355
+ */
356
+
213
357
  class greg {
214
358
  /**
215
359
  * Long names of the Gregorian months (1='January', 12='December')
@@ -224,7 +368,7 @@ class greg {
224
368
  */
225
369
 
226
370
  static isLeapYear(year) {
227
- return !(year % 4) && (!!(year % 100) || !(year % 400));
371
+ return isLeapYear$1(year);
228
372
  }
229
373
  /**
230
374
  * Number of days in the Gregorian month for given year
@@ -235,8 +379,7 @@ class greg {
235
379
 
236
380
 
237
381
  static daysInMonth(month, year) {
238
- // 1 based months
239
- return monthLengths[+this.isLeapYear(year)][month];
382
+ return daysInMonth$1(month, year);
240
383
  }
241
384
  /**
242
385
  * Returns true if the object is a Javascript Date
@@ -246,7 +389,7 @@ class greg {
246
389
 
247
390
 
248
391
  static isDate(obj) {
249
- return typeof obj === 'object' && Date.prototype === obj.__proto__;
392
+ return isDate(obj);
250
393
  }
251
394
  /**
252
395
  * Returns number of days since January 1 of that year
@@ -256,22 +399,7 @@ class greg {
256
399
 
257
400
 
258
401
  static dayOfYear(date) {
259
- if (!this.isDate(date)) {
260
- throw new TypeError('Argument to greg.dayOfYear not a Date');
261
- }
262
-
263
- let doy = date.getDate() + 31 * date.getMonth();
264
-
265
- if (date.getMonth() > 1) {
266
- // FEB
267
- doy -= Math.floor((4 * (date.getMonth() + 1) + 23) / 10);
268
-
269
- if (this.isLeapYear(date.getFullYear())) {
270
- doy++;
271
- }
272
- }
273
-
274
- return doy;
402
+ return dayOfYear(date);
275
403
  }
276
404
  /**
277
405
  * Converts Gregorian date to absolute R.D. (Rata Die) days
@@ -281,48 +409,7 @@ class greg {
281
409
 
282
410
 
283
411
  static greg2abs(date) {
284
- if (!this.isDate(date)) {
285
- throw new TypeError('Argument to greg.greg2abs not a Date');
286
- }
287
-
288
- const year = date.getFullYear() - 1;
289
- return this.dayOfYear(date) + // days this year
290
- 365 * year + ( // + days in prior years
291
- Math.floor(year / 4) - // + Julian Leap years
292
- Math.floor(year / 100) + // - century years
293
- Math.floor(year / 400)); // + Gregorian leap years
294
- }
295
- /**
296
- * @private
297
- * @param {number} theDate - R.D. number of days
298
- * @return {number}
299
- */
300
-
301
-
302
- static yearFromFixed(theDate) {
303
- const l0 = theDate - 1;
304
- const n400 = quotient(l0, 146097);
305
- const d1 = mod(l0, 146097);
306
- const n100 = quotient(d1, 36524);
307
- const d2 = mod(d1, 36524);
308
- const n4 = quotient(d2, 1461);
309
- const d3 = mod(d2, 1461);
310
- const n1 = quotient(d3, 365);
311
- const year = 400 * n400 + 100 * n100 + 4 * n4 + n1;
312
- return n100 != 4 && n1 != 4 ? year + 1 : year;
313
- }
314
- /**
315
- * @private
316
- * @param {number} year
317
- * @param {number} month
318
- * @param {number} day
319
- * @return {number}
320
- */
321
-
322
-
323
- static toFixed(year, month, day) {
324
- const py = year - 1;
325
- 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;
412
+ return greg2abs(date);
326
413
  }
327
414
  /**
328
415
  * Converts from Rata Die (R.D. number) to Gregorian date.
@@ -336,23 +423,7 @@ class greg {
336
423
 
337
424
 
338
425
  static abs2greg(theDate) {
339
- if (typeof theDate !== 'number') {
340
- throw new TypeError('Argument to greg.abs2greg not a Number');
341
- }
342
-
343
- theDate = Math.trunc(theDate);
344
- const year = this.yearFromFixed(theDate);
345
- const priorDays = theDate - this.toFixed(year, 1, 1);
346
- const correction = theDate < this.toFixed(year, 3, 1) ? 0 : this.isLeapYear(year) ? 1 : 2;
347
- const month = quotient(12 * (priorDays + correction) + 373, 367);
348
- const day = theDate - this.toFixed(year, month, 1) + 1;
349
- const dt = new Date(year, month - 1, day);
350
-
351
- if (year < 100 && year >= 0) {
352
- dt.setFullYear(year);
353
- }
354
-
355
- return dt;
426
+ return abs2greg(theDate);
356
427
  }
357
428
 
358
429
  }
@@ -544,37 +615,20 @@ Locale.addLocale('s', noopLocale);
544
615
  Locale.addLocale('', noopLocale);
545
616
  Locale.useLocale('en');
546
617
 
547
- /*
548
- Hebcal - A Jewish Calendar Generator
549
- Copyright (c) 1994-2020 Danny Sadinoff
550
- Portions copyright Eyal Schachter and Michael J. Radwin
551
-
552
- https://github.com/hebcal/hebcal-es6
553
-
554
- This program is free software; you can redistribute it and/or
555
- modify it under the terms of the GNU General Public License
556
- as published by the Free Software Foundation; either version 2
557
- of the License, or (at your option) any later version.
558
-
559
- This program is distributed in the hope that it will be useful,
560
- but WITHOUT ANY WARRANTY; without even the implied warranty of
561
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
562
- GNU General Public License for more details.
563
-
564
- You should have received a copy of the GNU General Public License
565
- along with this program. If not, see <http://www.gnu.org/licenses/>.
618
+ /**
619
+ * More minimal HDate
566
620
  */
567
621
  const NISAN$1 = 1;
568
- const IYYAR = 2;
569
- const SIVAN = 3;
570
- const TAMUZ = 4;
571
- const AV = 5;
622
+ const IYYAR = 2; // const SIVAN = 3;
623
+
624
+ const TAMUZ = 4; // const AV = 5;
625
+
572
626
  const ELUL = 6;
573
627
  const TISHREI = 7;
574
628
  const CHESHVAN$1 = 8;
575
629
  const KISLEV$1 = 9;
576
- const TEVET$1 = 10;
577
- const SHVAT$1 = 11;
630
+ const TEVET$1 = 10; // const SHVAT = 11;
631
+
578
632
  const ADAR_I$1 = 12;
579
633
  const ADAR_II$1 = 13;
580
634
  /**
@@ -630,16 +684,244 @@ const monthNames0 = ['', 'Nisan', 'Iyyar', 'Sivan', 'Tamuz', 'Av', 'Elul', 'Tish
630
684
  * @private
631
685
  */
632
686
 
633
- const monthNames = [monthNames0.concat(['Adar', 'Nisan']), monthNames0.concat(['Adar I', 'Adar II', 'Nisan'])]; // eslint-disable-next-line require-jsdoc
687
+ const monthNames = [monthNames0.concat(['Adar', 'Nisan']), monthNames0.concat(['Adar I', 'Adar II', 'Nisan'])];
688
+ const edCache = Object.create(null);
689
+ const EPOCH = -1373428; // Avg year length in the cycle (19 solar years with 235 lunar months)
690
+
691
+ const AVG_HEBYEAR_DAYS = 365.24682220597794;
692
+ /**
693
+ * Converts Hebrew date to R.D. (Rata Die) fixed days.
694
+ * R.D. 1 is the imaginary date Monday, January 1, 1 on the Gregorian
695
+ * Calendar.
696
+ * @param {number} year Hebrew year
697
+ * @param {number} month Hebrew month
698
+ * @param {number} day Hebrew date (1-30)
699
+ * @return {number}
700
+ */
701
+
702
+ function hebrew2abs(year, month, day) {
703
+ let tempabs = day;
704
+
705
+ if (month < TISHREI) {
706
+ for (let m = TISHREI; m <= monthsInYear(year); m++) {
707
+ tempabs += daysInMonth(m, year);
708
+ }
709
+
710
+ for (let m = NISAN$1; m < month; m++) {
711
+ tempabs += daysInMonth(m, year);
712
+ }
713
+ } else {
714
+ for (let m = TISHREI; m < month; m++) {
715
+ tempabs += daysInMonth(m, year);
716
+ }
717
+ }
718
+
719
+ return EPOCH + elapsedDays(year) + tempabs - 1;
720
+ }
721
+ /**
722
+ * @private
723
+ * @param {number} year
724
+ * @return {number}
725
+ */
726
+
727
+ function newYear(year) {
728
+ return EPOCH + elapsedDays(year) + newYearDelay(year);
729
+ }
730
+ /**
731
+ * @private
732
+ * @param {number} year
733
+ * @return {number}
734
+ */
735
+
736
+
737
+ function newYearDelay(year) {
738
+ const ny1 = elapsedDays(year);
739
+ const ny2 = elapsedDays(year + 1);
740
+
741
+ if (ny2 - ny1 === 356) {
742
+ return 2;
743
+ } else {
744
+ const ny0 = elapsedDays(year - 1);
745
+ return ny1 - ny0 === 382 ? 1 : 0;
746
+ }
747
+ }
748
+ /**
749
+ * Converts absolute R.D. days to Hebrew date
750
+ * @private
751
+ * @param {number} abs absolute R.D. days
752
+ * @return {SimpleHebrewDate}
753
+ */
754
+
755
+
756
+ function abs2hebrew(abs) {
757
+ if (typeof abs !== 'number' || isNaN(abs)) {
758
+ throw new TypeError(`invalid parameter to abs2hebrew ${abs}`);
759
+ }
760
+
761
+ abs = Math.trunc(abs); // first, quickly approximate year
762
+
763
+ let year = Math.floor((abs - EPOCH) / AVG_HEBYEAR_DAYS);
764
+
765
+ while (newYear(year) <= abs) {
766
+ ++year;
767
+ }
768
+
769
+ --year;
770
+ let month = abs < hebrew2abs(year, 1, 1) ? 7 : 1;
771
+
772
+ while (abs > hebrew2abs(year, month, daysInMonth(month, year))) {
773
+ ++month;
774
+ }
775
+
776
+ const day = 1 + abs - hebrew2abs(year, month, 1);
777
+ return {
778
+ yy: year,
779
+ mm: month,
780
+ dd: day
781
+ };
782
+ }
783
+ /**
784
+ * Returns true if Hebrew year is a leap year
785
+ * @param {number} year Hebrew year
786
+ * @return {boolean}
787
+ */
788
+
789
+ function isLeapYear(year) {
790
+ return (1 + year * 7) % 19 < 7;
791
+ }
792
+ /**
793
+ * Number of months in this Hebrew year (either 12 or 13 depending on leap year)
794
+ * @param {number} year Hebrew year
795
+ * @return {number}
796
+ */
797
+
798
+ function monthsInYear(year) {
799
+ return 12 + isLeapYear(year); // boolean is cast to 1 or 0
800
+ }
801
+ /**
802
+ * Number of days in Hebrew month in a given year (29 or 30)
803
+ * @param {number} month Hebrew month (e.g. months.TISHREI)
804
+ * @param {number} year Hebrew year
805
+ * @return {number}
806
+ */
807
+
808
+ function daysInMonth(month, year) {
809
+ switch (month) {
810
+ case IYYAR:
811
+ case TAMUZ:
812
+ case ELUL:
813
+ case TEVET$1:
814
+ case ADAR_II$1:
815
+ return 29;
816
+ }
817
+
818
+ if (month === ADAR_I$1 && !isLeapYear(year) || month === CHESHVAN$1 && !longCheshvan(year) || month === KISLEV$1 && shortKislev(year)) {
819
+ return 29;
820
+ } else {
821
+ return 30;
822
+ }
823
+ }
824
+ /**
825
+ * Returns a transliterated string name of Hebrew month in year,
826
+ * for example 'Elul' or 'Cheshvan'.
827
+ * @param {number} month Hebrew month (e.g. months.TISHREI)
828
+ * @param {number} year Hebrew year
829
+ * @return {string}
830
+ */
831
+
832
+ function getMonthName(month, year) {
833
+ if (typeof month !== 'number' || month < 1 || month > 14) {
834
+ throw new TypeError(`bad month argument ${month}`);
835
+ }
836
+
837
+ return monthNames[+isLeapYear(year)][month];
838
+ }
839
+ /**
840
+ * Days from sunday prior to start of Hebrew calendar to mean
841
+ * conjunction of Tishrei in Hebrew YEAR
842
+ * @param {number} year Hebrew year
843
+ * @return {number}
844
+ */
845
+
846
+ function elapsedDays(year) {
847
+ const elapsed = edCache[year] = edCache[year] || elapsedDays0(year);
848
+ return elapsed;
849
+ }
850
+ /**
851
+ * Days from sunday prior to start of Hebrew calendar to mean
852
+ * conjunction of Tishrei in Hebrew YEAR
853
+ * @private
854
+ * @param {number} year Hebrew year
855
+ * @return {number}
856
+ */
857
+
858
+ function elapsedDays0(year) {
859
+ const prevYear = year - 1;
860
+ const mElapsed = 235 * Math.floor(prevYear / 19) + // Months in complete 19 year lunar (Metonic) cycles so far
861
+ 12 * (prevYear % 19) + // Regular months in this cycle
862
+ Math.floor((prevYear % 19 * 7 + 1) / 19); // Leap months this cycle
863
+
864
+ const pElapsed = 204 + 793 * (mElapsed % 1080);
865
+ const hElapsed = 5 + 12 * mElapsed + 793 * Math.floor(mElapsed / 1080) + Math.floor(pElapsed / 1080);
866
+ const parts = pElapsed % 1080 + 1080 * (hElapsed % 24);
867
+ const day = 1 + 29 * mElapsed + Math.floor(hElapsed / 24);
868
+ const altDay = day + (parts >= 19440 || 2 === day % 7 && parts >= 9924 && !isLeapYear(year) || 1 === day % 7 && parts >= 16789 && isLeapYear(prevYear));
869
+ return altDay + (altDay % 7 === 0 || altDay % 7 === 3 || altDay % 7 === 5);
870
+ }
871
+ /**
872
+ * Number of days in the hebrew YEAR
873
+ * @param {number} year Hebrew year
874
+ * @return {number}
875
+ */
876
+
877
+
878
+ function daysInYear(year) {
879
+ return elapsedDays(year + 1) - elapsedDays(year);
880
+ }
881
+ /**
882
+ * true if Cheshvan is long in Hebrew year
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
+ * @param {number} year Hebrew year
893
+ * @return {boolean}
894
+ */
895
+
896
+ function shortKislev(year) {
897
+ return daysInYear(year) % 10 === 3;
898
+ }
899
+
900
+ /*
901
+ Hebcal - A Jewish Calendar Generator
902
+ Copyright (c) 1994-2020 Danny Sadinoff
903
+ Portions copyright Eyal Schachter and Michael J. Radwin
904
+
905
+ https://github.com/hebcal/hebcal-es6
906
+
907
+ This program is free software; you can redistribute it and/or
908
+ modify it under the terms of the GNU General Public License
909
+ as published by the Free Software Foundation; either version 2
910
+ of the License, or (at your option) any later version.
911
+
912
+ This program is distributed in the hope that it will be useful,
913
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
914
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
915
+ GNU General Public License for more details.
916
+
917
+ You should have received a copy of the GNU General Public License
918
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
919
+ */
634
920
 
635
921
  function throwTypeError(msg) {
636
922
  throw new TypeError(msg);
637
923
  }
638
924
 
639
- const edCache = Object.create(null);
640
- const EPOCH = -1373428; // Avg year length in the cycle (19 solar years with 235 lunar months)
641
-
642
- const AVG_HEBYEAR_DAYS = 365.24682220597794;
643
925
  const UNITS_DAY = 'day';
644
926
  const UNITS_WEEK = 'week';
645
927
  const UNITS_MONTH = 'month';
@@ -742,7 +1024,7 @@ class HDate {
742
1024
  yy: day.year
743
1025
  } : throwTypeError(`HDate called with bad argument: ${day}`);
744
1026
  const isNumber = typeof abs0 === 'number';
745
- const d = isNumber ? HDate.abs2hebrew(abs0) : abs0;
1027
+ const d = isNumber ? abs2hebrew(abs0) : abs0;
746
1028
  /**
747
1029
  * @private
748
1030
  * @type {number}
@@ -787,7 +1069,7 @@ class HDate {
787
1069
 
788
1070
 
789
1071
  isLeapYear() {
790
- return HDate.isLeapYear(this.year);
1072
+ return isLeapYear(this.year);
791
1073
  }
792
1074
  /**
793
1075
  * Gets the Hebrew month (1=NISAN, 7=TISHREI) of this Hebrew date
@@ -805,7 +1087,7 @@ class HDate {
805
1087
 
806
1088
 
807
1089
  getTishreiMonth() {
808
- const nummonths = HDate.monthsInYear(this.getFullYear());
1090
+ const nummonths = monthsInYear(this.getFullYear());
809
1091
  return (this.getMonth() + nummonths - 6) % nummonths || nummonths;
810
1092
  }
811
1093
  /**
@@ -815,7 +1097,7 @@ class HDate {
815
1097
 
816
1098
 
817
1099
  daysInMonth() {
818
- return HDate.daysInMonth(this.getMonth(), this.getFullYear());
1100
+ return daysInMonth(this.getMonth(), this.getFullYear());
819
1101
  }
820
1102
  /**
821
1103
  * Gets the day within the month (1-30)
@@ -894,7 +1176,7 @@ class HDate {
894
1176
 
895
1177
  abs() {
896
1178
  if (typeof this.abs0 !== 'number') {
897
- this.abs0 = HDate.hebrew2abs(this.year, this.month, this.day);
1179
+ this.abs0 = hebrew2abs(this.year, this.month, this.day);
898
1180
  }
899
1181
 
900
1182
  return this.abs0;
@@ -911,51 +1193,7 @@ class HDate {
911
1193
 
912
1194
 
913
1195
  static hebrew2abs(year, month, day) {
914
- let tempabs = day;
915
-
916
- if (month < TISHREI) {
917
- for (let m = TISHREI; m <= HDate.monthsInYear(year); m++) {
918
- tempabs += HDate.daysInMonth(m, year);
919
- }
920
-
921
- for (let m = NISAN$1; m < month; m++) {
922
- tempabs += HDate.daysInMonth(m, year);
923
- }
924
- } else {
925
- for (let m = TISHREI; m < month; m++) {
926
- tempabs += HDate.daysInMonth(m, year);
927
- }
928
- }
929
-
930
- return EPOCH + HDate.elapsedDays(year) + tempabs - 1;
931
- }
932
- /**
933
- * @private
934
- * @param {number} year
935
- * @return {number}
936
- */
937
-
938
-
939
- static newYear(year) {
940
- return EPOCH + HDate.elapsedDays(year) + HDate.newYearDelay(year);
941
- }
942
- /**
943
- * @private
944
- * @param {number} year
945
- * @return {number}
946
- */
947
-
948
-
949
- static newYearDelay(year) {
950
- const ny1 = HDate.elapsedDays(year);
951
- const ny2 = HDate.elapsedDays(year + 1);
952
-
953
- if (ny2 - ny1 === 356) {
954
- return 2;
955
- } else {
956
- const ny0 = HDate.elapsedDays(year - 1);
957
- return ny1 - ny0 === 382 ? 1 : 0;
958
- }
1196
+ return hebrew2abs(year, month, day);
959
1197
  }
960
1198
  /**
961
1199
  * Converts absolute R.D. days to Hebrew date
@@ -966,31 +1204,7 @@ class HDate {
966
1204
 
967
1205
 
968
1206
  static abs2hebrew(abs) {
969
- if (typeof abs !== 'number' || isNaN(abs)) {
970
- throw new TypeError(`invalid parameter to abs2hebrew ${abs}`);
971
- }
972
-
973
- abs = Math.trunc(abs); // first, quickly approximate year
974
-
975
- let year = Math.floor((abs - EPOCH) / AVG_HEBYEAR_DAYS);
976
-
977
- while (HDate.newYear(year) <= abs) {
978
- ++year;
979
- }
980
-
981
- --year;
982
- let month = abs < HDate.hebrew2abs(year, 1, 1) ? 7 : 1;
983
-
984
- while (abs > HDate.hebrew2abs(year, month, HDate.daysInMonth(month, year))) {
985
- ++month;
986
- }
987
-
988
- const day = 1 + abs - HDate.hebrew2abs(year, month, 1);
989
- return {
990
- yy: year,
991
- mm: month,
992
- dd: day
993
- };
1207
+ return abs2hebrew(abs);
994
1208
  }
995
1209
  /**
996
1210
  * Returns a transliterated Hebrew month name, e.g. `'Elul'` or `'Cheshvan'`.
@@ -999,7 +1213,7 @@ class HDate {
999
1213
 
1000
1214
 
1001
1215
  getMonthName() {
1002
- return HDate.getMonthName(this.getMonth(), this.getFullYear());
1216
+ return getMonthName(this.getMonth(), this.getFullYear());
1003
1217
  }
1004
1218
  /**
1005
1219
  * Renders this Hebrew date as a translated or transliterated string,
@@ -1305,7 +1519,7 @@ class HDate {
1305
1519
 
1306
1520
 
1307
1521
  static isLeapYear(year) {
1308
- return (1 + year * 7) % 19 < 7;
1522
+ return isLeapYear(year);
1309
1523
  }
1310
1524
  /**
1311
1525
  * Number of months in this Hebrew year (either 12 or 13 depending on leap year)
@@ -1315,7 +1529,7 @@ class HDate {
1315
1529
 
1316
1530
 
1317
1531
  static monthsInYear(year) {
1318
- return 12 + HDate.isLeapYear(year); // boolean is cast to 1 or 0
1532
+ return monthsInYear(year);
1319
1533
  }
1320
1534
  /**
1321
1535
  * Number of days in Hebrew month in a given year (29 or 30)
@@ -1326,11 +1540,7 @@ class HDate {
1326
1540
 
1327
1541
 
1328
1542
  static daysInMonth(month, year) {
1329
- 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)) {
1330
- return 29;
1331
- } else {
1332
- return 30;
1333
- }
1543
+ return daysInMonth(month, year);
1334
1544
  }
1335
1545
  /**
1336
1546
  * Returns a transliterated string name of Hebrew month in year,
@@ -1342,11 +1552,7 @@ class HDate {
1342
1552
 
1343
1553
 
1344
1554
  static getMonthName(month, year) {
1345
- if (typeof month !== 'number' || month < 1 || month > 14) {
1346
- throw new TypeError(`bad month argument ${month}`);
1347
- }
1348
-
1349
- return monthNames[+HDate.isLeapYear(year)][month];
1555
+ return getMonthName(month, year);
1350
1556
  }
1351
1557
  /**
1352
1558
  * Returns the Hebrew month number (NISAN=1, TISHREI=7)
@@ -1360,40 +1566,6 @@ class HDate {
1360
1566
  /* number */
1361
1567
  parseInt(month, 10) : HDate.monthFromName(month);
1362
1568
  }
1363
- /**
1364
- * Days from sunday prior to start of Hebrew calendar to mean
1365
- * conjunction of Tishrei in Hebrew YEAR
1366
- * @param {number} year Hebrew year
1367
- * @return {number}
1368
- */
1369
-
1370
-
1371
- static elapsedDays(year) {
1372
- const elapsed = edCache[year] = edCache[year] || HDate.elapsedDays0(year);
1373
- return elapsed;
1374
- }
1375
- /**
1376
- * Days from sunday prior to start of Hebrew calendar to mean
1377
- * conjunction of Tishrei in Hebrew YEAR
1378
- * @private
1379
- * @param {number} year Hebrew year
1380
- * @return {number}
1381
- */
1382
-
1383
-
1384
- static elapsedDays0(year) {
1385
- const prevYear = year - 1;
1386
- const mElapsed = 235 * Math.floor(prevYear / 19) + // Months in complete 19 year lunar (Metonic) cycles so far
1387
- 12 * (prevYear % 19) + // Regular months in this cycle
1388
- Math.floor((prevYear % 19 * 7 + 1) / 19); // Leap months this cycle
1389
-
1390
- const pElapsed = 204 + 793 * (mElapsed % 1080);
1391
- const hElapsed = 5 + 12 * mElapsed + 793 * Math.floor(mElapsed / 1080) + Math.floor(pElapsed / 1080);
1392
- const parts = pElapsed % 1080 + 1080 * (hElapsed % 24);
1393
- const day = 1 + 29 * mElapsed + Math.floor(hElapsed / 24);
1394
- const altDay = day + (parts >= 19440 || 2 == day % 7 && parts >= 9924 && !HDate.isLeapYear(year) || 1 == day % 7 && parts >= 16789 && HDate.isLeapYear(prevYear));
1395
- return altDay + (altDay % 7 === 0 || altDay % 7 == 3 || altDay % 7 == 5);
1396
- }
1397
1569
  /**
1398
1570
  * Number of days in the hebrew YEAR
1399
1571
  * @param {number} year Hebrew year
@@ -1402,7 +1574,7 @@ class HDate {
1402
1574
 
1403
1575
 
1404
1576
  static daysInYear(year) {
1405
- return HDate.elapsedDays(year + 1) - HDate.elapsedDays(year);
1577
+ return daysInYear(year);
1406
1578
  }
1407
1579
  /**
1408
1580
  * true if Cheshvan is long in Hebrew year
@@ -1412,7 +1584,7 @@ class HDate {
1412
1584
 
1413
1585
 
1414
1586
  static longCheshvan(year) {
1415
- return HDate.daysInYear(year) % 10 == 5;
1587
+ return longCheshvan(year);
1416
1588
  }
1417
1589
  /**
1418
1590
  * true if Kislev is short in Hebrew year
@@ -1422,7 +1594,7 @@ class HDate {
1422
1594
 
1423
1595
 
1424
1596
  static shortKislev(year) {
1425
- return HDate.daysInYear(year) % 10 == 3;
1597
+ return shortKislev(year);
1426
1598
  }
1427
1599
  /**
1428
1600
  * Converts Hebrew month string name to numeric
@@ -1464,41 +1636,41 @@ class HDate {
1464
1636
  /* this catches "november" */
1465
1637
  }
1466
1638
 
1467
- return NISAN$1;
1639
+ return months.NISAN;
1468
1640
 
1469
1641
  case 'i':
1470
- return IYYAR;
1642
+ return months.IYYAR;
1471
1643
 
1472
1644
  case 'e':
1473
- return ELUL;
1645
+ return months.ELUL;
1474
1646
 
1475
1647
  case 'c':
1476
1648
  case 'ח':
1477
- return CHESHVAN$1;
1649
+ return months.CHESHVAN;
1478
1650
 
1479
1651
  case 'k':
1480
1652
  case 'כ':
1481
- return KISLEV$1;
1653
+ return months.KISLEV;
1482
1654
 
1483
1655
  case 's':
1484
1656
  switch (c[1]) {
1485
1657
  case 'i':
1486
- return SIVAN;
1658
+ return months.SIVAN;
1487
1659
 
1488
1660
  case 'h':
1489
- return SHVAT$1;
1661
+ return months.SHVAT;
1490
1662
  }
1491
1663
 
1492
1664
  case 't':
1493
1665
  switch (c[1]) {
1494
1666
  case 'a':
1495
- return TAMUZ;
1667
+ return months.TAMUZ;
1496
1668
 
1497
1669
  case 'i':
1498
- return TISHREI;
1670
+ return months.TISHREI;
1499
1671
 
1500
1672
  case 'e':
1501
- return TEVET$1;
1673
+ return months.TEVET;
1502
1674
  }
1503
1675
 
1504
1676
  break;
@@ -1506,46 +1678,46 @@ class HDate {
1506
1678
  case 'a':
1507
1679
  switch (c[1]) {
1508
1680
  case 'v':
1509
- return AV;
1681
+ return months.AV;
1510
1682
 
1511
1683
  case 'd':
1512
1684
  if (/(1|[^i]i|a|א)$/i.test(monthName)) {
1513
- return ADAR_I$1;
1685
+ return months.ADAR_I;
1514
1686
  }
1515
1687
 
1516
- return ADAR_II$1;
1688
+ return months.ADAR_II;
1517
1689
  // else assume sheini
1518
1690
  }
1519
1691
 
1520
1692
  break;
1521
1693
 
1522
1694
  case 'ס':
1523
- return SIVAN;
1695
+ return months.SIVAN;
1524
1696
 
1525
1697
  case 'ט':
1526
- return TEVET$1;
1698
+ return months.TEVET;
1527
1699
 
1528
1700
  case 'ש':
1529
- return SHVAT$1;
1701
+ return months.SHVAT;
1530
1702
 
1531
1703
  case 'א':
1532
1704
  switch (c[1]) {
1533
1705
  case 'ב':
1534
- return AV;
1706
+ return months.AV;
1535
1707
 
1536
1708
  case 'ד':
1537
1709
  if (/(1|[^i]i|a|א)$/i.test(monthName)) {
1538
- return ADAR_I$1;
1710
+ return months.ADAR_I;
1539
1711
  }
1540
1712
 
1541
- return ADAR_II$1;
1713
+ return months.ADAR_II;
1542
1714
  // else assume sheini
1543
1715
 
1544
1716
  case 'י':
1545
- return IYYAR;
1717
+ return months.IYYAR;
1546
1718
 
1547
1719
  case 'ל':
1548
- return ELUL;
1720
+ return months.ELUL;
1549
1721
  }
1550
1722
 
1551
1723
  break;
@@ -1553,10 +1725,10 @@ class HDate {
1553
1725
  case 'ת':
1554
1726
  switch (c[1]) {
1555
1727
  case 'מ':
1556
- return TAMUZ;
1728
+ return months.TAMUZ;
1557
1729
 
1558
1730
  case 'ש':
1559
- return TISHREI;
1731
+ return months.TISHREI;
1560
1732
  }
1561
1733
 
1562
1734
  break;
@@ -1607,21 +1779,21 @@ function fix(date) {
1607
1779
 
1608
1780
  function fixDate(date) {
1609
1781
  if (date.day < 1) {
1610
- if (date.month == TISHREI) {
1782
+ if (date.month == months.TISHREI) {
1611
1783
  date.year -= 1;
1612
1784
  }
1613
1785
 
1614
- date.day += HDate.daysInMonth(date.month, date.year);
1786
+ date.day += daysInMonth(date.month, date.year);
1615
1787
  date.month -= 1;
1616
1788
  fix(date);
1617
1789
  }
1618
1790
 
1619
- if (date.day > HDate.daysInMonth(date.month, date.year)) {
1620
- if (date.month == ELUL) {
1791
+ if (date.day > daysInMonth(date.month, date.year)) {
1792
+ if (date.month === months.ELUL) {
1621
1793
  date.year += 1;
1622
1794
  }
1623
1795
 
1624
- date.day -= HDate.daysInMonth(date.month, date.year);
1796
+ date.day -= daysInMonth(date.month, date.year);
1625
1797
  date.month += 1;
1626
1798
  fix(date);
1627
1799
  }
@@ -1635,16 +1807,16 @@ function fixDate(date) {
1635
1807
 
1636
1808
 
1637
1809
  function fixMonth(date) {
1638
- if (date.month == ADAR_II$1 && !date.isLeapYear()) {
1810
+ if (date.month === months.ADAR_II && !date.isLeapYear()) {
1639
1811
  date.month -= 1; // to Adar I
1640
1812
 
1641
1813
  fix(date);
1642
1814
  } else if (date.month < 1) {
1643
- date.month += HDate.monthsInYear(date.year);
1815
+ date.month += monthsInYear(date.year);
1644
1816
  date.year -= 1;
1645
1817
  fix(date);
1646
- } else if (date.month > HDate.monthsInYear(date.year)) {
1647
- date.month -= HDate.monthsInYear(date.year);
1818
+ } else if (date.month > monthsInYear(date.year)) {
1819
+ date.month -= monthsInYear(date.year);
1648
1820
  date.year += 1;
1649
1821
  fix(date);
1650
1822
  }
@@ -1691,18 +1863,18 @@ function getYahrzeit_(hyear, gdate) {
1691
1863
  return undefined;
1692
1864
  }
1693
1865
 
1694
- if (hDeath.mm == CHESHVAN && hDeath.dd == 30 && !HDate.longCheshvan(hDeath.yy + 1)) {
1866
+ if (hDeath.mm == CHESHVAN && hDeath.dd == 30 && !longCheshvan(hDeath.yy + 1)) {
1695
1867
  // If it's Heshvan 30 it depends on the first anniversary;
1696
1868
  // if that was not Heshvan 30, use the day before Kislev 1.
1697
- hDeath = HDate.abs2hebrew(HDate.hebrew2abs(hyear, KISLEV, 1) - 1);
1698
- } else if (hDeath.mm == KISLEV && hDeath.dd == 30 && HDate.shortKislev(hDeath.yy + 1)) {
1869
+ hDeath = abs2hebrew(hebrew2abs(hyear, KISLEV, 1) - 1);
1870
+ } else if (hDeath.mm == KISLEV && hDeath.dd == 30 && shortKislev(hDeath.yy + 1)) {
1699
1871
  // If it's Kislev 30 it depends on the first anniversary;
1700
1872
  // if that was not Kislev 30, use the day before Teveth 1.
1701
- hDeath = HDate.abs2hebrew(HDate.hebrew2abs(hyear, TEVET, 1) - 1);
1873
+ hDeath = abs2hebrew(hebrew2abs(hyear, TEVET, 1) - 1);
1702
1874
  } else if (hDeath.mm == ADAR_II) {
1703
1875
  // If it's Adar II, use the same day in last month of year (Adar or Adar II).
1704
- hDeath.mm = HDate.monthsInYear(hyear);
1705
- } else if (hDeath.mm == ADAR_I && hDeath.dd == 30 && !HDate.isLeapYear(hyear)) {
1876
+ hDeath.mm = monthsInYear(hyear);
1877
+ } else if (hDeath.mm == ADAR_I && hDeath.dd == 30 && !isLeapYear(hyear)) {
1706
1878
  // If it's the 30th in Adar I and year is not a leap year
1707
1879
  // (so Adar has only 29 days), use the last day in Shevat.
1708
1880
  hDeath.dd = 30;
@@ -1711,10 +1883,10 @@ function getYahrzeit_(hyear, gdate) {
1711
1883
  // advance day to rosh chodesh if needed
1712
1884
 
1713
1885
 
1714
- if (hDeath.mm == CHESHVAN && hDeath.dd == 30 && !HDate.longCheshvan(hyear)) {
1886
+ if (hDeath.mm == CHESHVAN && hDeath.dd == 30 && !longCheshvan(hyear)) {
1715
1887
  hDeath.mm = KISLEV;
1716
1888
  hDeath.dd = 1;
1717
- } else if (hDeath.mm == KISLEV && hDeath.dd == 30 && HDate.shortKislev(hyear)) {
1889
+ } else if (hDeath.mm == KISLEV && hDeath.dd == 30 && shortKislev(hyear)) {
1718
1890
  hDeath.mm = TEVET;
1719
1891
  hDeath.dd = 1;
1720
1892
  }
@@ -1737,19 +1909,19 @@ function getBirthdayOrAnniversary_(hyear, gdate) {
1737
1909
  return undefined;
1738
1910
  }
1739
1911
 
1740
- const isOrigLeap = HDate.isLeapYear(origYear);
1912
+ const isOrigLeap = isLeapYear(origYear);
1741
1913
  let month = orig.getMonth();
1742
1914
  let day = orig.getDate();
1743
1915
 
1744
1916
  if (month == ADAR_I && !isOrigLeap || month == ADAR_II && isOrigLeap) {
1745
- month = HDate.monthsInYear(hyear);
1746
- } else if (month == CHESHVAN && day == 30 && !HDate.longCheshvan(hyear)) {
1917
+ month = monthsInYear(hyear);
1918
+ } else if (month == CHESHVAN && day == 30 && !longCheshvan(hyear)) {
1747
1919
  month = KISLEV;
1748
1920
  day = 1;
1749
- } else if (month == KISLEV && day == 30 && HDate.shortKislev(hyear)) {
1921
+ } else if (month == KISLEV && day == 30 && shortKislev(hyear)) {
1750
1922
  month = TEVET;
1751
1923
  day = 1;
1752
- } else if (month == ADAR_I && day == 30 && isOrigLeap && !HDate.isLeapYear(hyear)) {
1924
+ } else if (month == ADAR_I && day == 30 && isOrigLeap && !isLeapYear(hyear)) {
1753
1925
  month = NISAN;
1754
1926
  day = 1;
1755
1927
  }
@@ -1757,7 +1929,7 @@ function getBirthdayOrAnniversary_(hyear, gdate) {
1757
1929
  return new HDate(day, month, hyear);
1758
1930
  }
1759
1931
 
1760
- const version="3.37.0";
1932
+ const version="3.38.0";
1761
1933
 
1762
1934
  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};
1763
1935