@hebcal/core 3.39.0 → 3.40.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.
@@ -1,4 +1,4 @@
1
- /*! @hebcal/core v3.39.0 */
1
+ /*! @hebcal/core v3.40.0 */
2
2
  var hebcal = (function (exports) {
3
3
  'use strict';
4
4
 
@@ -75,11 +75,12 @@ function dayOfYear(date) {
75
75
  throw new TypeError("Argument not a Date: ".concat(date));
76
76
  }
77
77
 
78
- var doy = date.getDate() + 31 * date.getMonth();
78
+ var month = date.getMonth();
79
+ var doy = date.getDate() + 31 * month;
79
80
 
80
- if (date.getMonth() > 1) {
81
+ if (month > 1) {
81
82
  // FEB
82
- doy -= Math.floor((4 * (date.getMonth() + 1) + 23) / 10);
83
+ doy -= Math.floor((4 * (month + 1) + 23) / 10);
83
84
 
84
85
  if (isLeapYear$1(date.getFullYear())) {
85
86
  doy++;
@@ -136,7 +137,7 @@ function yearFromFixed(abs) {
136
137
 
137
138
  function toFixed(year, month, day) {
138
139
  var py = year - 1;
139
- 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;
140
+ return 365 * py + quotient(py, 4) - quotient(py, 100) + quotient(py, 400) + quotient(367 * month - 362, 12) + (month <= 2 ? 0 : isLeapYear$1(year) ? -1 : -2) + day;
140
141
  }
141
142
  /**
142
143
  * Converts from Rata Die (R.D. number) to Gregorian date.
@@ -1,2 +1,2 @@
1
- /*! @hebcal/core v3.39.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+=m(o,r);for(var a=1;a<t;a++)e+=m(a,r)}else for(var u=7;u<t;u++)e+=m(u,r);return l+M(r)+e-1}function y(r){return l+M(r)}function v(r){return(1+7*r)%19<7}function b(r){return 12+v(r)}function m(r,t){switch(r){case 2:case 4:case 6:case 10:case 13:return 29}return 12===r&&!v(t)||8===r&&!A(t)||9===r&&g(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 p(r){return M(r+1)-M(r)}function A(r){return p(r)%10==5}function g(r){return p(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,m(n,t));)++n;return{yy:t,mm:n,dd:1+r-s(t,n,1)}},daysInMonth:m,daysInYear:p,getMonthName:function(r,t){if("number"!=typeof r||isNaN(r)||r<1||r>14)throw new TypeError("bad month argument ".concat(r));return i[+v(t)][r]},hebrew2abs:s,isLeapYear:v,longCheshvan:A,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:g};return r.abs2greg=function(r){if("number"!=typeof r)throw new TypeError("Argument not a Number: ".concat(r));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 not a Date: ".concat(r));var t=r.getFullYear()-1;return function(r){if(!u(r))throw new TypeError("Argument not a Date: ".concat(r));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}({});
1
+ /*! @hebcal/core v3.40.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 365*e+o(e,4)-o(e,100)+o(e,400)+o(367*t-362,12)+(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+=m(o,r);for(var a=1;a<t;a++)e+=m(a,r)}else for(var u=7;u<t;u++)e+=m(u,r);return l+p(r)+e-1}function y(r){return l+p(r)}function v(r){return(1+7*r)%19<7}function b(r){return 12+v(r)}function m(r,t){switch(r){case 2:case 4:case 6:case 10:case 13:return 29}return 12===r&&!v(t)||8===r&&!A(t)||9===r&&I(t)?29:30}function p(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 p(r+1)-p(r)}function A(r){return M(r)%10==5}function I(r){return M(r)%10==3}var w={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,m(n,t));)++n;return{yy:t,mm:n,dd:1+r-s(t,n,1)}},daysInMonth:m,daysInYear:M,getMonthName:function(r,t){if("number"!=typeof r||isNaN(r)||r<1||r>14)throw new TypeError("bad month argument ".concat(r));return i[+v(t)][r]},hebrew2abs:s,isLeapYear:v,longCheshvan:A,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:I};return r.abs2greg=function(r){if("number"!=typeof r)throw new TypeError("Argument not a Number: ".concat(r));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 not a Date: ".concat(r));var t=r.getFullYear()-1;return function(r){if(!u(r))throw new TypeError("Argument not a Date: ".concat(r));var t=r.getMonth(),n=r.getDate()+31*t;return t>1&&(n-=Math.floor((4*(t+1)+23)/10),a(r.getFullYear())&&n++),n}(r)+365*t+(Math.floor(t/4)-Math.floor(t/100)+Math.floor(t/400))},r.hdate=w,Object.defineProperty(r,"__esModule",{value:!0}),r}({});
@@ -0,0 +1,457 @@
1
+ /*! @hebcal/core v3.40.0 */
2
+ /*
3
+ * More minimal greg routines
4
+ */
5
+
6
+ /** @private */
7
+ const lengths = [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
8
+ /** @private */
9
+ const monthLengths = [
10
+ lengths,
11
+ lengths.slice(),
12
+ ];
13
+ monthLengths[1][2] = 29;
14
+
15
+ /**
16
+ * @private
17
+ * @param {number} x
18
+ * @param {number} y
19
+ * @return {number}
20
+ */
21
+ function mod(x, y) {
22
+ return x - y * Math.floor(x / y);
23
+ }
24
+
25
+ /**
26
+ * @private
27
+ * @param {number} x
28
+ * @param {number} y
29
+ * @return {number}
30
+ */
31
+ function quotient(x, y) {
32
+ return Math.floor(x / y);
33
+ }
34
+
35
+ /**
36
+ * Returns true if the Gregorian year is a leap year
37
+ * @private
38
+ * @param {number} year Gregorian year
39
+ * @return {boolean}
40
+ */
41
+ function isLeapYear$1(year) {
42
+ return !(year % 4) && (!!(year % 100) || !(year % 400));
43
+ }
44
+
45
+ /**
46
+ * Returns true if the object is a Javascript Date
47
+ * @private
48
+ * @param {Object} obj
49
+ * @return {boolean}
50
+ */
51
+ function isDate(obj) {
52
+ return typeof obj === 'object' && Date.prototype === obj.__proto__;
53
+ }
54
+
55
+ /**
56
+ * Returns number of days since January 1 of that year
57
+ * @private
58
+ * @param {Date} date Gregorian date
59
+ * @return {number}
60
+ */
61
+ function dayOfYear(date) {
62
+ if (!isDate(date)) {
63
+ throw new TypeError(`Argument not a Date: ${date}`);
64
+ }
65
+ const month = date.getMonth();
66
+ let doy = date.getDate() + 31 * month;
67
+ if (month > 1) {
68
+ // FEB
69
+ doy -= Math.floor((4 * (month + 1) + 23) / 10);
70
+ if (isLeapYear$1(date.getFullYear())) {
71
+ doy++;
72
+ }
73
+ }
74
+ return doy;
75
+ }
76
+
77
+ /**
78
+ * Converts Gregorian date to absolute R.D. (Rata Die) days
79
+ * @private
80
+ * @param {Date} date Gregorian date
81
+ * @return {number}
82
+ */
83
+ function greg2abs(date) {
84
+ if (!isDate(date)) {
85
+ throw new TypeError(`Argument not a Date: ${date}`);
86
+ }
87
+ const year = date.getFullYear() - 1;
88
+ return (
89
+ dayOfYear(date) + // days this year
90
+ 365 * year + // + days in prior years
91
+ (Math.floor(year / 4) - // + Julian Leap years
92
+ Math.floor(year / 100) + // - century years
93
+ Math.floor(year / 400))
94
+ ); // + Gregorian leap years
95
+ }
96
+
97
+ /**
98
+ * @private
99
+ * @param {number} abs - R.D. number of days
100
+ * @return {number}
101
+ */
102
+ function yearFromFixed(abs) {
103
+ const l0 = abs - 1;
104
+ const n400 = quotient(l0, 146097);
105
+ const d1 = mod(l0, 146097);
106
+ const n100 = quotient(d1, 36524);
107
+ const d2 = mod(d1, 36524);
108
+ const n4 = quotient(d2, 1461);
109
+ const d3 = mod(d2, 1461);
110
+ const n1 = quotient(d3, 365);
111
+ const year = 400 * n400 + 100 * n100 + 4 * n4 + n1;
112
+ return n100 != 4 && n1 != 4 ? year + 1 : year;
113
+ }
114
+
115
+ /**
116
+ * @private
117
+ * @param {number} year
118
+ * @param {number} month
119
+ * @param {number} day
120
+ * @return {number}
121
+ */
122
+ function toFixed(year, month, day) {
123
+ const py = year - 1;
124
+ return 365 * py +
125
+ quotient(py, 4) -
126
+ quotient(py, 100) +
127
+ quotient(py, 400) +
128
+ quotient((367 * month - 362), 12) +
129
+ (month <= 2 ? 0 : (isLeapYear$1(year) ? -1 : -2)) +
130
+ day;
131
+ }
132
+
133
+ /**
134
+ * Converts from Rata Die (R.D. number) to Gregorian date.
135
+ * See the footnote on page 384 of ``Calendrical Calculations, Part II:
136
+ * Three Historical Calendars'' by E. M. Reingold, N. Dershowitz, and S. M.
137
+ * Clamen, Software--Practice and Experience, Volume 23, Number 4
138
+ * (April, 1993), pages 383-404 for an explanation.
139
+ * @private
140
+ * @param {number} abs - R.D. number of days
141
+ * @return {Date}
142
+ */
143
+ function abs2greg(abs) {
144
+ if (typeof abs !== 'number') {
145
+ throw new TypeError(`Argument not a Number: ${abs}`);
146
+ }
147
+ abs = Math.trunc(abs);
148
+ const year = yearFromFixed(abs);
149
+ const priorDays = abs - toFixed(year, 1, 1);
150
+ const correction = abs < toFixed(year, 3, 1) ? 0 : (isLeapYear$1(year) ? 1 : 2);
151
+ const month = quotient((12 * (priorDays + correction) + 373), 367);
152
+ const day = abs - toFixed(year, month, 1) + 1;
153
+ const dt = new Date(year, month - 1, day);
154
+ if (year < 100 && year >= 0) {
155
+ dt.setFullYear(year);
156
+ }
157
+ return dt;
158
+ }
159
+
160
+ /*
161
+ * More minimal HDate
162
+ */
163
+
164
+ const NISAN = 1;
165
+ const IYYAR = 2;
166
+ // const SIVAN = 3;
167
+ const TAMUZ = 4;
168
+ // const AV = 5;
169
+ const ELUL = 6;
170
+ const TISHREI = 7;
171
+ const CHESHVAN = 8;
172
+ const KISLEV = 9;
173
+ const TEVET = 10;
174
+ // const SHVAT = 11;
175
+ const ADAR_I = 12;
176
+ const ADAR_II = 13;
177
+
178
+ /**
179
+ * Hebrew months of the year (NISAN=1, TISHREI=7)
180
+ * @readonly
181
+ * @enum {number}
182
+ */
183
+ const months = {
184
+ /** Nissan / ניסן */
185
+ NISAN: 1,
186
+ /** Iyyar / אייר */
187
+ IYYAR: 2,
188
+ /** Sivan / סיון */
189
+ SIVAN: 3,
190
+ /** Tamuz (sometimes Tammuz) / תמוז */
191
+ TAMUZ: 4,
192
+ /** Av / אב */
193
+ AV: 5,
194
+ /** Elul / אלול */
195
+ ELUL: 6,
196
+ /** Tishrei / תִשְׁרֵי */
197
+ TISHREI: 7,
198
+ /** Cheshvan / חשון */
199
+ CHESHVAN: 8,
200
+ /** Kislev / כסלו */
201
+ KISLEV: 9,
202
+ /** Tevet / טבת */
203
+ TEVET: 10,
204
+ /** Sh'vat / שבט */
205
+ SHVAT: 11,
206
+ /** Adar or Adar Rishon / אדר */
207
+ ADAR_I: 12,
208
+ /** Adar Sheini (only on leap years) / אדר ב׳ */
209
+ ADAR_II: 13,
210
+ };
211
+
212
+ const monthNames0 = [
213
+ '',
214
+ 'Nisan',
215
+ 'Iyyar',
216
+ 'Sivan',
217
+ 'Tamuz',
218
+ 'Av',
219
+ 'Elul',
220
+ 'Tishrei',
221
+ 'Cheshvan',
222
+ 'Kislev',
223
+ 'Tevet',
224
+ 'Sh\'vat',
225
+ ];
226
+
227
+ /**
228
+ * Transliterations of Hebrew month names.
229
+ * Regular years are index 0 and leap years are index 1.
230
+ * @private
231
+ */
232
+ const monthNames = [
233
+ monthNames0.concat([
234
+ 'Adar',
235
+ 'Nisan',
236
+ ]),
237
+ monthNames0.concat([
238
+ 'Adar I',
239
+ 'Adar II',
240
+ 'Nisan',
241
+ ]),
242
+ ];
243
+
244
+ const edCache = Object.create(null);
245
+
246
+ const EPOCH = -1373428;
247
+ // Avg year length in the cycle (19 solar years with 235 lunar months)
248
+ const AVG_HEBYEAR_DAYS = 365.24682220597794;
249
+
250
+ /**
251
+ * Converts Hebrew date to R.D. (Rata Die) fixed days.
252
+ * R.D. 1 is the imaginary date Monday, January 1, 1 on the Gregorian
253
+ * Calendar.
254
+ * @private
255
+ * @param {number} year Hebrew year
256
+ * @param {number} month Hebrew month
257
+ * @param {number} day Hebrew date (1-30)
258
+ * @return {number}
259
+ */
260
+ function hebrew2abs(year, month, day) {
261
+ let tempabs = day;
262
+
263
+ if (month < TISHREI) {
264
+ for (let m = TISHREI; m <= monthsInYear(year); m++) {
265
+ tempabs += daysInMonth(m, year);
266
+ }
267
+ for (let m = NISAN; m < month; m++) {
268
+ tempabs += daysInMonth(m, year);
269
+ }
270
+ } else {
271
+ for (let m = TISHREI; m < month; m++) {
272
+ tempabs += daysInMonth(m, year);
273
+ }
274
+ }
275
+
276
+ return EPOCH + elapsedDays(year) + tempabs - 1;
277
+ }
278
+
279
+ /**
280
+ * @private
281
+ * @param {number} year
282
+ * @return {number}
283
+ */
284
+ function newYear(year) {
285
+ return EPOCH + elapsedDays(year);
286
+ }
287
+
288
+ /**
289
+ * Converts absolute R.D. days to Hebrew date
290
+ * @private
291
+ * @param {number} abs absolute R.D. days
292
+ * @return {SimpleHebrewDate}
293
+ */
294
+ function abs2hebrew(abs) {
295
+ if (typeof abs !== 'number' || isNaN(abs)) {
296
+ throw new TypeError(`invalid parameter to abs2hebrew ${abs}`);
297
+ }
298
+ abs = Math.trunc(abs);
299
+
300
+ // first, quickly approximate year
301
+ let year = Math.floor((abs - EPOCH) / AVG_HEBYEAR_DAYS);
302
+ while (newYear(year) <= abs) {
303
+ ++year;
304
+ }
305
+ --year;
306
+
307
+ let month = abs < hebrew2abs(year, 1, 1) ? 7 : 1;
308
+ while (abs > hebrew2abs(year, month, daysInMonth(month, year))) {
309
+ ++month;
310
+ }
311
+
312
+ const day = 1 + abs - hebrew2abs(year, month, 1);
313
+ return {yy: year, mm: month, dd: day};
314
+ }
315
+
316
+ /**
317
+ * Returns true if Hebrew year is a leap year
318
+ * @private
319
+ * @param {number} year Hebrew year
320
+ * @return {boolean}
321
+ */
322
+ function isLeapYear(year) {
323
+ return (1 + year * 7) % 19 < 7;
324
+ }
325
+
326
+ /**
327
+ * Number of months in this Hebrew year (either 12 or 13 depending on leap year)
328
+ * @private
329
+ * @param {number} year Hebrew year
330
+ * @return {number}
331
+ */
332
+ function monthsInYear(year) {
333
+ return 12 + isLeapYear(year); // boolean is cast to 1 or 0
334
+ }
335
+
336
+ /**
337
+ * Number of days in Hebrew month in a given year (29 or 30)
338
+ * @private
339
+ * @param {number} month Hebrew month (e.g. months.TISHREI)
340
+ * @param {number} year Hebrew year
341
+ * @return {number}
342
+ */
343
+ function daysInMonth(month, year) {
344
+ switch (month) {
345
+ case IYYAR:
346
+ case TAMUZ:
347
+ case ELUL:
348
+ case TEVET:
349
+ case ADAR_II:
350
+ return 29;
351
+ }
352
+ if ((month === ADAR_I && !isLeapYear(year)) ||
353
+ (month === CHESHVAN && !longCheshvan(year)) ||
354
+ (month === KISLEV && shortKislev(year))) {
355
+ return 29;
356
+ } else {
357
+ return 30;
358
+ }
359
+ }
360
+
361
+ /**
362
+ * Returns a transliterated string name of Hebrew month in year,
363
+ * for example 'Elul' or 'Cheshvan'.
364
+ * @private
365
+ * @param {number} month Hebrew month (e.g. months.TISHREI)
366
+ * @param {number} year Hebrew year
367
+ * @return {string}
368
+ */
369
+ function getMonthName(month, year) {
370
+ if (typeof month !== 'number' || isNaN(month) || month < 1 || month > 14) {
371
+ throw new TypeError(`bad month argument ${month}`);
372
+ }
373
+ return monthNames[+isLeapYear(year)][month];
374
+ }
375
+
376
+ /**
377
+ * Days from sunday prior to start of Hebrew calendar to mean
378
+ * conjunction of Tishrei in Hebrew YEAR
379
+ * @private
380
+ * @param {number} year Hebrew year
381
+ * @return {number}
382
+ */
383
+ function elapsedDays(year) {
384
+ const elapsed = edCache[year] = edCache[year] || elapsedDays0(year);
385
+ return elapsed;
386
+ }
387
+
388
+ /**
389
+ * Days from sunday prior to start of Hebrew calendar to mean
390
+ * conjunction of Tishrei in Hebrew YEAR
391
+ * @private
392
+ * @param {number} year Hebrew year
393
+ * @return {number}
394
+ */
395
+ function elapsedDays0(year) {
396
+ const prevYear = year - 1;
397
+ const mElapsed = 235 * Math.floor(prevYear / 19) + // Months in complete 19 year lunar (Metonic) cycles so far
398
+ 12 * (prevYear % 19) + // Regular months in this cycle
399
+ Math.floor(((prevYear % 19) * 7 + 1) / 19); // Leap months this cycle
400
+
401
+ const pElapsed = 204 + 793 * (mElapsed % 1080);
402
+
403
+ const hElapsed = 5 +
404
+ 12 * mElapsed +
405
+ 793 * Math.floor(mElapsed / 1080) +
406
+ Math.floor(pElapsed / 1080);
407
+
408
+ const parts = (pElapsed % 1080) + 1080 * (hElapsed % 24);
409
+
410
+ const day = 1 + 29 * mElapsed + Math.floor(hElapsed / 24);
411
+ const altDay = day +
412
+ (parts >= 19440 ||
413
+ (2 === day % 7 && parts >= 9924 && !isLeapYear(year)) ||
414
+ (1 === day % 7 && parts >= 16789 && isLeapYear(prevYear)));
415
+
416
+ return altDay + (altDay % 7 === 0 || altDay % 7 === 3 || altDay % 7 === 5);
417
+ }
418
+
419
+ /**
420
+ * Number of days in the hebrew YEAR.
421
+ * A common Hebrew calendar year can have a length of 353, 354 or 355 days
422
+ * A leap Hebrew calendar year can have a length of 383, 384 or 385 days
423
+ * @private
424
+ * @param {number} year Hebrew year
425
+ * @return {number}
426
+ */
427
+ function daysInYear(year) {
428
+ return elapsedDays(year + 1) - elapsedDays(year);
429
+ }
430
+
431
+ /**
432
+ * true if Cheshvan is long in Hebrew year
433
+ * @private
434
+ * @param {number} year Hebrew year
435
+ * @return {boolean}
436
+ */
437
+ function longCheshvan(year) {
438
+ return daysInYear(year) % 10 === 5;
439
+ }
440
+
441
+ /**
442
+ * true if Kislev is short in Hebrew year
443
+ * @private
444
+ * @param {number} year Hebrew year
445
+ * @return {boolean}
446
+ */
447
+ function shortKislev(year) {
448
+ return daysInYear(year) % 10 === 3;
449
+ }
450
+
451
+ const hdate = {
452
+ abs2hebrew, daysInMonth, daysInYear, getMonthName, hebrew2abs,
453
+ isLeapYear, longCheshvan, months,
454
+ monthsInYear, shortKislev,
455
+ };
456
+
457
+ export { abs2greg, greg2abs, hdate };
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- /*! @hebcal/core v3.39.0 */
1
+ /*! @hebcal/core v3.40.0 */
2
2
  'use strict';
3
3
 
4
4
  Object.defineProperty(exports, '__esModule', { value: true });
@@ -93,11 +93,12 @@ function dayOfYear(date) {
93
93
  throw new TypeError(`Argument not a Date: ${date}`);
94
94
  }
95
95
 
96
- let doy = date.getDate() + 31 * date.getMonth();
96
+ const month = date.getMonth();
97
+ let doy = date.getDate() + 31 * month;
97
98
 
98
- if (date.getMonth() > 1) {
99
+ if (month > 1) {
99
100
  // FEB
100
- doy -= Math.floor((4 * (date.getMonth() + 1) + 23) / 10);
101
+ doy -= Math.floor((4 * (month + 1) + 23) / 10);
101
102
 
102
103
  if (isLeapYear$1(date.getFullYear())) {
103
104
  doy++;
@@ -154,7 +155,7 @@ function yearFromFixed(abs) {
154
155
 
155
156
  function toFixed(year, month, day) {
156
157
  const py = year - 1;
157
- 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;
158
+ return 365 * py + quotient(py, 4) - quotient(py, 100) + quotient(py, 400) + quotient(367 * month - 362, 12) + (month <= 2 ? 0 : isLeapYear$1(year) ? -1 : -2) + day;
158
159
  }
159
160
  /**
160
161
  * Converts from Rata Die (R.D. number) to Gregorian date.
@@ -4193,6 +4194,10 @@ function throwError(errorMessage) {
4193
4194
  * Hebrew date, e.g. `['Noach']` or `['Matot', 'Masei']`
4194
4195
  * @property {boolean} chag True if this is a regular parasha HaShavua
4195
4196
  * Torah reading, false if it's a special holiday reading
4197
+ * @property {number|number[]} num the parsha number (or numbers) using 1-indexing.
4198
+ * A `number` for a regular (single) parsha, and a `number[]` for a doubled parsha.
4199
+ * For Parashat *Bereshit*, `num` would be equal to `1`, and for
4200
+ * *Matot-Masei* it would be `[42, 43]`
4196
4201
  */
4197
4202
 
4198
4203
  /**
@@ -4384,7 +4389,8 @@ class Sedra {
4384
4389
  if (index >= 0) {
4385
4390
  return {
4386
4391
  parsha: [parshiot[index]],
4387
- chag: false
4392
+ chag: false,
4393
+ num: index + 1
4388
4394
  };
4389
4395
  }
4390
4396
 
@@ -4392,7 +4398,8 @@ class Sedra {
4392
4398
 
4393
4399
  return {
4394
4400
  parsha: [parshiot[p1], parshiot[p1 + 1]],
4395
- chag: false
4401
+ chag: false,
4402
+ num: [p1 + 1, p1 + 2]
4396
4403
  };
4397
4404
  }
4398
4405
 
@@ -4609,8 +4616,9 @@ class ParshaEvent extends Event {
4609
4616
  * @param {string[]} parsha - untranslated name of single or double parsha,
4610
4617
  * such as ['Bereshit'] or ['Achrei Mot', 'Kedoshim']
4611
4618
  * @param {boolean} il
4619
+ * @param {number|number[]} num
4612
4620
  */
4613
- constructor(date, parsha, il) {
4621
+ constructor(date, parsha, il, num) {
4614
4622
  if (!Array.isArray(parsha) || parsha.length === 0 || parsha.length > 2) {
4615
4623
  throw new TypeError('Bad parsha argument');
4616
4624
  }
@@ -4619,6 +4627,7 @@ class ParshaEvent extends Event {
4619
4627
  super(date, desc, flags.PARSHA_HASHAVUA);
4620
4628
  this.parsha = parsha;
4621
4629
  this.il = Boolean(il);
4630
+ this.num = num || -1;
4622
4631
  }
4623
4632
  /**
4624
4633
  * @param {string} [locale] Optional locale name (i.e: `'he'`, `'fr'`). Defaults to active locale.
@@ -5521,7 +5530,7 @@ function getBirthdayOrAnniversary_(hyear, gdate) {
5521
5530
  return new HDate(day, month, hyear);
5522
5531
  }
5523
5532
 
5524
- var version="3.39.0";
5533
+ var version="3.40.0";
5525
5534
 
5526
5535
  var headers$1={"plural-forms":"nplurals=2; plural=(n > 1);",language:"en_CA@ashkenazi"};var contexts$1={"":{Berachot:["Berachos"],Shabbat:["Shabbos"],Taanit:["Taanis"],Yevamot:["Yevamos"],Ketubot:["Kesubos"],"Baba Batra":["Baba Basra"],Makkot:["Makkos"],Shevuot:["Shevuos"],Horayot:["Horayos"],Menachot:["Menachos"],Bechorot:["Bechoros"],Keritot:["Kerisos"],Midot:["Midos"],"Achrei Mot":["Achrei Mos"],Bechukotai:["Bechukosai"],"Beha'alotcha":["Beha'aloscha"],Bereshit:["Bereshis"],Chukat:["Chukas"],"Erev Shavuot":["Erev Shavuos"],"Erev Sukkot":["Erev Sukkos"],"Ki Tavo":["Ki Savo"],"Ki Teitzei":["Ki Seitzei"],"Ki Tisa":["Ki Sisa"],Matot:["Matos"],"Purim Katan":["Purim Koton"],Tazria:["Sazria"],"Shabbat Chazon":["Shabbos Chazon"],"Shabbat HaChodesh":["Shabbos HaChodesh"],"Shabbat HaGadol":["Shabbos HaGadol"],"Shabbat Nachamu":["Shabbos Nachamu"],"Shabbat Parah":["Shabbos Parah"],"Shabbat Shekalim":["Shabbos Shekalim"],"Shabbat Shuva":["Shabbos Shuvah"],"Shabbat Zachor":["Shabbos Zachor"],Shavuot:["Shavuos"],"Shavuot I":["Shavuos I"],"Shavuot II":["Shavuos II"],Shemot:["Shemos"],"Shmini Atzeret":["Shmini Atzeres"],"Simchat Torah":["Simchas Torah"],Sukkot:["Sukkos"],"Sukkot I":["Sukkos I"],"Sukkot II":["Sukkos II"],"Sukkot II (CH''M)":["Sukkos II (CH''M)"],"Sukkot III (CH''M)":["Sukkos III (CH''M)"],"Sukkot IV (CH''M)":["Sukkos IV (CH''M)"],"Sukkot V (CH''M)":["Sukkos V (CH''M)"],"Sukkot VI (CH''M)":["Sukkos VI (CH''M)"],"Sukkot VII (Hoshana Raba)":["Sukkos VII (Hoshana Raba)"],"Ta'anit Bechorot":["Ta'anis Bechoros"],"Ta'anit Esther":["Ta'anis Esther"],Toldot:["Toldos"],Vaetchanan:["Vaeschanan"],Yitro:["Yisro"],"Vezot Haberakhah":["Vezos Haberakhah"],Parashat:["Parshas"],"Leil Selichot":["Leil Selichos"],"Shabbat Mevarchim Chodesh":["Shabbos Mevorchim Chodesh"],"Shabbat Shirah":["Shabbos Shirah"],Tevet:["Teves"],"Asara B'Tevet":["Asara B'Teves"],Berakhot:["Berakhos"],Sheviit:["Sheviis"],Terumot:["Terumos"],Maasrot:["Maasros"],Eduyot:["Eduyos"],Avot:["Avos"],Bekhorot:["Bekhoros"],Middot:["Middos"],Oholot:["Oholos"],Tahorot:["Tahoros"],Mikvaot:["Mikvaos"]}};var poAshkenazi = {headers:headers$1,contexts:contexts$1};
5527
5536
 
@@ -5537,17 +5546,13 @@ const heNoNikud = {};
5537
5546
  Object.keys(heStrs).forEach(key => {
5538
5547
  heNoNikud[key] = [Locale.hebrewStripNikkud(heStrs[key][0])];
5539
5548
  });
5540
- const localeName = 'he-x-NoNikud';
5541
5549
  const poHeNoNikud = {
5542
- headers: {
5543
- 'plural-forms': 'nplurals=2; plural=(n!=1);',
5544
- 'language': localeName
5545
- },
5550
+ headers: poHe.headers,
5546
5551
  contexts: {
5547
5552
  '': heNoNikud
5548
5553
  }
5549
5554
  };
5550
- Locale.addLocale(localeName, poHeNoNikud);
5555
+ Locale.addLocale('he-x-NoNikud', poHeNoNikud);
5551
5556
 
5552
5557
  /*
5553
5558
  Hebcal - A Jewish Calendar Generator
@@ -5854,7 +5859,7 @@ function getMaskFromOptions(options) {
5854
5859
  }
5855
5860
 
5856
5861
  if (options.candlelighting) {
5857
- mask |= LIGHT_CANDLES | LIGHT_CANDLES_TZEIS;
5862
+ mask |= LIGHT_CANDLES | LIGHT_CANDLES_TZEIS | YOM_TOV_ENDS;
5858
5863
  } // suppression of defaults
5859
5864
 
5860
5865
 
@@ -6124,7 +6129,7 @@ class HebrewCalendar {
6124
6129
  const parsha0 = sedra.lookup(abs);
6125
6130
 
6126
6131
  if (!parsha0.chag) {
6127
- evts.push(new ParshaEvent(hd, parsha0.parsha, il));
6132
+ evts.push(new ParshaEvent(hd, parsha0.parsha, il, parsha0.num));
6128
6133
  }
6129
6134
  }
6130
6135