@hebcal/core 3.39.1 → 3.41.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/README.md +9 -3
- package/dist/bundle.js +107 -22
- package/dist/bundle.min.js +2 -2
- package/dist/greg0.mjs +172 -0
- package/dist/hdate-bundle.js +18 -6
- package/dist/hdate-bundle.min.js +2 -2
- package/dist/hdate.js +18 -6
- package/dist/hdate.mjs +267 -440
- package/dist/hdate0-bundle.js +6 -5
- package/dist/hdate0-bundle.min.js +2 -2
- package/dist/hdate0.mjs +457 -0
- package/dist/index.js +91 -20
- package/dist/index.mjs +91 -20
- package/hebcal.d.ts +23 -0
- package/package.json +5 -5
package/dist/hdate.mjs
CHANGED
|
@@ -1,116 +1,66 @@
|
|
|
1
|
-
/*! @hebcal/core v3.
|
|
1
|
+
/*! @hebcal/core v3.41.0 */
|
|
2
2
|
const GERESH = '׳';
|
|
3
3
|
const GERSHAYIM = '״';
|
|
4
|
+
|
|
4
5
|
/**
|
|
5
6
|
* @private
|
|
6
7
|
* @param {number} num
|
|
7
8
|
* @return {string}
|
|
8
9
|
*/
|
|
9
|
-
|
|
10
10
|
function num2heb(num) {
|
|
11
11
|
switch (num) {
|
|
12
|
-
case 1:
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
case
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
case
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
case
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
case
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
case
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
case
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
case
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
case 9:
|
|
37
|
-
return 'ט';
|
|
38
|
-
|
|
39
|
-
case 10:
|
|
40
|
-
return 'י';
|
|
41
|
-
|
|
42
|
-
case 20:
|
|
43
|
-
return 'כ';
|
|
44
|
-
|
|
45
|
-
case 30:
|
|
46
|
-
return 'ל';
|
|
47
|
-
|
|
48
|
-
case 40:
|
|
49
|
-
return 'מ';
|
|
50
|
-
|
|
51
|
-
case 50:
|
|
52
|
-
return 'נ';
|
|
53
|
-
|
|
54
|
-
case 60:
|
|
55
|
-
return 'ס';
|
|
56
|
-
|
|
57
|
-
case 70:
|
|
58
|
-
return 'ע';
|
|
59
|
-
|
|
60
|
-
case 80:
|
|
61
|
-
return 'פ';
|
|
62
|
-
|
|
63
|
-
case 90:
|
|
64
|
-
return 'צ';
|
|
65
|
-
|
|
66
|
-
case 100:
|
|
67
|
-
return 'ק';
|
|
68
|
-
|
|
69
|
-
case 200:
|
|
70
|
-
return 'ר';
|
|
71
|
-
|
|
72
|
-
case 300:
|
|
73
|
-
return 'ש';
|
|
74
|
-
|
|
75
|
-
case 400:
|
|
76
|
-
return 'ת';
|
|
77
|
-
|
|
78
|
-
default:
|
|
79
|
-
return '*INVALID*';
|
|
12
|
+
case 1: return 'א';
|
|
13
|
+
case 2: return 'ב';
|
|
14
|
+
case 3: return 'ג';
|
|
15
|
+
case 4: return 'ד';
|
|
16
|
+
case 5: return 'ה';
|
|
17
|
+
case 6: return 'ו';
|
|
18
|
+
case 7: return 'ז';
|
|
19
|
+
case 8: return 'ח';
|
|
20
|
+
case 9: return 'ט';
|
|
21
|
+
case 10: return 'י';
|
|
22
|
+
case 20: return 'כ';
|
|
23
|
+
case 30: return 'ל';
|
|
24
|
+
case 40: return 'מ';
|
|
25
|
+
case 50: return 'נ';
|
|
26
|
+
case 60: return 'ס';
|
|
27
|
+
case 70: return 'ע';
|
|
28
|
+
case 80: return 'פ';
|
|
29
|
+
case 90: return 'צ';
|
|
30
|
+
case 100: return 'ק';
|
|
31
|
+
case 200: return 'ר';
|
|
32
|
+
case 300: return 'ש';
|
|
33
|
+
case 400: return 'ת';
|
|
34
|
+
default: return '*INVALID*';
|
|
80
35
|
}
|
|
81
36
|
}
|
|
37
|
+
|
|
82
38
|
/**
|
|
83
39
|
* @private
|
|
84
40
|
* @param {number} num
|
|
85
41
|
* @return {number[]}
|
|
86
42
|
*/
|
|
87
|
-
|
|
88
|
-
|
|
89
43
|
function num2digits(num) {
|
|
90
44
|
const digits = [];
|
|
91
|
-
|
|
92
45
|
while (num > 0) {
|
|
93
46
|
if (num === 15 || num === 16) {
|
|
94
47
|
digits.push(9);
|
|
95
48
|
digits.push(num - 9);
|
|
96
49
|
break;
|
|
97
50
|
}
|
|
98
|
-
|
|
99
51
|
let incr = 100;
|
|
100
52
|
let i;
|
|
101
|
-
|
|
102
53
|
for (i = 400; i > num; i -= incr) {
|
|
103
54
|
if (i === incr) {
|
|
104
55
|
incr = incr / 10;
|
|
105
56
|
}
|
|
106
57
|
}
|
|
107
|
-
|
|
108
58
|
digits.push(i);
|
|
109
59
|
num -= i;
|
|
110
60
|
}
|
|
111
|
-
|
|
112
61
|
return digits;
|
|
113
62
|
}
|
|
63
|
+
|
|
114
64
|
/**
|
|
115
65
|
* Converts a numerical value to a string of Hebrew letters.
|
|
116
66
|
*
|
|
@@ -125,42 +75,30 @@ function num2digits(num) {
|
|
|
125
75
|
* @param {number} number
|
|
126
76
|
* @return {string}
|
|
127
77
|
*/
|
|
128
|
-
|
|
129
|
-
|
|
130
78
|
function gematriya(number) {
|
|
131
79
|
const num = parseInt(number, 10);
|
|
132
|
-
|
|
133
80
|
if (!num) {
|
|
134
81
|
throw new TypeError(`invalid parameter to gematriya ${number}`);
|
|
135
82
|
}
|
|
136
|
-
|
|
137
83
|
let str = '';
|
|
138
84
|
const thousands = Math.floor(num / 1000);
|
|
139
|
-
|
|
140
85
|
if (thousands > 0 && thousands !== 5) {
|
|
141
86
|
const tdigits = num2digits(thousands);
|
|
142
|
-
|
|
143
87
|
for (let i = 0; i < tdigits.length; i++) {
|
|
144
88
|
str += num2heb(tdigits[i]);
|
|
145
89
|
}
|
|
146
|
-
|
|
147
90
|
str += GERESH;
|
|
148
91
|
}
|
|
149
|
-
|
|
150
92
|
const digits = num2digits(num % 1000);
|
|
151
|
-
|
|
152
93
|
if (digits.length == 1) {
|
|
153
94
|
return str + num2heb(digits[0]) + GERESH;
|
|
154
95
|
}
|
|
155
|
-
|
|
156
96
|
for (let i = 0; i < digits.length; i++) {
|
|
157
97
|
if (i + 1 === digits.length) {
|
|
158
98
|
str += GERSHAYIM;
|
|
159
99
|
}
|
|
160
|
-
|
|
161
100
|
str += num2heb(digits[i]);
|
|
162
101
|
}
|
|
163
|
-
|
|
164
102
|
return str;
|
|
165
103
|
}
|
|
166
104
|
|
|
@@ -171,40 +109,42 @@ function gematriya(number) {
|
|
|
171
109
|
/** @private */
|
|
172
110
|
const lengths = [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
|
|
173
111
|
/** @private */
|
|
174
|
-
|
|
175
|
-
|
|
112
|
+
const monthLengths = [
|
|
113
|
+
lengths,
|
|
114
|
+
lengths.slice(),
|
|
115
|
+
];
|
|
176
116
|
monthLengths[1][2] = 29;
|
|
117
|
+
|
|
177
118
|
/**
|
|
178
119
|
* @private
|
|
179
120
|
* @param {number} x
|
|
180
121
|
* @param {number} y
|
|
181
122
|
* @return {number}
|
|
182
123
|
*/
|
|
183
|
-
|
|
184
124
|
function mod(x, y) {
|
|
185
125
|
return x - y * Math.floor(x / y);
|
|
186
126
|
}
|
|
127
|
+
|
|
187
128
|
/**
|
|
188
129
|
* @private
|
|
189
130
|
* @param {number} x
|
|
190
131
|
* @param {number} y
|
|
191
132
|
* @return {number}
|
|
192
133
|
*/
|
|
193
|
-
|
|
194
134
|
function quotient(x, y) {
|
|
195
135
|
return Math.floor(x / y);
|
|
196
136
|
}
|
|
137
|
+
|
|
197
138
|
/**
|
|
198
139
|
* Returns true if the Gregorian year is a leap year
|
|
199
140
|
* @private
|
|
200
141
|
* @param {number} year Gregorian year
|
|
201
142
|
* @return {boolean}
|
|
202
143
|
*/
|
|
203
|
-
|
|
204
|
-
|
|
205
144
|
function isLeapYear$1(year) {
|
|
206
145
|
return !(year % 4) && (!!(year % 100) || !(year % 400));
|
|
207
146
|
}
|
|
147
|
+
|
|
208
148
|
/**
|
|
209
149
|
* Number of days in the Gregorian month for given year
|
|
210
150
|
* @private
|
|
@@ -212,71 +152,68 @@ function isLeapYear$1(year) {
|
|
|
212
152
|
* @param {number} year Gregorian year
|
|
213
153
|
* @return {number}
|
|
214
154
|
*/
|
|
215
|
-
|
|
216
155
|
function daysInMonth$1(month, year) {
|
|
217
156
|
// 1 based months
|
|
218
157
|
return monthLengths[+isLeapYear$1(year)][month];
|
|
219
158
|
}
|
|
159
|
+
|
|
220
160
|
/**
|
|
221
161
|
* Returns true if the object is a Javascript Date
|
|
222
162
|
* @private
|
|
223
163
|
* @param {Object} obj
|
|
224
164
|
* @return {boolean}
|
|
225
165
|
*/
|
|
226
|
-
|
|
227
166
|
function isDate(obj) {
|
|
228
167
|
return typeof obj === 'object' && Date.prototype === obj.__proto__;
|
|
229
168
|
}
|
|
169
|
+
|
|
230
170
|
/**
|
|
231
171
|
* Returns number of days since January 1 of that year
|
|
232
172
|
* @private
|
|
233
173
|
* @param {Date} date Gregorian date
|
|
234
174
|
* @return {number}
|
|
235
175
|
*/
|
|
236
|
-
|
|
237
176
|
function dayOfYear(date) {
|
|
238
177
|
if (!isDate(date)) {
|
|
239
178
|
throw new TypeError(`Argument not a Date: ${date}`);
|
|
240
179
|
}
|
|
241
|
-
|
|
242
|
-
let doy = date.getDate() + 31 *
|
|
243
|
-
|
|
244
|
-
if (date.getMonth() > 1) {
|
|
180
|
+
const month = date.getMonth();
|
|
181
|
+
let doy = date.getDate() + 31 * month;
|
|
182
|
+
if (month > 1) {
|
|
245
183
|
// FEB
|
|
246
|
-
doy -= Math.floor((4 * (
|
|
247
|
-
|
|
184
|
+
doy -= Math.floor((4 * (month + 1) + 23) / 10);
|
|
248
185
|
if (isLeapYear$1(date.getFullYear())) {
|
|
249
186
|
doy++;
|
|
250
187
|
}
|
|
251
188
|
}
|
|
252
|
-
|
|
253
189
|
return doy;
|
|
254
190
|
}
|
|
191
|
+
|
|
255
192
|
/**
|
|
256
193
|
* Converts Gregorian date to absolute R.D. (Rata Die) days
|
|
257
194
|
* @private
|
|
258
195
|
* @param {Date} date Gregorian date
|
|
259
196
|
* @return {number}
|
|
260
197
|
*/
|
|
261
|
-
|
|
262
198
|
function greg2abs(date) {
|
|
263
199
|
if (!isDate(date)) {
|
|
264
200
|
throw new TypeError(`Argument not a Date: ${date}`);
|
|
265
201
|
}
|
|
266
|
-
|
|
267
202
|
const year = date.getFullYear() - 1;
|
|
268
|
-
return
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
203
|
+
return (
|
|
204
|
+
dayOfYear(date) + // days this year
|
|
205
|
+
365 * year + // + days in prior years
|
|
206
|
+
(Math.floor(year / 4) - // + Julian Leap years
|
|
207
|
+
Math.floor(year / 100) + // - century years
|
|
208
|
+
Math.floor(year / 400))
|
|
209
|
+
); // + Gregorian leap years
|
|
273
210
|
}
|
|
211
|
+
|
|
274
212
|
/**
|
|
275
213
|
* @private
|
|
276
214
|
* @param {number} abs - R.D. number of days
|
|
277
215
|
* @return {number}
|
|
278
216
|
*/
|
|
279
|
-
|
|
280
217
|
function yearFromFixed(abs) {
|
|
281
218
|
const l0 = abs - 1;
|
|
282
219
|
const n400 = quotient(l0, 146097);
|
|
@@ -289,6 +226,7 @@ function yearFromFixed(abs) {
|
|
|
289
226
|
const year = 400 * n400 + 100 * n100 + 4 * n4 + n1;
|
|
290
227
|
return n100 != 4 && n1 != 4 ? year + 1 : year;
|
|
291
228
|
}
|
|
229
|
+
|
|
292
230
|
/**
|
|
293
231
|
* @private
|
|
294
232
|
* @param {number} year
|
|
@@ -296,12 +234,17 @@ function yearFromFixed(abs) {
|
|
|
296
234
|
* @param {number} day
|
|
297
235
|
* @return {number}
|
|
298
236
|
*/
|
|
299
|
-
|
|
300
|
-
|
|
301
237
|
function toFixed(year, month, day) {
|
|
302
238
|
const py = year - 1;
|
|
303
|
-
return
|
|
239
|
+
return 365 * py +
|
|
240
|
+
quotient(py, 4) -
|
|
241
|
+
quotient(py, 100) +
|
|
242
|
+
quotient(py, 400) +
|
|
243
|
+
quotient((367 * month - 362), 12) +
|
|
244
|
+
(month <= 2 ? 0 : (isLeapYear$1(year) ? -1 : -2)) +
|
|
245
|
+
day;
|
|
304
246
|
}
|
|
247
|
+
|
|
305
248
|
/**
|
|
306
249
|
* Converts from Rata Die (R.D. number) to Gregorian date.
|
|
307
250
|
* See the footnote on page 384 of ``Calendrical Calculations, Part II:
|
|
@@ -312,25 +255,20 @@ function toFixed(year, month, day) {
|
|
|
312
255
|
* @param {number} abs - R.D. number of days
|
|
313
256
|
* @return {Date}
|
|
314
257
|
*/
|
|
315
|
-
|
|
316
|
-
|
|
317
258
|
function abs2greg(abs) {
|
|
318
259
|
if (typeof abs !== 'number') {
|
|
319
260
|
throw new TypeError(`Argument not a Number: ${abs}`);
|
|
320
261
|
}
|
|
321
|
-
|
|
322
262
|
abs = Math.trunc(abs);
|
|
323
263
|
const year = yearFromFixed(abs);
|
|
324
264
|
const priorDays = abs - toFixed(year, 1, 1);
|
|
325
|
-
const correction = abs < toFixed(year, 3, 1) ? 0 : isLeapYear$1(year) ? 1 : 2;
|
|
326
|
-
const month = quotient(12 * (priorDays + correction) + 373, 367);
|
|
265
|
+
const correction = abs < toFixed(year, 3, 1) ? 0 : (isLeapYear$1(year) ? 1 : 2);
|
|
266
|
+
const month = quotient((12 * (priorDays + correction) + 373), 367);
|
|
327
267
|
const day = abs - toFixed(year, month, 1) + 1;
|
|
328
268
|
const dt = new Date(year, month - 1, day);
|
|
329
|
-
|
|
330
269
|
if (year < 100 && year >= 0) {
|
|
331
270
|
dt.setFullYear(year);
|
|
332
271
|
}
|
|
333
|
-
|
|
334
272
|
return dt;
|
|
335
273
|
}
|
|
336
274
|
|
|
@@ -354,67 +292,78 @@ function abs2greg(abs) {
|
|
|
354
292
|
You should have received a copy of the GNU General Public License
|
|
355
293
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
356
294
|
*/
|
|
295
|
+
|
|
357
296
|
/**
|
|
358
297
|
* Gregorian date helper functions.
|
|
359
298
|
*/
|
|
360
|
-
|
|
361
299
|
class greg {
|
|
362
300
|
/**
|
|
363
301
|
* Long names of the Gregorian months (1='January', 12='December')
|
|
364
302
|
* @readonly
|
|
365
303
|
* @type {string[]}
|
|
366
304
|
*/
|
|
367
|
-
static monthNames = [
|
|
305
|
+
static monthNames = [
|
|
306
|
+
'',
|
|
307
|
+
'January',
|
|
308
|
+
'February',
|
|
309
|
+
'March',
|
|
310
|
+
'April',
|
|
311
|
+
'May',
|
|
312
|
+
'June',
|
|
313
|
+
'July',
|
|
314
|
+
'August',
|
|
315
|
+
'September',
|
|
316
|
+
'October',
|
|
317
|
+
'November',
|
|
318
|
+
'December',
|
|
319
|
+
];
|
|
320
|
+
|
|
368
321
|
/**
|
|
369
322
|
* Returns true if the Gregorian year is a leap year
|
|
370
323
|
* @param {number} year Gregorian year
|
|
371
324
|
* @return {boolean}
|
|
372
325
|
*/
|
|
373
|
-
|
|
374
326
|
static isLeapYear(year) {
|
|
375
327
|
return isLeapYear$1(year);
|
|
376
328
|
}
|
|
329
|
+
|
|
377
330
|
/**
|
|
378
331
|
* Number of days in the Gregorian month for given year
|
|
379
332
|
* @param {number} month Gregorian month (1=January, 12=December)
|
|
380
333
|
* @param {number} year Gregorian year
|
|
381
334
|
* @return {number}
|
|
382
335
|
*/
|
|
383
|
-
|
|
384
|
-
|
|
385
336
|
static daysInMonth(month, year) {
|
|
386
337
|
return daysInMonth$1(month, year);
|
|
387
338
|
}
|
|
339
|
+
|
|
388
340
|
/**
|
|
389
341
|
* Returns true if the object is a Javascript Date
|
|
390
342
|
* @param {Object} obj
|
|
391
343
|
* @return {boolean}
|
|
392
344
|
*/
|
|
393
|
-
|
|
394
|
-
|
|
395
345
|
static isDate(obj) {
|
|
396
346
|
return isDate(obj);
|
|
397
347
|
}
|
|
348
|
+
|
|
398
349
|
/**
|
|
399
350
|
* Returns number of days since January 1 of that year
|
|
400
351
|
* @param {Date} date Gregorian date
|
|
401
352
|
* @return {number}
|
|
402
353
|
*/
|
|
403
|
-
|
|
404
|
-
|
|
405
354
|
static dayOfYear(date) {
|
|
406
355
|
return dayOfYear(date);
|
|
407
356
|
}
|
|
357
|
+
|
|
408
358
|
/**
|
|
409
359
|
* Converts Gregorian date to absolute R.D. (Rata Die) days
|
|
410
360
|
* @param {Date} date Gregorian date
|
|
411
361
|
* @return {number}
|
|
412
362
|
*/
|
|
413
|
-
|
|
414
|
-
|
|
415
363
|
static greg2abs(date) {
|
|
416
364
|
return greg2abs(date);
|
|
417
365
|
}
|
|
366
|
+
|
|
418
367
|
/**
|
|
419
368
|
* Converts from Rata Die (R.D. number) to Gregorian date.
|
|
420
369
|
* See the footnote on page 384 of ``Calendrical Calculations, Part II:
|
|
@@ -424,28 +373,22 @@ class greg {
|
|
|
424
373
|
* @param {number} theDate - R.D. number of days
|
|
425
374
|
* @return {Date}
|
|
426
375
|
*/
|
|
427
|
-
|
|
428
|
-
|
|
429
376
|
static abs2greg(theDate) {
|
|
430
377
|
return abs2greg(theDate);
|
|
431
378
|
}
|
|
432
|
-
|
|
433
379
|
}
|
|
434
380
|
|
|
435
381
|
const noopLocale = {
|
|
436
|
-
headers: {
|
|
437
|
-
|
|
438
|
-
},
|
|
439
|
-
contexts: {
|
|
440
|
-
'': {}
|
|
441
|
-
}
|
|
382
|
+
headers: {'plural-forms': 'nplurals=2; plural=(n!=1);'},
|
|
383
|
+
contexts: {'': {}},
|
|
442
384
|
};
|
|
443
385
|
const alias = {
|
|
444
386
|
'h': 'he',
|
|
445
387
|
'a': 'ashkenazi',
|
|
446
388
|
's': 'en',
|
|
447
|
-
'': 'en'
|
|
389
|
+
'': 'en',
|
|
448
390
|
};
|
|
391
|
+
|
|
449
392
|
/**
|
|
450
393
|
* A locale in Hebcal is used for translations/transliterations of
|
|
451
394
|
* holidays. `@hebcal/core` supports four locales by default
|
|
@@ -454,16 +397,14 @@ const alias = {
|
|
|
454
397
|
* * `he` - Hebrew (e.g. "שַׁבָּת")
|
|
455
398
|
* * `he-x-NoNikud` - Hebrew without nikud (e.g. "שבת")
|
|
456
399
|
*/
|
|
457
|
-
|
|
458
400
|
class Locale {
|
|
459
401
|
/** @private */
|
|
460
402
|
static locales = Object.create(null);
|
|
461
403
|
/** @private */
|
|
462
|
-
|
|
463
404
|
static activeLocale = null;
|
|
464
405
|
/** @private */
|
|
465
|
-
|
|
466
406
|
static activeName = null;
|
|
407
|
+
|
|
467
408
|
/**
|
|
468
409
|
* Returns translation only if `locale` offers a non-empty translation for `id`.
|
|
469
410
|
* Otherwise, returns `undefined`.
|
|
@@ -471,49 +412,42 @@ class Locale {
|
|
|
471
412
|
* @param {string} [locale] Optional locale name (i.e: `'he'`, `'fr'`). Defaults to active locale.
|
|
472
413
|
* @return {string}
|
|
473
414
|
*/
|
|
474
|
-
|
|
475
415
|
static lookupTranslation(id, locale) {
|
|
476
416
|
const locale0 = locale && locale.toLowerCase();
|
|
477
|
-
const loc = typeof locale == 'string' && this.locales[locale0] || this.activeLocale;
|
|
417
|
+
const loc = (typeof locale == 'string' && this.locales[locale0]) || this.activeLocale;
|
|
478
418
|
const array = loc[id];
|
|
479
|
-
|
|
480
419
|
if (array && array.length && array[0].length) {
|
|
481
420
|
return array[0];
|
|
482
421
|
}
|
|
483
|
-
|
|
484
422
|
return undefined;
|
|
485
423
|
}
|
|
424
|
+
|
|
486
425
|
/**
|
|
487
426
|
* By default, if no translation was found, returns `id`.
|
|
488
427
|
* @param {string} id Message ID to translate
|
|
489
428
|
* @param {string} [locale] Optional locale name (i.e: `'he'`, `'fr'`). Defaults to active locale.
|
|
490
429
|
* @return {string}
|
|
491
430
|
*/
|
|
492
|
-
|
|
493
|
-
|
|
494
431
|
static gettext(id, locale) {
|
|
495
432
|
const text = this.lookupTranslation(id, locale);
|
|
496
|
-
|
|
497
433
|
if (typeof text == 'undefined') {
|
|
498
434
|
return id;
|
|
499
435
|
}
|
|
500
|
-
|
|
501
436
|
return text;
|
|
502
437
|
}
|
|
438
|
+
|
|
503
439
|
/**
|
|
504
440
|
* Register locale translations.
|
|
505
441
|
* @param {string} locale Locale name (i.e.: `'he'`, `'fr'`)
|
|
506
442
|
* @param {LocaleDate} data parsed data from a `.po` file.
|
|
507
443
|
*/
|
|
508
|
-
|
|
509
|
-
|
|
510
444
|
static addLocale(locale, data) {
|
|
511
445
|
if (typeof data.contexts !== 'object' || typeof data.contexts[''] !== 'object') {
|
|
512
446
|
throw new TypeError(`Locale '${locale}' invalid compact format`);
|
|
513
447
|
}
|
|
514
|
-
|
|
515
448
|
this.locales[locale.toLowerCase()] = data.contexts[''];
|
|
516
449
|
}
|
|
450
|
+
|
|
517
451
|
/**
|
|
518
452
|
* Activates a locale. Throws an error if the locale has not been previously added.
|
|
519
453
|
* After setting the locale to be used, all strings marked for translations
|
|
@@ -521,53 +455,44 @@ class Locale {
|
|
|
521
455
|
* @param {string} locale Locale name (i.e: `'he'`, `'fr'`)
|
|
522
456
|
* @return {LocaleData}
|
|
523
457
|
*/
|
|
524
|
-
|
|
525
|
-
|
|
526
458
|
static useLocale(locale) {
|
|
527
459
|
const locale0 = locale.toLowerCase();
|
|
528
460
|
const obj = this.locales[locale0];
|
|
529
|
-
|
|
530
461
|
if (!obj) {
|
|
531
462
|
throw new RangeError(`Locale '${locale}' not found`);
|
|
532
463
|
}
|
|
533
|
-
|
|
534
464
|
this.activeName = alias[locale0] || locale0;
|
|
535
465
|
this.activeLocale = obj;
|
|
536
466
|
return this.activeLocale;
|
|
537
467
|
}
|
|
468
|
+
|
|
538
469
|
/**
|
|
539
470
|
* Returns the name of the active locale (i.e. 'he', 'ashkenazi', 'fr')
|
|
540
471
|
* @return {string}
|
|
541
472
|
*/
|
|
542
|
-
|
|
543
|
-
|
|
544
473
|
static getLocaleName() {
|
|
545
474
|
return this.activeName;
|
|
546
475
|
}
|
|
476
|
+
|
|
547
477
|
/**
|
|
548
478
|
* Returns the names of registered locales
|
|
549
479
|
* @return {string[]}
|
|
550
480
|
*/
|
|
551
|
-
|
|
552
|
-
|
|
553
481
|
static getLocaleNames() {
|
|
554
482
|
return Object.keys(this.locales).sort();
|
|
555
483
|
}
|
|
484
|
+
|
|
556
485
|
/**
|
|
557
486
|
* @param {number} n
|
|
558
487
|
* @param {string} [locale] Optional locale name (i.e: `'he'`, `'fr'`). Defaults to active locale.
|
|
559
488
|
* @return {string}
|
|
560
489
|
*/
|
|
561
|
-
|
|
562
|
-
|
|
563
490
|
static ordinal(n, locale) {
|
|
564
491
|
const locale1 = locale && locale.toLowerCase();
|
|
565
492
|
const locale0 = locale1 || this.activeName;
|
|
566
|
-
|
|
567
493
|
if (!locale0) {
|
|
568
494
|
return this.getEnOrdinal(n);
|
|
569
495
|
}
|
|
570
|
-
|
|
571
496
|
switch (locale0) {
|
|
572
497
|
case 'en':
|
|
573
498
|
case 's':
|
|
@@ -577,43 +502,38 @@ class Locale {
|
|
|
577
502
|
case 'ashkenazi_poylish':
|
|
578
503
|
case 'ashkenazi_standard':
|
|
579
504
|
return this.getEnOrdinal(n);
|
|
580
|
-
|
|
581
505
|
case 'es':
|
|
582
506
|
return n + 'º';
|
|
583
|
-
|
|
584
507
|
case 'h':
|
|
585
508
|
case 'he':
|
|
586
509
|
case 'he-x-nonikud':
|
|
587
510
|
return String(n);
|
|
588
|
-
|
|
589
511
|
default:
|
|
590
512
|
return n + '.';
|
|
591
513
|
}
|
|
592
514
|
}
|
|
515
|
+
|
|
593
516
|
/**
|
|
594
517
|
* @private
|
|
595
518
|
* @param {number} n
|
|
596
519
|
* @return {string}
|
|
597
520
|
*/
|
|
598
|
-
|
|
599
|
-
|
|
600
521
|
static getEnOrdinal(n) {
|
|
601
522
|
const s = ['th', 'st', 'nd', 'rd'];
|
|
602
523
|
const v = n % 100;
|
|
603
524
|
return n + (s[(v - 20) % 10] || s[v] || s[0]);
|
|
604
525
|
}
|
|
526
|
+
|
|
605
527
|
/**
|
|
606
528
|
* Removes nekudot from Hebrew string
|
|
607
529
|
* @param {string} str
|
|
608
530
|
* @return {string}
|
|
609
531
|
*/
|
|
610
|
-
|
|
611
|
-
|
|
612
532
|
static hebrewStripNikkud(str) {
|
|
613
533
|
return str.replace(/[\u0590-\u05bd]/g, '').replace(/[\u05bf-\u05c7]/g, '');
|
|
614
534
|
}
|
|
615
|
-
|
|
616
535
|
}
|
|
536
|
+
|
|
617
537
|
Locale.addLocale('en', noopLocale);
|
|
618
538
|
Locale.addLocale('s', noopLocale);
|
|
619
539
|
Locale.addLocale('', noopLocale);
|
|
@@ -622,77 +542,93 @@ Locale.useLocale('en');
|
|
|
622
542
|
/*
|
|
623
543
|
* More minimal HDate
|
|
624
544
|
*/
|
|
625
|
-
const NISAN$1 = 1;
|
|
626
|
-
const IYYAR = 2; // const SIVAN = 3;
|
|
627
|
-
|
|
628
|
-
const TAMUZ = 4; // const AV = 5;
|
|
629
545
|
|
|
546
|
+
const NISAN$1 = 1;
|
|
547
|
+
const IYYAR = 2;
|
|
548
|
+
// const SIVAN = 3;
|
|
549
|
+
const TAMUZ = 4;
|
|
550
|
+
// const AV = 5;
|
|
630
551
|
const ELUL = 6;
|
|
631
552
|
const TISHREI = 7;
|
|
632
553
|
const CHESHVAN$1 = 8;
|
|
633
554
|
const KISLEV$1 = 9;
|
|
634
|
-
const TEVET$1 = 10;
|
|
635
|
-
|
|
555
|
+
const TEVET$1 = 10;
|
|
556
|
+
// const SHVAT = 11;
|
|
636
557
|
const ADAR_I$1 = 12;
|
|
637
558
|
const ADAR_II$1 = 13;
|
|
559
|
+
|
|
638
560
|
/**
|
|
639
561
|
* Hebrew months of the year (NISAN=1, TISHREI=7)
|
|
640
562
|
* @readonly
|
|
641
563
|
* @enum {number}
|
|
642
564
|
*/
|
|
643
|
-
|
|
644
565
|
const months = {
|
|
645
566
|
/** Nissan / ניסן */
|
|
646
567
|
NISAN: 1,
|
|
647
|
-
|
|
648
568
|
/** Iyyar / אייר */
|
|
649
569
|
IYYAR: 2,
|
|
650
|
-
|
|
651
570
|
/** Sivan / סיון */
|
|
652
571
|
SIVAN: 3,
|
|
653
|
-
|
|
654
572
|
/** Tamuz (sometimes Tammuz) / תמוז */
|
|
655
573
|
TAMUZ: 4,
|
|
656
|
-
|
|
657
574
|
/** Av / אב */
|
|
658
575
|
AV: 5,
|
|
659
|
-
|
|
660
576
|
/** Elul / אלול */
|
|
661
577
|
ELUL: 6,
|
|
662
|
-
|
|
663
578
|
/** Tishrei / תִשְׁרֵי */
|
|
664
579
|
TISHREI: 7,
|
|
665
|
-
|
|
666
580
|
/** Cheshvan / חשון */
|
|
667
581
|
CHESHVAN: 8,
|
|
668
|
-
|
|
669
582
|
/** Kislev / כסלו */
|
|
670
583
|
KISLEV: 9,
|
|
671
|
-
|
|
672
584
|
/** Tevet / טבת */
|
|
673
585
|
TEVET: 10,
|
|
674
|
-
|
|
675
586
|
/** Sh'vat / שבט */
|
|
676
587
|
SHVAT: 11,
|
|
677
|
-
|
|
678
588
|
/** Adar or Adar Rishon / אדר */
|
|
679
589
|
ADAR_I: 12,
|
|
680
|
-
|
|
681
590
|
/** Adar Sheini (only on leap years) / אדר ב׳ */
|
|
682
|
-
ADAR_II: 13
|
|
591
|
+
ADAR_II: 13,
|
|
683
592
|
};
|
|
684
|
-
|
|
593
|
+
|
|
594
|
+
const monthNames0 = [
|
|
595
|
+
'',
|
|
596
|
+
'Nisan',
|
|
597
|
+
'Iyyar',
|
|
598
|
+
'Sivan',
|
|
599
|
+
'Tamuz',
|
|
600
|
+
'Av',
|
|
601
|
+
'Elul',
|
|
602
|
+
'Tishrei',
|
|
603
|
+
'Cheshvan',
|
|
604
|
+
'Kislev',
|
|
605
|
+
'Tevet',
|
|
606
|
+
'Sh\'vat',
|
|
607
|
+
];
|
|
608
|
+
|
|
685
609
|
/**
|
|
686
610
|
* Transliterations of Hebrew month names.
|
|
687
611
|
* Regular years are index 0 and leap years are index 1.
|
|
688
612
|
* @private
|
|
689
613
|
*/
|
|
614
|
+
const monthNames = [
|
|
615
|
+
monthNames0.concat([
|
|
616
|
+
'Adar',
|
|
617
|
+
'Nisan',
|
|
618
|
+
]),
|
|
619
|
+
monthNames0.concat([
|
|
620
|
+
'Adar I',
|
|
621
|
+
'Adar II',
|
|
622
|
+
'Nisan',
|
|
623
|
+
]),
|
|
624
|
+
];
|
|
690
625
|
|
|
691
|
-
const monthNames = [monthNames0.concat(['Adar', 'Nisan']), monthNames0.concat(['Adar I', 'Adar II', 'Nisan'])];
|
|
692
626
|
const edCache = Object.create(null);
|
|
693
|
-
const EPOCH = -1373428; // Avg year length in the cycle (19 solar years with 235 lunar months)
|
|
694
627
|
|
|
628
|
+
const EPOCH = -1373428;
|
|
629
|
+
// Avg year length in the cycle (19 solar years with 235 lunar months)
|
|
695
630
|
const AVG_HEBYEAR_DAYS = 365.24682220597794;
|
|
631
|
+
|
|
696
632
|
/**
|
|
697
633
|
* Converts Hebrew date to R.D. (Rata Die) fixed days.
|
|
698
634
|
* R.D. 1 is the imaginary date Monday, January 1, 1 on the Gregorian
|
|
@@ -703,7 +639,6 @@ const AVG_HEBYEAR_DAYS = 365.24682220597794;
|
|
|
703
639
|
* @param {number} day Hebrew date (1-30)
|
|
704
640
|
* @return {number}
|
|
705
641
|
*/
|
|
706
|
-
|
|
707
642
|
function hebrew2abs(year, month, day) {
|
|
708
643
|
let tempabs = day;
|
|
709
644
|
|
|
@@ -711,7 +646,6 @@ function hebrew2abs(year, month, day) {
|
|
|
711
646
|
for (let m = TISHREI; m <= monthsInYear(year); m++) {
|
|
712
647
|
tempabs += daysInMonth(m, year);
|
|
713
648
|
}
|
|
714
|
-
|
|
715
649
|
for (let m = NISAN$1; m < month; m++) {
|
|
716
650
|
tempabs += daysInMonth(m, year);
|
|
717
651
|
}
|
|
@@ -723,70 +657,64 @@ function hebrew2abs(year, month, day) {
|
|
|
723
657
|
|
|
724
658
|
return EPOCH + elapsedDays(year) + tempabs - 1;
|
|
725
659
|
}
|
|
660
|
+
|
|
726
661
|
/**
|
|
727
662
|
* @private
|
|
728
663
|
* @param {number} year
|
|
729
664
|
* @return {number}
|
|
730
665
|
*/
|
|
731
|
-
|
|
732
666
|
function newYear(year) {
|
|
733
667
|
return EPOCH + elapsedDays(year);
|
|
734
668
|
}
|
|
669
|
+
|
|
735
670
|
/**
|
|
736
671
|
* Converts absolute R.D. days to Hebrew date
|
|
737
672
|
* @private
|
|
738
673
|
* @param {number} abs absolute R.D. days
|
|
739
674
|
* @return {SimpleHebrewDate}
|
|
740
675
|
*/
|
|
741
|
-
|
|
742
|
-
|
|
743
676
|
function abs2hebrew(abs) {
|
|
744
677
|
if (typeof abs !== 'number' || isNaN(abs)) {
|
|
745
678
|
throw new TypeError(`invalid parameter to abs2hebrew ${abs}`);
|
|
746
679
|
}
|
|
680
|
+
abs = Math.trunc(abs);
|
|
747
681
|
|
|
748
|
-
|
|
749
|
-
|
|
682
|
+
// first, quickly approximate year
|
|
750
683
|
let year = Math.floor((abs - EPOCH) / AVG_HEBYEAR_DAYS);
|
|
751
|
-
|
|
752
684
|
while (newYear(year) <= abs) {
|
|
753
685
|
++year;
|
|
754
686
|
}
|
|
755
|
-
|
|
756
687
|
--year;
|
|
757
|
-
let month = abs < hebrew2abs(year, 1, 1) ? 7 : 1;
|
|
758
688
|
|
|
689
|
+
let month = abs < hebrew2abs(year, 1, 1) ? 7 : 1;
|
|
759
690
|
while (abs > hebrew2abs(year, month, daysInMonth(month, year))) {
|
|
760
691
|
++month;
|
|
761
692
|
}
|
|
762
693
|
|
|
763
694
|
const day = 1 + abs - hebrew2abs(year, month, 1);
|
|
764
|
-
return {
|
|
765
|
-
yy: year,
|
|
766
|
-
mm: month,
|
|
767
|
-
dd: day
|
|
768
|
-
};
|
|
695
|
+
return {yy: year, mm: month, dd: day};
|
|
769
696
|
}
|
|
697
|
+
|
|
770
698
|
/**
|
|
771
699
|
* Returns true if Hebrew year is a leap year
|
|
772
700
|
* @private
|
|
773
701
|
* @param {number} year Hebrew year
|
|
774
702
|
* @return {boolean}
|
|
775
703
|
*/
|
|
776
|
-
|
|
777
704
|
function isLeapYear(year) {
|
|
778
705
|
return (1 + year * 7) % 19 < 7;
|
|
779
706
|
}
|
|
707
|
+
|
|
780
708
|
/**
|
|
781
709
|
* Number of months in this Hebrew year (either 12 or 13 depending on leap year)
|
|
782
710
|
* @private
|
|
783
711
|
* @param {number} year Hebrew year
|
|
784
712
|
* @return {number}
|
|
785
713
|
*/
|
|
786
|
-
|
|
787
714
|
function monthsInYear(year) {
|
|
788
715
|
return 12 + isLeapYear(year); // boolean is cast to 1 or 0
|
|
789
716
|
}
|
|
717
|
+
|
|
790
718
|
/**
|
|
791
719
|
* Number of days in Hebrew month in a given year (29 or 30)
|
|
792
720
|
* @private
|
|
@@ -794,7 +722,6 @@ function monthsInYear(year) {
|
|
|
794
722
|
* @param {number} year Hebrew year
|
|
795
723
|
* @return {number}
|
|
796
724
|
*/
|
|
797
|
-
|
|
798
725
|
function daysInMonth(month, year) {
|
|
799
726
|
switch (month) {
|
|
800
727
|
case IYYAR:
|
|
@@ -804,13 +731,15 @@ function daysInMonth(month, year) {
|
|
|
804
731
|
case ADAR_II$1:
|
|
805
732
|
return 29;
|
|
806
733
|
}
|
|
807
|
-
|
|
808
|
-
|
|
734
|
+
if ((month === ADAR_I$1 && !isLeapYear(year)) ||
|
|
735
|
+
(month === CHESHVAN$1 && !longCheshvan(year)) ||
|
|
736
|
+
(month === KISLEV$1 && shortKislev(year))) {
|
|
809
737
|
return 29;
|
|
810
738
|
} else {
|
|
811
739
|
return 30;
|
|
812
740
|
}
|
|
813
741
|
}
|
|
742
|
+
|
|
814
743
|
/**
|
|
815
744
|
* Returns a transliterated string name of Hebrew month in year,
|
|
816
745
|
* for example 'Elul' or 'Cheshvan'.
|
|
@@ -819,14 +748,13 @@ function daysInMonth(month, year) {
|
|
|
819
748
|
* @param {number} year Hebrew year
|
|
820
749
|
* @return {string}
|
|
821
750
|
*/
|
|
822
|
-
|
|
823
751
|
function getMonthName(month, year) {
|
|
824
752
|
if (typeof month !== 'number' || isNaN(month) || month < 1 || month > 14) {
|
|
825
753
|
throw new TypeError(`bad month argument ${month}`);
|
|
826
754
|
}
|
|
827
|
-
|
|
828
755
|
return monthNames[+isLeapYear(year)][month];
|
|
829
756
|
}
|
|
757
|
+
|
|
830
758
|
/**
|
|
831
759
|
* Days from sunday prior to start of Hebrew calendar to mean
|
|
832
760
|
* conjunction of Tishrei in Hebrew YEAR
|
|
@@ -834,11 +762,11 @@ function getMonthName(month, year) {
|
|
|
834
762
|
* @param {number} year Hebrew year
|
|
835
763
|
* @return {number}
|
|
836
764
|
*/
|
|
837
|
-
|
|
838
765
|
function elapsedDays(year) {
|
|
839
766
|
const elapsed = edCache[year] = edCache[year] || elapsedDays0(year);
|
|
840
767
|
return elapsed;
|
|
841
768
|
}
|
|
769
|
+
|
|
842
770
|
/**
|
|
843
771
|
* Days from sunday prior to start of Hebrew calendar to mean
|
|
844
772
|
* conjunction of Tishrei in Hebrew YEAR
|
|
@@ -846,20 +774,30 @@ function elapsedDays(year) {
|
|
|
846
774
|
* @param {number} year Hebrew year
|
|
847
775
|
* @return {number}
|
|
848
776
|
*/
|
|
849
|
-
|
|
850
777
|
function elapsedDays0(year) {
|
|
851
778
|
const prevYear = year - 1;
|
|
852
779
|
const mElapsed = 235 * Math.floor(prevYear / 19) + // Months in complete 19 year lunar (Metonic) cycles so far
|
|
853
|
-
|
|
854
|
-
|
|
780
|
+
12 * (prevYear % 19) + // Regular months in this cycle
|
|
781
|
+
Math.floor(((prevYear % 19) * 7 + 1) / 19); // Leap months this cycle
|
|
855
782
|
|
|
856
783
|
const pElapsed = 204 + 793 * (mElapsed % 1080);
|
|
857
|
-
|
|
858
|
-
const
|
|
784
|
+
|
|
785
|
+
const hElapsed = 5 +
|
|
786
|
+
12 * mElapsed +
|
|
787
|
+
793 * Math.floor(mElapsed / 1080) +
|
|
788
|
+
Math.floor(pElapsed / 1080);
|
|
789
|
+
|
|
790
|
+
const parts = (pElapsed % 1080) + 1080 * (hElapsed % 24);
|
|
791
|
+
|
|
859
792
|
const day = 1 + 29 * mElapsed + Math.floor(hElapsed / 24);
|
|
860
|
-
const altDay = day +
|
|
793
|
+
const altDay = day +
|
|
794
|
+
(parts >= 19440 ||
|
|
795
|
+
(2 === day % 7 && parts >= 9924 && !isLeapYear(year)) ||
|
|
796
|
+
(1 === day % 7 && parts >= 16789 && isLeapYear(prevYear)));
|
|
797
|
+
|
|
861
798
|
return altDay + (altDay % 7 === 0 || altDay % 7 === 3 || altDay % 7 === 5);
|
|
862
799
|
}
|
|
800
|
+
|
|
863
801
|
/**
|
|
864
802
|
* Number of days in the hebrew YEAR.
|
|
865
803
|
* A common Hebrew calendar year can have a length of 353, 354 or 355 days
|
|
@@ -868,28 +806,26 @@ function elapsedDays0(year) {
|
|
|
868
806
|
* @param {number} year Hebrew year
|
|
869
807
|
* @return {number}
|
|
870
808
|
*/
|
|
871
|
-
|
|
872
|
-
|
|
873
809
|
function daysInYear(year) {
|
|
874
810
|
return elapsedDays(year + 1) - elapsedDays(year);
|
|
875
811
|
}
|
|
812
|
+
|
|
876
813
|
/**
|
|
877
814
|
* true if Cheshvan is long in Hebrew year
|
|
878
815
|
* @private
|
|
879
816
|
* @param {number} year Hebrew year
|
|
880
817
|
* @return {boolean}
|
|
881
818
|
*/
|
|
882
|
-
|
|
883
819
|
function longCheshvan(year) {
|
|
884
820
|
return daysInYear(year) % 10 === 5;
|
|
885
821
|
}
|
|
822
|
+
|
|
886
823
|
/**
|
|
887
824
|
* true if Kislev is short in Hebrew year
|
|
888
825
|
* @private
|
|
889
826
|
* @param {number} year Hebrew year
|
|
890
827
|
* @return {boolean}
|
|
891
828
|
*/
|
|
892
|
-
|
|
893
829
|
function shortKislev(year) {
|
|
894
830
|
return daysInYear(year) % 10 === 3;
|
|
895
831
|
}
|
|
@@ -915,6 +851,7 @@ function shortKislev(year) {
|
|
|
915
851
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
916
852
|
*/
|
|
917
853
|
|
|
854
|
+
// eslint-disable-next-line require-jsdoc
|
|
918
855
|
function throwTypeError(msg) {
|
|
919
856
|
throw new TypeError(msg);
|
|
920
857
|
}
|
|
@@ -923,18 +860,9 @@ const UNITS_DAY = 'day';
|
|
|
923
860
|
const UNITS_WEEK = 'week';
|
|
924
861
|
const UNITS_MONTH = 'month';
|
|
925
862
|
const UNITS_YEAR = 'year';
|
|
926
|
-
const UNITS_SINGLE = {
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
M: UNITS_MONTH,
|
|
930
|
-
y: UNITS_YEAR
|
|
931
|
-
};
|
|
932
|
-
const UNITS_VALID = {
|
|
933
|
-
day: UNITS_DAY,
|
|
934
|
-
week: UNITS_WEEK,
|
|
935
|
-
month: UNITS_MONTH,
|
|
936
|
-
year: UNITS_YEAR
|
|
937
|
-
};
|
|
863
|
+
const UNITS_SINGLE = {d: UNITS_DAY, w: UNITS_WEEK, M: UNITS_MONTH, y: UNITS_YEAR};
|
|
864
|
+
const UNITS_VALID = {day: UNITS_DAY, week: UNITS_WEEK, month: UNITS_MONTH, year: UNITS_YEAR};
|
|
865
|
+
|
|
938
866
|
/**
|
|
939
867
|
* A simple Hebrew date object with numeric fields `yy`, `mm`, and `dd`
|
|
940
868
|
* @typedef {Object} SimpleHebrewDate
|
|
@@ -945,7 +873,6 @@ const UNITS_VALID = {
|
|
|
945
873
|
*/
|
|
946
874
|
|
|
947
875
|
/** Represents a Hebrew date */
|
|
948
|
-
|
|
949
876
|
class HDate {
|
|
950
877
|
/**
|
|
951
878
|
* Create a Hebrew date. There are 3 basic forms for the `HDate()` constructor.
|
|
@@ -981,10 +908,8 @@ class HDate {
|
|
|
981
908
|
if (arguments.length == 2 || arguments.length > 3) {
|
|
982
909
|
throw new TypeError('HDate constructor requires 0, 1 or 3 arguments');
|
|
983
910
|
}
|
|
984
|
-
|
|
985
911
|
if (arguments.length == 3) {
|
|
986
912
|
// Hebrew day, Hebrew month, Hebrew year
|
|
987
|
-
|
|
988
913
|
/**
|
|
989
914
|
* @private
|
|
990
915
|
* @type {number}
|
|
@@ -994,56 +919,44 @@ class HDate {
|
|
|
994
919
|
* @private
|
|
995
920
|
* @type {number}
|
|
996
921
|
*/
|
|
997
|
-
|
|
998
922
|
year = parseInt(year, 10);
|
|
999
|
-
|
|
1000
923
|
if (isNaN(year)) {
|
|
1001
924
|
throw new TypeError(`HDate called with bad year argument: ${year}`);
|
|
1002
925
|
}
|
|
1003
|
-
|
|
1004
926
|
this.year = year;
|
|
1005
927
|
this.setMonth(month); // will throw if we can't parse
|
|
1006
|
-
|
|
1007
928
|
day = parseInt(day, 10);
|
|
1008
|
-
|
|
1009
929
|
if (isNaN(day)) {
|
|
1010
930
|
throw new TypeError(`HDate called with bad day argument: ${day}`);
|
|
1011
931
|
}
|
|
1012
|
-
|
|
1013
932
|
this.setDate(day);
|
|
1014
933
|
} else {
|
|
1015
934
|
// 0 arguments
|
|
1016
935
|
if (typeof day === 'undefined') {
|
|
1017
936
|
day = new Date();
|
|
1018
|
-
}
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
dd: day.day,
|
|
1023
|
-
|
|
1024
|
-
yy: day.year
|
|
1025
|
-
} : throwTypeError(`HDate called with bad argument: ${day}`);
|
|
937
|
+
}
|
|
938
|
+
// 1 argument
|
|
939
|
+
const abs0 = (typeof day === 'number' && !isNaN(day)) ? day :
|
|
940
|
+
isDate(day) ? greg2abs(day) :
|
|
941
|
+
HDate.isHDate(day) ? {dd: day.day, mm: day.month, yy: day.year} :
|
|
942
|
+
throwTypeError(`HDate called with bad argument: ${day}`);
|
|
1026
943
|
const isNumber = typeof abs0 === 'number';
|
|
1027
944
|
const d = isNumber ? abs2hebrew(abs0) : abs0;
|
|
1028
945
|
/**
|
|
1029
946
|
* @private
|
|
1030
947
|
* @type {number}
|
|
1031
948
|
*/
|
|
1032
|
-
|
|
1033
949
|
this.day = d.dd;
|
|
1034
950
|
/**
|
|
1035
951
|
* @private
|
|
1036
952
|
* @type {number}
|
|
1037
953
|
*/
|
|
1038
|
-
|
|
1039
954
|
this.month = d.mm;
|
|
1040
955
|
/**
|
|
1041
956
|
* @private
|
|
1042
957
|
* @type {number}
|
|
1043
958
|
*/
|
|
1044
|
-
|
|
1045
959
|
this.year = d.yy;
|
|
1046
|
-
|
|
1047
960
|
if (isNumber) {
|
|
1048
961
|
/**
|
|
1049
962
|
* @private
|
|
@@ -1053,70 +966,64 @@ class HDate {
|
|
|
1053
966
|
}
|
|
1054
967
|
}
|
|
1055
968
|
}
|
|
969
|
+
|
|
1056
970
|
/**
|
|
1057
971
|
* Gets the Hebrew year of this Hebrew date
|
|
1058
972
|
* @return {number}
|
|
1059
973
|
*/
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
974
|
getFullYear() {
|
|
1063
975
|
return this.year;
|
|
1064
976
|
}
|
|
977
|
+
|
|
1065
978
|
/**
|
|
1066
979
|
* Tests if this date occurs during a leap year
|
|
1067
980
|
* @return {boolean}
|
|
1068
981
|
*/
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
982
|
isLeapYear() {
|
|
1072
983
|
return isLeapYear(this.year);
|
|
1073
984
|
}
|
|
985
|
+
|
|
1074
986
|
/**
|
|
1075
987
|
* Gets the Hebrew month (1=NISAN, 7=TISHREI) of this Hebrew date
|
|
1076
988
|
* @return {number}
|
|
1077
989
|
*/
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
990
|
getMonth() {
|
|
1081
991
|
return this.month;
|
|
1082
992
|
}
|
|
993
|
+
|
|
1083
994
|
/**
|
|
1084
995
|
* The Tishrei-based month of the date. 1 is Tishrei, 7 is Nisan, 13 is Elul in a leap year
|
|
1085
996
|
* @return {number}
|
|
1086
997
|
*/
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
998
|
getTishreiMonth() {
|
|
1090
999
|
const nummonths = monthsInYear(this.getFullYear());
|
|
1091
1000
|
return (this.getMonth() + nummonths - 6) % nummonths || nummonths;
|
|
1092
1001
|
}
|
|
1002
|
+
|
|
1093
1003
|
/**
|
|
1094
1004
|
* Number of days in the month of this Hebrew date
|
|
1095
1005
|
* @return {number}
|
|
1096
1006
|
*/
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
1007
|
daysInMonth() {
|
|
1100
1008
|
return daysInMonth(this.getMonth(), this.getFullYear());
|
|
1101
1009
|
}
|
|
1010
|
+
|
|
1102
1011
|
/**
|
|
1103
1012
|
* Gets the day within the month (1-30)
|
|
1104
1013
|
* @return {number}
|
|
1105
1014
|
*/
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
1015
|
getDate() {
|
|
1109
1016
|
return this.day;
|
|
1110
1017
|
}
|
|
1018
|
+
|
|
1111
1019
|
/**
|
|
1112
1020
|
* Gets the day of the week. 0=Sunday, 6=Saturday
|
|
1113
1021
|
* @return {number}
|
|
1114
1022
|
*/
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
1023
|
getDay() {
|
|
1118
1024
|
return mod(this.abs(), 7);
|
|
1119
1025
|
}
|
|
1026
|
+
|
|
1120
1027
|
/**
|
|
1121
1028
|
* Sets the year of the date. Returns the object it was called upon.
|
|
1122
1029
|
* @private
|
|
@@ -1124,47 +1031,43 @@ class HDate {
|
|
|
1124
1031
|
* @param {number} year
|
|
1125
1032
|
* @return {HDate}
|
|
1126
1033
|
*/
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
1034
|
setFullYear(year) {
|
|
1130
1035
|
this.year = year;
|
|
1131
1036
|
fix(this);
|
|
1132
1037
|
return this;
|
|
1133
1038
|
}
|
|
1039
|
+
|
|
1134
1040
|
/**
|
|
1135
1041
|
* Sets the day of the month of the date. Returns the object it was called upon
|
|
1136
1042
|
* @private
|
|
1137
1043
|
* @param {number} month
|
|
1138
1044
|
* @return {HDate}
|
|
1139
1045
|
*/
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
1046
|
setMonth(month) {
|
|
1143
1047
|
this.month = HDate.monthNum(month);
|
|
1144
1048
|
fix(this);
|
|
1145
1049
|
return this;
|
|
1146
1050
|
}
|
|
1051
|
+
|
|
1147
1052
|
/**
|
|
1148
1053
|
* @private
|
|
1149
1054
|
* @param {number} date
|
|
1150
1055
|
* @return {HDate}
|
|
1151
1056
|
*/
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
1057
|
setDate(date) {
|
|
1155
1058
|
this.day = date;
|
|
1156
1059
|
fix(this);
|
|
1157
1060
|
return this;
|
|
1158
1061
|
}
|
|
1062
|
+
|
|
1159
1063
|
/**
|
|
1160
1064
|
* Converts to Gregorian date
|
|
1161
1065
|
* @return {Date}
|
|
1162
1066
|
*/
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
1067
|
greg() {
|
|
1166
1068
|
return abs2greg(this.abs());
|
|
1167
1069
|
}
|
|
1070
|
+
|
|
1168
1071
|
/**
|
|
1169
1072
|
* Returns R.D. (Rata Die) fixed days.
|
|
1170
1073
|
* R.D. 1 == Monday, January 1, 1 (Gregorian)
|
|
@@ -1172,15 +1075,13 @@ class HDate {
|
|
|
1172
1075
|
* https://en.wikipedia.org/wiki/Rata_Die#Dershowitz_and_Reingold
|
|
1173
1076
|
* @return {number}
|
|
1174
1077
|
*/
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
1078
|
abs() {
|
|
1178
1079
|
if (typeof this.abs0 !== 'number') {
|
|
1179
1080
|
this.abs0 = hebrew2abs(this.year, this.month, this.day);
|
|
1180
1081
|
}
|
|
1181
|
-
|
|
1182
1082
|
return this.abs0;
|
|
1183
1083
|
}
|
|
1084
|
+
|
|
1184
1085
|
/**
|
|
1185
1086
|
* Converts Hebrew date to R.D. (Rata Die) fixed days.
|
|
1186
1087
|
* R.D. 1 is the imaginary date Monday, January 1, 1 on the Gregorian
|
|
@@ -1190,31 +1091,28 @@ class HDate {
|
|
|
1190
1091
|
* @param {number} day Hebrew date (1-30)
|
|
1191
1092
|
* @return {number}
|
|
1192
1093
|
*/
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
1094
|
static hebrew2abs(year, month, day) {
|
|
1196
1095
|
return hebrew2abs(year, month, day);
|
|
1197
1096
|
}
|
|
1097
|
+
|
|
1198
1098
|
/**
|
|
1199
1099
|
* Converts absolute R.D. days to Hebrew date
|
|
1200
1100
|
* @private
|
|
1201
1101
|
* @param {number} abs absolute R.D. days
|
|
1202
1102
|
* @return {SimpleHebrewDate}
|
|
1203
1103
|
*/
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
1104
|
static abs2hebrew(abs) {
|
|
1207
1105
|
return abs2hebrew(abs);
|
|
1208
1106
|
}
|
|
1107
|
+
|
|
1209
1108
|
/**
|
|
1210
1109
|
* Returns a transliterated Hebrew month name, e.g. `'Elul'` or `'Cheshvan'`.
|
|
1211
1110
|
* @return {string}
|
|
1212
1111
|
*/
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
1112
|
getMonthName() {
|
|
1216
1113
|
return getMonthName(this.getMonth(), this.getFullYear());
|
|
1217
1114
|
}
|
|
1115
|
+
|
|
1218
1116
|
/**
|
|
1219
1117
|
* Renders this Hebrew date as a translated or transliterated string,
|
|
1220
1118
|
* including ordinal e.g. `'15th of Cheshvan, 5769'`.
|
|
@@ -1228,16 +1126,13 @@ class HDate {
|
|
|
1228
1126
|
* @param {boolean} [showYear=true] Display year (defaults to true).
|
|
1229
1127
|
* @return {string}
|
|
1230
1128
|
*/
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
render(locale = null, showYear = true) {
|
|
1129
|
+
render(locale=null, showYear=true) {
|
|
1234
1130
|
const locale0 = locale || Locale.getLocaleName();
|
|
1235
1131
|
const day = this.getDate();
|
|
1236
1132
|
const monthName = Locale.gettext(this.getMonthName(), locale0);
|
|
1237
1133
|
const nth = Locale.ordinal(day, locale0);
|
|
1238
1134
|
const dayOf = HDate.getDayOfTranslation(locale0);
|
|
1239
1135
|
const dateStr = `${nth}${dayOf} ${monthName}`;
|
|
1240
|
-
|
|
1241
1136
|
if (showYear) {
|
|
1242
1137
|
const fullYear = this.getFullYear();
|
|
1243
1138
|
return `${dateStr}, ${fullYear}`;
|
|
@@ -1245,13 +1140,12 @@ class HDate {
|
|
|
1245
1140
|
return dateStr;
|
|
1246
1141
|
}
|
|
1247
1142
|
}
|
|
1143
|
+
|
|
1248
1144
|
/**
|
|
1249
1145
|
* @private
|
|
1250
1146
|
* @param {string} locale
|
|
1251
1147
|
* @return {string}
|
|
1252
1148
|
*/
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
1149
|
static getDayOfTranslation(locale) {
|
|
1256
1150
|
switch (locale) {
|
|
1257
1151
|
case 'en':
|
|
@@ -1260,19 +1154,16 @@ class HDate {
|
|
|
1260
1154
|
case 'ashkenazi':
|
|
1261
1155
|
return ' of';
|
|
1262
1156
|
}
|
|
1263
|
-
|
|
1264
1157
|
const ofStr = Locale.lookupTranslation('of', locale);
|
|
1265
|
-
|
|
1266
1158
|
if (ofStr) {
|
|
1267
1159
|
return ' ' + ofStr;
|
|
1268
1160
|
}
|
|
1269
|
-
|
|
1270
1161
|
if ('ashkenazi' === locale.substring(0, 9)) {
|
|
1271
1162
|
return ' of';
|
|
1272
1163
|
}
|
|
1273
|
-
|
|
1274
1164
|
return '';
|
|
1275
1165
|
}
|
|
1166
|
+
|
|
1276
1167
|
/**
|
|
1277
1168
|
* Renders this Hebrew date in Hebrew gematriya, regardless of locale.
|
|
1278
1169
|
* @example
|
|
@@ -1281,14 +1172,13 @@ class HDate {
|
|
|
1281
1172
|
* console.log(hd.renderGematriya()); // 'ט״ו חֶשְׁוָן תשס״ט'
|
|
1282
1173
|
* @return {string}
|
|
1283
1174
|
*/
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
1175
|
renderGematriya() {
|
|
1287
1176
|
const d = this.getDate();
|
|
1288
1177
|
const m = Locale.gettext(this.getMonthName(), 'he');
|
|
1289
1178
|
const y = this.getFullYear();
|
|
1290
1179
|
return gematriya(d) + ' ' + m + ' ' + gematriya(y);
|
|
1291
1180
|
}
|
|
1181
|
+
|
|
1292
1182
|
/**
|
|
1293
1183
|
* Returns an `HDate` representing the a dayNumber before the current date.
|
|
1294
1184
|
* Sunday=0, Saturday=6
|
|
@@ -1297,11 +1187,10 @@ class HDate {
|
|
|
1297
1187
|
* @param {number} day day of week
|
|
1298
1188
|
* @return {HDate}
|
|
1299
1189
|
*/
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
1190
|
before(day) {
|
|
1303
1191
|
return onOrBefore(day, this, -1);
|
|
1304
1192
|
}
|
|
1193
|
+
|
|
1305
1194
|
/**
|
|
1306
1195
|
* Returns an `HDate` representing the a dayNumber on or before the current date.
|
|
1307
1196
|
* Sunday=0, Saturday=6
|
|
@@ -1312,11 +1201,10 @@ class HDate {
|
|
|
1312
1201
|
* @param {number} dow day of week
|
|
1313
1202
|
* @return {HDate}
|
|
1314
1203
|
*/
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
1204
|
onOrBefore(dow) {
|
|
1318
1205
|
return onOrBefore(dow, this, 0);
|
|
1319
1206
|
}
|
|
1207
|
+
|
|
1320
1208
|
/**
|
|
1321
1209
|
* Returns an `HDate` representing the nearest dayNumber to the current date
|
|
1322
1210
|
* Sunday=0, Saturday=6
|
|
@@ -1326,11 +1214,10 @@ class HDate {
|
|
|
1326
1214
|
* @param {number} dow day of week
|
|
1327
1215
|
* @return {HDate}
|
|
1328
1216
|
*/
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
1217
|
nearest(dow) {
|
|
1332
1218
|
return onOrBefore(dow, this, 3);
|
|
1333
1219
|
}
|
|
1220
|
+
|
|
1334
1221
|
/**
|
|
1335
1222
|
* Returns an `HDate` representing the a dayNumber on or after the current date.
|
|
1336
1223
|
* Sunday=0, Saturday=6
|
|
@@ -1341,11 +1228,10 @@ class HDate {
|
|
|
1341
1228
|
* @param {number} dow day of week
|
|
1342
1229
|
* @return {HDate}
|
|
1343
1230
|
*/
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
1231
|
onOrAfter(dow) {
|
|
1347
1232
|
return onOrBefore(dow, this, 6);
|
|
1348
1233
|
}
|
|
1234
|
+
|
|
1349
1235
|
/**
|
|
1350
1236
|
* Returns an `HDate` representing the a dayNumber after the current date.
|
|
1351
1237
|
* Sunday=0, Saturday=6
|
|
@@ -1356,29 +1242,26 @@ class HDate {
|
|
|
1356
1242
|
* @param {number} day day of week
|
|
1357
1243
|
* @return {HDate}
|
|
1358
1244
|
*/
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
1245
|
after(day) {
|
|
1362
1246
|
return onOrBefore(day, this, 7);
|
|
1363
1247
|
}
|
|
1248
|
+
|
|
1364
1249
|
/**
|
|
1365
1250
|
* Returns the next Hebrew date
|
|
1366
1251
|
* @return {HDate}
|
|
1367
1252
|
*/
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
1253
|
next() {
|
|
1371
1254
|
return new HDate(this.abs() + 1);
|
|
1372
1255
|
}
|
|
1256
|
+
|
|
1373
1257
|
/**
|
|
1374
1258
|
* Returns the previous Hebrew date
|
|
1375
1259
|
* @return {HDate}
|
|
1376
1260
|
*/
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
1261
|
prev() {
|
|
1380
1262
|
return new HDate(this.abs() - 1);
|
|
1381
1263
|
}
|
|
1264
|
+
|
|
1382
1265
|
/**
|
|
1383
1266
|
* Returns a cloned `HDate` object with a specified amount of time added
|
|
1384
1267
|
*
|
|
@@ -1395,46 +1278,39 @@ class HDate {
|
|
|
1395
1278
|
* @param {string} [units]
|
|
1396
1279
|
* @return {HDate}
|
|
1397
1280
|
*/
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
add(number, units = 'd') {
|
|
1281
|
+
add(number, units='d') {
|
|
1401
1282
|
number = parseInt(number, 10);
|
|
1402
|
-
|
|
1403
1283
|
if (!number) {
|
|
1404
1284
|
return new HDate(this);
|
|
1405
1285
|
}
|
|
1406
|
-
|
|
1407
1286
|
units = HDate.standardizeUnits(units);
|
|
1408
|
-
|
|
1409
1287
|
if (units === UNITS_DAY) {
|
|
1410
1288
|
return new HDate(this.abs() + number);
|
|
1411
1289
|
} else if (units === UNITS_WEEK) {
|
|
1412
|
-
return new HDate(this.abs() + 7 * number);
|
|
1290
|
+
return new HDate(this.abs() + (7 * number));
|
|
1413
1291
|
} else if (units === UNITS_YEAR) {
|
|
1414
1292
|
return new HDate(this.getDate(), this.getMonth(), this.getFullYear() + number);
|
|
1415
1293
|
} else if (units === UNITS_MONTH) {
|
|
1416
1294
|
let hd = new HDate(this);
|
|
1417
1295
|
const sign = number > 0 ? 1 : -1;
|
|
1418
1296
|
number = Math.abs(number);
|
|
1419
|
-
|
|
1420
1297
|
for (let i = 0; i < number; i++) {
|
|
1421
|
-
hd = new HDate(hd.abs() + sign * hd.daysInMonth());
|
|
1298
|
+
hd = new HDate(hd.abs() + (sign * hd.daysInMonth()));
|
|
1422
1299
|
}
|
|
1423
|
-
|
|
1424
1300
|
return hd;
|
|
1425
1301
|
}
|
|
1426
1302
|
}
|
|
1303
|
+
|
|
1427
1304
|
/**
|
|
1428
1305
|
* @private
|
|
1429
1306
|
* @param {string} units
|
|
1430
1307
|
* @return {string}
|
|
1431
1308
|
*/
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
1309
|
static standardizeUnits(units) {
|
|
1435
1310
|
const full = UNITS_SINGLE[units] || String(units || '').toLowerCase().replace(/s$/, '');
|
|
1436
1311
|
return UNITS_VALID[full] || throwTypeError(`Invalid units '${units}'`);
|
|
1437
1312
|
}
|
|
1313
|
+
|
|
1438
1314
|
/**
|
|
1439
1315
|
* Returns a cloned `HDate` object with a specified amount of time subracted
|
|
1440
1316
|
*
|
|
@@ -1457,11 +1333,10 @@ class HDate {
|
|
|
1457
1333
|
* @param {string} [units]
|
|
1458
1334
|
* @return {HDate}
|
|
1459
1335
|
*/
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
subtract(number, units = 'd') {
|
|
1336
|
+
subtract(number, units='d') {
|
|
1463
1337
|
return this.add(number * -1, units);
|
|
1464
1338
|
}
|
|
1339
|
+
|
|
1465
1340
|
/**
|
|
1466
1341
|
* Returns the difference in days between the two given HDates.
|
|
1467
1342
|
*
|
|
@@ -1479,69 +1354,63 @@ class HDate {
|
|
|
1479
1354
|
* @param {HDate} other Hebrew date to compare
|
|
1480
1355
|
* @return {number}
|
|
1481
1356
|
*/
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
1357
|
deltaDays(other) {
|
|
1485
1358
|
if (!HDate.isHDate(other)) {
|
|
1486
1359
|
throw new TypeError(`Bad argument: ${other}`);
|
|
1487
1360
|
}
|
|
1488
|
-
|
|
1489
1361
|
return this.abs() - other.abs();
|
|
1490
1362
|
}
|
|
1363
|
+
|
|
1491
1364
|
/**
|
|
1492
1365
|
* Compares this date to another date, returning `true` if the dates match.
|
|
1493
1366
|
* @param {HDate} other Hebrew date to compare
|
|
1494
1367
|
* @return {boolean}
|
|
1495
1368
|
*/
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
1369
|
isSameDate(other) {
|
|
1499
1370
|
if (HDate.isHDate(other)) {
|
|
1500
|
-
return this.year == other.year &&
|
|
1371
|
+
return this.year == other.year &&
|
|
1372
|
+
this.month == other.month &&
|
|
1373
|
+
this.day == other.day;
|
|
1501
1374
|
}
|
|
1502
|
-
|
|
1503
1375
|
return false;
|
|
1504
1376
|
}
|
|
1505
|
-
/** @return {string} */
|
|
1506
|
-
|
|
1507
1377
|
|
|
1378
|
+
/** @return {string} */
|
|
1508
1379
|
toString() {
|
|
1509
1380
|
const day = this.getDate();
|
|
1510
1381
|
const fullYear = this.getFullYear();
|
|
1511
1382
|
const monthName = this.getMonthName();
|
|
1512
1383
|
return `${day} ${monthName} ${fullYear}`;
|
|
1513
1384
|
}
|
|
1385
|
+
|
|
1514
1386
|
/**
|
|
1515
1387
|
* Returns true if Hebrew year is a leap year
|
|
1516
1388
|
* @param {number} year Hebrew year
|
|
1517
1389
|
* @return {boolean}
|
|
1518
1390
|
*/
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
1391
|
static isLeapYear(year) {
|
|
1522
1392
|
return isLeapYear(year);
|
|
1523
1393
|
}
|
|
1394
|
+
|
|
1524
1395
|
/**
|
|
1525
1396
|
* Number of months in this Hebrew year (either 12 or 13 depending on leap year)
|
|
1526
1397
|
* @param {number} year Hebrew year
|
|
1527
1398
|
* @return {number}
|
|
1528
1399
|
*/
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
1400
|
static monthsInYear(year) {
|
|
1532
1401
|
return monthsInYear(year);
|
|
1533
1402
|
}
|
|
1403
|
+
|
|
1534
1404
|
/**
|
|
1535
1405
|
* Number of days in Hebrew month in a given year (29 or 30)
|
|
1536
1406
|
* @param {number} month Hebrew month (e.g. months.TISHREI)
|
|
1537
1407
|
* @param {number} year Hebrew year
|
|
1538
1408
|
* @return {number}
|
|
1539
1409
|
*/
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
1410
|
static daysInMonth(month, year) {
|
|
1543
1411
|
return daysInMonth(month, year);
|
|
1544
1412
|
}
|
|
1413
|
+
|
|
1545
1414
|
/**
|
|
1546
1415
|
* Returns a transliterated string name of Hebrew month in year,
|
|
1547
1416
|
* for example 'Elul' or 'Cheshvan'.
|
|
@@ -1549,77 +1418,66 @@ class HDate {
|
|
|
1549
1418
|
* @param {number} year Hebrew year
|
|
1550
1419
|
* @return {string}
|
|
1551
1420
|
*/
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
1421
|
static getMonthName(month, year) {
|
|
1555
1422
|
return getMonthName(month, year);
|
|
1556
1423
|
}
|
|
1424
|
+
|
|
1557
1425
|
/**
|
|
1558
1426
|
* Returns the Hebrew month number (NISAN=1, TISHREI=7)
|
|
1559
1427
|
* @param {number|string} month A number, or Hebrew month name string
|
|
1560
1428
|
* @return {number}
|
|
1561
1429
|
*/
|
|
1562
|
-
|
|
1563
|
-
|
|
1564
1430
|
static monthNum(month) {
|
|
1565
1431
|
if (typeof month === 'number') {
|
|
1566
1432
|
if (isNaN(month) || month > 14) {
|
|
1567
1433
|
throw new RangeError(`Invalid month number: ${month}`);
|
|
1568
1434
|
}
|
|
1569
|
-
|
|
1570
1435
|
return month;
|
|
1571
1436
|
}
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
|
-
|
|
1575
|
-
parseInt(month, 10) : HDate.monthFromName(month);
|
|
1437
|
+
return month.charCodeAt(0) >= 48 && month.charCodeAt(0) <= 57 ? /* number */
|
|
1438
|
+
parseInt(month, 10) :
|
|
1439
|
+
HDate.monthFromName(month);
|
|
1576
1440
|
}
|
|
1441
|
+
|
|
1577
1442
|
/**
|
|
1578
1443
|
* Number of days in the hebrew YEAR
|
|
1579
1444
|
* @param {number} year Hebrew year
|
|
1580
1445
|
* @return {number}
|
|
1581
1446
|
*/
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
1447
|
static daysInYear(year) {
|
|
1585
1448
|
return daysInYear(year);
|
|
1586
1449
|
}
|
|
1450
|
+
|
|
1587
1451
|
/**
|
|
1588
1452
|
* true if Cheshvan is long in Hebrew year
|
|
1589
1453
|
* @param {number} year Hebrew year
|
|
1590
1454
|
* @return {boolean}
|
|
1591
1455
|
*/
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
1456
|
static longCheshvan(year) {
|
|
1595
1457
|
return longCheshvan(year);
|
|
1596
1458
|
}
|
|
1459
|
+
|
|
1597
1460
|
/**
|
|
1598
1461
|
* true if Kislev is short in Hebrew year
|
|
1599
1462
|
* @param {number} year Hebrew year
|
|
1600
1463
|
* @return {boolean}
|
|
1601
1464
|
*/
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
1465
|
static shortKislev(year) {
|
|
1605
1466
|
return shortKislev(year);
|
|
1606
1467
|
}
|
|
1468
|
+
|
|
1607
1469
|
/**
|
|
1608
1470
|
* Converts Hebrew month string name to numeric
|
|
1609
1471
|
* @param {string} monthName monthName
|
|
1610
1472
|
* @return {number}
|
|
1611
1473
|
*/
|
|
1612
|
-
|
|
1613
|
-
|
|
1614
1474
|
static monthFromName(monthName) {
|
|
1615
1475
|
if (typeof monthName === 'number') {
|
|
1616
1476
|
if (isNaN(monthName) || monthName < 1 || monthName > 14) {
|
|
1617
1477
|
throw new RangeError(`Invalid month name: ${monthName}`);
|
|
1618
1478
|
}
|
|
1619
|
-
|
|
1620
1479
|
return monthName;
|
|
1621
1480
|
}
|
|
1622
|
-
|
|
1623
1481
|
const c = monthName.toLowerCase();
|
|
1624
1482
|
/*
|
|
1625
1483
|
the Hebrew months are unique to their second letter
|
|
@@ -1633,7 +1491,8 @@ class HDate {
|
|
|
1633
1491
|
Si Sh Sivan, Shvat
|
|
1634
1492
|
Ta Ti Te Tamuz, Tishrei, Tevet
|
|
1635
1493
|
Av Ad Av, Adar
|
|
1636
|
-
|
|
1494
|
+
|
|
1495
|
+
אב אד אי אל אב אדר אייר אלול
|
|
1637
1496
|
ח חשון
|
|
1638
1497
|
ט טבת
|
|
1639
1498
|
כ כסלו
|
|
@@ -1642,115 +1501,84 @@ class HDate {
|
|
|
1642
1501
|
ש שבט
|
|
1643
1502
|
תמ תש תמוז תשרי
|
|
1644
1503
|
*/
|
|
1645
|
-
|
|
1646
1504
|
switch (c[0]) {
|
|
1647
1505
|
case 'n':
|
|
1648
1506
|
case 'נ':
|
|
1649
1507
|
if (c[1] == 'o') {
|
|
1650
|
-
break;
|
|
1651
|
-
/* this catches "november" */
|
|
1508
|
+
break; /* this catches "november" */
|
|
1652
1509
|
}
|
|
1653
|
-
|
|
1654
1510
|
return months.NISAN;
|
|
1655
|
-
|
|
1656
1511
|
case 'i':
|
|
1657
1512
|
return months.IYYAR;
|
|
1658
|
-
|
|
1659
1513
|
case 'e':
|
|
1660
1514
|
return months.ELUL;
|
|
1661
|
-
|
|
1662
1515
|
case 'c':
|
|
1663
1516
|
case 'ח':
|
|
1664
1517
|
return months.CHESHVAN;
|
|
1665
|
-
|
|
1666
1518
|
case 'k':
|
|
1667
1519
|
case 'כ':
|
|
1668
1520
|
return months.KISLEV;
|
|
1669
|
-
|
|
1670
1521
|
case 's':
|
|
1671
1522
|
switch (c[1]) {
|
|
1672
1523
|
case 'i':
|
|
1673
1524
|
return months.SIVAN;
|
|
1674
|
-
|
|
1675
1525
|
case 'h':
|
|
1676
1526
|
return months.SHVAT;
|
|
1677
1527
|
}
|
|
1678
|
-
|
|
1679
1528
|
case 't':
|
|
1680
1529
|
switch (c[1]) {
|
|
1681
1530
|
case 'a':
|
|
1682
1531
|
return months.TAMUZ;
|
|
1683
|
-
|
|
1684
1532
|
case 'i':
|
|
1685
1533
|
return months.TISHREI;
|
|
1686
|
-
|
|
1687
1534
|
case 'e':
|
|
1688
1535
|
return months.TEVET;
|
|
1689
1536
|
}
|
|
1690
|
-
|
|
1691
1537
|
break;
|
|
1692
|
-
|
|
1693
1538
|
case 'a':
|
|
1694
1539
|
switch (c[1]) {
|
|
1695
1540
|
case 'v':
|
|
1696
1541
|
return months.AV;
|
|
1697
|
-
|
|
1698
1542
|
case 'd':
|
|
1699
1543
|
if (/(1|[^i]i|a|א)$/i.test(monthName)) {
|
|
1700
1544
|
return months.ADAR_I;
|
|
1701
1545
|
}
|
|
1702
|
-
|
|
1703
|
-
return months.ADAR_II;
|
|
1704
|
-
// else assume sheini
|
|
1546
|
+
return months.ADAR_II; // else assume sheini
|
|
1705
1547
|
}
|
|
1706
|
-
|
|
1707
1548
|
break;
|
|
1708
|
-
|
|
1709
1549
|
case 'ס':
|
|
1710
1550
|
return months.SIVAN;
|
|
1711
|
-
|
|
1712
1551
|
case 'ט':
|
|
1713
1552
|
return months.TEVET;
|
|
1714
|
-
|
|
1715
1553
|
case 'ש':
|
|
1716
1554
|
return months.SHVAT;
|
|
1717
|
-
|
|
1718
1555
|
case 'א':
|
|
1719
1556
|
switch (c[1]) {
|
|
1720
1557
|
case 'ב':
|
|
1721
1558
|
return months.AV;
|
|
1722
|
-
|
|
1723
1559
|
case 'ד':
|
|
1724
1560
|
if (/(1|[^i]i|a|א)$/i.test(monthName)) {
|
|
1725
1561
|
return months.ADAR_I;
|
|
1726
1562
|
}
|
|
1727
|
-
|
|
1728
|
-
return months.ADAR_II;
|
|
1729
|
-
// else assume sheini
|
|
1730
|
-
|
|
1563
|
+
return months.ADAR_II; // else assume sheini
|
|
1731
1564
|
case 'י':
|
|
1732
1565
|
return months.IYYAR;
|
|
1733
|
-
|
|
1734
1566
|
case 'ל':
|
|
1735
1567
|
return months.ELUL;
|
|
1736
1568
|
}
|
|
1737
|
-
|
|
1738
1569
|
break;
|
|
1739
|
-
|
|
1740
1570
|
case 'ת':
|
|
1741
1571
|
switch (c[1]) {
|
|
1742
1572
|
case 'מ':
|
|
1743
1573
|
return months.TAMUZ;
|
|
1744
|
-
|
|
1745
1574
|
case 'ש':
|
|
1746
1575
|
return months.TISHREI;
|
|
1747
1576
|
}
|
|
1748
|
-
|
|
1749
1577
|
break;
|
|
1750
1578
|
}
|
|
1751
|
-
|
|
1752
1579
|
throw new RangeError(`Unable to parse month name: ${monthName}`);
|
|
1753
1580
|
}
|
|
1581
|
+
|
|
1754
1582
|
/**
|
|
1755
1583
|
* Note: Applying this function to d+6 gives us the DAYNAME on or after an
|
|
1756
1584
|
* absolute day d. Similarly, applying it to d+3 gives the DAYNAME nearest to
|
|
@@ -1760,71 +1588,65 @@ class HDate {
|
|
|
1760
1588
|
* @param {number} absdate
|
|
1761
1589
|
* @return {number}
|
|
1762
1590
|
*/
|
|
1763
|
-
|
|
1764
|
-
|
|
1765
1591
|
static dayOnOrBefore(dayOfWeek, absdate) {
|
|
1766
|
-
return absdate - (absdate - dayOfWeek) % 7;
|
|
1592
|
+
return absdate - ((absdate - dayOfWeek) % 7);
|
|
1767
1593
|
}
|
|
1594
|
+
|
|
1768
1595
|
/**
|
|
1769
1596
|
* Tests if the object is an instance of `HDate`
|
|
1770
1597
|
* @param {any} obj
|
|
1771
1598
|
* @return {boolean}
|
|
1772
1599
|
*/
|
|
1773
|
-
|
|
1774
|
-
|
|
1775
1600
|
static isHDate(obj) {
|
|
1776
|
-
return obj !== null && typeof obj === 'object' &&
|
|
1601
|
+
return obj !== null && typeof obj === 'object' &&
|
|
1602
|
+
typeof obj.year === 'number' &&
|
|
1603
|
+
typeof obj.month === 'number' &&
|
|
1604
|
+
typeof obj.day === 'number' &&
|
|
1605
|
+
typeof obj.greg === 'function' &&
|
|
1606
|
+
typeof obj.abs === 'function';
|
|
1777
1607
|
}
|
|
1778
|
-
|
|
1779
1608
|
}
|
|
1609
|
+
|
|
1780
1610
|
/**
|
|
1781
1611
|
* @private
|
|
1782
1612
|
* @param {HDate} date
|
|
1783
1613
|
*/
|
|
1784
|
-
|
|
1785
1614
|
function fix(date) {
|
|
1786
1615
|
fixMonth(date);
|
|
1787
1616
|
fixDate(date);
|
|
1788
1617
|
}
|
|
1618
|
+
|
|
1789
1619
|
/**
|
|
1790
1620
|
* @private
|
|
1791
1621
|
* @param {HDate} date
|
|
1792
1622
|
*/
|
|
1793
|
-
|
|
1794
|
-
|
|
1795
1623
|
function fixDate(date) {
|
|
1796
1624
|
if (date.day < 1) {
|
|
1797
1625
|
if (date.month == months.TISHREI) {
|
|
1798
1626
|
date.year -= 1;
|
|
1799
1627
|
}
|
|
1800
|
-
|
|
1801
1628
|
date.day += daysInMonth(date.month, date.year);
|
|
1802
1629
|
date.month -= 1;
|
|
1803
1630
|
fix(date);
|
|
1804
1631
|
}
|
|
1805
|
-
|
|
1806
1632
|
if (date.day > daysInMonth(date.month, date.year)) {
|
|
1807
1633
|
if (date.month === months.ELUL) {
|
|
1808
1634
|
date.year += 1;
|
|
1809
1635
|
}
|
|
1810
|
-
|
|
1811
1636
|
date.day -= daysInMonth(date.month, date.year);
|
|
1812
1637
|
date.month += 1;
|
|
1813
1638
|
fix(date);
|
|
1814
1639
|
}
|
|
1815
|
-
|
|
1816
1640
|
fixMonth(date);
|
|
1817
1641
|
}
|
|
1642
|
+
|
|
1818
1643
|
/**
|
|
1819
1644
|
* @private
|
|
1820
1645
|
* @param {HDate} date
|
|
1821
1646
|
*/
|
|
1822
|
-
|
|
1823
|
-
|
|
1824
1647
|
function fixMonth(date) {
|
|
1825
1648
|
if (date.month === months.ADAR_II && !date.isLeapYear()) {
|
|
1826
1649
|
date.month -= 1; // to Adar I
|
|
1827
|
-
|
|
1828
1650
|
fix(date);
|
|
1829
1651
|
} else if (date.month < 1) {
|
|
1830
1652
|
date.month += monthsInYear(date.year);
|
|
@@ -1835,9 +1657,9 @@ function fixMonth(date) {
|
|
|
1835
1657
|
date.year += 1;
|
|
1836
1658
|
fix(date);
|
|
1837
1659
|
}
|
|
1838
|
-
|
|
1839
1660
|
delete date.abs0;
|
|
1840
1661
|
}
|
|
1662
|
+
|
|
1841
1663
|
/**
|
|
1842
1664
|
* @private
|
|
1843
1665
|
* @param {number} day
|
|
@@ -1845,8 +1667,6 @@ function fixMonth(date) {
|
|
|
1845
1667
|
* @param {number} offset
|
|
1846
1668
|
* @return {HDate}
|
|
1847
1669
|
*/
|
|
1848
|
-
|
|
1849
|
-
|
|
1850
1670
|
function onOrBefore(day, t, offset) {
|
|
1851
1671
|
return new HDate(HDate.dayOnOrBefore(day, t.abs() + offset));
|
|
1852
1672
|
}
|
|
@@ -1858,21 +1678,20 @@ const TEVET = months.TEVET;
|
|
|
1858
1678
|
const SHVAT = months.SHVAT;
|
|
1859
1679
|
const ADAR_I = months.ADAR_I;
|
|
1860
1680
|
const ADAR_II = months.ADAR_II;
|
|
1681
|
+
|
|
1861
1682
|
/**
|
|
1862
1683
|
* @private
|
|
1863
1684
|
* @param {number} hyear Hebrew year
|
|
1864
1685
|
* @param {Date|HDate} gdate Gregorian or Hebrew date of death
|
|
1865
1686
|
* @return {HDate} anniversary occurring in hyear
|
|
1866
1687
|
*/
|
|
1867
|
-
|
|
1868
1688
|
function getYahrzeit_(hyear, gdate) {
|
|
1869
1689
|
const orig = HDate.isHDate(gdate) ? gdate : new HDate(gdate);
|
|
1870
1690
|
let hDeath = {
|
|
1871
1691
|
yy: orig.getFullYear(),
|
|
1872
1692
|
mm: orig.getMonth(),
|
|
1873
|
-
dd: orig.getDate()
|
|
1693
|
+
dd: orig.getDate(),
|
|
1874
1694
|
};
|
|
1875
|
-
|
|
1876
1695
|
if (hyear <= hDeath.yy) {
|
|
1877
1696
|
// `Hebrew year ${hyear} occurs on or before original date in ${hDeath.yy}`
|
|
1878
1697
|
return undefined;
|
|
@@ -1894,10 +1713,10 @@ function getYahrzeit_(hyear, gdate) {
|
|
|
1894
1713
|
// (so Adar has only 29 days), use the last day in Shevat.
|
|
1895
1714
|
hDeath.dd = 30;
|
|
1896
1715
|
hDeath.mm = SHVAT;
|
|
1897
|
-
}
|
|
1898
|
-
//
|
|
1899
|
-
|
|
1716
|
+
}
|
|
1717
|
+
// In all other cases, use the normal anniversary of the date of death.
|
|
1900
1718
|
|
|
1719
|
+
// advance day to rosh chodesh if needed
|
|
1901
1720
|
if (hDeath.mm == CHESHVAN && hDeath.dd == 30 && !longCheshvan(hyear)) {
|
|
1902
1721
|
hDeath.mm = KISLEV;
|
|
1903
1722
|
hDeath.dd = 1;
|
|
@@ -1908,27 +1727,25 @@ function getYahrzeit_(hyear, gdate) {
|
|
|
1908
1727
|
|
|
1909
1728
|
return new HDate(hDeath.dd, hDeath.mm, hyear);
|
|
1910
1729
|
}
|
|
1730
|
+
|
|
1911
1731
|
/**
|
|
1912
1732
|
* @private
|
|
1913
1733
|
* @param {number} hyear Hebrew year
|
|
1914
1734
|
* @param {Date|HDate} gdate Gregorian or Hebrew date of event
|
|
1915
1735
|
* @return {HDate} anniversary occurring in `hyear`
|
|
1916
1736
|
*/
|
|
1917
|
-
|
|
1918
1737
|
function getBirthdayOrAnniversary_(hyear, gdate) {
|
|
1919
1738
|
const orig = HDate.isHDate(gdate) ? gdate : new HDate(gdate);
|
|
1920
1739
|
const origYear = orig.getFullYear();
|
|
1921
|
-
|
|
1922
1740
|
if (hyear <= origYear) {
|
|
1923
1741
|
// `Hebrew year ${hyear} occurs on or before original date in ${origYear}`
|
|
1924
1742
|
return undefined;
|
|
1925
1743
|
}
|
|
1926
|
-
|
|
1927
1744
|
const isOrigLeap = isLeapYear(origYear);
|
|
1928
1745
|
let month = orig.getMonth();
|
|
1929
1746
|
let day = orig.getDate();
|
|
1930
1747
|
|
|
1931
|
-
if (month == ADAR_I && !isOrigLeap || month == ADAR_II && isOrigLeap) {
|
|
1748
|
+
if ((month == ADAR_I && !isOrigLeap) || (month == ADAR_II && isOrigLeap)) {
|
|
1932
1749
|
month = monthsInYear(hyear);
|
|
1933
1750
|
} else if (month == CHESHVAN && day == 30 && !longCheshvan(hyear)) {
|
|
1934
1751
|
month = KISLEV;
|
|
@@ -1944,11 +1761,21 @@ function getBirthdayOrAnniversary_(hyear, gdate) {
|
|
|
1944
1761
|
return new HDate(day, month, hyear);
|
|
1945
1762
|
}
|
|
1946
1763
|
|
|
1947
|
-
const version="3.
|
|
1764
|
+
const version="3.41.0";
|
|
1948
1765
|
|
|
1949
1766
|
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};
|
|
1950
1767
|
|
|
1951
1768
|
Locale.addLocale('he', poHeMin);
|
|
1952
1769
|
Locale.addLocale('h', poHeMin);
|
|
1953
1770
|
|
|
1771
|
+
const heStrs = poHeMin.contexts[''];
|
|
1772
|
+
const heNoNikud = {};
|
|
1773
|
+
Object.keys(heStrs).forEach((key) => {
|
|
1774
|
+
heNoNikud[key] = [Locale.hebrewStripNikkud(heStrs[key][0])];
|
|
1775
|
+
});
|
|
1776
|
+
Locale.addLocale('he-x-NoNikud', {
|
|
1777
|
+
headers: poHeMin.headers,
|
|
1778
|
+
contexts: {'': heNoNikud},
|
|
1779
|
+
});
|
|
1780
|
+
|
|
1954
1781
|
export { HDate, Locale, gematriya, getBirthdayOrAnniversary_ as getBirthdayOrAnniversary, getYahrzeit_ as getYahrzeit, greg, months, version };
|