diff --git a/package.json b/package.json index dbe8179a..229ef692 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/yahrzeit.js b/src/yahrzeit.js index a0b0d3da..54c4d421 100644 --- a/src/yahrzeit.js +++ b/src/yahrzeit.js @@ -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); @@ -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} */