@hebcal/core 5.6.1 → 5.7.1

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.
Files changed (110) hide show
  1. package/README.md +23 -1
  2. package/dist/CalOptions.d.ts +1 -1
  3. package/dist/HolidayEvent.d.ts +0 -5
  4. package/dist/YomKippurKatanEvent.d.ts +0 -1
  5. package/dist/bundle.js +9739 -9578
  6. package/dist/bundle.js.map +1 -1
  7. package/dist/bundle.min.js +2 -2
  8. package/dist/bundle.min.js.map +1 -1
  9. package/dist/calendar.d.ts +110 -0
  10. package/dist/candles.d.ts +10 -1
  11. package/dist/es/CalOptions.d.ts +158 -0
  12. package/dist/es/DailyLearning.d.ts +21 -0
  13. package/dist/es/DailyLearning.js +36 -0
  14. package/dist/es/DailyLearning.js.map +1 -0
  15. package/dist/es/HebrewDateEvent.d.ts +37 -0
  16. package/dist/es/HebrewDateEvent.js +77 -0
  17. package/dist/es/HebrewDateEvent.js.map +1 -0
  18. package/dist/es/HolidayEvent.d.ts +76 -0
  19. package/dist/es/HolidayEvent.js +165 -0
  20. package/dist/es/HolidayEvent.js.map +1 -0
  21. package/dist/es/MevarchimChodeshEvent.d.ts +25 -0
  22. package/dist/es/MevarchimChodeshEvent.js +54 -0
  23. package/dist/es/MevarchimChodeshEvent.js.map +1 -0
  24. package/dist/es/ParshaEvent.d.ts +23 -0
  25. package/dist/es/ParshaEvent.js +53 -0
  26. package/dist/es/ParshaEvent.js.map +1 -0
  27. package/dist/es/TimedEvent.d.ts +47 -0
  28. package/dist/es/TimedEvent.js +97 -0
  29. package/dist/es/TimedEvent.js.map +1 -0
  30. package/dist/es/YomKippurKatanEvent.d.ts +23 -0
  31. package/dist/es/YomKippurKatanEvent.js +43 -0
  32. package/dist/es/YomKippurKatanEvent.js.map +1 -0
  33. package/dist/es/ashkenazi.po.d.ts +67 -0
  34. package/dist/es/ashkenazi.po.js +5 -0
  35. package/dist/es/ashkenazi.po.js.map +1 -0
  36. package/dist/es/calendar.d.ts +110 -0
  37. package/dist/es/calendar.js +615 -0
  38. package/dist/es/calendar.js.map +1 -0
  39. package/dist/es/candles.d.ts +37 -0
  40. package/dist/es/candles.js +161 -0
  41. package/dist/es/candles.js.map +1 -0
  42. package/dist/es/event.d.ts +187 -0
  43. package/dist/es/event.js +243 -0
  44. package/dist/es/event.js.map +1 -0
  45. package/dist/es/getStartAndEnd.d.ts +6 -0
  46. package/dist/es/getStartAndEnd.js +102 -0
  47. package/dist/es/getStartAndEnd.js.map +1 -0
  48. package/dist/es/hallel.d.ts +6 -0
  49. package/dist/es/hallel.js +52 -0
  50. package/dist/es/hallel.js.map +1 -0
  51. package/dist/es/he.po.d.ts +246 -0
  52. package/dist/es/he.po.js +5 -0
  53. package/dist/es/he.po.js.map +1 -0
  54. package/dist/es/hebcal.d.ts +259 -0
  55. package/dist/es/hebcal.js +336 -0
  56. package/dist/es/hebcal.js.map +1 -0
  57. package/dist/es/holidays.d.ts +22 -0
  58. package/dist/es/holidays.js +321 -0
  59. package/dist/es/holidays.js.map +1 -0
  60. package/dist/es/index.d.ts +23 -0
  61. package/dist/es/index.js +22 -0
  62. package/dist/es/index.js.map +1 -0
  63. package/dist/es/locale.d.ts +1 -0
  64. package/dist/es/locale.js +21 -0
  65. package/dist/es/locale.js.map +1 -0
  66. package/dist/es/location.d.ts +73 -0
  67. package/dist/es/location.js +306 -0
  68. package/dist/es/location.js.map +1 -0
  69. package/dist/es/modern.d.ts +18 -0
  70. package/dist/es/modern.js +64 -0
  71. package/dist/es/modern.js.map +1 -0
  72. package/dist/es/molad.d.ts +62 -0
  73. package/dist/es/molad.js +141 -0
  74. package/dist/es/molad.js.map +1 -0
  75. package/dist/es/omer.d.ts +37 -0
  76. package/dist/es/omer.js +88 -0
  77. package/dist/es/omer.js.map +1 -0
  78. package/dist/es/parshaName.d.ts +3 -0
  79. package/dist/es/parshaName.js +19 -0
  80. package/dist/es/parshaName.js.map +1 -0
  81. package/dist/es/pkgVersion.d.ts +2 -0
  82. package/dist/es/pkgVersion.js +6 -0
  83. package/dist/es/pkgVersion.js.map +1 -0
  84. package/dist/es/reformatTimeStr.d.ts +8 -0
  85. package/dist/es/reformatTimeStr.js +52 -0
  86. package/dist/es/reformatTimeStr.js.map +1 -0
  87. package/dist/es/sedra.d.ts +107 -0
  88. package/dist/es/sedra.js +494 -0
  89. package/dist/es/sedra.js.map +1 -0
  90. package/dist/es/staticHolidays.d.ts +176 -0
  91. package/dist/es/staticHolidays.js +626 -0
  92. package/dist/es/staticHolidays.js.map +1 -0
  93. package/dist/es/tachanun.d.ts +29 -0
  94. package/dist/es/tachanun.js +125 -0
  95. package/dist/es/tachanun.js.map +1 -0
  96. package/dist/es/zmanim.d.ts +341 -0
  97. package/dist/es/zmanim.js +573 -0
  98. package/dist/es/zmanim.js.map +1 -0
  99. package/dist/event.d.ts +1 -0
  100. package/dist/holidays.d.ts +13 -0
  101. package/dist/index.cjs +2762 -10041
  102. package/dist/index.cjs.map +1 -1
  103. package/dist/index.d.ts +3 -2
  104. package/dist/module.d.ts +101 -80
  105. package/dist/pkgVersion.d.ts +1 -1
  106. package/dist/sedra.d.ts +4 -4
  107. package/dist/tachanun.d.ts +17 -1
  108. package/package.json +18 -6
  109. package/dist/index.mjs +0 -11998
  110. package/dist/index.mjs.map +0 -1
