Skip to content

Commit

Permalink
Use "bce" in suffix of hebcal.com URLs for events before common era
Browse files Browse the repository at this point in the history
  • Loading branch information
mjradwin committed May 20, 2021
1 parent f64b513 commit e8439d9
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 4 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@hebcal/core",
"version": "3.17.1",
"version": "3.17.2",
"author": "Michael J. Radwin (https://github.com/mjradwin)",
"contributors": [
"Eyal Schachter (https://github.com/Scimonster)",
Expand Down
8 changes: 6 additions & 2 deletions src/holidays.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ export class HolidayEvent extends Event {
}
/** @return {string} */
urlDateSuffix() {
return this.getDate().greg().getFullYear();
const year = this.getDate().greg().getFullYear();
return year < 0 ? -year + 'bce' : year;
}
}

Expand Down Expand Up @@ -103,7 +104,10 @@ export class AsaraBTevetEvent extends HolidayEvent {
}
/** @return {string} */
urlDateSuffix() {
return this.getDate().greg().toISOString().substring(0, 10).replace(/-/g, '');
const isoDateTime = this.getDate().greg().toISOString();
const isoDate = isoDateTime.substring(0, isoDateTime.indexOf('T'));
const suffix = isoDate[0] === '-' ? 'bce' : '';
return isoDate.replace(/-/g, '') + suffix;
}
}

Expand Down
11 changes: 11 additions & 0 deletions src/holidays.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,17 @@ test('asara-btevet-url', (t) => {
t.deepEqual(urls, expected);
});

test('bce-url', (t) => {
const urls = HebrewCalendar.calendar({year: -776})
.filter((ev) => ev.getDesc() === 'Asara B\'Tevet' || ev.getDesc() === 'Yom Kippur')
.map((ev) => ev.url());
const expected = [
'https://www.hebcal.com/holidays/yom-kippur-776bce',
'https://www.hebcal.com/holidays/asara-btevet-0007761217bce',
];
t.deepEqual(urls, expected);
});

test('getHolidaysForYear-ce', (t) => {
const map = HebrewCalendar.getHolidaysForYear(5888);
const rh = map.get('1 Tishrei 5888').map(eventDateDesc)[0];
Expand Down
10 changes: 9 additions & 1 deletion src/sedra.js
Original file line number Diff line number Diff line change
Expand Up @@ -515,9 +515,17 @@ export class ParshaEvent extends Event {
}
/** @return {string} */
url() {
const dt = this.getDate().greg().toISOString().substring(0, 10).replace(/-/g, '');
const dt = this.urlDateSuffix();
const url = 'https://www.hebcal.com/sedrot/' +
this.basename().toLowerCase().replace(/'/g, '').replace(/ /g, '-') + '-' + dt;
return this.il ? url + '?i=on' : url;
}

/** @return {string} */
urlDateSuffix() {
const isoDateTime = this.getDate().greg().toISOString();
const isoDate = isoDateTime.substring(0, isoDateTime.indexOf('T'));
const suffix = isoDate[0] === '-' ? 'bce' : '';
return isoDate.replace(/-/g, '') + suffix;
}
}
5 changes: 5 additions & 0 deletions src/sedra.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,3 +132,8 @@ test('complete-incomplete-types', (t) => {
t.not(sedraIL.find(0), null);
}
});

test('bce-url', (t) => {
const ev = new ParshaEvent(new HDate(new Date(-428, 8, 30)), ['Bereshit']);
t.is(ev.url(), 'https://www.hebcal.com/sedrot/bereshit-0004280930bce');
});

0 comments on commit e8439d9

Please sign in to comment.