@hebcal/core 6.0.6 → 6.0.7
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 +2 -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 +2 -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 +15 -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,163 @@
|
|
|
1
|
+
/* eslint-disable max-len */
|
|
2
|
+
import { months } from '@hebcal/hdate';
|
|
3
|
+
import { flags } from './event';
|
|
4
|
+
import { ChanukahEvent, HolidayEvent } from './HolidayEvent';
|
|
5
|
+
import { Zmanim } from './zmanim';
|
|
6
|
+
import { TimedEvent, CandleLightingEvent, HavdalahEvent } from './TimedEvent';
|
|
7
|
+
const LIGHT_CANDLES = flags.LIGHT_CANDLES;
|
|
8
|
+
const LIGHT_CANDLES_TZEIS = flags.LIGHT_CANDLES_TZEIS;
|
|
9
|
+
/**
|
|
10
|
+
* @private
|
|
11
|
+
*/
|
|
12
|
+
export function makeCandleEvent(ev, hd, options, isFriday, isSaturday) {
|
|
13
|
+
let havdalahTitle = false;
|
|
14
|
+
let useHavdalahOffset = isSaturday;
|
|
15
|
+
let mask = ev ? ev.getFlags() : LIGHT_CANDLES;
|
|
16
|
+
if (typeof ev !== 'undefined') {
|
|
17
|
+
// if linked event && dow == FRI, use Candle lighting time & title
|
|
18
|
+
if (!isFriday) {
|
|
19
|
+
if (mask & (LIGHT_CANDLES_TZEIS | flags.CHANUKAH_CANDLES)) {
|
|
20
|
+
useHavdalahOffset = true;
|
|
21
|
+
}
|
|
22
|
+
else if (mask & flags.YOM_TOV_ENDS) {
|
|
23
|
+
havdalahTitle = true;
|
|
24
|
+
useHavdalahOffset = true;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
else if (isSaturday) {
|
|
29
|
+
havdalahTitle = true;
|
|
30
|
+
mask = LIGHT_CANDLES_TZEIS;
|
|
31
|
+
}
|
|
32
|
+
// if Havdalah offset is 0 or undefined, we'll use tzeit time
|
|
33
|
+
const offset = useHavdalahOffset
|
|
34
|
+
? Number(options.havdalahMins)
|
|
35
|
+
: Number(options.candleLightingMins);
|
|
36
|
+
const location = options.location;
|
|
37
|
+
const useElevation = Boolean(options.useElevation);
|
|
38
|
+
const zmanim = new Zmanim(location, hd, useElevation);
|
|
39
|
+
const time = useHavdalahOffset && !offset
|
|
40
|
+
? zmanim.tzeit(options.havdalahDeg)
|
|
41
|
+
: zmanim.sunsetOffset(offset, true);
|
|
42
|
+
if (isNaN(time.getTime())) {
|
|
43
|
+
return undefined; // no sunset
|
|
44
|
+
}
|
|
45
|
+
if (havdalahTitle) {
|
|
46
|
+
return new HavdalahEvent(hd, mask, time, location, options.havdalahMins, ev, options);
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
mask |= LIGHT_CANDLES;
|
|
50
|
+
return new CandleLightingEvent(hd, mask, time, location, ev, options);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
const FAST_BEGINS = 'Fast begins';
|
|
54
|
+
const FAST_ENDS = 'Fast ends';
|
|
55
|
+
/** A fast day also contains a start and end time */
|
|
56
|
+
export class FastDayEvent extends HolidayEvent {
|
|
57
|
+
constructor(linkedEvent, startEvent, endEvent) {
|
|
58
|
+
super(linkedEvent.getDate(), linkedEvent.getDesc(), linkedEvent.getFlags());
|
|
59
|
+
this.linkedEvent = linkedEvent;
|
|
60
|
+
this.startEvent = startEvent;
|
|
61
|
+
this.endEvent = endEvent;
|
|
62
|
+
}
|
|
63
|
+
render(locale) {
|
|
64
|
+
return this.linkedEvent.render(locale);
|
|
65
|
+
}
|
|
66
|
+
renderBrief(locale) {
|
|
67
|
+
return this.linkedEvent.renderBrief(locale);
|
|
68
|
+
}
|
|
69
|
+
urlDateSuffix() {
|
|
70
|
+
return this.linkedEvent.urlDateSuffix();
|
|
71
|
+
}
|
|
72
|
+
url() {
|
|
73
|
+
return this.linkedEvent.url();
|
|
74
|
+
}
|
|
75
|
+
getEmoji() {
|
|
76
|
+
return this.linkedEvent.getEmoji();
|
|
77
|
+
}
|
|
78
|
+
getCategories() {
|
|
79
|
+
return this.linkedEvent.getCategories();
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Makes a pair of events representing fast start and end times
|
|
84
|
+
* @private
|
|
85
|
+
*/
|
|
86
|
+
export function makeFastStartEnd(ev, options) {
|
|
87
|
+
const desc = ev.getDesc();
|
|
88
|
+
if (desc === 'Yom Kippur') {
|
|
89
|
+
throw new RangeError('YK does not require this function');
|
|
90
|
+
}
|
|
91
|
+
const hd = ev.getDate();
|
|
92
|
+
const dt = hd.greg();
|
|
93
|
+
const location = options.location;
|
|
94
|
+
const fastEndDeg = options.fastEndDeg;
|
|
95
|
+
const useElevation = Boolean(options.useElevation);
|
|
96
|
+
const zmanim = new Zmanim(location, dt, useElevation);
|
|
97
|
+
let startEvent;
|
|
98
|
+
let endEvent;
|
|
99
|
+
if (desc === "Erev Tish'a B'Av") {
|
|
100
|
+
const sunset = zmanim.sunset();
|
|
101
|
+
if (!isNaN(sunset.getTime())) {
|
|
102
|
+
startEvent = makeTimedEvent(ev, sunset, FAST_BEGINS, options);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
else if (desc.startsWith("Tish'a B'Av")) {
|
|
106
|
+
const tzeit = zmanim.tzeit(fastEndDeg);
|
|
107
|
+
if (!isNaN(tzeit.getTime())) {
|
|
108
|
+
endEvent = makeTimedEvent(ev, tzeit, FAST_ENDS, options);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
else {
|
|
112
|
+
const dawn = zmanim.alotHaShachar();
|
|
113
|
+
if (!isNaN(dawn.getTime())) {
|
|
114
|
+
startEvent = makeTimedEvent(ev, dawn, FAST_BEGINS, options);
|
|
115
|
+
}
|
|
116
|
+
if (dt.getDay() !== 5 &&
|
|
117
|
+
!(hd.getDate() === 14 && hd.getMonth() === months.NISAN)) {
|
|
118
|
+
const tzeit = zmanim.tzeit(fastEndDeg);
|
|
119
|
+
if (!isNaN(tzeit.getTime())) {
|
|
120
|
+
endEvent = makeTimedEvent(ev, tzeit, FAST_ENDS, options);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
const ev2 = new FastDayEvent(ev, startEvent, endEvent);
|
|
125
|
+
// copy properties such as memo or emoji
|
|
126
|
+
Object.assign(ev2, ev);
|
|
127
|
+
return ev2;
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* @private
|
|
131
|
+
*/
|
|
132
|
+
function makeTimedEvent(ev, time, desc, options) {
|
|
133
|
+
const location = options.location;
|
|
134
|
+
const hd = ev.getDate();
|
|
135
|
+
return new TimedEvent(hd, desc, ev.getFlags(), time, location, ev, options);
|
|
136
|
+
}
|
|
137
|
+
export class TimedChanukahEvent extends ChanukahEvent {
|
|
138
|
+
constructor(ev, eventTime, location) {
|
|
139
|
+
super(ev.getDate(), ev.getDesc(), ev.getFlags(), ev.chanukahDay);
|
|
140
|
+
this.eventTime = Zmanim.roundTime(eventTime);
|
|
141
|
+
const timeFormat = location.getTimeFormatter();
|
|
142
|
+
this.eventTimeStr = Zmanim.formatTime(this.eventTime, timeFormat);
|
|
143
|
+
this.location = location;
|
|
144
|
+
this.emoji = ev.emoji;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Makes a candle-lighting event for Chankah (not on Friday/Saturday).
|
|
149
|
+
* At one point this used civil dusk (6 degrees below horizon).
|
|
150
|
+
* Another source suggests 4.6667 degrees below horizon.
|
|
151
|
+
* @private
|
|
152
|
+
*/
|
|
153
|
+
export function makeWeekdayChanukahCandleLighting(ev, options) {
|
|
154
|
+
const hd = ev.getDate();
|
|
155
|
+
const location = options.location;
|
|
156
|
+
const useElevation = Boolean(options.useElevation);
|
|
157
|
+
const zmanim = new Zmanim(location, hd.greg(), useElevation);
|
|
158
|
+
const candleLightingTime = zmanim.beinHaShmashos();
|
|
159
|
+
if (isNaN(candleLightingTime.getTime())) {
|
|
160
|
+
return null;
|
|
161
|
+
}
|
|
162
|
+
return new TimedChanukahEvent(ev, candleLightingTime, location);
|
|
163
|
+
}
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
import { HDate } from '@hebcal/hdate';
|
|
2
|
+
import './locale';
|
|
3
|
+
/**
|
|
4
|
+
* Holiday flags for Event. These flags are typically
|
|
5
|
+
* combined using bitwise arithmetic to form a mask.
|
|
6
|
+
* @readonly
|
|
7
|
+
* @enum {number}
|
|
8
|
+
*/
|
|
9
|
+
export declare const flags: {
|
|
10
|
+
/** Chag, yontiff, yom tov */
|
|
11
|
+
readonly CHAG: 1;
|
|
12
|
+
/** Light candles 18 minutes before sundown */
|
|
13
|
+
readonly LIGHT_CANDLES: 2;
|
|
14
|
+
/** End of holiday (end of Yom Tov) */
|
|
15
|
+
readonly YOM_TOV_ENDS: 4;
|
|
16
|
+
/** Observed only in the Diaspora (chutz l'aretz) */
|
|
17
|
+
readonly CHUL_ONLY: 8;
|
|
18
|
+
/** Observed only in Israel */
|
|
19
|
+
readonly IL_ONLY: 16;
|
|
20
|
+
/** Light candles in the evening at Tzeit time (3 small stars) */
|
|
21
|
+
readonly LIGHT_CANDLES_TZEIS: 32;
|
|
22
|
+
/** Candle-lighting for Chanukah */
|
|
23
|
+
readonly CHANUKAH_CANDLES: 64;
|
|
24
|
+
/** Rosh Chodesh, beginning of a new Hebrew month */
|
|
25
|
+
readonly ROSH_CHODESH: 128;
|
|
26
|
+
/** Minor fasts like Tzom Tammuz, Ta'anit Esther, ... */
|
|
27
|
+
readonly MINOR_FAST: 256;
|
|
28
|
+
/** Shabbat Shekalim, Zachor, ... */
|
|
29
|
+
readonly SPECIAL_SHABBAT: 512;
|
|
30
|
+
/** Weekly sedrot on Saturdays */
|
|
31
|
+
readonly PARSHA_HASHAVUA: 1024;
|
|
32
|
+
/** Daily page of Talmud (Bavli) */
|
|
33
|
+
readonly DAF_YOMI: 2048;
|
|
34
|
+
/** Days of the Omer */
|
|
35
|
+
readonly OMER_COUNT: 4096;
|
|
36
|
+
/** Yom HaShoah, Yom HaAtzma'ut, ... */
|
|
37
|
+
readonly MODERN_HOLIDAY: 8192;
|
|
38
|
+
/** Yom Kippur and Tish'a B'Av */
|
|
39
|
+
readonly MAJOR_FAST: 16384;
|
|
40
|
+
/** On the Saturday before Rosh Chodesh */
|
|
41
|
+
readonly SHABBAT_MEVARCHIM: 32768;
|
|
42
|
+
/** Molad */
|
|
43
|
+
readonly MOLAD: 65536;
|
|
44
|
+
/** Yahrzeit or Hebrew Anniversary */
|
|
45
|
+
readonly USER_EVENT: 131072;
|
|
46
|
+
/** Daily Hebrew date ("11th of Sivan, 5780") */
|
|
47
|
+
readonly HEBREW_DATE: 262144;
|
|
48
|
+
/** A holiday that's not major, modern, rosh chodesh, or a fast day */
|
|
49
|
+
readonly MINOR_HOLIDAY: 524288;
|
|
50
|
+
/** Evening before a major or minor holiday */
|
|
51
|
+
readonly EREV: 1048576;
|
|
52
|
+
/** Chol haMoed, intermediate days of Pesach or Sukkot */
|
|
53
|
+
readonly CHOL_HAMOED: 2097152;
|
|
54
|
+
/** Mishna Yomi */
|
|
55
|
+
readonly MISHNA_YOMI: 4194304;
|
|
56
|
+
/** Yom Kippur Katan, minor day of atonement on the day preceeding each Rosh Chodesh */
|
|
57
|
+
readonly YOM_KIPPUR_KATAN: 8388608;
|
|
58
|
+
/** Daily page of Jerusalem Talmud (Yerushalmi) */
|
|
59
|
+
readonly YERUSHALMI_YOMI: 16777216;
|
|
60
|
+
/** Nach Yomi */
|
|
61
|
+
readonly NACH_YOMI: 33554432;
|
|
62
|
+
/** Daily Learning */
|
|
63
|
+
readonly DAILY_LEARNING: 67108864;
|
|
64
|
+
/** Yizkor */
|
|
65
|
+
readonly YIZKOR: 134217728;
|
|
66
|
+
};
|
|
67
|
+
/**
|
|
68
|
+
* Represents an Event with a title, date, and flags.
|
|
69
|
+
*
|
|
70
|
+
* Events are used to represent holidays, candle-lighting times,
|
|
71
|
+
* Torah readings, and more.
|
|
72
|
+
*
|
|
73
|
+
* To get the title of the event a language other than English
|
|
74
|
+
* with Sephardic transliterations, use the `render()` method.
|
|
75
|
+
*/
|
|
76
|
+
export declare class Event {
|
|
77
|
+
/** Hebrew date of this event */
|
|
78
|
+
readonly date: HDate;
|
|
79
|
+
/**
|
|
80
|
+
* Untranslated title of this event. Note that these description
|
|
81
|
+
* strings are always in English and will remain stable across releases.
|
|
82
|
+
* To get the title of the event in another language, use the
|
|
83
|
+
* `render()` method.
|
|
84
|
+
*/
|
|
85
|
+
readonly desc: string;
|
|
86
|
+
/** Bitmask of optional event flags. See {@link flags} */
|
|
87
|
+
readonly mask: number;
|
|
88
|
+
/** Optional emoji character such as ✡️, 🕯️, 🕎, 🕍, 🌒 */
|
|
89
|
+
emoji?: string;
|
|
90
|
+
/** Optional longer description or memo text */
|
|
91
|
+
memo?: string;
|
|
92
|
+
/** Alarms are used by iCalendar feeds */
|
|
93
|
+
alarm?: Date | string | boolean;
|
|
94
|
+
/**
|
|
95
|
+
* Constructs Event
|
|
96
|
+
* @param date Hebrew date event occurs
|
|
97
|
+
* @param desc Description (not translated)
|
|
98
|
+
* @param [mask=0] optional bitmask of holiday flags (see {@link flags})
|
|
99
|
+
* @param [attrs={}] optional additional attributes (e.g. `eventTimeStr`, `cholHaMoedDay`)
|
|
100
|
+
*/
|
|
101
|
+
constructor(date: HDate, desc: string, mask?: number, attrs?: object);
|
|
102
|
+
/**
|
|
103
|
+
* Hebrew date of this event
|
|
104
|
+
*/
|
|
105
|
+
getDate(): HDate;
|
|
106
|
+
/**
|
|
107
|
+
* Gregorian date of this event
|
|
108
|
+
*/
|
|
109
|
+
greg(): Date;
|
|
110
|
+
/**
|
|
111
|
+
* Untranslated title of this event. Note that these description
|
|
112
|
+
* strings are always in English and will remain stable across releases.
|
|
113
|
+
* To get the title of the event in another language, use the
|
|
114
|
+
* `render()` method.
|
|
115
|
+
*/
|
|
116
|
+
getDesc(): string;
|
|
117
|
+
/**
|
|
118
|
+
* Bitmask of optional event flags. See {@link flags}
|
|
119
|
+
*/
|
|
120
|
+
getFlags(): number;
|
|
121
|
+
/**
|
|
122
|
+
* Returns (translated) description of this event
|
|
123
|
+
* @example
|
|
124
|
+
* const ev = new Event(new HDate(6, 'Sivan', 5749), 'Shavuot', flags.CHAG);
|
|
125
|
+
* ev.render('en'); // 'Shavuot'
|
|
126
|
+
* ev.render('he'); // 'שָׁבוּעוֹת'
|
|
127
|
+
* ev.render('ashkenazi'); // 'Shavuos'
|
|
128
|
+
* @param [locale] Optional locale name (defaults to empty locale)
|
|
129
|
+
*/
|
|
130
|
+
render(locale?: string): string;
|
|
131
|
+
/**
|
|
132
|
+
* Returns a brief (translated) description of this event.
|
|
133
|
+
* For most events, this is the same as render(). For some events, it procudes
|
|
134
|
+
* a shorter text (e.g. without a time or added description).
|
|
135
|
+
* @param [locale] Optional locale name (defaults to empty locale)
|
|
136
|
+
*/
|
|
137
|
+
renderBrief(locale?: string): string;
|
|
138
|
+
/**
|
|
139
|
+
* Optional holiday-specific Emoji or `null`.
|
|
140
|
+
*/
|
|
141
|
+
getEmoji(): string | null;
|
|
142
|
+
/**
|
|
143
|
+
* Returns a simplified (untranslated) description for this event. For example,
|
|
144
|
+
* the `HolidayEvent` class supports
|
|
145
|
+
* "Erev Pesach" => "Pesach", and "Sukkot III (CH''M)" => "Sukkot".
|
|
146
|
+
* For many holidays the basename and the event description are the same.
|
|
147
|
+
*/
|
|
148
|
+
basename(): string;
|
|
149
|
+
/**
|
|
150
|
+
* Returns a URL to hebcal.com or sefaria.org for more detail on the event.
|
|
151
|
+
* Returns `undefined` for events with no detail page.
|
|
152
|
+
*/
|
|
153
|
+
url(): string | undefined;
|
|
154
|
+
/**
|
|
155
|
+
* Is this event observed in Israel?
|
|
156
|
+
* @example
|
|
157
|
+
* const ev1 = new Event(new HDate(7, 'Sivan', 5749), 'Shavuot II', flags.CHAG | flags.CHUL_ONLY);
|
|
158
|
+
* ev1.observedInIsrael(); // false
|
|
159
|
+
* const ev2 = new Event(new HDate(26, 'Kislev', 5749), 'Chanukah: 3 Candles', 0);
|
|
160
|
+
* ev2.observedInIsrael(); // true
|
|
161
|
+
*/
|
|
162
|
+
observedInIsrael(): boolean;
|
|
163
|
+
/**
|
|
164
|
+
* Is this event observed in the Diaspora?
|
|
165
|
+
* @example
|
|
166
|
+
* const ev1 = new Event(new HDate(7, 'Sivan', 5749), 'Shavuot II', flags.CHAG | flags.CHUL_ONLY);
|
|
167
|
+
* ev1.observedInDiaspora(); // true
|
|
168
|
+
* const ev2 = new Event(new HDate(26, 'Kislev', 5749), 'Chanukah: 3 Candles', 0);
|
|
169
|
+
* ev2.observedInDiaspora(); // true
|
|
170
|
+
*/
|
|
171
|
+
observedInDiaspora(): boolean;
|
|
172
|
+
/**
|
|
173
|
+
* Is this event observed in Israel/Diaspora?
|
|
174
|
+
* @example
|
|
175
|
+
* const ev1 = new Event(new HDate(7, 'Sivan', 5749), 'Shavuot II', flags.CHAG | flags.CHUL_ONLY);
|
|
176
|
+
* ev1.observedIn(false); // true
|
|
177
|
+
* ev1.observedIn(true); // false
|
|
178
|
+
* const ev2 = new Event(new HDate(26, 'Kislev', 5749), 'Chanukah: 3 Candles', 0);
|
|
179
|
+
* ev2.observedIn(false); // true
|
|
180
|
+
* ev2.observedIn(true); // true
|
|
181
|
+
* @param il
|
|
182
|
+
*/
|
|
183
|
+
observedIn(il: boolean): boolean;
|
|
184
|
+
/**
|
|
185
|
+
* Returns a list of event categories
|
|
186
|
+
*/
|
|
187
|
+
getCategories(): string[];
|
|
188
|
+
}
|
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
import { HDate, Locale } from '@hebcal/hdate';
|
|
2
|
+
import './locale'; // Adds Hebrew and Ashkenazic translations
|
|
3
|
+
/**
|
|
4
|
+
* Holiday flags for Event. These flags are typically
|
|
5
|
+
* combined using bitwise arithmetic to form a mask.
|
|
6
|
+
* @readonly
|
|
7
|
+
* @enum {number}
|
|
8
|
+
*/
|
|
9
|
+
export const flags = {
|
|
10
|
+
/** Chag, yontiff, yom tov */
|
|
11
|
+
CHAG: 0x000001,
|
|
12
|
+
/** Light candles 18 minutes before sundown */
|
|
13
|
+
LIGHT_CANDLES: 0x000002,
|
|
14
|
+
/** End of holiday (end of Yom Tov) */
|
|
15
|
+
YOM_TOV_ENDS: 0x000004,
|
|
16
|
+
/** Observed only in the Diaspora (chutz l'aretz) */
|
|
17
|
+
CHUL_ONLY: 0x000008,
|
|
18
|
+
/** Observed only in Israel */
|
|
19
|
+
IL_ONLY: 0x000010,
|
|
20
|
+
/** Light candles in the evening at Tzeit time (3 small stars) */
|
|
21
|
+
LIGHT_CANDLES_TZEIS: 0x000020,
|
|
22
|
+
/** Candle-lighting for Chanukah */
|
|
23
|
+
CHANUKAH_CANDLES: 0x000040,
|
|
24
|
+
/** Rosh Chodesh, beginning of a new Hebrew month */
|
|
25
|
+
ROSH_CHODESH: 0x000080,
|
|
26
|
+
/** Minor fasts like Tzom Tammuz, Ta'anit Esther, ... */
|
|
27
|
+
MINOR_FAST: 0x000100,
|
|
28
|
+
/** Shabbat Shekalim, Zachor, ... */
|
|
29
|
+
SPECIAL_SHABBAT: 0x000200,
|
|
30
|
+
/** Weekly sedrot on Saturdays */
|
|
31
|
+
PARSHA_HASHAVUA: 0x000400,
|
|
32
|
+
/** Daily page of Talmud (Bavli) */
|
|
33
|
+
DAF_YOMI: 0x000800,
|
|
34
|
+
/** Days of the Omer */
|
|
35
|
+
OMER_COUNT: 0x001000,
|
|
36
|
+
/** Yom HaShoah, Yom HaAtzma'ut, ... */
|
|
37
|
+
MODERN_HOLIDAY: 0x002000,
|
|
38
|
+
/** Yom Kippur and Tish'a B'Av */
|
|
39
|
+
MAJOR_FAST: 0x004000,
|
|
40
|
+
/** On the Saturday before Rosh Chodesh */
|
|
41
|
+
SHABBAT_MEVARCHIM: 0x008000,
|
|
42
|
+
/** Molad */
|
|
43
|
+
MOLAD: 0x010000,
|
|
44
|
+
/** Yahrzeit or Hebrew Anniversary */
|
|
45
|
+
USER_EVENT: 0x020000,
|
|
46
|
+
/** Daily Hebrew date ("11th of Sivan, 5780") */
|
|
47
|
+
HEBREW_DATE: 0x040000,
|
|
48
|
+
/** A holiday that's not major, modern, rosh chodesh, or a fast day */
|
|
49
|
+
MINOR_HOLIDAY: 0x080000,
|
|
50
|
+
/** Evening before a major or minor holiday */
|
|
51
|
+
EREV: 0x100000,
|
|
52
|
+
/** Chol haMoed, intermediate days of Pesach or Sukkot */
|
|
53
|
+
CHOL_HAMOED: 0x200000,
|
|
54
|
+
/** Mishna Yomi */
|
|
55
|
+
MISHNA_YOMI: 0x400000,
|
|
56
|
+
/** Yom Kippur Katan, minor day of atonement on the day preceeding each Rosh Chodesh */
|
|
57
|
+
YOM_KIPPUR_KATAN: 0x800000,
|
|
58
|
+
/** Daily page of Jerusalem Talmud (Yerushalmi) */
|
|
59
|
+
YERUSHALMI_YOMI: 0x1000000,
|
|
60
|
+
/** Nach Yomi */
|
|
61
|
+
NACH_YOMI: 0x2000000,
|
|
62
|
+
/** Daily Learning */
|
|
63
|
+
DAILY_LEARNING: 0x4000000,
|
|
64
|
+
/** Yizkor */
|
|
65
|
+
YIZKOR: 0x8000000,
|
|
66
|
+
};
|
|
67
|
+
const flagToCategory = [
|
|
68
|
+
[flags.MAJOR_FAST, 'holiday', 'major', 'fast'],
|
|
69
|
+
[flags.CHANUKAH_CANDLES, 'holiday', 'major'],
|
|
70
|
+
[flags.HEBREW_DATE, 'hebdate'],
|
|
71
|
+
[flags.MINOR_FAST, 'holiday', 'fast'],
|
|
72
|
+
[flags.MINOR_HOLIDAY, 'holiday', 'minor'],
|
|
73
|
+
[flags.MODERN_HOLIDAY, 'holiday', 'modern'],
|
|
74
|
+
[flags.MOLAD, 'molad'],
|
|
75
|
+
[flags.OMER_COUNT, 'omer'],
|
|
76
|
+
[flags.PARSHA_HASHAVUA, 'parashat'], // backwards-compat
|
|
77
|
+
[flags.ROSH_CHODESH, 'roshchodesh'],
|
|
78
|
+
[flags.SHABBAT_MEVARCHIM, 'mevarchim'],
|
|
79
|
+
[flags.SPECIAL_SHABBAT, 'holiday', 'shabbat'],
|
|
80
|
+
[flags.USER_EVENT, 'user'],
|
|
81
|
+
[flags.YIZKOR, 'yizkor'],
|
|
82
|
+
];
|
|
83
|
+
/**
|
|
84
|
+
* Represents an Event with a title, date, and flags.
|
|
85
|
+
*
|
|
86
|
+
* Events are used to represent holidays, candle-lighting times,
|
|
87
|
+
* Torah readings, and more.
|
|
88
|
+
*
|
|
89
|
+
* To get the title of the event a language other than English
|
|
90
|
+
* with Sephardic transliterations, use the `render()` method.
|
|
91
|
+
*/
|
|
92
|
+
export class Event {
|
|
93
|
+
/**
|
|
94
|
+
* Constructs Event
|
|
95
|
+
* @param date Hebrew date event occurs
|
|
96
|
+
* @param desc Description (not translated)
|
|
97
|
+
* @param [mask=0] optional bitmask of holiday flags (see {@link flags})
|
|
98
|
+
* @param [attrs={}] optional additional attributes (e.g. `eventTimeStr`, `cholHaMoedDay`)
|
|
99
|
+
*/
|
|
100
|
+
constructor(date, desc, mask = 0, attrs) {
|
|
101
|
+
if (!HDate.isHDate(date)) {
|
|
102
|
+
throw new TypeError(`Invalid Event date: ${date}`);
|
|
103
|
+
}
|
|
104
|
+
else if (typeof desc !== 'string') {
|
|
105
|
+
throw new TypeError(`Invalid Event description: ${desc}`);
|
|
106
|
+
}
|
|
107
|
+
this.date = date;
|
|
108
|
+
this.desc = desc;
|
|
109
|
+
this.mask = +mask;
|
|
110
|
+
if (typeof attrs === 'object' && attrs !== null) {
|
|
111
|
+
Object.assign(this, attrs);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Hebrew date of this event
|
|
116
|
+
*/
|
|
117
|
+
getDate() {
|
|
118
|
+
return this.date;
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Gregorian date of this event
|
|
122
|
+
*/
|
|
123
|
+
greg() {
|
|
124
|
+
return this.date.greg();
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Untranslated title of this event. Note that these description
|
|
128
|
+
* strings are always in English and will remain stable across releases.
|
|
129
|
+
* To get the title of the event in another language, use the
|
|
130
|
+
* `render()` method.
|
|
131
|
+
*/
|
|
132
|
+
getDesc() {
|
|
133
|
+
return this.desc;
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Bitmask of optional event flags. See {@link flags}
|
|
137
|
+
*/
|
|
138
|
+
getFlags() {
|
|
139
|
+
return this.mask;
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Returns (translated) description of this event
|
|
143
|
+
* @example
|
|
144
|
+
* const ev = new Event(new HDate(6, 'Sivan', 5749), 'Shavuot', flags.CHAG);
|
|
145
|
+
* ev.render('en'); // 'Shavuot'
|
|
146
|
+
* ev.render('he'); // 'שָׁבוּעוֹת'
|
|
147
|
+
* ev.render('ashkenazi'); // 'Shavuos'
|
|
148
|
+
* @param [locale] Optional locale name (defaults to empty locale)
|
|
149
|
+
*/
|
|
150
|
+
render(locale) {
|
|
151
|
+
return Locale.gettext(this.desc, locale);
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Returns a brief (translated) description of this event.
|
|
155
|
+
* For most events, this is the same as render(). For some events, it procudes
|
|
156
|
+
* a shorter text (e.g. without a time or added description).
|
|
157
|
+
* @param [locale] Optional locale name (defaults to empty locale)
|
|
158
|
+
*/
|
|
159
|
+
renderBrief(locale) {
|
|
160
|
+
return this.render(locale);
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Optional holiday-specific Emoji or `null`.
|
|
164
|
+
*/
|
|
165
|
+
getEmoji() {
|
|
166
|
+
return this.emoji || null;
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Returns a simplified (untranslated) description for this event. For example,
|
|
170
|
+
* the `HolidayEvent` class supports
|
|
171
|
+
* "Erev Pesach" => "Pesach", and "Sukkot III (CH''M)" => "Sukkot".
|
|
172
|
+
* For many holidays the basename and the event description are the same.
|
|
173
|
+
*/
|
|
174
|
+
basename() {
|
|
175
|
+
return this.getDesc();
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* Returns a URL to hebcal.com or sefaria.org for more detail on the event.
|
|
179
|
+
* Returns `undefined` for events with no detail page.
|
|
180
|
+
*/
|
|
181
|
+
url() {
|
|
182
|
+
return undefined;
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Is this event observed in Israel?
|
|
186
|
+
* @example
|
|
187
|
+
* const ev1 = new Event(new HDate(7, 'Sivan', 5749), 'Shavuot II', flags.CHAG | flags.CHUL_ONLY);
|
|
188
|
+
* ev1.observedInIsrael(); // false
|
|
189
|
+
* const ev2 = new Event(new HDate(26, 'Kislev', 5749), 'Chanukah: 3 Candles', 0);
|
|
190
|
+
* ev2.observedInIsrael(); // true
|
|
191
|
+
*/
|
|
192
|
+
observedInIsrael() {
|
|
193
|
+
return !(this.mask & flags.CHUL_ONLY);
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* Is this event observed in the Diaspora?
|
|
197
|
+
* @example
|
|
198
|
+
* const ev1 = new Event(new HDate(7, 'Sivan', 5749), 'Shavuot II', flags.CHAG | flags.CHUL_ONLY);
|
|
199
|
+
* ev1.observedInDiaspora(); // true
|
|
200
|
+
* const ev2 = new Event(new HDate(26, 'Kislev', 5749), 'Chanukah: 3 Candles', 0);
|
|
201
|
+
* ev2.observedInDiaspora(); // true
|
|
202
|
+
*/
|
|
203
|
+
observedInDiaspora() {
|
|
204
|
+
return !(this.mask & flags.IL_ONLY);
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* Is this event observed in Israel/Diaspora?
|
|
208
|
+
* @example
|
|
209
|
+
* const ev1 = new Event(new HDate(7, 'Sivan', 5749), 'Shavuot II', flags.CHAG | flags.CHUL_ONLY);
|
|
210
|
+
* ev1.observedIn(false); // true
|
|
211
|
+
* ev1.observedIn(true); // false
|
|
212
|
+
* const ev2 = new Event(new HDate(26, 'Kislev', 5749), 'Chanukah: 3 Candles', 0);
|
|
213
|
+
* ev2.observedIn(false); // true
|
|
214
|
+
* ev2.observedIn(true); // true
|
|
215
|
+
* @param il
|
|
216
|
+
*/
|
|
217
|
+
observedIn(il) {
|
|
218
|
+
return il ? this.observedInIsrael() : this.observedInDiaspora();
|
|
219
|
+
}
|
|
220
|
+
/**
|
|
221
|
+
* Returns a list of event categories
|
|
222
|
+
*/
|
|
223
|
+
getCategories() {
|
|
224
|
+
const mask = this.getFlags();
|
|
225
|
+
for (const attrs of flagToCategory) {
|
|
226
|
+
const attr0 = attrs[0];
|
|
227
|
+
if (mask & attr0) {
|
|
228
|
+
return attrs.slice(1);
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
return ['unknown'];
|
|
232
|
+
}
|
|
233
|
+
}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { greg2abs, isDate, daysInGregMonth, HDate, months } from '@hebcal/hdate';
|
|
2
|
+
const TISHREI = months.TISHREI;
|
|
3
|
+
/**
|
|
4
|
+
* Gets the R.D. days for a number, Date, or HDate
|
|
5
|
+
* @private
|
|
6
|
+
*/
|
|
7
|
+
function getAbs(d) {
|
|
8
|
+
if (typeof d === 'number')
|
|
9
|
+
return d;
|
|
10
|
+
if (isDate(d))
|
|
11
|
+
return greg2abs(d);
|
|
12
|
+
if (HDate.isHDate(d))
|
|
13
|
+
return d.abs();
|
|
14
|
+
throw new TypeError(`Invalid date type: ${d}`);
|
|
15
|
+
}
|
|
16
|
+
function getYear(options) {
|
|
17
|
+
if (typeof options.year !== 'undefined') {
|
|
18
|
+
return Number(options.year);
|
|
19
|
+
}
|
|
20
|
+
return options.isHebrewYear
|
|
21
|
+
? new HDate().getFullYear()
|
|
22
|
+
: new Date().getFullYear();
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Parse options object to determine start & end days
|
|
26
|
+
* @private
|
|
27
|
+
*/
|
|
28
|
+
export function getStartAndEnd(options) {
|
|
29
|
+
if ((options.start && !options.end) || (options.end && !options.start)) {
|
|
30
|
+
throw new TypeError('Both options.start and options.end are required');
|
|
31
|
+
}
|
|
32
|
+
else if (options.start && options.end) {
|
|
33
|
+
return [getAbs(options.start), getAbs(options.end)];
|
|
34
|
+
}
|
|
35
|
+
const isHebrewYear = Boolean(options.isHebrewYear);
|
|
36
|
+
const theYear = getYear(options);
|
|
37
|
+
if (isNaN(theYear)) {
|
|
38
|
+
throw new RangeError(`Invalid year ${options.year}`);
|
|
39
|
+
}
|
|
40
|
+
else if (isHebrewYear && theYear < 1) {
|
|
41
|
+
throw new RangeError(`Invalid Hebrew year ${theYear}`);
|
|
42
|
+
}
|
|
43
|
+
const theMonth = getMonth(options);
|
|
44
|
+
const numYears = Number(options.numYears) || 1;
|
|
45
|
+
if (isHebrewYear) {
|
|
46
|
+
return startEndHebrew(theMonth, theYear, numYears);
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
return startEndGregorian(theMonth, theYear, numYears);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
function getMonth(options) {
|
|
53
|
+
if (options.month) {
|
|
54
|
+
if (options.isHebrewYear) {
|
|
55
|
+
return HDate.monthNum(options.month);
|
|
56
|
+
}
|
|
57
|
+
else if (typeof options.month === 'number') {
|
|
58
|
+
return options.month;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return NaN;
|
|
62
|
+
}
|
|
63
|
+
function startEndGregorian(theMonth, theYear, numYears) {
|
|
64
|
+
const gregMonth = theMonth ? theMonth - 1 : 0;
|
|
65
|
+
const startGreg = new Date(theYear, gregMonth, 1);
|
|
66
|
+
if (theYear < 100) {
|
|
67
|
+
startGreg.setFullYear(theYear);
|
|
68
|
+
}
|
|
69
|
+
const startAbs = greg2abs(startGreg);
|
|
70
|
+
let endAbs;
|
|
71
|
+
if (theMonth) {
|
|
72
|
+
endAbs = startAbs + daysInGregMonth(theMonth, theYear) - 1;
|
|
73
|
+
}
|
|
74
|
+
else {
|
|
75
|
+
const endYear = theYear + numYears;
|
|
76
|
+
const endGreg = new Date(endYear, 0, 1);
|
|
77
|
+
if (endYear < 100) {
|
|
78
|
+
endGreg.setFullYear(endYear);
|
|
79
|
+
}
|
|
80
|
+
endAbs = greg2abs(endGreg) - 1;
|
|
81
|
+
}
|
|
82
|
+
return [startAbs, endAbs];
|
|
83
|
+
}
|
|
84
|
+
function startEndHebrew(theMonth, theYear, numYears) {
|
|
85
|
+
const startDate = new HDate(1, theMonth || TISHREI, theYear);
|
|
86
|
+
let startAbs = startDate.abs();
|
|
87
|
+
const endAbs = theMonth
|
|
88
|
+
? startAbs + startDate.daysInMonth()
|
|
89
|
+
: new HDate(1, TISHREI, theYear + numYears).abs() - 1;
|
|
90
|
+
// for full Hebrew year, start on Erev Rosh Hashana which
|
|
91
|
+
// is technically in the previous Hebrew year
|
|
92
|
+
// (but conveniently lets us get candle-lighting time for Erev)
|
|
93
|
+
if (!theMonth && theYear > 1) {
|
|
94
|
+
startAbs--;
|
|
95
|
+
}
|
|
96
|
+
return [startAbs, endAbs];
|
|
97
|
+
}
|