Skip to content

Commit 59f9df0

Browse files
committed
Format BCE dates correctly
1 parent 1fd295e commit 59f9df0

File tree

5 files changed

+49
-7
lines changed

5 files changed

+49
-7
lines changed

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@hebcal/rest-api",
3-
"version": "3.4.0",
3+
"version": "3.4.1",
44
"author": "Michael J. Radwin (https://github.com/mjradwin)",
55
"keywords": [
66
"hebcal"
@@ -21,7 +21,7 @@
2121
"url": "https://github.com/hebcal/hebcal-rest-api/issues"
2222
},
2323
"dependencies": {
24-
"@hebcal/core": "^3.17.0",
24+
"@hebcal/core": "^3.17.3",
2525
"@hebcal/geo-sqlite": "^3.4.1",
2626
"@hebcal/leyning": "^4.4.0"
2727
},
@@ -61,7 +61,7 @@
6161
"@rollup/plugin-node-resolve": "^13.0.0",
6262
"ava": "^3.15.0",
6363
"core-js": "^3.12.1",
64-
"eslint": "^7.26.0",
64+
"eslint": "^7.27.0",
6565
"eslint-config-google": "^0.14.0",
6666
"jsdoc": "^3.6.7",
6767
"jsdoc-to-markdown": "^5.0.3",

src/classic-rest-api.spec.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,25 @@ test('eventToClassicApiObject', (t) => {
7979
t.deepEqual(shavuotActual, shavuotExpected);
8080
});
8181

82+
test('bce', (t) => {
83+
const options = {
84+
start: new Date(-1, 4, 6),
85+
end: new Date(-1, 4, 6),
86+
il: false,
87+
};
88+
const ev = HebrewCalendar.calendar(options)[0];
89+
const apiObj = eventToClassicApiObject(ev, options);
90+
const expected = {
91+
title: 'Erev Shavuot',
92+
date: '-00001-05-06',
93+
category: 'holiday',
94+
subcat: 'major',
95+
hebrew: 'ערב שבועות',
96+
memo: 'Festival of Weeks. Commemorates the giving of the Torah at Mount Sinai',
97+
};
98+
t.deepEqual(apiObj, expected);
99+
});
100+
82101
test('eventsToClassicApi', (t) => {
83102
const location = Location.lookup('Vancouver');
84103
const options = {

src/common.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,9 @@ export function pad2(number) {
5454
* @return {string}
5555
*/
5656
export function pad4(number) {
57-
if (number < 10) {
57+
if (number < 0) {
58+
return '-0' + pad4(-number);
59+
} else if (number < 10) {
5860
return '000' + number;
5961
} else if (number < 100) {
6062
return '00' + number;

src/fullcalendar.spec.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,3 +214,22 @@ test('fastStartEnd', (t) => {
214214
];
215215
t.deepEqual(fc, expected);
216216
});
217+
218+
test('bce', (t) => {
219+
const options = {
220+
start: new Date(-1, 4, 6),
221+
end: new Date(-1, 4, 6),
222+
il: false,
223+
};
224+
const ev = HebrewCalendar.calendar(options)[0];
225+
const fc = eventToFullCalendar(ev);
226+
const expected = {
227+
title: 'Erev Shavuot',
228+
start: '-00001-05-06',
229+
allDay: true,
230+
className: 'holiday major',
231+
hebrew: 'ערב שבועות',
232+
description: 'Festival of Weeks. Commemorates the giving of the Torah at Mount Sinai',
233+
};
234+
t.deepEqual(fc, expected);
235+
});

src/rss.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ function getLinkAndGuid(ev, il, mainUrl) {
1313
let guid;
1414
const dt = ev.eventTime || ev.getDate().greg();
1515
const dtStr0 = dt.toISOString();
16-
const dtStr = encodeURIComponent(dtStr0.substring(0, ev.eventTime ? 19 : 10));
16+
const timeIdx = dtStr0.indexOf('T');
17+
const dtStr = encodeURIComponent(dtStr0.substring(0, ev.eventTime ? timeIdx + 9 : timeIdx));
1718
const url0 = ev.url();
1819
const url = appendIsraelAndTracking(url0 || mainUrl, il, 'shabbat1c', 'rss').replace(/&/g, '&amp;');
1920
if (url0) {
@@ -98,7 +99,8 @@ export function eventToRssItem(ev, evPubDate, lastBuildDate, dayFormat, location
9899
let subj = ev.render();
99100
const evDate = ev.getDate().greg();
100101
const pubDate = getPubDate(ev, evPubDate, evDate, lastBuildDate);
101-
const linkGuid = getLinkAndGuid(ev, location.getIsrael(), mainUrl);
102+
const il = location ? location.getIsrael() : false;
103+
const linkGuid = getLinkAndGuid(ev, il, mainUrl);
102104
const link = linkGuid[0];
103105
const guid = linkGuid[1];
104106
const description = dayFormat.format(evDate);
@@ -109,7 +111,7 @@ export function eventToRssItem(ev, evPubDate, lastBuildDate, dayFormat, location
109111
if (candles) {
110112
const colon = subj.indexOf(': ');
111113
if (colon != -1) {
112-
const options = {location, il: location.getIsrael(), locale: Locale.getLocaleName()};
114+
const options = {location, il, locale: Locale.getLocaleName()};
113115
const time = HebrewCalendar.reformatTimeStr(ev.eventTimeStr, 'pm', options);
114116
subj = subj.substring(0, colon) + ': ' + time;
115117
}

0 commit comments

Comments
 (0)