Skip to content

Commit

Permalink
Allow empty yahrzeit ics download (e.g. with no VEVENTs)
Browse files Browse the repository at this point in the history
  • Loading branch information
mjradwin committed Jun 26, 2024
1 parent 003ba5a commit 41049c4
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 14 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
"@hebcal/core": "^5.4.5",
"@hebcal/geo-sqlite": "^5.0.5",
"@hebcal/hdate": "^0.10.1",
"@hebcal/icalendar": "^5.0.6",
"@hebcal/icalendar": "^5.1.0",
"@hebcal/learning": "^5.0.8",
"@hebcal/leyning": "^8.1.9",
"@hebcal/locales": "^5.0.1",
Expand Down
31 changes: 18 additions & 13 deletions src/yahrzeit.js
Original file line number Diff line number Diff line change
Expand Up @@ -479,19 +479,7 @@ export async function yahrzeitDownload(ctx) {
ctx.state.trace.set('makeYahrzeitEvents-start', Date.now());
const events = await makeYahrzeitEvents(maxId, query, reminder);
ctx.state.trace.set('makeYahrzeitEvents-end', Date.now());
if (events.length === 0) {
ctx.throw(400, 'No events');
}
let lastModified = details.lastModified;
const now = new Date();
if (!lastModified) {
// An old /v2/y/ URL won't have a lastModified
lastModified = now;
}
const firstEventDt = events[0].getDate().greg();
if (firstEventDt > lastModified && firstEventDt < now) {
lastModified = firstEventDt;
}
const lastModified = makeLastModified(details, events);
query.lastModified = ctx.lastModified = lastModified; // store in query for eTag
const startYear = parseInt(query.start, 10) || getDefaultStartYear();
const extension = rpath.substring(rpath.length - 4);
Expand Down Expand Up @@ -528,6 +516,23 @@ export async function yahrzeitDownload(ctx) {
}
}

function makeLastModified(details, events) {
let lastModified = details.lastModified;
const now = new Date();
if (!lastModified) {
// An old /v2/y/ URL won't have a lastModified
lastModified = now;
}
if (events.length === 0) {
return lastModified;
}
const firstEventDt = events[0].getDate().greg();
if (firstEventDt > lastModified && firstEventDt < now) {
lastModified = firstEventDt;
}
return lastModified;
}

/**
* @return {number}
*/
Expand Down

0 comments on commit 41049c4

Please sign in to comment.