@@ -0,0 +1,615 @@
1
+ /*! @hebcal/core v5.7.1 */
2
+ import { months, Locale, abs2greg, HDate } from '@hebcal/hdate';
3
+ import { makeCandleEvent, makeFastStartEnd, makeWeekdayChanukahCandleLighting } from './candles.js';
4
+ import { flags } from './event.js';
5
+ import { getStartAndEnd } from './getStartAndEnd.js';
6
+ import { HebrewDateEvent } from './HebrewDateEvent.js';
7
+ import { getHolidaysForYear_ } from './holidays.js';
8
+ import { ParshaEvent } from './ParshaEvent.js';
9
+ import { getSedra } from './sedra.js';
10
+ import { HavdalahEvent } from './TimedEvent.js';
11
+ import { DailyLearning } from './DailyLearning.js';
12
+ import { MevarchimChodeshEvent } from './MevarchimChodeshEvent.js';
13
+ import { MoladEvent, Molad } from './molad.js';
14
+ import { OmerEvent } from './omer.js';
15
+ import { Zmanim } from './zmanim.js';
16
+ import { Location } from './location.js';
17
+
18
+ /**
19
+ * Calculates holidays and other Hebrew calendar events based on {@link CalOptions}.
20
+ *
21
+ * Each holiday is represented by an {@link Event} object which includes a date,
22
+ * a description, flags and optional attributes.
23
+ * If given no options, returns holidays for the Diaspora for the current Gregorian year.
24
+ *
25
+ * The date range returned by this function can be controlled by:
26
+ * * `options.year` - Gregorian (e.g. 1993) or Hebrew year (e.g. 5749)
27
+ * * `options.isHebrewYear` - to interpret `year` as Hebrew year
28
+ * * `options.numYears` - generate calendar for multiple years (default 1)
29
+ * * `options.month` - Gregorian or Hebrew month (to filter results to a single month)
30
+ *
31
+ * Alternatively, specify start and end days with `Date` or {@link HDate} instances:
32
+ * * `options.start` - use specific start date (requires `end` date)
33
+ * * `options.end` - use specific end date (requires `start` date)
34
+ *
35
+ * Unless `options.noHolidays == true`, default holidays include:
36
+ * * Major holidays - Rosh Hashana, Yom Kippur, Pesach, Sukkot, etc.
37
+ * * Minor holidays - Purim, Chanukah, Tu BiShvat, Lag BaOmer, etc.
38
+ * * Minor fasts - Ta'anit Esther, Tzom Gedaliah, etc. (unless `options.noMinorFast`)
39
+ * * Special Shabbatot - Shabbat Shekalim, Zachor, etc. (unless `options.noSpecialShabbat`)
40
+ * * Modern Holidays - Yom HaShoah, Yom HaAtzma'ut, etc. (unless `options.noModern`)
41
+ * * Rosh Chodesh (unless `options.noRoshChodesh`)
42
+ *
43
+ * Holiday and Torah reading schedules differ between Israel and the Disapora.
44
+ * Set `options.il=true` to use the Israeli schedule.
45
+ *
46
+ * Additional non-default event types can be specified:
47
+ * * Parashat HaShavua - weekly Torah Reading on Saturdays (`options.sedrot`)
48
+ * * Counting of the Omer (`options.omer`)
49
+ * * Shabbat Mevarchim HaChodesh on Saturday before Rosh Chodesh (`options.shabbatMevarchim`)
50
+ * * Molad announcement on Saturday before Rosh Chodesh (`options.molad`)
51
+ * * Yom Kippur Katan (`options.yomKippurKatan`)
52
+ *
53
+ * Daily Study of texts are supported by the
54
+ * {@link https://github.com/hebcal/hebcal-learning @hebcal/learning} package,
55
+ * for example:
56
+ * * Babylonian Talmud Daf Yomi (`options.dailyLearning.dafYomi`)
57
+ * * Jerusalem Talmud (Yerushalmi) Yomi (`options.dailyLearning.yerushalmi`)
58
+ * * Mishna Yomi (`options.dailyLearning.mishnaYomi`)
59
+ * * Nach Yomi (`options.dailyLearning.nachYomi`)
60
+ *
61
+ * Candle-lighting and Havdalah times are approximated using latitude and longitude
62
+ * specified by the {@link Location} class. The `Location` class contains a small
63
+ * database of cities with their associated geographic information and time-zone information.
64
+ * If you ever have any doubts about Hebcal's times, consult your local halachic authority.
65
+ * If you enter geographic coordinates above the arctic circle or antarctic circle,
66
+ * the times are guaranteed to be wrong.
67
+ *
68
+ * To add candle-lighting options, set `options.candlelighting=true` and set
69
+ * `options.location` to an instance of `Location`. By default, candle lighting
70
+ * time is 18 minutes before sundown (40 minutes for Jerusalem,
71
+ * 30 minutes for Haifa and Zikhron Ya'akov) and Havdalah is
72
+ * calculated according to Tzeit Hakochavim - Nightfall (the point when 3 small stars
73
+ * are observable in the night time sky with the naked eye). The default Havdalah
74
+ * option (Tzeit Hakochavim) is calculated when the sun is 8.5° below the horizon.
75
+ * These defaults can be changed using these options:
76
+ * * `options.candleLightingMins` - minutes before sundown to light candles
77
+ * * `options.havdalahMins` - minutes after sundown for Havdalah (typical values are 42, 50, or 72).
78
+ * Havdalah times are suppressed when `options.havdalahMins=0`.
79
+ * * `options.havdalahDeg` - degrees for solar depression for Havdalah.
80
+ * Default is 8.5 degrees for 3 small stars. Use 7.083 degrees for 3 medium-sized stars.
81
+ * Havdalah times are suppressed when `options.havdalahDeg=0`.
82
+ *
83
+ * If both `options.candlelighting=true` and `options.location` is specified,
84
+ * Chanukah candle-lighting times and minor fast start/end times will also be generated.
85
+ * Chanukah candle-lighting is at Bein HaShmashos (13.5 minutes before
86
+ * the sun is 7.083° below the horizon in the evening)
87
+ * on weekdays, at regular candle-lighting time on Fridays, and at regular Havdalah time on
88
+ * Saturday night (see above).
89
+ *
90
+ * Minor fasts begin at Alot HaShachar (sun is 16.1° below the horizon in the morning) and
91
+ * end when 3 medium-sized stars are observable in the night sky (sun is 7.083° below the horizon
92
+ * in the evening).
93
+ *
94
+ * Two options also exist for generating an Event with the Hebrew date:
95
+ * * `options.addHebrewDates` - print the Hebrew date for the entire date range
96
+ * * `options.addHebrewDatesForEvents` - print the Hebrew date for dates with some events
97
+ *
98
+ * Lastly, translation and transliteration of event titles is controlled by
99
+ * `options.locale` and the {@link Locale} API.
100
+ * `@hebcal/core` supports three locales by default:
101
+ * * `en` - default, Sephardic transliterations (e.g. "Shabbat")
102
+ * * `ashkenazi` - Ashkenazi transliterations (e.g. "Shabbos")
103
+ * * `he` - Hebrew (e.g. "שַׁבָּת")
104
+ *
105
+ * Additional locales (such as `ru` or `fr`) are supported by the
106
+ * {@link https://github.com/hebcal/hebcal-locales @hebcal/locales} package
107
+ *
108
+ * @example
109
+ * import {HebrewCalendar, HDate, Location, Event} from '@hebcal/core';
110
+ * const options: CalOptions = {
111
+ * year: 1981,
112
+ * isHebrewYear: false,
113
+ * candlelighting: true,
114
+ * location: Location.lookup('San Francisco'),
115
+ * sedrot: true,
116
+ * omer: true,
117
+ * };
118
+ * const events = HebrewCalendar.calendar(options);
119
+ * for (const ev of events) {
120
+ * const hd = ev.getDate();
121
+ * const date = hd.greg();
122
+ * console.log(date.toLocaleDateString(), ev.render('en'), hd.toString());
123
+ * }
124
+ */
125
+ function calendar(options = {}) {
126
+ options = Object.assign({}, options); // so we can modify freely
127
+ checkCandleOptions(options);
128
+ const location = (options.location = options.location || defaultLocation);
129
+ const il = (options.il = options.il || location.getIsrael() || false);
130
+ const hasUserMask = typeof options.mask === 'number';
131
+ options.mask = getMaskFromOptions(options);
132
+ if (options.ashkenazi || options.locale) {
133
+ if (options.locale && typeof options.locale !== 'string') {
134
+ throw new TypeError(`Invalid options.locale: ${options.locale}`);
135
+ }
136
+ const locale = options.ashkenazi ? 'ashkenazi' : options.locale;
137
+ const translationObj = Locale.useLocale(locale);
138
+ if (!translationObj) {
139
+ throw new TypeError(`Locale '${locale}' not found; did you forget to import @hebcal/locales?`);
140
+ }
141
+ }
142
+ else {
143
+ Locale.useLocale('en');
144
+ }
145
+ const evts = [];
146
+ let sedra;
147
+ let holidaysYear;
148
+ let beginOmer = -1;
149
+ let endOmer = -1;
150
+ let currentYear = -1;
151
+ const startAndEnd = getStartAndEnd(options);
152
+ warnUnrecognizedOptions(options);
153
+ const startAbs = startAndEnd[0];
154
+ const endAbs = startAndEnd[1];
155
+ const startGreg = abs2greg(startAbs);
156
+ if (startGreg.getFullYear() < 100) {
157
+ options.candlelighting = false;
158
+ }
159
+ for (let abs = startAbs; abs <= endAbs; abs++) {
160
+ const hd = new HDate(abs);
161
+ const hyear = hd.getFullYear();
162
+ if (hyear !== currentYear) {
163
+ currentYear = hyear;
164
+ holidaysYear = getHolidaysForYear_(currentYear);
165
+ if (options.sedrot) {
166
+ sedra = getSedra(currentYear, il);
167
+ }
168
+ if (options.omer) {
169
+ beginOmer = HDate.hebrew2abs(currentYear, NISAN, 16);
170
+ endOmer = HDate.hebrew2abs(currentYear, SIVAN, 5);
171
+ }
172
+ }
173
+ const prevEventsLength = evts.length;
174
+ const dow = hd.getDay();
175
+ const isFriday = dow === FRI;
176
+ const isSaturday = dow === SAT;
177
+ let candlesEv;
178
+ const holidays = holidaysYear.get(hd.toString()) || [];
179
+ for (const ev of holidays) {
180
+ candlesEv = appendHolidayAndRelated(candlesEv, evts, ev, options, isFriday, isSaturday, hasUserMask);
181
+ }
182
+ if (options.sedrot && isSaturday) {
183
+ const parsha0 = sedra.lookup(abs);
184
+ if (!parsha0.chag) {
185
+ evts.push(new ParshaEvent(hd, parsha0.parsha, il, parsha0.num));
186
+ }
187
+ }
188
+ const dailyLearning = options.dailyLearning;
189
+ if (typeof dailyLearning === 'object') {
190
+ const events = makeDailyLearning(hd, dailyLearning, il);
191
+ evts.push(...events);
192
+ }
193
+ if (options.omer && abs >= beginOmer && abs <= endOmer) {
194
+ const omer = abs - beginOmer + 1;
195
+ const omerEv = makeOmerEvent(hd, omer, options);
196
+ evts.push(omerEv);
197
+ }
198
+ if (isSaturday && (options.molad || options.shabbatMevarchim)) {
199
+ const events = makeMoladAndMevarchimChodesh(hd, options);
200
+ evts.push(...events);
201
+ }
202
+ if (!candlesEv && options.candlelighting && (isFriday || isSaturday)) {
203
+ candlesEv = makeCandleEvent(undefined, hd, options, isFriday, isSaturday);
204
+ if (isFriday && candlesEv && sedra) {
205
+ const parsha = sedra.lookup(abs);
206
+ const pe = new ParshaEvent(hd.next(), parsha.parsha, il, parsha.num);
207
+ candlesEv.memo = pe.render(options.locale);
208
+ }
209
+ }
210
+ // suppress Havdalah when options.havdalahMins=0 or options.havdalahDeg=0
211
+ if (candlesEv instanceof HavdalahEvent &&
212
+ (options.havdalahMins === 0 || options.havdalahDeg === 0)) {
213
+ candlesEv = undefined;
214
+ }
215
+ if (candlesEv) {
216
+ evts.push(candlesEv);
217
+ }
218
+ if (options.addHebrewDates ||
219
+ (options.addHebrewDatesForEvents && prevEventsLength !== evts.length)) {
220
+ const e2 = new HebrewDateEvent(hd);
221
+ if (prevEventsLength === evts.length) {
222
+ evts.push(e2);
223
+ }
224
+ else {
225
+ evts.splice(prevEventsLength, 0, e2);
226
+ }
227
+ }
228
+ }
229
+ return evts;
230
+ }
231
+ const FRI = 5;
232
+ const SAT = 6;
233
+ const NISAN = months.NISAN;
234
+ const SIVAN = months.SIVAN;
235
+ const ELUL = months.ELUL;
236
+ const LIGHT_CANDLES = flags.LIGHT_CANDLES;
237
+ const YOM_TOV_ENDS = flags.YOM_TOV_ENDS;
238
+ const CHUL_ONLY = flags.CHUL_ONLY;
239
+ const IL_ONLY = flags.IL_ONLY;
240
+ const LIGHT_CANDLES_TZEIS = flags.LIGHT_CANDLES_TZEIS;
241
+ const CHANUKAH_CANDLES = flags.CHANUKAH_CANDLES;
242
+ const MINOR_FAST = flags.MINOR_FAST;
243
+ const SPECIAL_SHABBAT = flags.SPECIAL_SHABBAT;
244
+ const MODERN_HOLIDAY = flags.MODERN_HOLIDAY;
245
+ const MAJOR_FAST = flags.MAJOR_FAST;
246
+ const ROSH_CHODESH = flags.ROSH_CHODESH;
247
+ const PARSHA_HASHAVUA = flags.PARSHA_HASHAVUA;
248
+ const DAF_YOMI = flags.DAF_YOMI;
249
+ const MISHNA_YOMI = flags.MISHNA_YOMI;
250
+ const NACH_YOMI = flags.NACH_YOMI;
251
+ const YERUSHALMI_YOMI = flags.YERUSHALMI_YOMI;
252
+ const OMER_COUNT = flags.OMER_COUNT;
253
+ const SHABBAT_MEVARCHIM = flags.SHABBAT_MEVARCHIM;
254
+ const MINOR_HOLIDAY = flags.MINOR_HOLIDAY;
255
+ const EREV = flags.EREV;
256
+ const CHOL_HAMOED = flags.CHOL_HAMOED;
257
+ const YOM_KIPPUR_KATAN = flags.YOM_KIPPUR_KATAN;
258
+ const unrecognizedAlreadyWarned = new Set();
259
+ const RECOGNIZED_OPTIONS = {
260
+ location: 1,
261
+ year: 1,
262
+ isHebrewYear: 1,
263
+ month: 1,
264
+ numYears: 1,
265
+ start: 1,
266
+ end: 1,
267
+ candlelighting: 1,
268
+ candleLightingMins: 1,
269
+ havdalahMins: 1,
270
+ havdalahDeg: 1,
271
+ fastEndDeg: 1,
272
+ sedrot: 1,
273
+ il: 1,
274
+ noMinorFast: 1,
275
+ noModern: 1,
276
+ shabbatMevarchim: 1,
277
+ noRoshChodesh: 1,
278
+ noSpecialShabbat: 1,
279
+ noHolidays: 1,
280
+ omer: 1,
281
+ molad: 1,
282
+ ashkenazi: 1,
283
+ locale: 1,
284
+ addHebrewDates: 1,
285
+ addHebrewDatesForEvents: 1,
286
+ mask: 1,
287
+ yomKippurKatan: 1,
288
+ hour12: 1,
289
+ dailyLearning: 1,
290
+ useElevation: 1,
291
+ };
292
+ /**
293
+ * @private
294
+ */
295
+ function warnUnrecognizedOptions(options) {
296
+ for (const k of Object.keys(options)) {
297
+ if (typeof RECOGNIZED_OPTIONS[k] === 'undefined' &&
298
+ !unrecognizedAlreadyWarned.has(k)) {
299
+ console.warn(`Ignoring unrecognized HebrewCalendar option: ${k}`);
300
+ unrecognizedAlreadyWarned.add(k);
301
+ }
302
+ }
303
+ }
304
+ const israelCityOffset = {
305
+ Jerusalem: 40,
306
+ Haifa: 30,
307
+ "Zikhron Ya'aqov": 30,
308
+ "Zikhron Ya'akov": 30,
309
+ 'Zikhron Yaakov': 30,
310
+ "Zichron Ya'akov": 30,
311
+ 'Zichron Yaakov': 30,
312
+ };
313
+ const geoIdCandleOffset = {
314
+ '281184': 40, // Jerusalem
315
+ '294801': 30, // Haifa
316
+ '293067': 30, // Zikhron Yaakov
317
+ };
318
+ /**
319
+ * @private
320
+ * @constant
321
+ * This calculation is based on the position of the sun 36 minutes after sunset in Jerusalem
322
+ * around the equinox / equilux, which is 8.5° below geometric zenith.
323
+ * The Ohr Meir considers this the time that 3 small stars are visible,
324
+ * which is later than the required 3 medium stars.
325
+ * @see {https://kosherjava.com/zmanim/docs/api/com/kosherjava/zmanim/ZmanimCalendar.html#ZENITH_8_POINT_5}
326
+ */
327
+ const TZEIT_3SMALL_STARS = 8.5;
328
+ /**
329
+ * @private
330
+ * @constant
331
+ * This calculation is based on observation of 3 medium sized stars by Dr. Baruch Cohen
332
+ * in his calendar published in in 1899 in Strasbourg, France.
333
+ * This calculates to 7.0833333° below geometric zenith.
334
+ * @see {https://kosherjava.com/zmanim/docs/api/com/kosherjava/zmanim/ComplexZmanimCalendar.html#ZENITH_7_POINT_083}
335
+ */
336
+ const TZEIT_3MEDIUM_STARS = 7.0833333;
337
+ /**
338
+ * Modifies options in-place
339
+ * @private
340
+ */
341
+ function checkCandleOptions(options) {
342
+ if (!options.candlelighting) {
343
+ return;
344
+ }
345
+ const location = options.location;
346
+ if (typeof location === 'undefined' || !(location instanceof Location)) {
347
+ throw new TypeError('options.candlelighting requires valid options.location');
348
+ }
349
+ if (typeof options.havdalahMins === 'number' &&
350
+ typeof options.havdalahDeg === 'number') {
351
+ throw new TypeError('options.havdalahMins and options.havdalahDeg are mutually exclusive');
352
+ }
353
+ let min = Number(options.candleLightingMins) || 18;
354
+ if (location.getIsrael() && Math.abs(min) === 18) {
355
+ min = overrideIsraelCandleMins(location, min);
356
+ }
357
+ options.candleLightingMins = -1 * Math.abs(min);
358
+ if (typeof options.havdalahMins === 'number') {
359
+ options.havdalahMins = Math.abs(options.havdalahMins);
360
+ }
361
+ else if (typeof options.havdalahDeg === 'number') {
362
+ options.havdalahDeg = Math.abs(options.havdalahDeg);
363
+ }
364
+ else {
365
+ options.havdalahDeg = TZEIT_3SMALL_STARS;
366
+ }
367
+ if (typeof options.fastEndDeg !== 'number') {
368
+ options.fastEndDeg = TZEIT_3MEDIUM_STARS;
369
+ }
370
+ }
371
+ function overrideIsraelCandleMins(location, min) {
372
+ const geoid = location.getGeoId();
373
+ if (geoid) {
374
+ const offset = geoIdCandleOffset[geoid];
375
+ if (typeof offset === 'number') {
376
+ return offset;
377
+ }
378
+ }
379
+ const shortName = location.getShortName();
380
+ if (shortName) {
381
+ const offset = israelCityOffset[shortName];
382
+ if (typeof offset === 'number') {
383
+ return offset;
384
+ }
385
+ }
386
+ return min;
387
+ }
388
+ /**
389
+ * Mask to filter Holiday array
390
+ * @private
391
+ */
392
+ function getMaskFromOptions(options) {
393
+ var _a;
394
+ if (typeof options.mask === 'number') {
395
+ return setOptionsFromMask(options);
396
+ }
397
+ const il = options.il || ((_a = options.location) === null || _a === void 0 ? void 0 : _a.getIsrael()) || false;
398
+ let mask = 0;
399
+ // default options
400
+ if (!options.noHolidays) {
401
+ mask |=
402
+ ROSH_CHODESH |
403
+ YOM_TOV_ENDS |
404
+ MINOR_FAST |
405
+ SPECIAL_SHABBAT |
406
+ MODERN_HOLIDAY |
407
+ MAJOR_FAST |
408
+ MINOR_HOLIDAY |
409
+ EREV |
410
+ CHOL_HAMOED |
411
+ LIGHT_CANDLES |
412
+ LIGHT_CANDLES_TZEIS |
413
+ CHANUKAH_CANDLES;
414
+ }
415
+ if (options.candlelighting) {
416
+ mask |= LIGHT_CANDLES | LIGHT_CANDLES_TZEIS | YOM_TOV_ENDS;
417
+ }
418
+ // suppression of defaults
419
+ if (options.noRoshChodesh) {
420
+ mask &= ~ROSH_CHODESH;
421
+ }
422
+ if (options.noModern) {
423
+ mask &= ~MODERN_HOLIDAY;
424
+ }
425
+ if (options.noMinorFast) {
426
+ mask &= ~MINOR_FAST;
427
+ }
428
+ if (options.noSpecialShabbat) {
429
+ mask &= ~SPECIAL_SHABBAT;
430
+ mask &= ~SHABBAT_MEVARCHIM;
431
+ }
432
+ if (il) {
433
+ mask |= IL_ONLY;
434
+ }
435
+ else {
436
+ mask |= CHUL_ONLY;
437
+ }
438
+ // non-default options
439
+ if (options.sedrot) {
440
+ mask |= PARSHA_HASHAVUA;
441
+ }
442
+ if (options.omer) {
443
+ mask |= OMER_COUNT;
444
+ }
445
+ if (options.shabbatMevarchim) {
446
+ mask |= SHABBAT_MEVARCHIM;
447
+ }
448
+ if (options.yomKippurKatan) {
449
+ mask |= YOM_KIPPUR_KATAN;
450
+ }
451
+ if (options.dailyLearning) {
452
+ const dailyLearning = options.dailyLearning;
453
+ if (dailyLearning.dafYomi) {
454
+ mask |= DAF_YOMI;
455
+ }
456
+ if (dailyLearning.mishnaYomi) {
457
+ mask |= MISHNA_YOMI;
458
+ }
459
+ if (dailyLearning.nachYomi) {
460
+ mask |= NACH_YOMI;
461
+ }
462
+ if (dailyLearning.yerushalmi) {
463
+ mask |= YERUSHALMI_YOMI;
464
+ }
465
+ }
466
+ return mask;
467
+ }
468
+ const MASK_LIGHT_CANDLES = LIGHT_CANDLES | LIGHT_CANDLES_TZEIS | CHANUKAH_CANDLES | YOM_TOV_ENDS;
469
+ const defaultLocation = new Location(0, 0, false, 'UTC');
470
+ /**
471
+ * @private
472
+ */
473
+ function setOptionsFromMask(options) {
474
+ const m = options.mask || 0;
475
+ if (m & ROSH_CHODESH)
476
+ delete options.noRoshChodesh;
477
+ if (m & MODERN_HOLIDAY)
478
+ delete options.noModern;
479
+ if (m & MINOR_FAST)
480
+ delete options.noMinorFast;
481
+ if (m & SPECIAL_SHABBAT)
482
+ delete options.noSpecialShabbat;
483
+ if (m & PARSHA_HASHAVUA)
484
+ options.sedrot = true;
485
+ if (m & (DAF_YOMI | MISHNA_YOMI | NACH_YOMI | YERUSHALMI_YOMI)) {
486
+ options.dailyLearning = options.dailyLearning || {};
487
+ if (m & DAF_YOMI) {
488
+ options.dailyLearning.dafYomi = true;
489
+ }
490
+ if (m & MISHNA_YOMI) {
491
+ options.dailyLearning.mishnaYomi = true;
492
+ }
493
+ if (m & NACH_YOMI) {
494
+ options.dailyLearning.nachYomi = true;
495
+ }
496
+ if (m & YERUSHALMI_YOMI) {
497
+ options.dailyLearning.yerushalmi = 1;
498
+ }
499
+ }
500
+ if (m & OMER_COUNT)
501
+ options.omer = true;
502
+ if (m & SHABBAT_MEVARCHIM)
503
+ options.shabbatMevarchim = true;
504
+ if (m & YOM_KIPPUR_KATAN)
505
+ options.yomKippurKatan = true;
506
+ return m;
507
+ }
508
+ /**
509
+ * Appends the Event `ev` to the `events` array. Also may add related
510
+ * timed events like candle-lighting or fast start/end
511
+ * @private
512
+ */
513
+ function appendHolidayAndRelated(candlesEv, events, ev, options, isFriday, isSaturday, hasUserMask) {
514
+ const il = options.il || false;
515
+ if (!ev.observedIn(il)) {
516
+ return candlesEv; // holiday isn't observed here; bail out early
517
+ }
518
+ const eFlags = ev.getFlags();
519
+ if ((!options.yomKippurKatan && eFlags & YOM_KIPPUR_KATAN) ||
520
+ (options.noModern && eFlags & MODERN_HOLIDAY)) {
521
+ return candlesEv; // bail out early
522
+ }
523
+ const isMajorFast = Boolean(eFlags & MAJOR_FAST);
524
+ const isMinorFast = Boolean(eFlags & MINOR_FAST);
525
+ let fastEv;
526
+ if (options.candlelighting && (isMajorFast || isMinorFast)) {
527
+ ev = fastEv = makeFastStartEnd(ev, options);
528
+ if (fastEv.startEvent &&
529
+ (isMajorFast || (isMinorFast && !options.noMinorFast))) {
530
+ events.push(fastEv.startEvent);
531
+ }
532
+ }
533
+ if (eFlags & Number(options.mask) || (!eFlags && !hasUserMask)) {
534
+ if (options.candlelighting && eFlags & MASK_LIGHT_CANDLES) {
535
+ const hd = ev.getDate();
536
+ candlesEv = makeCandleEvent(ev, hd, options, isFriday, isSaturday);
537
+ if (eFlags & CHANUKAH_CANDLES && candlesEv && !options.noHolidays) {
538
+ // Replace Chanukah event with a clone that includes candle lighting time.
539
+ // For clarity, allow a "duplicate" candle lighting event to remain for Shabbat
540
+ const chanukahEv = makeWeekdayChanukahCandleLighting(ev, hd, options);
541
+ if (chanukahEv) {
542
+ if (isFriday || isSaturday) {
543
+ chanukahEv.eventTime = candlesEv.eventTime;
544
+ chanukahEv.eventTimeStr = candlesEv.eventTimeStr;
545
+ }
546
+ ev = chanukahEv;
547
+ }
548
+ candlesEv = undefined;
549
+ }
550
+ }
551
+ if (!options.noHolidays ||
552
+ (options.yomKippurKatan && eFlags & YOM_KIPPUR_KATAN)) {
553
+ events.push(ev); // the original event itself
554
+ }
555
+ }
556
+ if ((isMajorFast || (isMinorFast && !options.noMinorFast)) &&
557
+ fastEv &&
558
+ fastEv.endEvent) {
559
+ events.push(fastEv.endEvent);
560
+ }
561
+ return candlesEv;
562
+ }
563
+ function makeMoladAndMevarchimChodesh(hd, options) {
564
+ const evts = [];
565
+ const hmonth = hd.getMonth();
566
+ const hdate = hd.getDate();
567
+ if (hmonth !== ELUL && hdate >= 23 && hdate <= 29) {
568
+ const hyear = hd.getFullYear();
569
+ const monNext = hmonth === HDate.monthsInYear(hyear) ? NISAN : hmonth + 1;
570
+ if (options.molad) {
571
+ evts.push(new MoladEvent(hd, hyear, monNext, options));
572
+ }
573
+ if (options.shabbatMevarchim) {
574
+ const nextMonthName = HDate.getMonthName(monNext, hyear);
575
+ const molad = new Molad(hyear, monNext);
576
+ const memo = molad.render(options.locale || 'en', options);
577
+ evts.push(new MevarchimChodeshEvent(hd, nextMonthName, memo));
578
+ }
579
+ }
580
+ return evts;
581
+ }
582
+ function dailyLearningName(key, val) {
583
+ if (key === 'yerushalmi') {
584
+ return val === 2 ? 'yerushalmi-schottenstein' : 'yerushalmi-vilna';
585
+ }
586
+ return key;
587
+ }
588
+ function makeDailyLearning(hd, dailyLearning, il) {
589
+ const evts = [];
590
+ for (const [key, val] of Object.entries(dailyLearning)) {
591
+ if (val) {
592
+ const name = dailyLearningName(key, val);
593
+ const learningEv = DailyLearning.lookup(name, hd, il);
594
+ if (learningEv) {
595
+ evts.push(learningEv);
596
+ }
597
+ }
598
+ }
599
+ return evts;
600
+ }
601
+ function makeOmerEvent(hd, omerDay, options) {
602
+ const omerEv = new OmerEvent(hd, omerDay);
603
+ if (options.candlelighting) {
604
+ const location = options.location;
605
+ const zmanim = new Zmanim(location, hd.prev(), false);
606
+ const tzeit = zmanim.tzeit(7.0833);
607
+ if (!isNaN(tzeit.getTime())) {
608
+ omerEv.alarm = tzeit;
609
+ }
610
+ }
611
+ return omerEv;
612
+ }
613
+
614
+ export { calendar };
615
+ //# sourceMappingURL=calendar.js.map