@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.
@@ -0,0 +1,472 @@
1
+ /*! @hebcal/core v3.38.0 */
2
+ var hebcal = (function (exports) {
3
+ 'use strict';
4
+
5
+ function _typeof(obj) {
6
+ "@babel/helpers - typeof";
7
+
8
+ return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) {
9
+ return typeof obj;
10
+ } : function (obj) {
11
+ return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
12
+ }, _typeof(obj);
13
+ }
14
+
15
+ /**
16
+ * More minimal greg routines
17
+ */
18
+ var lengths = [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
19
+ var monthLengths = [lengths, lengths.slice()];
20
+ monthLengths[1][2] = 29;
21
+ /**
22
+ * @private
23
+ * @param {number} x
24
+ * @param {number} y
25
+ * @return {number}
26
+ */
27
+
28
+ function mod(x, y) {
29
+ return x - y * Math.floor(x / y);
30
+ }
31
+ /**
32
+ * @private
33
+ * @param {number} x
34
+ * @param {number} y
35
+ * @return {number}
36
+ */
37
+
38
+ function quotient(x, y) {
39
+ return Math.floor(x / y);
40
+ }
41
+ /**
42
+ * Returns true if the Gregorian year is a leap year
43
+ * @private
44
+ * @param {number} year Gregorian year
45
+ * @return {boolean}
46
+ */
47
+
48
+
49
+ function isLeapYear$1(year) {
50
+ return !(year % 4) && (!!(year % 100) || !(year % 400));
51
+ }
52
+ /**
53
+ * Returns true if the object is a Javascript Date
54
+ * @private
55
+ * @param {Object} obj
56
+ * @return {boolean}
57
+ */
58
+
59
+ function isDate(obj) {
60
+ return _typeof(obj) === 'object' && Date.prototype === obj.__proto__;
61
+ }
62
+ /**
63
+ * Returns number of days since January 1 of that year
64
+ * @private
65
+ * @param {Date} date Gregorian date
66
+ * @return {number}
67
+ */
68
+
69
+ function dayOfYear(date) {
70
+ if (!isDate(date)) {
71
+ throw new TypeError('Argument to greg.dayOfYear not a Date');
72
+ }
73
+
74
+ var doy = date.getDate() + 31 * date.getMonth();
75
+
76
+ if (date.getMonth() > 1) {
77
+ // FEB
78
+ doy -= Math.floor((4 * (date.getMonth() + 1) + 23) / 10);
79
+
80
+ if (isLeapYear$1(date.getFullYear())) {
81
+ doy++;
82
+ }
83
+ }
84
+
85
+ return doy;
86
+ }
87
+ /**
88
+ * Converts Gregorian date to absolute R.D. (Rata Die) days
89
+ * @private
90
+ * @param {Date} date Gregorian date
91
+ * @return {number}
92
+ */
93
+
94
+ function greg2abs(date) {
95
+ if (!isDate(date)) {
96
+ throw new TypeError('Argument to greg.greg2abs not a Date');
97
+ }
98
+
99
+ var year = date.getFullYear() - 1;
100
+ return dayOfYear(date) + // days this year
101
+ 365 * year + ( // + days in prior years
102
+ Math.floor(year / 4) - // + Julian Leap years
103
+ Math.floor(year / 100) + // - century years
104
+ Math.floor(year / 400)); // + Gregorian leap years
105
+ }
106
+ /**
107
+ * @private
108
+ * @param {number} abs - R.D. number of days
109
+ * @return {number}
110
+ */
111
+
112
+ function yearFromFixed(abs) {
113
+ var l0 = abs - 1;
114
+ var n400 = quotient(l0, 146097);
115
+ var d1 = mod(l0, 146097);
116
+ var n100 = quotient(d1, 36524);
117
+ var d2 = mod(d1, 36524);
118
+ var n4 = quotient(d2, 1461);
119
+ var d3 = mod(d2, 1461);
120
+ var n1 = quotient(d3, 365);
121
+ var year = 400 * n400 + 100 * n100 + 4 * n4 + n1;
122
+ return n100 != 4 && n1 != 4 ? year + 1 : year;
123
+ }
124
+ /**
125
+ * @private
126
+ * @param {number} year
127
+ * @param {number} month
128
+ * @param {number} day
129
+ * @return {number}
130
+ */
131
+
132
+
133
+ function toFixed(year, month, day) {
134
+ var py = year - 1;
135
+ 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;
136
+ }
137
+ /**
138
+ * Converts from Rata Die (R.D. number) to Gregorian date.
139
+ * See the footnote on page 384 of ``Calendrical Calculations, Part II:
140
+ * Three Historical Calendars'' by E. M. Reingold, N. Dershowitz, and S. M.
141
+ * Clamen, Software--Practice and Experience, Volume 23, Number 4
142
+ * (April, 1993), pages 383-404 for an explanation.
143
+ * @private
144
+ * @param {number} abs - R.D. number of days
145
+ * @return {Date}
146
+ */
147
+
148
+
149
+ function abs2greg(abs) {
150
+ if (typeof abs !== 'number') {
151
+ throw new TypeError('Argument to greg.abs2greg not a Number');
152
+ }
153
+
154
+ abs = Math.trunc(abs);
155
+ var year = yearFromFixed(abs);
156
+ var priorDays = abs - toFixed(year, 1, 1);
157
+ var correction = abs < toFixed(year, 3, 1) ? 0 : isLeapYear$1(year) ? 1 : 2;
158
+ var month = quotient(12 * (priorDays + correction) + 373, 367);
159
+ var day = abs - toFixed(year, month, 1) + 1;
160
+ var dt = new Date(year, month - 1, day);
161
+
162
+ if (year < 100 && year >= 0) {
163
+ dt.setFullYear(year);
164
+ }
165
+
166
+ return dt;
167
+ }
168
+
169
+ /**
170
+ * More minimal HDate
171
+ */
172
+ var NISAN = 1;
173
+ var IYYAR = 2; // const SIVAN = 3;
174
+
175
+ var TAMUZ = 4; // const AV = 5;
176
+
177
+ var ELUL = 6;
178
+ var TISHREI = 7;
179
+ var CHESHVAN = 8;
180
+ var KISLEV = 9;
181
+ var TEVET = 10; // const SHVAT = 11;
182
+
183
+ var ADAR_I = 12;
184
+ var ADAR_II = 13;
185
+ /**
186
+ * Hebrew months of the year (NISAN=1, TISHREI=7)
187
+ * @readonly
188
+ * @enum {number}
189
+ */
190
+
191
+ var months = {
192
+ /** Nissan / ניסן */
193
+ NISAN: 1,
194
+
195
+ /** Iyyar / אייר */
196
+ IYYAR: 2,
197
+
198
+ /** Sivan / סיון */
199
+ SIVAN: 3,
200
+
201
+ /** Tamuz (sometimes Tammuz) / תמוז */
202
+ TAMUZ: 4,
203
+
204
+ /** Av / אב */
205
+ AV: 5,
206
+
207
+ /** Elul / אלול */
208
+ ELUL: 6,
209
+
210
+ /** Tishrei / תִשְׁרֵי */
211
+ TISHREI: 7,
212
+
213
+ /** Cheshvan / חשון */
214
+ CHESHVAN: 8,
215
+
216
+ /** Kislev / כסלו */
217
+ KISLEV: 9,
218
+
219
+ /** Tevet / טבת */
220
+ TEVET: 10,
221
+
222
+ /** Sh'vat / שבט */
223
+ SHVAT: 11,
224
+
225
+ /** Adar or Adar Rishon / אדר */
226
+ ADAR_I: 12,
227
+
228
+ /** Adar Sheini (only on leap years) / אדר ב׳ */
229
+ ADAR_II: 13
230
+ };
231
+ var monthNames0 = ['', 'Nisan', 'Iyyar', 'Sivan', 'Tamuz', 'Av', 'Elul', 'Tishrei', 'Cheshvan', 'Kislev', 'Tevet', 'Sh\'vat'];
232
+ /**
233
+ * Transliterations of Hebrew month names.
234
+ * Regular years are index 0 and leap years are index 1.
235
+ * @private
236
+ */
237
+
238
+ var monthNames = [monthNames0.concat(['Adar', 'Nisan']), monthNames0.concat(['Adar I', 'Adar II', 'Nisan'])];
239
+ var edCache = Object.create(null);
240
+ var EPOCH = -1373428; // Avg year length in the cycle (19 solar years with 235 lunar months)
241
+
242
+ var AVG_HEBYEAR_DAYS = 365.24682220597794;
243
+ /**
244
+ * Converts Hebrew date to R.D. (Rata Die) fixed days.
245
+ * R.D. 1 is the imaginary date Monday, January 1, 1 on the Gregorian
246
+ * Calendar.
247
+ * @param {number} year Hebrew year
248
+ * @param {number} month Hebrew month
249
+ * @param {number} day Hebrew date (1-30)
250
+ * @return {number}
251
+ */
252
+
253
+ function hebrew2abs(year, month, day) {
254
+ var tempabs = day;
255
+
256
+ if (month < TISHREI) {
257
+ for (var m = TISHREI; m <= monthsInYear(year); m++) {
258
+ tempabs += daysInMonth(m, year);
259
+ }
260
+
261
+ for (var _m = NISAN; _m < month; _m++) {
262
+ tempabs += daysInMonth(_m, year);
263
+ }
264
+ } else {
265
+ for (var _m2 = TISHREI; _m2 < month; _m2++) {
266
+ tempabs += daysInMonth(_m2, year);
267
+ }
268
+ }
269
+
270
+ return EPOCH + elapsedDays(year) + tempabs - 1;
271
+ }
272
+ /**
273
+ * @private
274
+ * @param {number} year
275
+ * @return {number}
276
+ */
277
+
278
+ function newYear(year) {
279
+ return EPOCH + elapsedDays(year) + newYearDelay(year);
280
+ }
281
+ /**
282
+ * @private
283
+ * @param {number} year
284
+ * @return {number}
285
+ */
286
+
287
+
288
+ function newYearDelay(year) {
289
+ var ny1 = elapsedDays(year);
290
+ var ny2 = elapsedDays(year + 1);
291
+
292
+ if (ny2 - ny1 === 356) {
293
+ return 2;
294
+ } else {
295
+ var ny0 = elapsedDays(year - 1);
296
+ return ny1 - ny0 === 382 ? 1 : 0;
297
+ }
298
+ }
299
+ /**
300
+ * Converts absolute R.D. days to Hebrew date
301
+ * @private
302
+ * @param {number} abs absolute R.D. days
303
+ * @return {SimpleHebrewDate}
304
+ */
305
+
306
+
307
+ function abs2hebrew(abs) {
308
+ if (typeof abs !== 'number' || isNaN(abs)) {
309
+ throw new TypeError("invalid parameter to abs2hebrew ".concat(abs));
310
+ }
311
+
312
+ abs = Math.trunc(abs); // first, quickly approximate year
313
+
314
+ var year = Math.floor((abs - EPOCH) / AVG_HEBYEAR_DAYS);
315
+
316
+ while (newYear(year) <= abs) {
317
+ ++year;
318
+ }
319
+
320
+ --year;
321
+ var month = abs < hebrew2abs(year, 1, 1) ? 7 : 1;
322
+
323
+ while (abs > hebrew2abs(year, month, daysInMonth(month, year))) {
324
+ ++month;
325
+ }
326
+
327
+ var day = 1 + abs - hebrew2abs(year, month, 1);
328
+ return {
329
+ yy: year,
330
+ mm: month,
331
+ dd: day
332
+ };
333
+ }
334
+ /**
335
+ * Returns true if Hebrew year is a leap year
336
+ * @param {number} year Hebrew year
337
+ * @return {boolean}
338
+ */
339
+
340
+ function isLeapYear(year) {
341
+ return (1 + year * 7) % 19 < 7;
342
+ }
343
+ /**
344
+ * Number of months in this Hebrew year (either 12 or 13 depending on leap year)
345
+ * @param {number} year Hebrew year
346
+ * @return {number}
347
+ */
348
+
349
+ function monthsInYear(year) {
350
+ return 12 + isLeapYear(year); // boolean is cast to 1 or 0
351
+ }
352
+ /**
353
+ * Number of days in Hebrew month in a given year (29 or 30)
354
+ * @param {number} month Hebrew month (e.g. months.TISHREI)
355
+ * @param {number} year Hebrew year
356
+ * @return {number}
357
+ */
358
+
359
+ function daysInMonth(month, year) {
360
+ switch (month) {
361
+ case IYYAR:
362
+ case TAMUZ:
363
+ case ELUL:
364
+ case TEVET:
365
+ case ADAR_II:
366
+ return 29;
367
+ }
368
+
369
+ if (month === ADAR_I && !isLeapYear(year) || month === CHESHVAN && !longCheshvan(year) || month === KISLEV && shortKislev(year)) {
370
+ return 29;
371
+ } else {
372
+ return 30;
373
+ }
374
+ }
375
+ /**
376
+ * Returns a transliterated string name of Hebrew month in year,
377
+ * for example 'Elul' or 'Cheshvan'.
378
+ * @param {number} month Hebrew month (e.g. months.TISHREI)
379
+ * @param {number} year Hebrew year
380
+ * @return {string}
381
+ */
382
+
383
+ function getMonthName(month, year) {
384
+ if (typeof month !== 'number' || month < 1 || month > 14) {
385
+ throw new TypeError("bad month argument ".concat(month));
386
+ }
387
+
388
+ return monthNames[+isLeapYear(year)][month];
389
+ }
390
+ /**
391
+ * Days from sunday prior to start of Hebrew calendar to mean
392
+ * conjunction of Tishrei in Hebrew YEAR
393
+ * @param {number} year Hebrew year
394
+ * @return {number}
395
+ */
396
+
397
+ function elapsedDays(year) {
398
+ var elapsed = edCache[year] = edCache[year] || elapsedDays0(year);
399
+ return elapsed;
400
+ }
401
+ /**
402
+ * Days from sunday prior to start of Hebrew calendar to mean
403
+ * conjunction of Tishrei in Hebrew YEAR
404
+ * @private
405
+ * @param {number} year Hebrew year
406
+ * @return {number}
407
+ */
408
+
409
+ function elapsedDays0(year) {
410
+ var prevYear = year - 1;
411
+ var mElapsed = 235 * Math.floor(prevYear / 19) + // Months in complete 19 year lunar (Metonic) cycles so far
412
+ 12 * (prevYear % 19) + // Regular months in this cycle
413
+ Math.floor((prevYear % 19 * 7 + 1) / 19); // Leap months this cycle
414
+
415
+ var pElapsed = 204 + 793 * (mElapsed % 1080);
416
+ var hElapsed = 5 + 12 * mElapsed + 793 * Math.floor(mElapsed / 1080) + Math.floor(pElapsed / 1080);
417
+ var parts = pElapsed % 1080 + 1080 * (hElapsed % 24);
418
+ var day = 1 + 29 * mElapsed + Math.floor(hElapsed / 24);
419
+ var altDay = day + (parts >= 19440 || 2 === day % 7 && parts >= 9924 && !isLeapYear(year) || 1 === day % 7 && parts >= 16789 && isLeapYear(prevYear));
420
+ return altDay + (altDay % 7 === 0 || altDay % 7 === 3 || altDay % 7 === 5);
421
+ }
422
+ /**
423
+ * Number of days in the hebrew YEAR
424
+ * @param {number} year Hebrew year
425
+ * @return {number}
426
+ */
427
+
428
+
429
+ function daysInYear(year) {
430
+ return elapsedDays(year + 1) - elapsedDays(year);
431
+ }
432
+ /**
433
+ * true if Cheshvan is long in Hebrew year
434
+ * @param {number} year Hebrew year
435
+ * @return {boolean}
436
+ */
437
+
438
+ function longCheshvan(year) {
439
+ return daysInYear(year) % 10 === 5;
440
+ }
441
+ /**
442
+ * true if Kislev is short in Hebrew year
443
+ * @param {number} year Hebrew year
444
+ * @return {boolean}
445
+ */
446
+
447
+ function shortKislev(year) {
448
+ return daysInYear(year) % 10 === 3;
449
+ }
450
+
451
+ var hdate = {
452
+ abs2hebrew: abs2hebrew,
453
+ daysInMonth: daysInMonth,
454
+ daysInYear: daysInYear,
455
+ getMonthName: getMonthName,
456
+ hebrew2abs: hebrew2abs,
457
+ isLeapYear: isLeapYear,
458
+ longCheshvan: longCheshvan,
459
+ months: months,
460
+ monthsInYear: monthsInYear,
461
+ shortKislev: shortKislev
462
+ };
463
+
464
+ exports.abs2greg = abs2greg;
465
+ exports.greg2abs = greg2abs;
466
+ exports.hdate = hdate;
467
+
468
+ Object.defineProperty(exports, '__esModule', { value: true });
469
+
470
+ return exports;
471
+
472
+ })({});
@@ -0,0 +1,2 @@
1
+ /*! @hebcal/core v3.38.0 */
2
+ var hebcal=function(r){"use strict";function t(r){return t="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(r){return typeof r}:function(r){return r&&"function"==typeof Symbol&&r.constructor===Symbol&&r!==Symbol.prototype?"symbol":typeof r},t(r)}var n=[0,31,28,31,30,31,30,31,31,30,31,30,31];function e(r,t){return r-t*Math.floor(r/t)}function o(r,t){return Math.floor(r/t)}function a(r){return!(r%4||!(r%100)&&r%400)}function u(r){return"object"===t(r)&&Date.prototype===r.__proto__}function f(r,t,n){var e=r-1;return 0+365*e+o(e,4)-o(e,100)+o(e,400)+o(367*t-362,12)+Math.floor(t<=2?0:a(r)?-1:-2)+n}[n,n.slice()][1][2]=29;var c=["","Nisan","Iyyar","Sivan","Tamuz","Av","Elul","Tishrei","Cheshvan","Kislev","Tevet","Sh'vat"],i=[c.concat(["Adar","Nisan"]),c.concat(["Adar I","Adar II","Nisan"])],h=Object.create(null),l=-1373428;function s(r,t,n){var e=n;if(t<7){for(var o=7;o<=b(r);o++)e+=g(o,r);for(var a=1;a<t;a++)e+=g(a,r)}else for(var u=7;u<t;u++)e+=g(u,r);return l+m(r)+e-1}function y(r){return l+m(r)+function(r){var t=m(r);return m(r+1)-t==356?2:t-m(r-1)==382?1:0}(r)}function v(r){return(1+7*r)%19<7}function b(r){return 12+v(r)}function g(r,t){switch(r){case 2:case 4:case 6:case 10:case 13:return 29}return 12===r&&!v(t)||8===r&&!p(t)||9===r&&A(t)?29:30}function m(r){var t=h[r]=h[r]||function(r){var t=r-1,n=235*Math.floor(t/19)+t%19*12+Math.floor((t%19*7+1)/19),e=204+n%1080*793,o=5+12*n+793*Math.floor(n/1080)+Math.floor(e/1080),a=e%1080+o%24*1080,u=1+29*n+Math.floor(o/24),f=u+(a>=19440||2==u%7&&a>=9924&&!v(r)||1==u%7&&a>=16789&&v(t));return f+(f%7==0||f%7==3||f%7==5)}(r);return t}function M(r){return m(r+1)-m(r)}function p(r){return M(r)%10==5}function A(r){return M(r)%10==3}var I={abs2hebrew:function(r){if("number"!=typeof r||isNaN(r))throw new TypeError("invalid parameter to abs2hebrew ".concat(r));r=Math.trunc(r);for(var t=Math.floor((r-l)/365.24682220597794);y(t)<=r;)++t;for(var n=r<s(--t,1,1)?7:1;r>s(t,n,g(n,t));)++n;return{yy:t,mm:n,dd:1+r-s(t,n,1)}},daysInMonth:g,daysInYear:M,getMonthName:function(r,t){if("number"!=typeof r||r<1||r>14)throw new TypeError("bad month argument ".concat(r));return i[+v(t)][r]},hebrew2abs:s,isLeapYear:v,longCheshvan:p,months:{NISAN:1,IYYAR:2,SIVAN:3,TAMUZ:4,AV:5,ELUL:6,TISHREI:7,CHESHVAN:8,KISLEV:9,TEVET:10,SHVAT:11,ADAR_I:12,ADAR_II:13},monthsInYear:b,shortKislev:A};return r.abs2greg=function(r){if("number"!=typeof r)throw new TypeError("Argument to greg.abs2greg not a Number");var t=function(r){var t=r-1,n=o(t,146097),a=e(t,146097),u=o(a,36524),f=e(a,36524),c=o(f,1461),i=o(e(f,1461),365),h=400*n+100*u+4*c+i;return 4!=u&&4!=i?h+1:h}(r=Math.trunc(r)),n=o(12*(r-f(t,1,1)+(r<f(t,3,1)?0:a(t)?1:2))+373,367),u=r-f(t,n,1)+1,c=new Date(t,n-1,u);return t<100&&t>=0&&c.setFullYear(t),c},r.greg2abs=function(r){if(!u(r))throw new TypeError("Argument to greg.greg2abs not a Date");var t=r.getFullYear()-1;return function(r){if(!u(r))throw new TypeError("Argument to greg.dayOfYear not a Date");var t=r.getDate()+31*r.getMonth();return r.getMonth()>1&&(t-=Math.floor((4*(r.getMonth()+1)+23)/10),a(r.getFullYear())&&t++),t}(r)+365*t+(Math.floor(t/4)-Math.floor(t/100)+Math.floor(t/400))},r.hdate=I,Object.defineProperty(r,"__esModule",{value:!0}),r}({});