Skip to content

Commit 987a20c

Browse files
committed
Fix Chanukah URL for previous year when final days are in January
1 parent a104227 commit 987a20c

File tree

4 files changed

+37
-4
lines changed

4 files changed

+37
-4
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@hebcal/core",
3-
"version": "5.8.9",
3+
"version": "5.8.10",
44
"author": "Michael J. Radwin (https://github.com/mjradwin)",
55
"contributors": [
66
"Eyal Schachter (https://github.com/Scimonster)",

src/HolidayEvent.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ export class HolidayEvent extends Event {
112112

113113
/**
114114
* Because Asara B'Tevet often occurs twice in the same Gregorian year,
115-
* we subclass HolidayEvent to override the `url()` method.
115+
* we subclass HolidayEvent to generate the correct URL.
116116
*/
117117
export class AsaraBTevetEvent extends HolidayEvent {
118118
urlDateSuffix(): string {
@@ -121,6 +121,21 @@ export class AsaraBTevetEvent extends HolidayEvent {
121121
}
122122
}
123123

124+
/**
125+
* Because Chanukah sometimes starts in December and ends in January,
126+
* we subclass HolidayEvent to generate the correct URL.
127+
*/
128+
export class ChanukahEvent extends HolidayEvent {
129+
urlDateSuffix(): string {
130+
const dt = this.getDate().greg();
131+
let year = dt.getFullYear();
132+
if (dt.getMonth() === 0) {
133+
year--;
134+
}
135+
return String(year);
136+
}
137+
}
138+
124139
/** Represents Rosh Hashana, the Jewish New Year */
125140
export class RoshHashanaEvent extends HolidayEvent {
126141
private readonly hyear: number;

src/holidays.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import {
3131
import {YomKippurKatanEvent} from './YomKippurKatanEvent';
3232
import {
3333
HolidayEvent,
34+
ChanukahEvent,
3435
AsaraBTevetEvent,
3536
RoshHashanaEvent,
3637
RoshChodeshEvent,
@@ -190,7 +191,7 @@ export function getHolidaysForYear_(year: number): HolidayYearMap {
190191
for (let candles = 2; candles <= 8; candles++) {
191192
const hd = new HDate(23 + candles, KISLEV, year);
192193
add(
193-
new HolidayEvent(
194+
new ChanukahEvent(
194195
hd,
195196
`Chanukah: ${candles} Candles`,
196197
MINOR_HOLIDAY | CHANUKAH_CANDLES,
@@ -202,7 +203,7 @@ export function getHolidaysForYear_(year: number): HolidayYearMap {
202203
);
203204
}
204205
add(
205-
new HolidayEvent(
206+
new ChanukahEvent(
206207
new HDate(32, KISLEV, year),
207208
hdesc.CHANUKAH_8TH_DAY,
208209
MINOR_HOLIDAY,

test/holidays.spec.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,23 @@ test('asara-btevet-url', () => {
154154
expect(urls).toEqual(expected);
155155
});
156156

157+
test('chanukah-url', () => {
158+
const events = HebrewCalendar.calendar({
159+
start: new Date(2024, 11, 30),
160+
end: new Date(2025, 0, 2),
161+
});
162+
const urls = events
163+
.filter((ev) => ev.basename() === 'Chanukah')
164+
.map((ev) => ev.url());
165+
const expected = [
166+
'https://www.hebcal.com/holidays/chanukah-2024',
167+
'https://www.hebcal.com/holidays/chanukah-2024',
168+
'https://www.hebcal.com/holidays/chanukah-2024',
169+
'https://www.hebcal.com/holidays/chanukah-2024',
170+
];
171+
expect(urls).toEqual(expected);
172+
});
173+
157174
test('early-ce-url', () => {
158175
const ev = new HolidayEvent(new HDate(new Date(100, 8, 30)), 'Yom Kippur');
159176
expect(ev.url()).toBe('https://www.hebcal.com/holidays/yom-kippur-100');

0 commit comments

Comments
 (0)