Skip to content

Commit

Permalink
Use same logic for default year (Hebrew or Gregorian) on hebcal form
Browse files Browse the repository at this point in the history
  • Loading branch information
mjradwin committed Sep 8, 2023
1 parent 6b71ec2 commit 5165beb
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/hebcal.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {makeHebcalOptions, processCookieAndQuery, possiblySetCookie,
hebcalFormDefaults,
makeIcalOpts,
CACHE_CONTROL_7DAYS,
getDefaultYear,
getDefaultHebrewYear, makeHebrewCalendar,
makeGeoUrlArgs,
shortenUrl,
Expand Down Expand Up @@ -72,9 +73,17 @@ export async function hebcalApp(ctx) {
const startEnd = typeof options.start === 'object' && typeof options.end === 'object';
if (empty(q.year) && !startEnd) {
const dt = new Date();
q.year = options.year = options.isHebrewYear ?
getDefaultHebrewYear(new HDate(dt)) :
dt.getMonth() === 11 ? dt.getFullYear() + 1 : dt.getFullYear();
const hd = new HDate(dt);
const yearInfo = getDefaultYear(dt, hd);
const ytStr = ctx.request.query.yt;
if (empty(ytStr)) {
const isHebrewYear = options.isHebrewYear = yearInfo.isHebrewYear;
q.yt = isHebrewYear ? 'H' : 'G';
q.year = options.year = isHebrewYear ? yearInfo.hy : yearInfo.gregRange;
} else {
q.year = options.year = (ytStr === 'H') ? yearInfo.hy :
dt.getMonth() === 11 ? dt.getFullYear() + 1 : dt.getFullYear();
}
}
if (ctx.status < 400 && q.v === '1') {
ctx.response.etag = eTagFromOptions(options, {outputType: q.cfg});
Expand Down

0 comments on commit 5165beb

Please sign in to comment.