@hebcal/core 6.0.6 → 6.0.8
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 +42 -27
- package/dist/bundle.js +13 -8
- package/dist/bundle.js.map +1 -1
- package/dist/bundle.min.js +3 -3
- package/dist/bundle.min.js.map +1 -1
- package/dist/esm/DailyLearning.js +1 -1
- package/dist/esm/HebrewDateEvent.js +1 -1
- package/dist/esm/HolidayEvent.js +1 -1
- package/dist/esm/MevarchimChodeshEvent.js +1 -1
- package/dist/esm/ParshaEvent.js +1 -1
- package/dist/esm/TimedEvent.js +1 -1
- package/dist/esm/YomKippurKatanEvent.js +1 -1
- package/dist/esm/ashkenazi.po.js +1 -1
- package/dist/esm/calendar.js +1 -1
- package/dist/esm/candles.js +1 -1
- package/dist/esm/event.js +1 -1
- package/dist/esm/getStartAndEnd.js +1 -1
- package/dist/esm/hallel.js +1 -1
- package/dist/esm/he-x-NoNikud.po.d.ts +3 -0
- package/dist/esm/he-x-NoNikud.po.js +2 -2
- package/dist/esm/he-x-NoNikud.po.js.map +1 -1
- package/dist/esm/he.po.d.ts +1 -0
- package/dist/esm/he.po.js +2 -2
- package/dist/esm/he.po.js.map +1 -1
- package/dist/esm/hebcal.js +1 -1
- package/dist/esm/holidays.js +1 -1
- package/dist/esm/index.js +1 -1
- package/dist/esm/isAssurBemlacha.js +1 -1
- package/dist/esm/locale.js +1 -1
- package/dist/esm/location.js +2 -2
- package/dist/esm/location.js.map +1 -1
- package/dist/esm/modern.js +1 -1
- package/dist/esm/molad.js +1 -1
- package/dist/esm/omer.js +1 -1
- package/dist/esm/parshaName.js +1 -1
- package/dist/esm/parshaYear.d.ts +2 -2
- package/dist/esm/parshaYear.js +1 -1
- package/dist/esm/parshaYear.js.map +1 -1
- package/dist/esm/pkgVersion.d.ts +1 -1
- package/dist/esm/pkgVersion.js +2 -2
- package/dist/esm/pkgVersion.js.map +1 -1
- package/dist/esm/reformatTimeStr.js +1 -1
- package/dist/esm/sedra.d.ts +5 -1
- package/dist/esm/sedra.js +9 -3
- package/dist/esm/sedra.js.map +1 -1
- package/dist/esm/staticHolidays.js +1 -2
- package/dist/esm/staticHolidays.js.map +1 -1
- package/dist/esm/tachanun.js +1 -1
- package/dist/esm/zmanim.js +1 -1
- package/dist/he-x-NoNikud.po.d.ts +3 -0
- package/dist/he.po.d.ts +1 -0
- package/dist/parshaYear.d.ts +2 -2
- package/dist/pkgVersion.d.ts +1 -1
- package/dist/po2json.d.ts +1 -0
- package/dist/po2json.js +41 -0
- package/dist/sedra.d.ts +5 -1
- package/dist/size-demo/dist/getHoliday.d.ts +1944 -0
- package/dist/size-demo/dist/getHoliday.js +3712 -0
- package/dist/size-demo/dist/parshiyot.js +10662 -0
- package/dist/size-demo/dist/sedra.d.ts +1411 -0
- package/dist/size-demo/dist/sedra.js +2359 -0
- package/dist/size-demo/dist/tachanun.d.ts +1015 -0
- package/dist/size-demo/dist/tachanun.js +1755 -0
- package/dist/size-demo/getHoliday.d.ts +1 -0
- package/dist/size-demo/getHoliday.js +3 -0
- package/dist/size-demo/parshiyot.d.ts +1 -0
- package/dist/size-demo/parshiyot.js +11 -0
- package/dist/size-demo/rollup.config.d.ts +3 -0
- package/dist/size-demo/rollup.config.js +47 -0
- package/dist/size-demo/sedra.d.ts +1 -0
- package/dist/size-demo/sedra.js +3 -0
- package/dist/size-demo/tachanun.d.ts +1 -0
- package/dist/size-demo/tachanun.js +3 -0
- package/dist/src/CalOptions.d.ts +168 -0
- package/dist/src/CalOptions.js +1 -0
- package/dist/src/DailyLearning.d.ts +32 -0
- package/dist/src/DailyLearning.js +55 -0
- package/dist/src/HebrewDateEvent.d.ts +37 -0
- package/dist/src/HebrewDateEvent.js +72 -0
- package/dist/src/HolidayEvent.d.ts +83 -0
- package/dist/src/HolidayEvent.js +186 -0
- package/dist/src/MevarchimChodeshEvent.d.ts +26 -0
- package/dist/src/MevarchimChodeshEvent.js +50 -0
- package/dist/src/ParshaEvent.d.ts +19 -0
- package/dist/src/ParshaEvent.js +43 -0
- package/dist/src/TimedEvent.d.ts +47 -0
- package/dist/src/TimedEvent.js +92 -0
- package/dist/src/YomKippurKatanEvent.d.ts +23 -0
- package/dist/src/YomKippurKatanEvent.js +38 -0
- package/dist/src/ashkenazi.po.d.ts +70 -0
- package/dist/src/ashkenazi.po.js +1 -0
- package/dist/src/calendar.d.ts +111 -0
- package/dist/src/calendar.js +660 -0
- package/dist/src/candles.d.ts +44 -0
- package/dist/src/candles.js +163 -0
- package/dist/src/event.d.ts +188 -0
- package/dist/src/event.js +233 -0
- package/dist/src/getStartAndEnd.d.ts +6 -0
- package/dist/src/getStartAndEnd.js +97 -0
- package/dist/src/hallel.d.ts +6 -0
- package/dist/src/hallel.js +47 -0
- package/dist/src/he-x-NoNikud.po.d.ts +16 -0
- package/dist/src/he-x-NoNikud.po.js +1 -0
- package/dist/src/he.po.d.ts +195 -0
- package/dist/src/he.po.js +1 -0
- package/dist/src/hebcal.d.ts +260 -0
- package/dist/src/hebcal.js +332 -0
- package/dist/src/holidays.d.ts +22 -0
- package/dist/src/holidays.js +288 -0
- package/dist/src/index.d.ts +26 -0
- package/dist/src/index.js +24 -0
- package/dist/src/isAssurBemlacha.d.ts +9 -0
- package/dist/src/isAssurBemlacha.js +62 -0
- package/dist/src/locale.d.ts +2 -0
- package/dist/src/locale.js +11 -0
- package/dist/src/location.d.ts +73 -0
- package/dist/src/location.js +306 -0
- package/dist/src/modern.d.ts +18 -0
- package/dist/src/modern.js +59 -0
- package/dist/src/molad.d.ts +62 -0
- package/dist/src/molad.js +169 -0
- package/dist/src/omer.d.ts +53 -0
- package/dist/src/omer.js +302 -0
- package/dist/src/parshaName.d.ts +2 -0
- package/dist/src/parshaName.js +13 -0
- package/dist/src/parshaYear.d.ts +9 -0
- package/dist/src/parshaYear.js +24 -0
- package/dist/src/pkgVersion.d.ts +2 -0
- package/dist/src/pkgVersion.js +2 -0
- package/dist/src/reformatTimeStr.d.ts +8 -0
- package/dist/src/reformatTimeStr.js +48 -0
- package/dist/src/sedra.d.ts +95 -0
- package/dist/src/sedra.js +477 -0
- package/dist/src/staticHolidays.d.ts +176 -0
- package/dist/src/staticHolidays.js +614 -0
- package/dist/src/tachanun.d.ts +29 -0
- package/dist/src/tachanun.js +120 -0
- package/dist/src/zmanim.d.ts +347 -0
- package/dist/src/zmanim.js +579 -0
- package/dist/version.d.ts +1 -0
- package/dist/version.js +9 -0
- package/package.json +11 -8
|
@@ -0,0 +1,1755 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*! @hebcal/hdate v0.21.1, distributed under GPLv2 https://www.gnu.org/licenses/gpl-2.0.txt */
|
|
3
|
+
/* eslint-disable @typescript-eslint/no-namespace, no-inner-declarations */
|
|
4
|
+
/** @private */
|
|
5
|
+
const lengths = [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
|
|
6
|
+
/** @private */
|
|
7
|
+
const monthLengths = [lengths, lengths.slice()];
|
|
8
|
+
monthLengths[1][2] = 29;
|
|
9
|
+
/**
|
|
10
|
+
* @private
|
|
11
|
+
*/
|
|
12
|
+
function mod$1(x, y) {
|
|
13
|
+
return x - y * Math.floor(x / y);
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* @private
|
|
17
|
+
*/
|
|
18
|
+
function quotient(x, y) {
|
|
19
|
+
return Math.floor(x / y);
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* @private
|
|
23
|
+
* @param abs - R.D. number of days
|
|
24
|
+
*/
|
|
25
|
+
function yearFromFixed(abs) {
|
|
26
|
+
const l0 = abs - 1;
|
|
27
|
+
const n400 = quotient(l0, 146097);
|
|
28
|
+
const d1 = mod$1(l0, 146097);
|
|
29
|
+
const n100 = quotient(d1, 36524);
|
|
30
|
+
const d2 = mod$1(d1, 36524);
|
|
31
|
+
const n4 = quotient(d2, 1461);
|
|
32
|
+
const d3 = mod$1(d2, 1461);
|
|
33
|
+
const n1 = quotient(d3, 365);
|
|
34
|
+
const year = 400 * n400 + 100 * n100 + 4 * n4 + n1;
|
|
35
|
+
return n100 !== 4 && n1 !== 4 ? year + 1 : year;
|
|
36
|
+
}
|
|
37
|
+
/*
|
|
38
|
+
const ABS_14SEP1752 = 639797;
|
|
39
|
+
const ABS_2SEP1752 = 639785;
|
|
40
|
+
*/
|
|
41
|
+
/*
|
|
42
|
+
* Formerly in namespace, now top-level
|
|
43
|
+
*/
|
|
44
|
+
/**
|
|
45
|
+
* Returns true if the Gregorian year is a leap year
|
|
46
|
+
* @param year Gregorian year
|
|
47
|
+
*/
|
|
48
|
+
function isGregLeapYear(year) {
|
|
49
|
+
return !(year % 4) && (!!(year % 100) || !(year % 400));
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Number of days in the Gregorian month for given year
|
|
53
|
+
* @param month Gregorian month (1=January, 12=December)
|
|
54
|
+
* @param year Gregorian year
|
|
55
|
+
*/
|
|
56
|
+
function daysInGregMonth(month, year) {
|
|
57
|
+
// 1 based months
|
|
58
|
+
return monthLengths[+isGregLeapYear(year)][month];
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Returns true if the object is a Javascript Date
|
|
62
|
+
*/
|
|
63
|
+
function isDate(obj) {
|
|
64
|
+
// eslint-disable-next-line no-prototype-builtins
|
|
65
|
+
return typeof obj === 'object' && Date.prototype.isPrototypeOf(obj);
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* @private
|
|
69
|
+
* @param year
|
|
70
|
+
* @param month (1-12)
|
|
71
|
+
* @param day (1-31)
|
|
72
|
+
*/
|
|
73
|
+
function toFixed(year, month, day) {
|
|
74
|
+
const py = year - 1;
|
|
75
|
+
return (365 * py +
|
|
76
|
+
quotient(py, 4) -
|
|
77
|
+
quotient(py, 100) +
|
|
78
|
+
quotient(py, 400) +
|
|
79
|
+
quotient(367 * month - 362, 12) +
|
|
80
|
+
(month <= 2 ? 0 : isGregLeapYear(year) ? -1 : -2) +
|
|
81
|
+
day);
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Converts Gregorian date to absolute R.D. (Rata Die) days
|
|
85
|
+
* @param date Gregorian date
|
|
86
|
+
*/
|
|
87
|
+
function greg2abs(date) {
|
|
88
|
+
if (!isDate(date)) {
|
|
89
|
+
throw new TypeError(`not a Date: ${date}`);
|
|
90
|
+
}
|
|
91
|
+
else if (isNaN(date.getTime())) {
|
|
92
|
+
throw new RangeError('Invalid Date');
|
|
93
|
+
}
|
|
94
|
+
const abs = toFixed(date.getFullYear(), date.getMonth() + 1, date.getDate());
|
|
95
|
+
/*
|
|
96
|
+
if (abs < ABS_14SEP1752 && abs > ABS_2SEP1752) {
|
|
97
|
+
throw new RangeError(`Invalid Date: ${date}`);
|
|
98
|
+
}
|
|
99
|
+
*/
|
|
100
|
+
return abs;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Converts from Rata Die (R.D. number) to Gregorian date.
|
|
104
|
+
* See the footnote on page 384 of ``Calendrical Calculations, Part II:
|
|
105
|
+
* Three Historical Calendars'' by E. M. Reingold, N. Dershowitz, and S. M.
|
|
106
|
+
* Clamen, Software--Practice and Experience, Volume 23, Number 4
|
|
107
|
+
* (April, 1993), pages 383-404 for an explanation.
|
|
108
|
+
*
|
|
109
|
+
* Note that this function returns the daytime portion of the date.
|
|
110
|
+
* For example, the 15th of Cheshvan 5769 began at sundown on
|
|
111
|
+
* 12 November 2008 and continues through 13 November 2008. This
|
|
112
|
+
* function would return only the date 13 November 2008.
|
|
113
|
+
* @param abs - R.D. number of days
|
|
114
|
+
* @example
|
|
115
|
+
* const abs = hebrew2abs(5769, months.CHESHVAN, 15);
|
|
116
|
+
* const date = abs2greg(abs); // 13 November 2008
|
|
117
|
+
* const year = date.getFullYear(); // 2008
|
|
118
|
+
* const monthNum = date.getMonth() + 1; // 11
|
|
119
|
+
* const day = date.getDate(); // 13
|
|
120
|
+
*/
|
|
121
|
+
function abs2greg(abs) {
|
|
122
|
+
if (typeof abs !== 'number' || isNaN(abs)) {
|
|
123
|
+
throw new TypeError(`not a Number: ${abs}`);
|
|
124
|
+
}
|
|
125
|
+
abs = Math.trunc(abs);
|
|
126
|
+
/*
|
|
127
|
+
if (abs < ABS_14SEP1752 && abs > ABS_2SEP1752) {
|
|
128
|
+
throw new RangeError(`Invalid Date: ${abs}`);
|
|
129
|
+
}
|
|
130
|
+
*/
|
|
131
|
+
const year = yearFromFixed(abs);
|
|
132
|
+
const priorDays = abs - toFixed(year, 1, 1);
|
|
133
|
+
const correction = abs < toFixed(year, 3, 1) ? 0 : isGregLeapYear(year) ? 1 : 2;
|
|
134
|
+
const month = quotient(12 * (priorDays + correction) + 373, 367);
|
|
135
|
+
const day = abs - toFixed(year, month, 1) + 1;
|
|
136
|
+
const dt = new Date(year, month - 1, day);
|
|
137
|
+
if (year < 100 && year >= 0) {
|
|
138
|
+
dt.setFullYear(year);
|
|
139
|
+
}
|
|
140
|
+
return dt;
|
|
141
|
+
}
|
|
142
|
+
/*! @hebcal/hdate v0.21.1, distributed under GPLv2 https://www.gnu.org/licenses/gpl-2.0.txt */
|
|
143
|
+
/* eslint-disable @typescript-eslint/no-explicit-any, @typescript-eslint/no-namespace */
|
|
144
|
+
/**
|
|
145
|
+
* Gregorian date helper functions
|
|
146
|
+
*/
|
|
147
|
+
var greg;
|
|
148
|
+
(function (greg) {
|
|
149
|
+
})(greg || (greg = {}));
|
|
150
|
+
greg.abs2greg = abs2greg;
|
|
151
|
+
greg.daysInMonth = daysInGregMonth;
|
|
152
|
+
greg.greg2abs = greg2abs;
|
|
153
|
+
greg.isDate = isDate;
|
|
154
|
+
greg.isLeapYear = isGregLeapYear;
|
|
155
|
+
/*! @hebcal/hdate v0.21.1, distributed under GPLv2 https://www.gnu.org/licenses/gpl-2.0.txt */
|
|
156
|
+
/**
|
|
157
|
+
* Removes niqqud from Hebrew string
|
|
158
|
+
*/
|
|
159
|
+
function hebrewStripNikkud(str) {
|
|
160
|
+
const a = str.normalize();
|
|
161
|
+
// now strip out niqqud and trope
|
|
162
|
+
return a.replace(/[\u0590-\u05bd]/g, '').replace(/[\u05bf-\u05c7]/g, '');
|
|
163
|
+
}
|
|
164
|
+
/*! @hebcal/hdate v0.21.1, distributed under GPLv2 https://www.gnu.org/licenses/gpl-2.0.txt */
|
|
165
|
+
/*
|
|
166
|
+
* More minimal HDate
|
|
167
|
+
*/
|
|
168
|
+
const NISAN$1 = 1;
|
|
169
|
+
const IYYAR$1 = 2;
|
|
170
|
+
const SIVAN = 3;
|
|
171
|
+
const TAMUZ = 4;
|
|
172
|
+
const AV = 5;
|
|
173
|
+
const ELUL = 6;
|
|
174
|
+
const TISHREI = 7;
|
|
175
|
+
const CHESHVAN = 8;
|
|
176
|
+
const KISLEV = 9;
|
|
177
|
+
const TEVET = 10;
|
|
178
|
+
const SHVAT = 11;
|
|
179
|
+
const ADAR_I = 12;
|
|
180
|
+
const ADAR_II = 13;
|
|
181
|
+
/**
|
|
182
|
+
* Hebrew months of the year (NISAN=1, TISHREI=7)
|
|
183
|
+
* @readonly
|
|
184
|
+
* @enum {number}
|
|
185
|
+
*/
|
|
186
|
+
const months = {
|
|
187
|
+
/** Nissan / ניסן */
|
|
188
|
+
NISAN: NISAN$1,
|
|
189
|
+
/** Iyyar / אייר */
|
|
190
|
+
IYYAR: IYYAR$1,
|
|
191
|
+
/** Sivan / סיון */
|
|
192
|
+
SIVAN,
|
|
193
|
+
/** Av / אב */
|
|
194
|
+
AV,
|
|
195
|
+
/** Elul / אלול */
|
|
196
|
+
ELUL,
|
|
197
|
+
/** Tishrei / תִּשְׁרֵי */
|
|
198
|
+
TISHREI,
|
|
199
|
+
/** Kislev / כסלו */
|
|
200
|
+
KISLEV,
|
|
201
|
+
/** Sh'vat / שבט */
|
|
202
|
+
SHVAT,
|
|
203
|
+
/** Adar or Adar Rishon / אדר */
|
|
204
|
+
ADAR_I,
|
|
205
|
+
/** Adar Sheini (only on leap years) / אדר ב׳ */
|
|
206
|
+
ADAR_II,
|
|
207
|
+
};
|
|
208
|
+
const NISAN_STR = 'Nisan';
|
|
209
|
+
const monthNames0 = [
|
|
210
|
+
'',
|
|
211
|
+
NISAN_STR,
|
|
212
|
+
'Iyyar',
|
|
213
|
+
'Sivan',
|
|
214
|
+
'Tamuz',
|
|
215
|
+
'Av',
|
|
216
|
+
'Elul',
|
|
217
|
+
'Tishrei',
|
|
218
|
+
'Cheshvan',
|
|
219
|
+
'Kislev',
|
|
220
|
+
'Tevet',
|
|
221
|
+
"Sh'vat",
|
|
222
|
+
];
|
|
223
|
+
/*
|
|
224
|
+
* Transliterations of Hebrew month names.
|
|
225
|
+
* Regular years are index 0 and leap years are index 1.
|
|
226
|
+
* @private
|
|
227
|
+
*/
|
|
228
|
+
const monthNames = [
|
|
229
|
+
[...monthNames0, 'Adar', NISAN_STR],
|
|
230
|
+
[...monthNames0, 'Adar I', 'Adar II', NISAN_STR],
|
|
231
|
+
];
|
|
232
|
+
const edCache = new Map();
|
|
233
|
+
const EPOCH = -1373428;
|
|
234
|
+
// Avg year length in the cycle (19 solar years with 235 lunar months)
|
|
235
|
+
const AVG_HEBYEAR_DAYS = 365.24682220597794;
|
|
236
|
+
/**
|
|
237
|
+
* @private
|
|
238
|
+
*/
|
|
239
|
+
function assertNumber(n, name) {
|
|
240
|
+
if (typeof n !== 'number' || isNaN(n)) {
|
|
241
|
+
throw new TypeError(`param '${name}' not a number: ${n}`);
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
/**
|
|
245
|
+
* Converts Hebrew date to R.D. (Rata Die) fixed days.
|
|
246
|
+
* R.D. 1 is the imaginary date Monday, January 1, 1 on the Gregorian
|
|
247
|
+
* Calendar.
|
|
248
|
+
* @param year Hebrew year
|
|
249
|
+
* @param month Hebrew month
|
|
250
|
+
* @param day Hebrew date (1-30)
|
|
251
|
+
* @example
|
|
252
|
+
* const abs = hebrew2abs(5769, months.CHESHVAN, 15);
|
|
253
|
+
*/
|
|
254
|
+
function hebrew2abs(year, month, day) {
|
|
255
|
+
assertNumber(year, 'year');
|
|
256
|
+
assertNumber(month, 'month');
|
|
257
|
+
assertNumber(day, 'day');
|
|
258
|
+
if (year < 1) {
|
|
259
|
+
throw new RangeError(`hebrew2abs: invalid year ${year}`);
|
|
260
|
+
}
|
|
261
|
+
let tempabs = day;
|
|
262
|
+
if (month < TISHREI) {
|
|
263
|
+
for (let m = TISHREI; m <= monthsInYear(year); m++) {
|
|
264
|
+
tempabs += daysInMonth(m, year);
|
|
265
|
+
}
|
|
266
|
+
for (let m = NISAN$1; m < month; m++) {
|
|
267
|
+
tempabs += daysInMonth(m, year);
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
else {
|
|
271
|
+
for (let m = TISHREI; m < month; m++) {
|
|
272
|
+
tempabs += daysInMonth(m, year);
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
return EPOCH + elapsedDays(year) + tempabs - 1;
|
|
276
|
+
}
|
|
277
|
+
/**
|
|
278
|
+
* @private
|
|
279
|
+
*/
|
|
280
|
+
function newYear(year) {
|
|
281
|
+
return EPOCH + elapsedDays(year);
|
|
282
|
+
}
|
|
283
|
+
/**
|
|
284
|
+
* Converts absolute R.D. days to Hebrew date
|
|
285
|
+
* @param abs absolute R.D. days
|
|
286
|
+
*/
|
|
287
|
+
function abs2hebrew(abs) {
|
|
288
|
+
assertNumber(abs, 'abs');
|
|
289
|
+
abs = Math.trunc(abs);
|
|
290
|
+
if (abs <= EPOCH) {
|
|
291
|
+
throw new RangeError(`abs2hebrew: ${abs} is before epoch`);
|
|
292
|
+
}
|
|
293
|
+
// first, quickly approximate year
|
|
294
|
+
let year = Math.floor((abs - EPOCH) / AVG_HEBYEAR_DAYS);
|
|
295
|
+
while (newYear(year) <= abs) {
|
|
296
|
+
++year;
|
|
297
|
+
}
|
|
298
|
+
--year;
|
|
299
|
+
let month = abs < hebrew2abs(year, 1, 1) ? 7 : 1;
|
|
300
|
+
while (abs > hebrew2abs(year, month, daysInMonth(month, year))) {
|
|
301
|
+
++month;
|
|
302
|
+
}
|
|
303
|
+
const day = 1 + abs - hebrew2abs(year, month, 1);
|
|
304
|
+
return { yy: year, mm: month, dd: day };
|
|
305
|
+
}
|
|
306
|
+
/**
|
|
307
|
+
* Returns true if Hebrew year is a leap year
|
|
308
|
+
* @param year Hebrew year
|
|
309
|
+
*/
|
|
310
|
+
function isLeapYear(year) {
|
|
311
|
+
return (1 + year * 7) % 19 < 7;
|
|
312
|
+
}
|
|
313
|
+
/**
|
|
314
|
+
* Number of months in this Hebrew year (either 12 or 13 depending on leap year)
|
|
315
|
+
* @param year Hebrew year
|
|
316
|
+
*/
|
|
317
|
+
function monthsInYear(year) {
|
|
318
|
+
return 12 + +isLeapYear(year); // boolean is cast to 1 or 0
|
|
319
|
+
}
|
|
320
|
+
/**
|
|
321
|
+
* Number of days in Hebrew month in a given year (29 or 30)
|
|
322
|
+
* @param month Hebrew month (e.g. months.TISHREI)
|
|
323
|
+
* @param year Hebrew year
|
|
324
|
+
*/
|
|
325
|
+
function daysInMonth(month, year) {
|
|
326
|
+
switch (month) {
|
|
327
|
+
case IYYAR$1:
|
|
328
|
+
case TAMUZ:
|
|
329
|
+
case ELUL:
|
|
330
|
+
case TEVET:
|
|
331
|
+
case ADAR_II:
|
|
332
|
+
return 29;
|
|
333
|
+
}
|
|
334
|
+
if ((month === ADAR_I && !isLeapYear(year)) ||
|
|
335
|
+
(month === CHESHVAN && !longCheshvan(year)) ||
|
|
336
|
+
(month === KISLEV && shortKislev(year))) {
|
|
337
|
+
return 29;
|
|
338
|
+
}
|
|
339
|
+
else {
|
|
340
|
+
return 30;
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
/**
|
|
344
|
+
* Returns a transliterated string name of Hebrew month in year,
|
|
345
|
+
* for example 'Elul' or 'Cheshvan'.
|
|
346
|
+
* @param month Hebrew month (e.g. months.TISHREI)
|
|
347
|
+
* @param year Hebrew year
|
|
348
|
+
*/
|
|
349
|
+
function getMonthName(month, year) {
|
|
350
|
+
assertNumber(month, 'month');
|
|
351
|
+
assertNumber(year, 'year');
|
|
352
|
+
if (month < 1 || month > 14) {
|
|
353
|
+
throw new TypeError(`bad monthNum: ${month}`);
|
|
354
|
+
}
|
|
355
|
+
return monthNames[+isLeapYear(year)][month];
|
|
356
|
+
}
|
|
357
|
+
/**
|
|
358
|
+
* Days from sunday prior to start of Hebrew calendar to mean
|
|
359
|
+
* conjunction of Tishrei in Hebrew YEAR
|
|
360
|
+
* @param year Hebrew year
|
|
361
|
+
*/
|
|
362
|
+
function elapsedDays(year) {
|
|
363
|
+
const n = edCache.get(year);
|
|
364
|
+
if (typeof n === 'number') {
|
|
365
|
+
return n;
|
|
366
|
+
}
|
|
367
|
+
const elapsed = elapsedDays0(year);
|
|
368
|
+
edCache.set(year, elapsed);
|
|
369
|
+
return elapsed;
|
|
370
|
+
}
|
|
371
|
+
/**
|
|
372
|
+
* Days from sunday prior to start of Hebrew calendar to mean
|
|
373
|
+
* conjunction of Tishrei in Hebrew YEAR
|
|
374
|
+
* @private
|
|
375
|
+
* @param year Hebrew year
|
|
376
|
+
*/
|
|
377
|
+
function elapsedDays0(year) {
|
|
378
|
+
const prevYear = year - 1;
|
|
379
|
+
const mElapsed = 235 * Math.floor(prevYear / 19) + // Months in complete 19 year lunar (Metonic) cycles so far
|
|
380
|
+
12 * (prevYear % 19) + // Regular months in this cycle
|
|
381
|
+
Math.floor(((prevYear % 19) * 7 + 1) / 19); // Leap months this cycle
|
|
382
|
+
const pElapsed = 204 + 793 * (mElapsed % 1080);
|
|
383
|
+
const hElapsed = 5 +
|
|
384
|
+
12 * mElapsed +
|
|
385
|
+
793 * Math.floor(mElapsed / 1080) +
|
|
386
|
+
Math.floor(pElapsed / 1080);
|
|
387
|
+
const parts = (pElapsed % 1080) + 1080 * (hElapsed % 24);
|
|
388
|
+
const day = 1 + 29 * mElapsed + Math.floor(hElapsed / 24);
|
|
389
|
+
let altDay = day;
|
|
390
|
+
if (parts >= 19440 ||
|
|
391
|
+
(2 === day % 7 && parts >= 9924 && !isLeapYear(year)) ||
|
|
392
|
+
(1 === day % 7 && parts >= 16789 && isLeapYear(prevYear))) {
|
|
393
|
+
altDay++;
|
|
394
|
+
}
|
|
395
|
+
if (altDay % 7 === 0 || altDay % 7 === 3 || altDay % 7 === 5) {
|
|
396
|
+
return altDay + 1;
|
|
397
|
+
}
|
|
398
|
+
else {
|
|
399
|
+
return altDay;
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
/**
|
|
403
|
+
* Number of days in the hebrew YEAR.
|
|
404
|
+
* A common Hebrew calendar year can have a length of 353, 354 or 355 days
|
|
405
|
+
* A leap Hebrew calendar year can have a length of 383, 384 or 385 days
|
|
406
|
+
* @param year Hebrew year
|
|
407
|
+
*/
|
|
408
|
+
function daysInYear(year) {
|
|
409
|
+
return elapsedDays(year + 1) - elapsedDays(year);
|
|
410
|
+
}
|
|
411
|
+
/**
|
|
412
|
+
* true if Cheshvan is long in Hebrew year
|
|
413
|
+
* @param year Hebrew year
|
|
414
|
+
*/
|
|
415
|
+
function longCheshvan(year) {
|
|
416
|
+
return daysInYear(year) % 10 === 5;
|
|
417
|
+
}
|
|
418
|
+
/**
|
|
419
|
+
* true if Kislev is short in Hebrew year
|
|
420
|
+
* @param year Hebrew year
|
|
421
|
+
*/
|
|
422
|
+
function shortKislev(year) {
|
|
423
|
+
return daysInYear(year) % 10 === 3;
|
|
424
|
+
}
|
|
425
|
+
/**
|
|
426
|
+
* Converts Hebrew month string name to numeric
|
|
427
|
+
* @param monthName monthName
|
|
428
|
+
*/
|
|
429
|
+
function monthFromName(monthName) {
|
|
430
|
+
if (typeof monthName === 'number') {
|
|
431
|
+
if (isNaN(monthName) || monthName < 1 || monthName > 14) {
|
|
432
|
+
throw new RangeError(`bad monthName: ${monthName}`);
|
|
433
|
+
}
|
|
434
|
+
return monthName;
|
|
435
|
+
}
|
|
436
|
+
let c = monthName.trim().toLowerCase();
|
|
437
|
+
// remove all niqud and trailing gershayim (for Adar Alef/Bet)
|
|
438
|
+
c = hebrewStripNikkud(c).replace(/׳$/, '');
|
|
439
|
+
// If Hebrew month starts with a bet (for example `בתמוז`) then ignore it
|
|
440
|
+
if (c[0] === 'ב') {
|
|
441
|
+
c = c.substring(1);
|
|
442
|
+
}
|
|
443
|
+
/*
|
|
444
|
+
the Hebrew months are unique to their second letter
|
|
445
|
+
N Nisan (November?)
|
|
446
|
+
I Iyyar
|
|
447
|
+
E Elul
|
|
448
|
+
C Cheshvan
|
|
449
|
+
K Kislev
|
|
450
|
+
1 1Adar
|
|
451
|
+
2 2Adar
|
|
452
|
+
Si Sh Sivan, Shvat
|
|
453
|
+
Ta Ti Te Tamuz, Tishrei, Tevet
|
|
454
|
+
Av Ad Av, Adar
|
|
455
|
+
|
|
456
|
+
אב אד אי אל אב אדר אייר אלול
|
|
457
|
+
ח חשון
|
|
458
|
+
ט טבת
|
|
459
|
+
כ כסלו
|
|
460
|
+
נ ניסן
|
|
461
|
+
ס סיון
|
|
462
|
+
ש שבט
|
|
463
|
+
תמ תש תמוז תשרי
|
|
464
|
+
*/
|
|
465
|
+
switch (c[0]) {
|
|
466
|
+
case 'n':
|
|
467
|
+
case 'נ':
|
|
468
|
+
if (c[1] === 'o') {
|
|
469
|
+
break; /* this catches "november" */
|
|
470
|
+
}
|
|
471
|
+
return NISAN$1;
|
|
472
|
+
case 'i':
|
|
473
|
+
return IYYAR$1;
|
|
474
|
+
case 'e':
|
|
475
|
+
return ELUL;
|
|
476
|
+
case 'c':
|
|
477
|
+
case 'ח':
|
|
478
|
+
return CHESHVAN;
|
|
479
|
+
case 'k':
|
|
480
|
+
case 'כ':
|
|
481
|
+
return KISLEV;
|
|
482
|
+
case 's':
|
|
483
|
+
switch (c[1]) {
|
|
484
|
+
case 'i':
|
|
485
|
+
return SIVAN;
|
|
486
|
+
case 'h':
|
|
487
|
+
return SHVAT;
|
|
488
|
+
}
|
|
489
|
+
break;
|
|
490
|
+
case 't':
|
|
491
|
+
switch (c[1]) {
|
|
492
|
+
case 'a':
|
|
493
|
+
return TAMUZ;
|
|
494
|
+
case 'i':
|
|
495
|
+
return TISHREI;
|
|
496
|
+
case 'e':
|
|
497
|
+
return TEVET;
|
|
498
|
+
}
|
|
499
|
+
break;
|
|
500
|
+
case 'a':
|
|
501
|
+
switch (c[1]) {
|
|
502
|
+
case 'v':
|
|
503
|
+
return AV;
|
|
504
|
+
case 'd':
|
|
505
|
+
if (/(1|[^i]i|a|א)$/i.test(c)) {
|
|
506
|
+
return ADAR_I;
|
|
507
|
+
}
|
|
508
|
+
return ADAR_II; // else assume sheini
|
|
509
|
+
}
|
|
510
|
+
break;
|
|
511
|
+
case 'ס':
|
|
512
|
+
return SIVAN;
|
|
513
|
+
case 'ט':
|
|
514
|
+
return TEVET;
|
|
515
|
+
case 'ש':
|
|
516
|
+
return SHVAT;
|
|
517
|
+
case 'א':
|
|
518
|
+
switch (c[1]) {
|
|
519
|
+
case 'ב':
|
|
520
|
+
return AV;
|
|
521
|
+
case 'ד':
|
|
522
|
+
if (/(1|[^i]i|a|א)$/i.test(c)) {
|
|
523
|
+
return ADAR_I;
|
|
524
|
+
}
|
|
525
|
+
return ADAR_II; // else assume sheini
|
|
526
|
+
case 'י':
|
|
527
|
+
return IYYAR$1;
|
|
528
|
+
case 'ל':
|
|
529
|
+
return ELUL;
|
|
530
|
+
}
|
|
531
|
+
break;
|
|
532
|
+
case 'ת':
|
|
533
|
+
switch (c[1]) {
|
|
534
|
+
case 'מ':
|
|
535
|
+
return TAMUZ;
|
|
536
|
+
case 'ש':
|
|
537
|
+
return TISHREI;
|
|
538
|
+
}
|
|
539
|
+
break;
|
|
540
|
+
}
|
|
541
|
+
throw new RangeError(`bad monthName: ${monthName}`);
|
|
542
|
+
}
|
|
543
|
+
/*! @hebcal/hdate v0.21.1, distributed under GPLv2 https://www.gnu.org/licenses/gpl-2.0.txt */
|
|
544
|
+
const GERESH = '׳';
|
|
545
|
+
const GERSHAYIM = '״';
|
|
546
|
+
const heb2num = {
|
|
547
|
+
א: 1,
|
|
548
|
+
ב: 2,
|
|
549
|
+
ג: 3,
|
|
550
|
+
ד: 4,
|
|
551
|
+
ה: 5,
|
|
552
|
+
ו: 6,
|
|
553
|
+
ז: 7,
|
|
554
|
+
ח: 8,
|
|
555
|
+
ט: 9,
|
|
556
|
+
י: 10,
|
|
557
|
+
כ: 20,
|
|
558
|
+
ל: 30,
|
|
559
|
+
מ: 40,
|
|
560
|
+
נ: 50,
|
|
561
|
+
ס: 60,
|
|
562
|
+
ע: 70,
|
|
563
|
+
פ: 80,
|
|
564
|
+
צ: 90,
|
|
565
|
+
ק: 100,
|
|
566
|
+
ר: 200,
|
|
567
|
+
ש: 300,
|
|
568
|
+
ת: 400,
|
|
569
|
+
};
|
|
570
|
+
const num2heb = {};
|
|
571
|
+
for (const [key, val] of Object.entries(heb2num)) {
|
|
572
|
+
num2heb[val] = key;
|
|
573
|
+
}
|
|
574
|
+
function num2digits(num) {
|
|
575
|
+
const digits = [];
|
|
576
|
+
while (num > 0) {
|
|
577
|
+
if (num === 15 || num === 16) {
|
|
578
|
+
digits.push(9);
|
|
579
|
+
digits.push(num - 9);
|
|
580
|
+
break;
|
|
581
|
+
}
|
|
582
|
+
let incr = 100;
|
|
583
|
+
let i;
|
|
584
|
+
for (i = 400; i > num; i -= incr) {
|
|
585
|
+
if (i === incr) {
|
|
586
|
+
incr = incr / 10;
|
|
587
|
+
}
|
|
588
|
+
}
|
|
589
|
+
digits.push(i);
|
|
590
|
+
num -= i;
|
|
591
|
+
}
|
|
592
|
+
return digits;
|
|
593
|
+
}
|
|
594
|
+
/**
|
|
595
|
+
* Converts a numerical value to a string of Hebrew letters.
|
|
596
|
+
*
|
|
597
|
+
* When specifying years of the Hebrew calendar in the present millennium,
|
|
598
|
+
* we omit the thousands (which is presently 5 [ה]).
|
|
599
|
+
* @example
|
|
600
|
+
* gematriya(5774) // 'תשע״ד' - cropped to 774
|
|
601
|
+
* gematriya(25) // 'כ״ה'
|
|
602
|
+
* gematriya(60) // 'ס׳'
|
|
603
|
+
* gematriya(3761) // 'ג׳תשס״א'
|
|
604
|
+
* gematriya(1123) // 'א׳קכ״ג'
|
|
605
|
+
*/
|
|
606
|
+
function gematriya(num) {
|
|
607
|
+
const num1 = parseInt(num, 10);
|
|
608
|
+
if (!num1 || num1 < 0) {
|
|
609
|
+
throw new TypeError(`invalid number: ${num}`);
|
|
610
|
+
}
|
|
611
|
+
let str = '';
|
|
612
|
+
const thousands = Math.floor(num1 / 1000);
|
|
613
|
+
if (thousands > 0 && thousands !== 5) {
|
|
614
|
+
const tdigits = num2digits(thousands);
|
|
615
|
+
for (const tdig of tdigits) {
|
|
616
|
+
str += num2heb[tdig];
|
|
617
|
+
}
|
|
618
|
+
str += GERESH;
|
|
619
|
+
}
|
|
620
|
+
const digits = num2digits(num1 % 1000);
|
|
621
|
+
if (digits.length === 1) {
|
|
622
|
+
return str + num2heb[digits[0]] + GERESH;
|
|
623
|
+
}
|
|
624
|
+
for (let i = 0; i < digits.length; i++) {
|
|
625
|
+
if (i + 1 === digits.length) {
|
|
626
|
+
str += GERSHAYIM;
|
|
627
|
+
}
|
|
628
|
+
str += num2heb[digits[i]];
|
|
629
|
+
}
|
|
630
|
+
return str;
|
|
631
|
+
}
|
|
632
|
+
/**
|
|
633
|
+
* Converts a string of Hebrew letters to a numerical value.
|
|
634
|
+
*
|
|
635
|
+
* Only considers the value of Hebrew letters `א` through `ת`.
|
|
636
|
+
* Ignores final Hebrew letters such as `ך` (kaf sofit) or `ם` (mem sofit)
|
|
637
|
+
* and vowels (nekudot).
|
|
638
|
+
*/
|
|
639
|
+
function gematriyaStrToNum(str) {
|
|
640
|
+
let num = 0;
|
|
641
|
+
const gereshIdx = str.indexOf(GERESH);
|
|
642
|
+
if (gereshIdx !== -1 && gereshIdx !== str.length - 1) {
|
|
643
|
+
const thousands = str.substring(0, gereshIdx);
|
|
644
|
+
num += gematriyaStrToNum(thousands) * 1000;
|
|
645
|
+
str = str.substring(gereshIdx);
|
|
646
|
+
}
|
|
647
|
+
for (const ch of str) {
|
|
648
|
+
const n = heb2num[ch];
|
|
649
|
+
if (typeof n === 'number') {
|
|
650
|
+
num += n;
|
|
651
|
+
}
|
|
652
|
+
}
|
|
653
|
+
return num;
|
|
654
|
+
}
|
|
655
|
+
/*! @hebcal/hdate v0.21.1, distributed under GPLv2 https://www.gnu.org/licenses/gpl-2.0.txt */
|
|
656
|
+
var poAshkenazi = { "headers": { "plural-forms": "nplurals=2; plural=(n > 1);", "language": "en_CA@ashkenazi" }, "contexts": { "": { "Tevet": ["Teves"] } } };
|
|
657
|
+
/*! @hebcal/hdate v0.21.1, distributed under GPLv2 https://www.gnu.org/licenses/gpl-2.0.txt */
|
|
658
|
+
var poHe = { "headers": { "plural-forms": "nplurals=2; plural=(n > 1);", "language": "he" }, "contexts": { "": { "Adar": ["אֲדָר"], "Adar I": ["אֲדָר א׳"], "Adar II": ["אֲדָר ב׳"], "Av": ["אָב"], "Cheshvan": ["חֶשְׁוָן"], "Elul": ["אֱלוּל"], "Iyyar": ["אִיָּיר"], "Kislev": ["כִּסְלֵו"], "Nisan": ["נִיסָן"], "Sh'vat": ["שְׁבָט"], "Sivan": ["סִיוָן"], "Tamuz": ["תַּמּוּז"], "Tevet": ["טֵבֵת"], "Tishrei": ["תִּשְׁרֵי"] } } };
|
|
659
|
+
/*! @hebcal/hdate v0.21.1, distributed under GPLv2 https://www.gnu.org/licenses/gpl-2.0.txt */
|
|
660
|
+
const noopLocale = {
|
|
661
|
+
headers: { 'plural-forms': 'nplurals=2; plural=(n!=1);' },
|
|
662
|
+
contexts: { '': {} },
|
|
663
|
+
};
|
|
664
|
+
const alias = {
|
|
665
|
+
h: 'he',
|
|
666
|
+
a: 'ashkenazi',
|
|
667
|
+
s: 'en',
|
|
668
|
+
'': 'en',
|
|
669
|
+
};
|
|
670
|
+
/** @private */
|
|
671
|
+
const locales = new Map();
|
|
672
|
+
/** @private */
|
|
673
|
+
function getEnOrdinal(n) {
|
|
674
|
+
const s = ['th', 'st', 'nd', 'rd'];
|
|
675
|
+
const v = n % 100;
|
|
676
|
+
return n + (s[(v - 20) % 10] || s[v] || s[0]);
|
|
677
|
+
}
|
|
678
|
+
/** @private */
|
|
679
|
+
function checkLocale(locale) {
|
|
680
|
+
if (typeof locale !== 'string') {
|
|
681
|
+
throw new TypeError(`Invalid locale name: ${locale}`);
|
|
682
|
+
}
|
|
683
|
+
locale = alias[locale] || locale;
|
|
684
|
+
return locale.toLowerCase();
|
|
685
|
+
}
|
|
686
|
+
/** @private */
|
|
687
|
+
function getExistingLocale(locale) {
|
|
688
|
+
const locale1 = checkLocale(locale);
|
|
689
|
+
const loc = locales.get(locale1);
|
|
690
|
+
if (!loc) {
|
|
691
|
+
throw new RangeError(`Locale '${locale}' not found`);
|
|
692
|
+
}
|
|
693
|
+
return loc;
|
|
694
|
+
}
|
|
695
|
+
/**
|
|
696
|
+
* A locale in Hebcal is used for translations/transliterations of
|
|
697
|
+
* holidays. `@hebcal/hdate` supports four locales by default
|
|
698
|
+
* * `en` - default, Sephardic transliterations (e.g. "Shabbat")
|
|
699
|
+
* * `ashkenazi` - Ashkenazi transliterations (e.g. "Shabbos")
|
|
700
|
+
* * `he` - Hebrew (e.g. "שַׁבָּת")
|
|
701
|
+
* * `he-x-NoNikud` - Hebrew without nikud (e.g. "שבת")
|
|
702
|
+
*/
|
|
703
|
+
class Locale {
|
|
704
|
+
/**
|
|
705
|
+
* Returns translation only if `locale` offers a non-empty translation for `id`.
|
|
706
|
+
* Otherwise, returns `undefined`.
|
|
707
|
+
* @param id Message ID to translate
|
|
708
|
+
* @param [locale] Optional locale name (i.e: `'he'`, `'fr'`). Defaults to no-op locale.
|
|
709
|
+
*/
|
|
710
|
+
static lookupTranslation(id, locale) {
|
|
711
|
+
const loc = (typeof locale === 'string' && locales.get(checkLocale(locale))) ||
|
|
712
|
+
noopLocale.contexts[''];
|
|
713
|
+
const array = loc[id];
|
|
714
|
+
if ((array === null || array === void 0 ? void 0 : array.length) && array[0].length) {
|
|
715
|
+
return array[0];
|
|
716
|
+
}
|
|
717
|
+
return undefined;
|
|
718
|
+
}
|
|
719
|
+
/**
|
|
720
|
+
* By default, if no translation was found, returns `id`.
|
|
721
|
+
* @param id Message ID to translate
|
|
722
|
+
* @param [locale] Optional locale name (i.e: `'he'`, `'fr'`). Defaults to no-op locale.
|
|
723
|
+
*/
|
|
724
|
+
static gettext(id, locale) {
|
|
725
|
+
const text = this.lookupTranslation(id, locale);
|
|
726
|
+
if (typeof text === 'undefined') {
|
|
727
|
+
return id;
|
|
728
|
+
}
|
|
729
|
+
return text;
|
|
730
|
+
}
|
|
731
|
+
/**
|
|
732
|
+
* Register locale translations.
|
|
733
|
+
* @param locale Locale name (i.e.: `'he'`, `'fr'`)
|
|
734
|
+
* @param data parsed data from a `.po` file.
|
|
735
|
+
*/
|
|
736
|
+
static addLocale(locale, data) {
|
|
737
|
+
locale = checkLocale(locale);
|
|
738
|
+
const ctx = data.contexts;
|
|
739
|
+
if (typeof ctx !== 'object' || typeof ctx[''] !== 'object') {
|
|
740
|
+
throw new TypeError(`Locale '${locale}' invalid compact format`);
|
|
741
|
+
}
|
|
742
|
+
locales.set(locale, ctx['']);
|
|
743
|
+
}
|
|
744
|
+
/**
|
|
745
|
+
* Adds a translation to `locale`, replacing any previous translation.
|
|
746
|
+
* @param locale Locale name (i.e: `'he'`, `'fr'`).
|
|
747
|
+
* @param id Message ID to translate
|
|
748
|
+
* @param translation Translation text
|
|
749
|
+
*/
|
|
750
|
+
static addTranslation(locale, id, translation) {
|
|
751
|
+
const loc = getExistingLocale(locale);
|
|
752
|
+
if (typeof id !== 'string' || id.length === 0) {
|
|
753
|
+
throw new TypeError(`Invalid id string: ${id}`);
|
|
754
|
+
}
|
|
755
|
+
const isArray = Array.isArray(translation);
|
|
756
|
+
if (isArray) {
|
|
757
|
+
const t0 = translation[0];
|
|
758
|
+
if (typeof t0 !== 'string' || t0.length === 0) {
|
|
759
|
+
throw new TypeError(`Invalid translation array: ${translation}`);
|
|
760
|
+
}
|
|
761
|
+
}
|
|
762
|
+
else if (typeof translation !== 'string') {
|
|
763
|
+
throw new TypeError(`Invalid translation string: ${translation}`);
|
|
764
|
+
}
|
|
765
|
+
loc[id] = isArray ? translation : [translation];
|
|
766
|
+
}
|
|
767
|
+
/**
|
|
768
|
+
* Adds multiple translations to `locale`, replacing any previous translations.
|
|
769
|
+
* @param locale Locale name (i.e: `'he'`, `'fr'`).
|
|
770
|
+
* @param data parsed data from a `.po` file.
|
|
771
|
+
*/
|
|
772
|
+
static addTranslations(locale, data) {
|
|
773
|
+
const loc = getExistingLocale(locale);
|
|
774
|
+
const ctx = data.contexts;
|
|
775
|
+
if (typeof ctx !== 'object' || typeof ctx[''] !== 'object') {
|
|
776
|
+
throw new TypeError(`Locale '${locale}' invalid compact format`);
|
|
777
|
+
}
|
|
778
|
+
Object.assign(loc, ctx['']);
|
|
779
|
+
}
|
|
780
|
+
/**
|
|
781
|
+
* Returns the names of registered locales
|
|
782
|
+
*/
|
|
783
|
+
static getLocaleNames() {
|
|
784
|
+
const keys = Array.from(locales.keys());
|
|
785
|
+
return keys.sort((a, b) => a.localeCompare(b));
|
|
786
|
+
}
|
|
787
|
+
/**
|
|
788
|
+
* Checks whether a locale has been registered
|
|
789
|
+
* @param locale Locale name (i.e: `'he'`, `'fr'`).
|
|
790
|
+
*/
|
|
791
|
+
static hasLocale(locale) {
|
|
792
|
+
const locale1 = checkLocale(locale);
|
|
793
|
+
return locales.has(locale1);
|
|
794
|
+
}
|
|
795
|
+
/**
|
|
796
|
+
* Renders a number in ordinal, such as 1st, 2nd or 3rd
|
|
797
|
+
* @param [locale] Optional locale name (i.e: `'he'`, `'fr'`). Defaults to no-op locale.
|
|
798
|
+
*/
|
|
799
|
+
static ordinal(n, locale) {
|
|
800
|
+
let locale0 = locale === null || locale === void 0 ? void 0 : locale.toLowerCase();
|
|
801
|
+
if (!locale0) {
|
|
802
|
+
return getEnOrdinal(n);
|
|
803
|
+
}
|
|
804
|
+
locale0 = alias[locale0] || locale0;
|
|
805
|
+
switch (locale0) {
|
|
806
|
+
case 'en':
|
|
807
|
+
case 'ashkenazi':
|
|
808
|
+
return getEnOrdinal(n);
|
|
809
|
+
case 'es':
|
|
810
|
+
return n + 'º';
|
|
811
|
+
case 'he':
|
|
812
|
+
case 'he-x-nonikud':
|
|
813
|
+
return String(n);
|
|
814
|
+
}
|
|
815
|
+
if (locale0.startsWith('ashkenazi')) {
|
|
816
|
+
return getEnOrdinal(n);
|
|
817
|
+
}
|
|
818
|
+
return n + '.';
|
|
819
|
+
}
|
|
820
|
+
/**
|
|
821
|
+
* Removes nekudot from Hebrew string
|
|
822
|
+
*/
|
|
823
|
+
static hebrewStripNikkud(str) {
|
|
824
|
+
return hebrewStripNikkud(str);
|
|
825
|
+
}
|
|
826
|
+
/**
|
|
827
|
+
* Makes a copy of entire Hebrew locale with no niqqud
|
|
828
|
+
*/
|
|
829
|
+
static copyLocaleNoNikud(data) {
|
|
830
|
+
const strs = data.contexts[''];
|
|
831
|
+
const m = {};
|
|
832
|
+
for (const [key, val] of Object.entries(strs)) {
|
|
833
|
+
m[key] = [hebrewStripNikkud(val[0])];
|
|
834
|
+
}
|
|
835
|
+
return {
|
|
836
|
+
headers: data.headers,
|
|
837
|
+
contexts: { '': m },
|
|
838
|
+
};
|
|
839
|
+
}
|
|
840
|
+
}
|
|
841
|
+
Locale.addLocale('en', noopLocale);
|
|
842
|
+
/* Ashkenazic transliterations */
|
|
843
|
+
Locale.addLocale('ashkenazi', poAshkenazi);
|
|
844
|
+
/* Hebrew with nikkud */
|
|
845
|
+
Locale.addLocale('he', poHe);
|
|
846
|
+
/* Hebrew without nikkud */
|
|
847
|
+
const poHeNoNikud = Locale.copyLocaleNoNikud(poHe);
|
|
848
|
+
Locale.addLocale('he-x-NoNikud', poHeNoNikud);
|
|
849
|
+
/*! @hebcal/hdate v0.21.1, distributed under GPLv2 https://www.gnu.org/licenses/gpl-2.0.txt */
|
|
850
|
+
/*
|
|
851
|
+
Hebcal - A Jewish Calendar Generator
|
|
852
|
+
Copyright (c) 1994-2020 Danny Sadinoff
|
|
853
|
+
Portions copyright Eyal Schachter and Michael J. Radwin
|
|
854
|
+
|
|
855
|
+
https://github.com/hebcal/hebcal-es6
|
|
856
|
+
|
|
857
|
+
This program is free software; you can redistribute it and/or
|
|
858
|
+
modify it under the terms of the GNU General Public License
|
|
859
|
+
as published by the Free Software Foundation; either version 2
|
|
860
|
+
of the License, or (at your option) any later version.
|
|
861
|
+
|
|
862
|
+
This program is distributed in the hope that it will be useful,
|
|
863
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
864
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
865
|
+
GNU General Public License for more details.
|
|
866
|
+
|
|
867
|
+
You should have received a copy of the GNU General Public License
|
|
868
|
+
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
869
|
+
*/
|
|
870
|
+
function mod(x, y) {
|
|
871
|
+
return x - y * Math.floor(x / y);
|
|
872
|
+
}
|
|
873
|
+
function isSimpleHebrewDate(obj) {
|
|
874
|
+
return obj.yy !== undefined;
|
|
875
|
+
}
|
|
876
|
+
const UNITS_DAY = 'day';
|
|
877
|
+
const UNITS_WEEK = 'week';
|
|
878
|
+
const UNITS_MONTH = 'month';
|
|
879
|
+
const UNITS_YEAR = 'year';
|
|
880
|
+
/**
|
|
881
|
+
* A `HDate` represents a Hebrew calendar date.
|
|
882
|
+
*
|
|
883
|
+
* An instance of this class encapsulates a date in the Hebrew calendar system.
|
|
884
|
+
* It consists of a year, month, and day, without any associated time or location data.
|
|
885
|
+
* The Hebrew calendar is a lunisolar calendar, meaning it is based on both lunar and solar cycles.
|
|
886
|
+
*
|
|
887
|
+
* A Hebrew date internally stores three numbers:
|
|
888
|
+
* - year: The Hebrew year (1-9999). Counted from the traditional Hebrew date of creation (3761 BCE in the Gregorian calendar)
|
|
889
|
+
* - month: The Hebrew month (1-13). Month 1 is Nisan, month 7 is Tishrei. There are 12 months in a regular year and 13 months in a leap year.
|
|
890
|
+
* - day: The day of the month (1-30)
|
|
891
|
+
*
|
|
892
|
+
* This class uses Rata Die to convert between the Hebrew and Gregorian calendars.
|
|
893
|
+
*
|
|
894
|
+
* To calculate times of day, use `Zmanim` class from `@hebcal/core`
|
|
895
|
+
* @see {@link https://en.wikipedia.org/wiki/Rata_Die | Rata Die}
|
|
896
|
+
* @see {@link https://hebcal.github.io/api/core/classes/Zmanim.html | Zmanim}
|
|
897
|
+
*/
|
|
898
|
+
class HDate {
|
|
899
|
+
/**
|
|
900
|
+
* Create a Hebrew date. There are 3 basic forms for the `HDate()` constructor.
|
|
901
|
+
*
|
|
902
|
+
* 1. No parameters - represents the current Hebrew date at time of instantiation
|
|
903
|
+
* 2. One parameter
|
|
904
|
+
* * `Date` - represents the Hebrew date corresponding to the Gregorian date using
|
|
905
|
+
* local time. Hours, minutes, seconds and milliseconds are ignored.
|
|
906
|
+
* * `HDate` - clones a copy of the given Hebrew date
|
|
907
|
+
* * `number` - Converts absolute R.D. days to Hebrew date.
|
|
908
|
+
* R.D. 1 == the imaginary date January 1, 1 (Gregorian)
|
|
909
|
+
* 3. Three parameters: Hebrew day, Hebrew month, Hebrew year. Hebrew day should
|
|
910
|
+
* be a number between 1-30, Hebrew month can be a number or string, and
|
|
911
|
+
* Hebrew year is always a number.
|
|
912
|
+
* @example
|
|
913
|
+
* import {HDate, months} from '@hebcal/hdate';
|
|
914
|
+
*
|
|
915
|
+
* const hd1 = new HDate();
|
|
916
|
+
* const hd2 = new HDate(new Date(2008, 10, 13));
|
|
917
|
+
* const hd3 = new HDate(15, 'Cheshvan', 5769);
|
|
918
|
+
* const hd4 = new HDate(15, months.CHESHVAN, 5769);
|
|
919
|
+
* const hd5 = new HDate(733359); // ==> 15 Cheshvan 5769
|
|
920
|
+
* const monthName = 'אייר';
|
|
921
|
+
* const hd6 = new HDate(5, monthName, 5773);
|
|
922
|
+
* @param [day] - Day of month (1-30) if a `number`.
|
|
923
|
+
* If a `Date` is specified, represents the Hebrew date corresponding to the
|
|
924
|
+
* Gregorian date using local time.
|
|
925
|
+
* If an `HDate` is specified, clones a copy of the given Hebrew date.
|
|
926
|
+
* @param [month] - Hebrew month of year (1=NISAN, 7=TISHREI)
|
|
927
|
+
* @param [year] - Hebrew year
|
|
928
|
+
*/
|
|
929
|
+
constructor(day, month, year) {
|
|
930
|
+
if (arguments.length === 2 || arguments.length > 3) {
|
|
931
|
+
throw new TypeError('HDate constructor requires 0, 1 or 3 arguments');
|
|
932
|
+
}
|
|
933
|
+
if (arguments.length === 3) {
|
|
934
|
+
// Hebrew day, Hebrew month, Hebrew year
|
|
935
|
+
this.dd = this.mm = 1;
|
|
936
|
+
const yy = typeof year === 'string' ? parseInt(year, 10) : year;
|
|
937
|
+
if (isNaN(yy)) {
|
|
938
|
+
throw new TypeError(`HDate called with bad year: ${year}`);
|
|
939
|
+
}
|
|
940
|
+
this.yy = yy;
|
|
941
|
+
setMonth(this, month); // will throw if we can't parse
|
|
942
|
+
const dd = typeof day === 'string' ? parseInt(day, 10) : day;
|
|
943
|
+
if (isNaN(dd)) {
|
|
944
|
+
throw new TypeError(`HDate called with bad day: ${day}`);
|
|
945
|
+
}
|
|
946
|
+
setDate(this, dd);
|
|
947
|
+
}
|
|
948
|
+
else {
|
|
949
|
+
// 0 arguments
|
|
950
|
+
if (typeof day === 'undefined' || day === null) {
|
|
951
|
+
day = new Date();
|
|
952
|
+
}
|
|
953
|
+
// 1 argument
|
|
954
|
+
const abs0 = typeof day === 'number' && !isNaN(day)
|
|
955
|
+
? day
|
|
956
|
+
: isDate(day)
|
|
957
|
+
? greg2abs(day)
|
|
958
|
+
: isSimpleHebrewDate(day)
|
|
959
|
+
? day
|
|
960
|
+
: null;
|
|
961
|
+
if (abs0 === null) {
|
|
962
|
+
throw new TypeError(`HDate called with bad arg: ${day}`);
|
|
963
|
+
}
|
|
964
|
+
const isNumber = typeof abs0 === 'number';
|
|
965
|
+
const d = isNumber ? abs2hebrew(abs0) : abs0;
|
|
966
|
+
this.yy = d.yy;
|
|
967
|
+
this.mm = d.mm;
|
|
968
|
+
this.dd = d.dd;
|
|
969
|
+
if (isNumber) {
|
|
970
|
+
this.rd = abs0;
|
|
971
|
+
}
|
|
972
|
+
}
|
|
973
|
+
}
|
|
974
|
+
/**
|
|
975
|
+
* Returns the Hebrew year of this Hebrew date
|
|
976
|
+
* @returns an integer >= 1
|
|
977
|
+
* @example
|
|
978
|
+
* const hd = new HDate(new Date(2008, 10, 13)); // 15 Cheshvan 5769
|
|
979
|
+
* hd.getFullYear(); // 5769
|
|
980
|
+
*/
|
|
981
|
+
getFullYear() {
|
|
982
|
+
return this.yy;
|
|
983
|
+
}
|
|
984
|
+
/**
|
|
985
|
+
* Returns `true` if this Hebrew date occurs during a Hebrew leap year
|
|
986
|
+
* @example
|
|
987
|
+
* const hd = new HDate(new Date(2008, 10, 13)); // 15 Cheshvan 5769
|
|
988
|
+
* hd.isLeapYear(); // false
|
|
989
|
+
*/
|
|
990
|
+
isLeapYear() {
|
|
991
|
+
return isLeapYear(this.yy);
|
|
992
|
+
}
|
|
993
|
+
/**
|
|
994
|
+
* Returns the Hebrew month (1=NISAN, 7=TISHREI) of this Hebrew date
|
|
995
|
+
* @returns an integer 1-13
|
|
996
|
+
* @example
|
|
997
|
+
* const hd = new HDate(new Date(2008, 10, 13)); // 15 Cheshvan 5769
|
|
998
|
+
* hd.getMonth(); // 8
|
|
999
|
+
*/
|
|
1000
|
+
getMonth() {
|
|
1001
|
+
return this.mm;
|
|
1002
|
+
}
|
|
1003
|
+
/**
|
|
1004
|
+
* The Tishrei-based month of this Hebrew date. 1 is Tishrei, 7 is Nisan, 13 is Elul in a leap year
|
|
1005
|
+
* @returns an integer 1-13
|
|
1006
|
+
* @example
|
|
1007
|
+
* const hd = new HDate(new Date(2008, 10, 13)); // 15 Cheshvan 5769
|
|
1008
|
+
* hd.getTishreiMonth(); // 2
|
|
1009
|
+
*/
|
|
1010
|
+
getTishreiMonth() {
|
|
1011
|
+
const nummonths = monthsInYear(this.getFullYear());
|
|
1012
|
+
return (this.getMonth() + nummonths - 6) % nummonths || nummonths;
|
|
1013
|
+
}
|
|
1014
|
+
/**
|
|
1015
|
+
* Number of days in the month of this Hebrew date (29 or 30)
|
|
1016
|
+
* @returns an integer 29-30
|
|
1017
|
+
* @example
|
|
1018
|
+
* const hd = new HDate(new Date(2008, 10, 13)); // 15 Cheshvan 5769
|
|
1019
|
+
* hd.daysInMonth(); // 29
|
|
1020
|
+
*/
|
|
1021
|
+
daysInMonth() {
|
|
1022
|
+
return daysInMonth(this.getMonth(), this.getFullYear());
|
|
1023
|
+
}
|
|
1024
|
+
/**
|
|
1025
|
+
* Gets the day within the month (1-30)
|
|
1026
|
+
* @returns an integer 1-30
|
|
1027
|
+
* @example
|
|
1028
|
+
* const hd = new HDate(new Date(2008, 10, 13)); // 15 Cheshvan 5769
|
|
1029
|
+
* hd.getDate(); // 15
|
|
1030
|
+
*/
|
|
1031
|
+
getDate() {
|
|
1032
|
+
return this.dd;
|
|
1033
|
+
}
|
|
1034
|
+
/**
|
|
1035
|
+
* Returns the day of the week for this Hebrew date,
|
|
1036
|
+
* where 0 represents Sunday, 1 represents Monday, 6 represents Saturday.
|
|
1037
|
+
*
|
|
1038
|
+
* For the day of the month, see `getDate()`
|
|
1039
|
+
* @returns an integer 0-6
|
|
1040
|
+
* @example
|
|
1041
|
+
* const hd = new HDate(new Date(2008, 10, 13)); // 15 Cheshvan 5769
|
|
1042
|
+
* hd.getDate(); // 4
|
|
1043
|
+
*/
|
|
1044
|
+
getDay() {
|
|
1045
|
+
return mod(this.abs(), 7);
|
|
1046
|
+
}
|
|
1047
|
+
/**
|
|
1048
|
+
* Converts this Hebrew date to the corresponding Gregorian date.
|
|
1049
|
+
*
|
|
1050
|
+
* The returned `Date` object will be in the local (i.e. host system) time zone.
|
|
1051
|
+
* Hours, minutes, seconds and milliseconds will all be zero.
|
|
1052
|
+
*
|
|
1053
|
+
* Note that this function returns the daytime portion of the date.
|
|
1054
|
+
* For example, the 15th of Cheshvan 5769 began at sundown on
|
|
1055
|
+
* 12 November 2008 and continues through 13 November 2008. This
|
|
1056
|
+
* function would return only the date 13 November 2008.
|
|
1057
|
+
* @example
|
|
1058
|
+
* const hd = new HDate(15, 'Cheshvan', 5769);
|
|
1059
|
+
* const date = hd.greg(); // 13 November 2008
|
|
1060
|
+
* const year = date.getFullYear(); // 2008
|
|
1061
|
+
* const monthNum = date.getMonth() + 1; // 11
|
|
1062
|
+
* const day = date.getDate(); // 13
|
|
1063
|
+
*/
|
|
1064
|
+
greg() {
|
|
1065
|
+
return abs2greg(this.abs());
|
|
1066
|
+
}
|
|
1067
|
+
/**
|
|
1068
|
+
* Converts from Hebrew date representation to R.D. (Rata Die) fixed days.
|
|
1069
|
+
* R.D. 1 is the imaginary date Monday, January 1, 1 (Gregorian).
|
|
1070
|
+
* Note also that R.D. = Julian Date − 1,721,424.5
|
|
1071
|
+
* @see {@link https://en.wikipedia.org/wiki/Rata_Die | Rata Die}
|
|
1072
|
+
* @example
|
|
1073
|
+
* const hd = new HDate(15, 'Cheshvan', 5769);
|
|
1074
|
+
* hd.abs(); // 733359
|
|
1075
|
+
*/
|
|
1076
|
+
abs() {
|
|
1077
|
+
if (typeof this.rd !== 'number') {
|
|
1078
|
+
this.rd = hebrew2abs(this.yy, this.mm, this.dd);
|
|
1079
|
+
}
|
|
1080
|
+
return this.rd;
|
|
1081
|
+
}
|
|
1082
|
+
/**
|
|
1083
|
+
* Converts Hebrew date to R.D. (Rata Die) fixed days.
|
|
1084
|
+
* R.D. 1 is the imaginary date Monday, January 1, 1 on the Gregorian
|
|
1085
|
+
* Calendar.
|
|
1086
|
+
* @param year Hebrew year
|
|
1087
|
+
* @param month Hebrew month (1=NISAN, 7=TISHREI)
|
|
1088
|
+
* @param day Hebrew date (1-30)
|
|
1089
|
+
* @example
|
|
1090
|
+
* import {HDate, months} from '@hebcal/hdate';
|
|
1091
|
+
* HDate.hebrew2abs(5769, months.CHESHVAN, 15); // 733359
|
|
1092
|
+
*/
|
|
1093
|
+
static hebrew2abs(year, month, day) {
|
|
1094
|
+
return hebrew2abs(year, month, day);
|
|
1095
|
+
}
|
|
1096
|
+
/**
|
|
1097
|
+
* Returns a transliterated Hebrew month name, e.g. `'Elul'` or `'Cheshvan'`.
|
|
1098
|
+
* @example
|
|
1099
|
+
* const hd = new HDate(new Date(2008, 10, 13)); // 15 Cheshvan 5769
|
|
1100
|
+
* hd.getMonthName(); // 'Cheshvan'
|
|
1101
|
+
*/
|
|
1102
|
+
getMonthName() {
|
|
1103
|
+
return getMonthName(this.getMonth(), this.getFullYear());
|
|
1104
|
+
}
|
|
1105
|
+
/**
|
|
1106
|
+
* Renders this Hebrew date as a translated or transliterated string,
|
|
1107
|
+
* including ordinal e.g. `'15th of Cheshvan, 5769'`.
|
|
1108
|
+
* @example
|
|
1109
|
+
* import {HDate, months} from '@hebcal/hdate';
|
|
1110
|
+
*
|
|
1111
|
+
* const hd = new HDate(15, months.CHESHVAN, 5769);
|
|
1112
|
+
* console.log(hd.render('en')); // '15th of Cheshvan, 5769'
|
|
1113
|
+
* console.log(hd.render('he')); // '15 חֶשְׁוָן, 5769'
|
|
1114
|
+
* console.log(hd.render('en', false)); // '15th of Cheshvan'
|
|
1115
|
+
* console.log(hd.render('he', false)); // '15 חֶשְׁוָן'
|
|
1116
|
+
* @param [locale] Optional locale name (defaults to active locale).
|
|
1117
|
+
* @param [showYear=true] Display year (defaults to true).
|
|
1118
|
+
* @see {@link Locale}
|
|
1119
|
+
*/
|
|
1120
|
+
render(locale, showYear = true) {
|
|
1121
|
+
const locale0 = locale || 'en';
|
|
1122
|
+
const day = this.getDate();
|
|
1123
|
+
const monthName0 = Locale.gettext(this.getMonthName(), locale0);
|
|
1124
|
+
const monthName = monthName0.replace(/'/g, '’');
|
|
1125
|
+
const nth = Locale.ordinal(day, locale0);
|
|
1126
|
+
const dayOf = getDayOfTranslation(locale0);
|
|
1127
|
+
const dateStr = `${nth}${dayOf} ${monthName}`;
|
|
1128
|
+
if (showYear) {
|
|
1129
|
+
const fullYear = this.getFullYear();
|
|
1130
|
+
return `${dateStr}, ${fullYear}`;
|
|
1131
|
+
}
|
|
1132
|
+
else {
|
|
1133
|
+
return dateStr;
|
|
1134
|
+
}
|
|
1135
|
+
}
|
|
1136
|
+
/**
|
|
1137
|
+
* Renders this Hebrew date in Hebrew gematriya, regardless of locale.
|
|
1138
|
+
* @param suppressNikud - suppress nekudot (default false)
|
|
1139
|
+
* @param suppressYear - suppress Hebrew year (default false)
|
|
1140
|
+
* @example
|
|
1141
|
+
* import {HDate, months} from '@hebcal/hdate';
|
|
1142
|
+
* const hd = new HDate(15, months.CHESHVAN, 5769);
|
|
1143
|
+
* hd.renderGematriya(); // 'ט״ו חֶשְׁוָן תשס״ט'
|
|
1144
|
+
* hd.renderGematriya(true); // 'ט״ו חשון תשס״ט'
|
|
1145
|
+
* hd.renderGematriya(false, true); // 'ט״ו חֶשְׁוָן'
|
|
1146
|
+
*/
|
|
1147
|
+
renderGematriya(suppressNikud = false, suppressYear = false) {
|
|
1148
|
+
const d = this.getDate();
|
|
1149
|
+
const locale = suppressNikud ? 'he-x-NoNikud' : 'he';
|
|
1150
|
+
const m = Locale.gettext(this.getMonthName(), locale);
|
|
1151
|
+
const prefix = gematriya(d) + ' ' + m;
|
|
1152
|
+
if (suppressYear) {
|
|
1153
|
+
return prefix;
|
|
1154
|
+
}
|
|
1155
|
+
const y = this.getFullYear();
|
|
1156
|
+
return prefix + ' ' + gematriya(y);
|
|
1157
|
+
}
|
|
1158
|
+
/**
|
|
1159
|
+
* Returns an `HDate` corresponding to the specified day of week
|
|
1160
|
+
* **before** this Hebrew date
|
|
1161
|
+
* @example
|
|
1162
|
+
* new HDate(new Date('Wednesday February 19, 2014')).before(6).greg() // Sat Feb 15 2014
|
|
1163
|
+
* @param dayOfWeek day of week: Sunday=0, Saturday=6
|
|
1164
|
+
*/
|
|
1165
|
+
before(dayOfWeek) {
|
|
1166
|
+
return onOrBefore(dayOfWeek, this, -1);
|
|
1167
|
+
}
|
|
1168
|
+
/**
|
|
1169
|
+
* Returns an `HDate` corresponding to the specified day of week
|
|
1170
|
+
* **on or before** this Hebrew date
|
|
1171
|
+
* @example
|
|
1172
|
+
* new HDate(new Date('Wednesday February 19, 2014')).onOrBefore(6).greg() // Sat Feb 15 2014
|
|
1173
|
+
* new HDate(new Date('Saturday February 22, 2014')).onOrBefore(6).greg() // Sat Feb 22 2014
|
|
1174
|
+
* new HDate(new Date('Sunday February 23, 2014')).onOrBefore(6).greg() // Sat Feb 22 2014
|
|
1175
|
+
* @param dayOfWeek day of week: Sunday=0, Saturday=6
|
|
1176
|
+
*/
|
|
1177
|
+
onOrBefore(dayOfWeek) {
|
|
1178
|
+
return onOrBefore(dayOfWeek, this, 0);
|
|
1179
|
+
}
|
|
1180
|
+
/**
|
|
1181
|
+
* Returns an `HDate` corresponding to the specified day of week
|
|
1182
|
+
* **nearest** to this Hebrew date
|
|
1183
|
+
* @example
|
|
1184
|
+
* new HDate(new Date('Wednesday February 19, 2014')).nearest(6).greg() // Sat Feb 22 2014
|
|
1185
|
+
* new HDate(new Date('Tuesday February 18, 2014')).nearest(6).greg() // Sat Feb 15 2014
|
|
1186
|
+
* @param dayOfWeek day of week: Sunday=0, Saturday=6
|
|
1187
|
+
*/
|
|
1188
|
+
nearest(dayOfWeek) {
|
|
1189
|
+
return onOrBefore(dayOfWeek, this, 3);
|
|
1190
|
+
}
|
|
1191
|
+
/**
|
|
1192
|
+
* Returns an `HDate` corresponding to the specified day of week
|
|
1193
|
+
* **on or after** this Hebrew date
|
|
1194
|
+
* @example
|
|
1195
|
+
* new HDate(new Date('Wednesday February 19, 2014')).onOrAfter(6).greg() // Sat Feb 22 2014
|
|
1196
|
+
* new HDate(new Date('Saturday February 22, 2014')).onOrAfter(6).greg() // Sat Feb 22 2014
|
|
1197
|
+
* new HDate(new Date('Sunday February 23, 2014')).onOrAfter(6).greg() // Sat Mar 01 2014
|
|
1198
|
+
* @param dayOfWeek day of week: Sunday=0, Saturday=6
|
|
1199
|
+
*/
|
|
1200
|
+
onOrAfter(dayOfWeek) {
|
|
1201
|
+
return onOrBefore(dayOfWeek, this, 6);
|
|
1202
|
+
}
|
|
1203
|
+
/**
|
|
1204
|
+
* Returns an `HDate` corresponding to the specified day of week
|
|
1205
|
+
* **after** this Hebrew date
|
|
1206
|
+
* @example
|
|
1207
|
+
* new HDate(new Date('Wednesday February 19, 2014')).after(6).greg() // Sat Feb 22 2014
|
|
1208
|
+
* new HDate(new Date('Saturday February 22, 2014')).after(6).greg() // Sat Mar 01 2014
|
|
1209
|
+
* new HDate(new Date('Sunday February 23, 2014')).after(6).greg() // Sat Mar 01 2014
|
|
1210
|
+
* @param dayOfWeek day of week: Sunday=0, Saturday=6
|
|
1211
|
+
*/
|
|
1212
|
+
after(dayOfWeek) {
|
|
1213
|
+
return onOrBefore(dayOfWeek, this, 7);
|
|
1214
|
+
}
|
|
1215
|
+
/**
|
|
1216
|
+
* Returns the next Hebrew date
|
|
1217
|
+
* @example
|
|
1218
|
+
* const hd = new HDate(new Date(2008, 10, 13)); // 15 Cheshvan 5769
|
|
1219
|
+
* hd.next(); // '16 Cheshvan 5769'
|
|
1220
|
+
*/
|
|
1221
|
+
next() {
|
|
1222
|
+
return new HDate(this.abs() + 1);
|
|
1223
|
+
}
|
|
1224
|
+
/**
|
|
1225
|
+
* Returns the previous Hebrew date
|
|
1226
|
+
* @example
|
|
1227
|
+
* const hd = new HDate(new Date(2008, 10, 13)); // 15 Cheshvan 5769
|
|
1228
|
+
* hd.prev(); // '14 Cheshvan 5769'
|
|
1229
|
+
*/
|
|
1230
|
+
prev() {
|
|
1231
|
+
return new HDate(this.abs() - 1);
|
|
1232
|
+
}
|
|
1233
|
+
/**
|
|
1234
|
+
* Returns a cloned `HDate` object with a specified amount of time added
|
|
1235
|
+
*
|
|
1236
|
+
* Units are case insensitive, and support plural and short forms.
|
|
1237
|
+
* Note, short forms are case sensitive.
|
|
1238
|
+
*
|
|
1239
|
+
* | Unit | Shorthand | Description
|
|
1240
|
+
* | --- | --- | --- |
|
|
1241
|
+
* | `day` | `d` | days |
|
|
1242
|
+
* | `week` | `w` | weeks |
|
|
1243
|
+
* | `month` | `M` | months |
|
|
1244
|
+
* | `year` | `y` | years |
|
|
1245
|
+
*/
|
|
1246
|
+
add(amount, units = 'd') {
|
|
1247
|
+
amount =
|
|
1248
|
+
typeof amount === 'string' ? parseInt(amount, 10) : amount;
|
|
1249
|
+
if (!amount) {
|
|
1250
|
+
return new HDate(this);
|
|
1251
|
+
}
|
|
1252
|
+
units = standardizeUnits(units);
|
|
1253
|
+
if (units === UNITS_DAY) {
|
|
1254
|
+
return new HDate(this.abs() + amount);
|
|
1255
|
+
}
|
|
1256
|
+
else if (units === UNITS_WEEK) {
|
|
1257
|
+
return new HDate(this.abs() + 7 * amount);
|
|
1258
|
+
}
|
|
1259
|
+
else if (units === UNITS_YEAR) {
|
|
1260
|
+
return new HDate(this.getDate(), this.getMonth(), this.getFullYear() + amount);
|
|
1261
|
+
}
|
|
1262
|
+
else {
|
|
1263
|
+
// units === UNITS_MONTH
|
|
1264
|
+
let hd = new HDate(this);
|
|
1265
|
+
const sign = amount > 0 ? 1 : -1;
|
|
1266
|
+
amount = Math.abs(amount);
|
|
1267
|
+
for (let i = 0; i < amount; i++) {
|
|
1268
|
+
hd = new HDate(hd.abs() + sign * hd.daysInMonth());
|
|
1269
|
+
}
|
|
1270
|
+
return hd;
|
|
1271
|
+
}
|
|
1272
|
+
}
|
|
1273
|
+
/**
|
|
1274
|
+
* Returns a cloned `HDate` object with a specified amount of time subracted
|
|
1275
|
+
*
|
|
1276
|
+
* Units are case insensitive, and support plural and short forms.
|
|
1277
|
+
* Note, short forms are case sensitive.
|
|
1278
|
+
*
|
|
1279
|
+
* | Unit | Shorthand | Description
|
|
1280
|
+
* | --- | --- | --- |
|
|
1281
|
+
* | `day` | `d` | days |
|
|
1282
|
+
* | `week` | `w` | weeks |
|
|
1283
|
+
* | `month` | `M` | months |
|
|
1284
|
+
* | `year` | `y` | years |
|
|
1285
|
+
* @example
|
|
1286
|
+
* import {HDate, months} from '@hebcal/hdate';
|
|
1287
|
+
*
|
|
1288
|
+
* const hd1 = new HDate(15, months.CHESHVAN, 5769);
|
|
1289
|
+
* const hd2 = hd1.add(1, 'weeks'); // 7 Kislev 5769
|
|
1290
|
+
* const hd3 = hd1.add(-3, 'M'); // 30 Av 5768
|
|
1291
|
+
*/
|
|
1292
|
+
subtract(amount, units = 'd') {
|
|
1293
|
+
return this.add(amount * -1, units);
|
|
1294
|
+
}
|
|
1295
|
+
/**
|
|
1296
|
+
* Returns the difference in days between the two given HDates.
|
|
1297
|
+
*
|
|
1298
|
+
* The result is positive if `this` date is comes chronologically
|
|
1299
|
+
* after the `other` date, and negative
|
|
1300
|
+
* if the order of the two dates is reversed.
|
|
1301
|
+
*
|
|
1302
|
+
* The result is zero if the two dates are identical.
|
|
1303
|
+
* @example
|
|
1304
|
+
* import {HDate, months} from '@hebcal/hdate';
|
|
1305
|
+
*
|
|
1306
|
+
* const hd1 = new HDate(25, months.KISLEV, 5770);
|
|
1307
|
+
* const hd2 = new HDate(15, months.CHESHVAN, 5769);
|
|
1308
|
+
* const days = hd1.deltaDays(hd2); // 394
|
|
1309
|
+
* @param other Hebrew date to compare
|
|
1310
|
+
*/
|
|
1311
|
+
deltaDays(other) {
|
|
1312
|
+
return this.abs() - other.abs();
|
|
1313
|
+
}
|
|
1314
|
+
/**
|
|
1315
|
+
* Compares this Hebrew date to another date, returning `true` if the dates match.
|
|
1316
|
+
* @param other Hebrew date to compare
|
|
1317
|
+
* @example
|
|
1318
|
+
* const hd1 = new HDate(new Date(2008, 10, 13));
|
|
1319
|
+
* const hd2 = new HDate(15, 'Cheshvan', 5769);
|
|
1320
|
+
* hd1.isSameDate(hd2); // true
|
|
1321
|
+
*/
|
|
1322
|
+
isSameDate(other) {
|
|
1323
|
+
return this.yy === other.yy && this.mm === other.mm && this.dd === other.dd;
|
|
1324
|
+
}
|
|
1325
|
+
/**
|
|
1326
|
+
* Returns a string representation of this Hebrew date using English transliterations
|
|
1327
|
+
* @example
|
|
1328
|
+
* const hd = new HDate(new Date(2008, 10, 13)); // 15 Cheshvan 5769
|
|
1329
|
+
* hd.toString(); // '15 Cheshvan 5769'
|
|
1330
|
+
*/
|
|
1331
|
+
toString() {
|
|
1332
|
+
const day = this.getDate();
|
|
1333
|
+
const fullYear = this.getFullYear();
|
|
1334
|
+
const monthName = this.getMonthName();
|
|
1335
|
+
return `${day} ${monthName} ${fullYear}`;
|
|
1336
|
+
}
|
|
1337
|
+
/**
|
|
1338
|
+
* Returns true if Hebrew year is a leap year
|
|
1339
|
+
* @param year Hebrew year
|
|
1340
|
+
* @example
|
|
1341
|
+
* HDate.isLeapYear(5783); // false
|
|
1342
|
+
* HDate.isLeapYear(5784); // true
|
|
1343
|
+
*/
|
|
1344
|
+
static isLeapYear(year) {
|
|
1345
|
+
return isLeapYear(year);
|
|
1346
|
+
}
|
|
1347
|
+
/**
|
|
1348
|
+
* Number of months in this Hebrew year (either 12 or 13 depending on leap year)
|
|
1349
|
+
* @param year Hebrew year
|
|
1350
|
+
* @example
|
|
1351
|
+
* HDate.monthsInYear(5783); // 12
|
|
1352
|
+
* HDate.monthsInYear(5784); // 13
|
|
1353
|
+
*/
|
|
1354
|
+
static monthsInYear(year) {
|
|
1355
|
+
return monthsInYear(year);
|
|
1356
|
+
}
|
|
1357
|
+
/**
|
|
1358
|
+
* Number of days in Hebrew month in a given year (29 or 30)
|
|
1359
|
+
* @param month Hebrew month (e.g. months.TISHREI)
|
|
1360
|
+
* @param year Hebrew year
|
|
1361
|
+
* @example
|
|
1362
|
+
* import {HDate, months} from '@hebcal/hdate';
|
|
1363
|
+
* HDate.daysInMonth(months.CHESHVAN, 5769); // 29
|
|
1364
|
+
*/
|
|
1365
|
+
static daysInMonth(month, year) {
|
|
1366
|
+
return daysInMonth(month, year);
|
|
1367
|
+
}
|
|
1368
|
+
/**
|
|
1369
|
+
* Returns a transliterated string name of Hebrew month in year,
|
|
1370
|
+
* for example 'Elul' or 'Cheshvan'.
|
|
1371
|
+
* @param month Hebrew month (e.g. months.TISHREI)
|
|
1372
|
+
* @param year Hebrew year
|
|
1373
|
+
* @example
|
|
1374
|
+
* import {HDate, months} from '@hebcal/hdate';
|
|
1375
|
+
* HDate.getMonthName(months.CHESHVAN, 5769); // 'Cheshvan'
|
|
1376
|
+
*/
|
|
1377
|
+
static getMonthName(month, year) {
|
|
1378
|
+
return getMonthName(month, year);
|
|
1379
|
+
}
|
|
1380
|
+
/**
|
|
1381
|
+
* Returns the Hebrew month number (NISAN=1, TISHREI=7)
|
|
1382
|
+
* @param month A number, or Hebrew month name string
|
|
1383
|
+
* @example
|
|
1384
|
+
* import {HDate, months} from '@hebcal/hdate';
|
|
1385
|
+
* HDate.monthNum(months.CHESHVAN); // 8
|
|
1386
|
+
* HDate.monthNum('Cheshvan'); // 8
|
|
1387
|
+
* HDate.monthNum('חשון'); // 8
|
|
1388
|
+
*/
|
|
1389
|
+
static monthNum(month) {
|
|
1390
|
+
if (typeof month === 'number') {
|
|
1391
|
+
if (isNaN(month) || month > 14) {
|
|
1392
|
+
throw new RangeError(`bad monthNum: ${month}`);
|
|
1393
|
+
}
|
|
1394
|
+
return month;
|
|
1395
|
+
}
|
|
1396
|
+
return month.charCodeAt(0) >= 48 && month.charCodeAt(0) <= 57 /* number */
|
|
1397
|
+
? parseInt(month, 10)
|
|
1398
|
+
: monthFromName(month);
|
|
1399
|
+
}
|
|
1400
|
+
/**
|
|
1401
|
+
* Number of days in the Hebrew year.
|
|
1402
|
+
* Regular years can have 353, 354, or 355 days.
|
|
1403
|
+
* Leap years can have 383, 384, or 385 days.
|
|
1404
|
+
* @param year Hebrew year
|
|
1405
|
+
* @example
|
|
1406
|
+
* HDate.daysInYear(5783); // 355
|
|
1407
|
+
* HDate.daysInYear(5784); // 383
|
|
1408
|
+
*/
|
|
1409
|
+
static daysInYear(year) {
|
|
1410
|
+
return daysInYear(year);
|
|
1411
|
+
}
|
|
1412
|
+
/**
|
|
1413
|
+
* true if Cheshvan is long in Hebrew year
|
|
1414
|
+
* @param year Hebrew year
|
|
1415
|
+
* @example
|
|
1416
|
+
* HDate.longCheshvan(5783); // true
|
|
1417
|
+
* HDate.longCheshvan(5784); // false
|
|
1418
|
+
*/
|
|
1419
|
+
static longCheshvan(year) {
|
|
1420
|
+
return longCheshvan(year);
|
|
1421
|
+
}
|
|
1422
|
+
/**
|
|
1423
|
+
* true if Kislev is short in Hebrew year
|
|
1424
|
+
* @param year Hebrew year
|
|
1425
|
+
* @example
|
|
1426
|
+
* HDate.shortKislev(5783); // false
|
|
1427
|
+
* HDate.shortKislev(5784); // true
|
|
1428
|
+
*/
|
|
1429
|
+
static shortKislev(year) {
|
|
1430
|
+
return shortKislev(year);
|
|
1431
|
+
}
|
|
1432
|
+
/**
|
|
1433
|
+
* Converts Hebrew month string name to numeric
|
|
1434
|
+
* @example
|
|
1435
|
+
* import {HDate, months} from '@hebcal/hdate';
|
|
1436
|
+
* HDate.monthFromName(months.CHESHVAN); // 8
|
|
1437
|
+
* HDate.monthFromName('Cheshvan'); // 8
|
|
1438
|
+
* HDate.monthFromName('חשון'); // 8
|
|
1439
|
+
*/
|
|
1440
|
+
static monthFromName(monthName) {
|
|
1441
|
+
return monthFromName(monthName);
|
|
1442
|
+
}
|
|
1443
|
+
/**
|
|
1444
|
+
* Convenience function for determining the R.D. date
|
|
1445
|
+
* near a specified R.D. date, corresponding to the specified day of week.
|
|
1446
|
+
*
|
|
1447
|
+
* Note: Applying this function to d+6 gives us the `dayOfWeek` on or after an
|
|
1448
|
+
* absolute day d. Similarly, applying it to d+3 gives the `dayOfWeek` nearest to
|
|
1449
|
+
* absolute date d, applying it to d-1 gives the `dayOfWeek` previous to absolute
|
|
1450
|
+
* date d, and applying it to d+7 gives the `dayOfWeek` following absolute date d.
|
|
1451
|
+
* @param dayOfWeek day of week: Sunday=0, Saturday=6
|
|
1452
|
+
*/
|
|
1453
|
+
static dayOnOrBefore(dayOfWeek, absdate) {
|
|
1454
|
+
return absdate - ((absdate - dayOfWeek) % 7);
|
|
1455
|
+
}
|
|
1456
|
+
/**
|
|
1457
|
+
* Tests if the object is an instance of `HDate`
|
|
1458
|
+
* @example
|
|
1459
|
+
* HDate.isHDate(new HDate()); // true
|
|
1460
|
+
* HDate.isHDate(new Date()); // false
|
|
1461
|
+
* HDate.isHDate(null); // false
|
|
1462
|
+
* HDate.isHDate(12345); // false
|
|
1463
|
+
* HDate.isHDate('15 Cheshvan 5769'); // false
|
|
1464
|
+
*/
|
|
1465
|
+
static isHDate(obj) {
|
|
1466
|
+
return (obj !== null &&
|
|
1467
|
+
typeof obj === 'object' &&
|
|
1468
|
+
typeof obj.yy === 'number' &&
|
|
1469
|
+
typeof obj.mm === 'number' &&
|
|
1470
|
+
typeof obj.dd === 'number' &&
|
|
1471
|
+
typeof obj.greg === 'function' &&
|
|
1472
|
+
typeof obj.abs === 'function');
|
|
1473
|
+
}
|
|
1474
|
+
/**
|
|
1475
|
+
* Construct a new instance of `HDate` from a Gematriya-formatted string
|
|
1476
|
+
* @example
|
|
1477
|
+
* HDate.fromGematriyaString('כ״ז בְּתַמּוּז תשפ״ג') // 27 Tamuz 5783
|
|
1478
|
+
* HDate.fromGematriyaString('כ׳ סיון תש״ד') // 20 Sivan 5704
|
|
1479
|
+
* HDate.fromGematriyaString('ה׳ אִיָיר תש״ח') // 5 Iyyar 5708
|
|
1480
|
+
*/
|
|
1481
|
+
static fromGematriyaString(str, currentThousands = 5000) {
|
|
1482
|
+
const parts = str.split(' ').filter(x => x.length !== 0);
|
|
1483
|
+
const numParts = parts.length;
|
|
1484
|
+
if (numParts !== 3 && numParts !== 4) {
|
|
1485
|
+
throw new RangeError(`cannot parse gematriya str: "${str}"`);
|
|
1486
|
+
}
|
|
1487
|
+
const day = gematriyaStrToNum(parts[0]);
|
|
1488
|
+
const monthStr = numParts === 3 ? parts[1] : parts[1] + ' ' + parts[2];
|
|
1489
|
+
const month = monthFromName(monthStr);
|
|
1490
|
+
const yearStr = numParts === 3 ? parts[2] : parts[3];
|
|
1491
|
+
let year = gematriyaStrToNum(yearStr);
|
|
1492
|
+
if (year < 1000) {
|
|
1493
|
+
year += currentThousands;
|
|
1494
|
+
}
|
|
1495
|
+
return new HDate(day, month, year);
|
|
1496
|
+
}
|
|
1497
|
+
}
|
|
1498
|
+
function standardizeUnits(units) {
|
|
1499
|
+
switch (units) {
|
|
1500
|
+
case 'd':
|
|
1501
|
+
return UNITS_DAY;
|
|
1502
|
+
case 'w':
|
|
1503
|
+
return UNITS_WEEK;
|
|
1504
|
+
case 'M':
|
|
1505
|
+
return UNITS_MONTH;
|
|
1506
|
+
case 'y':
|
|
1507
|
+
return UNITS_YEAR;
|
|
1508
|
+
}
|
|
1509
|
+
const str = String(units || '')
|
|
1510
|
+
.toLowerCase()
|
|
1511
|
+
.replace(/s$/, '');
|
|
1512
|
+
switch (str) {
|
|
1513
|
+
case UNITS_DAY:
|
|
1514
|
+
case UNITS_WEEK:
|
|
1515
|
+
case UNITS_MONTH:
|
|
1516
|
+
case UNITS_YEAR:
|
|
1517
|
+
return str;
|
|
1518
|
+
}
|
|
1519
|
+
throw new TypeError(`Invalid units '${units}'`);
|
|
1520
|
+
}
|
|
1521
|
+
function getDayOfTranslation(locale) {
|
|
1522
|
+
switch (locale) {
|
|
1523
|
+
case 'en':
|
|
1524
|
+
case 's':
|
|
1525
|
+
case 'a':
|
|
1526
|
+
case 'ashkenazi':
|
|
1527
|
+
return ' of';
|
|
1528
|
+
}
|
|
1529
|
+
const ofStr = Locale.lookupTranslation('of', locale);
|
|
1530
|
+
if (ofStr) {
|
|
1531
|
+
return ' ' + ofStr;
|
|
1532
|
+
}
|
|
1533
|
+
if (locale.startsWith('ashkenazi')) {
|
|
1534
|
+
return ' of';
|
|
1535
|
+
}
|
|
1536
|
+
return '';
|
|
1537
|
+
}
|
|
1538
|
+
/**
|
|
1539
|
+
* Sets the day of the month of the date. Returns the object it was called upon
|
|
1540
|
+
* @private
|
|
1541
|
+
* @param month A number, or Hebrew month name string
|
|
1542
|
+
*/
|
|
1543
|
+
function setMonth(hd, month) {
|
|
1544
|
+
hd.mm = HDate.monthNum(month);
|
|
1545
|
+
fix(hd);
|
|
1546
|
+
return hd;
|
|
1547
|
+
}
|
|
1548
|
+
function setDate(hd, date) {
|
|
1549
|
+
hd.dd = date;
|
|
1550
|
+
fix(hd);
|
|
1551
|
+
return hd;
|
|
1552
|
+
}
|
|
1553
|
+
function fix(hd) {
|
|
1554
|
+
fixMonth(hd);
|
|
1555
|
+
fixDate(hd);
|
|
1556
|
+
}
|
|
1557
|
+
function fixDate(hd) {
|
|
1558
|
+
if (hd.dd < 1) {
|
|
1559
|
+
if (hd.mm === months.TISHREI) {
|
|
1560
|
+
hd.yy -= 1;
|
|
1561
|
+
}
|
|
1562
|
+
hd.dd += daysInMonth(hd.mm, hd.yy);
|
|
1563
|
+
hd.mm -= 1;
|
|
1564
|
+
fix(hd);
|
|
1565
|
+
}
|
|
1566
|
+
if (hd.dd > daysInMonth(hd.mm, hd.yy)) {
|
|
1567
|
+
if (hd.mm === months.ELUL) {
|
|
1568
|
+
hd.yy += 1;
|
|
1569
|
+
}
|
|
1570
|
+
hd.dd -= daysInMonth(hd.mm, hd.yy);
|
|
1571
|
+
if (hd.mm === monthsInYear(hd.yy)) {
|
|
1572
|
+
hd.mm = 1; // rollover to NISAN
|
|
1573
|
+
}
|
|
1574
|
+
else {
|
|
1575
|
+
hd.mm += 1;
|
|
1576
|
+
}
|
|
1577
|
+
fix(hd);
|
|
1578
|
+
}
|
|
1579
|
+
fixMonth(hd);
|
|
1580
|
+
}
|
|
1581
|
+
function fixMonth(hd) {
|
|
1582
|
+
if (hd.mm === months.ADAR_II && !hd.isLeapYear()) {
|
|
1583
|
+
hd.mm -= 1; // to Adar I
|
|
1584
|
+
fix(hd);
|
|
1585
|
+
}
|
|
1586
|
+
else if (hd.mm < 1) {
|
|
1587
|
+
hd.mm += monthsInYear(hd.yy);
|
|
1588
|
+
hd.yy -= 1;
|
|
1589
|
+
fix(hd);
|
|
1590
|
+
}
|
|
1591
|
+
else if (hd.mm > monthsInYear(hd.yy)) {
|
|
1592
|
+
hd.mm -= monthsInYear(hd.yy);
|
|
1593
|
+
hd.yy += 1;
|
|
1594
|
+
fix(hd);
|
|
1595
|
+
}
|
|
1596
|
+
delete hd.rd;
|
|
1597
|
+
}
|
|
1598
|
+
function onOrBefore(day, t, offset) {
|
|
1599
|
+
return new HDate(HDate.dayOnOrBefore(day, t.abs() + offset));
|
|
1600
|
+
}
|
|
1601
|
+
/*! @hebcal/core v6.0.7, distributed under GPLv2 https://www.gnu.org/licenses/gpl-2.0.txt */
|
|
1602
|
+
const SUN = 0;
|
|
1603
|
+
const TUE = 2;
|
|
1604
|
+
const SAT = 6;
|
|
1605
|
+
const NISAN = months.NISAN;
|
|
1606
|
+
const IYYAR = months.IYYAR;
|
|
1607
|
+
/**
|
|
1608
|
+
* Yom HaAtzma'ut only celebrated after 1948
|
|
1609
|
+
* @private
|
|
1610
|
+
* @param year
|
|
1611
|
+
*/
|
|
1612
|
+
function dateYomHaZikaron(year) {
|
|
1613
|
+
if (year < 5708) {
|
|
1614
|
+
return null;
|
|
1615
|
+
}
|
|
1616
|
+
let day;
|
|
1617
|
+
const pesach = new HDate(15, NISAN, year);
|
|
1618
|
+
const pdow = pesach.getDay();
|
|
1619
|
+
if (pdow === SUN) {
|
|
1620
|
+
day = 2;
|
|
1621
|
+
}
|
|
1622
|
+
else if (pdow === SAT) {
|
|
1623
|
+
day = 3;
|
|
1624
|
+
}
|
|
1625
|
+
else if (year < 5764) {
|
|
1626
|
+
day = 4;
|
|
1627
|
+
}
|
|
1628
|
+
else if (pdow === TUE) {
|
|
1629
|
+
day = 5;
|
|
1630
|
+
}
|
|
1631
|
+
else {
|
|
1632
|
+
day = 4;
|
|
1633
|
+
}
|
|
1634
|
+
return new HDate(day, IYYAR, year);
|
|
1635
|
+
}
|
|
1636
|
+
/*! @hebcal/core v6.0.7, distributed under GPLv2 https://www.gnu.org/licenses/gpl-2.0.txt */
|
|
1637
|
+
function range(start, end) {
|
|
1638
|
+
const arr = [];
|
|
1639
|
+
for (let i = start; i <= end; i++) {
|
|
1640
|
+
arr.push(i);
|
|
1641
|
+
}
|
|
1642
|
+
return arr;
|
|
1643
|
+
}
|
|
1644
|
+
const NONE = {
|
|
1645
|
+
shacharit: false,
|
|
1646
|
+
mincha: false,
|
|
1647
|
+
allCongs: false,
|
|
1648
|
+
};
|
|
1649
|
+
/**
|
|
1650
|
+
* Return details on what Tachanun (or Tzidchatcha on Shabbat) is said on `hdate`.
|
|
1651
|
+
*
|
|
1652
|
+
* Tachanun is not said on Rosh Chodesh, the month of Nisan, Lag Baomer,
|
|
1653
|
+
* Rosh Chodesh Sivan until Isru Chag, Tisha B'av, 15 Av, Erev Rosh Hashanah,
|
|
1654
|
+
* Rosh Hashanah, Erev Yom Kippur until after Simchat Torah, Chanukah,
|
|
1655
|
+
* Tu B'shvat, Purim and Shushan Purim, and Purim and Shushan Purim Katan.
|
|
1656
|
+
*
|
|
1657
|
+
* In some congregations Tachanun is not said until from Rosh Chodesh Sivan
|
|
1658
|
+
* until 14th Sivan, Sukkot until after Rosh Chodesh Cheshvan, Pesach Sheini,
|
|
1659
|
+
* Yom Ha'atzmaut, and Yom Yerushalayim.
|
|
1660
|
+
*
|
|
1661
|
+
* Tachanun is not said at Mincha on days before it is not said at Shacharit.
|
|
1662
|
+
*
|
|
1663
|
+
* Tachanun is not said at Shacharit on Shabbat, but is at Mincha, usually.
|
|
1664
|
+
*/
|
|
1665
|
+
function tachanun(hdate, il) {
|
|
1666
|
+
return tachanun0(hdate, il, true);
|
|
1667
|
+
}
|
|
1668
|
+
function tachanun0(hdate, il, checkNext) {
|
|
1669
|
+
const year = hdate.yy;
|
|
1670
|
+
const dates = tachanunYear(year);
|
|
1671
|
+
const abs = hdate.abs();
|
|
1672
|
+
if (dates.none.indexOf(abs) > -1) {
|
|
1673
|
+
return NONE;
|
|
1674
|
+
}
|
|
1675
|
+
const dow = hdate.getDay();
|
|
1676
|
+
const ret = {
|
|
1677
|
+
shacharit: false,
|
|
1678
|
+
mincha: false,
|
|
1679
|
+
allCongs: false,
|
|
1680
|
+
};
|
|
1681
|
+
if (dates.some.indexOf(abs) === -1) {
|
|
1682
|
+
ret.allCongs = true;
|
|
1683
|
+
}
|
|
1684
|
+
if (dow !== 6) {
|
|
1685
|
+
ret.shacharit = true;
|
|
1686
|
+
}
|
|
1687
|
+
const tomorrow = abs + 1;
|
|
1688
|
+
if (checkNext && dates.yesPrev.indexOf(tomorrow) === -1) {
|
|
1689
|
+
const tmp = tachanun0(new HDate(tomorrow), il, false);
|
|
1690
|
+
ret.mincha = tmp.shacharit;
|
|
1691
|
+
}
|
|
1692
|
+
else {
|
|
1693
|
+
ret.mincha = dow !== 5;
|
|
1694
|
+
}
|
|
1695
|
+
if (ret.allCongs && !ret.mincha && !ret.shacharit) {
|
|
1696
|
+
return NONE;
|
|
1697
|
+
}
|
|
1698
|
+
return ret;
|
|
1699
|
+
}
|
|
1700
|
+
function tachanunYear(year, il) {
|
|
1701
|
+
const leap = HDate.isLeapYear(year);
|
|
1702
|
+
const monthsInYear = HDate.monthsInYear(year);
|
|
1703
|
+
let av9dt = new HDate(9, months.AV, year);
|
|
1704
|
+
if (av9dt.getDay() === 6) {
|
|
1705
|
+
av9dt = av9dt.next();
|
|
1706
|
+
}
|
|
1707
|
+
let shushPurim = new HDate(15, months.ADAR_II, year);
|
|
1708
|
+
if (shushPurim.getDay() === 6) {
|
|
1709
|
+
shushPurim = shushPurim.next();
|
|
1710
|
+
}
|
|
1711
|
+
const none = [
|
|
1712
|
+
new HDate(2, months.TISHREI, year), // Rosh Hashana II
|
|
1713
|
+
].concat(
|
|
1714
|
+
// Rosh Chodesh - 1st of every month. Also includes RH day 1 (1 Tishrei)
|
|
1715
|
+
range(1, monthsInYear).map(month => new HDate(1, month, year)),
|
|
1716
|
+
// Rosh Chodesh - 30th of months that have one
|
|
1717
|
+
range(1, monthsInYear)
|
|
1718
|
+
.filter(month => HDate.daysInMonth(month, year) === 30)
|
|
1719
|
+
.map(month => new HDate(30, month, year)),
|
|
1720
|
+
// entire month of Nisan
|
|
1721
|
+
range(1, HDate.daysInMonth(months.NISAN, year)).map(mday => new HDate(mday, months.NISAN, year)), new HDate(18, months.IYYAR, year), // Lag BaOmer
|
|
1722
|
+
// Rosh Chodesh Sivan thru Isru Chag
|
|
1723
|
+
range(1, 8 - (1)).map(mday => new HDate(mday, months.SIVAN, year)), av9dt, // Tisha B'Av
|
|
1724
|
+
new HDate(15, months.AV, year), // Tu B'Av
|
|
1725
|
+
new HDate(29, months.ELUL, year), // Erev Rosh Hashanah
|
|
1726
|
+
// Erev Yom Kippur thru Isru Chag
|
|
1727
|
+
range(9, 24 - (1)).map(mday => new HDate(mday, months.TISHREI, year)),
|
|
1728
|
+
// Chanukah
|
|
1729
|
+
range(25, 33).map(mday => new HDate(mday, months.KISLEV, year)), new HDate(15, months.SHVAT, year), // Tu BiShvat
|
|
1730
|
+
new HDate(14, months.ADAR_II, year), // Purim
|
|
1731
|
+
shushPurim, leap ? new HDate(14, months.ADAR_I, year) : [] // Purim Katan
|
|
1732
|
+
);
|
|
1733
|
+
const some = [
|
|
1734
|
+
new HDate(14, months.IYYAR, year), // Pesach Sheini
|
|
1735
|
+
].concat(
|
|
1736
|
+
// Until 14 Sivan
|
|
1737
|
+
range(1, 13).map(mday => new HDate(mday, months.SIVAN, year)),
|
|
1738
|
+
// Until after Rosh Chodesh Cheshvan
|
|
1739
|
+
range(20, 31).map(mday => new HDate(mday, months.TISHREI, year)),
|
|
1740
|
+
// Yom HaAtzma'ut, which changes based on day of week
|
|
1741
|
+
year >= 5708 ? dateYomHaZikaron(year).next() : [],
|
|
1742
|
+
// Yom Yerushalayim
|
|
1743
|
+
year >= 5727 ? new HDate(28, months.IYYAR, year) : []);
|
|
1744
|
+
const yesPrev = [
|
|
1745
|
+
new HDate(29, months.ELUL, year - 1), // Erev Rosh Hashanah
|
|
1746
|
+
new HDate(9, months.TISHREI, year), // Erev Yom Kippur
|
|
1747
|
+
new HDate(14, months.IYYAR, year), // Pesach Sheini
|
|
1748
|
+
];
|
|
1749
|
+
return {
|
|
1750
|
+
none: none.map(hd => hd.abs()).sort((a, b) => a - b),
|
|
1751
|
+
some: some.map(hd => hd.abs()).sort((a, b) => a - b),
|
|
1752
|
+
yesPrev: yesPrev.map(hd => hd.abs()).sort((a, b) => a - b),
|
|
1753
|
+
};
|
|
1754
|
+
}
|
|
1755
|
+
console.log(tachanun(new HDate(1, 1, 5757), true));
|