diff --git a/app/components/DuskCalculator.tsx b/app/components/DuskCalculator.tsx index d952fda..071f9fe 100644 --- a/app/components/DuskCalculator.tsx +++ b/app/components/DuskCalculator.tsx @@ -1,6 +1,8 @@ import { addMinutes } from "date-fns"; import * as SunCalc from "suncalc"; +import { getPacificOffset } from "~/utils"; + const LAT_LONG = [-117.7, 33.5].reverse() as [number, number]; // determine whether a America/Los_Angeles reservation @@ -15,7 +17,8 @@ export const DuskCalculator = ({ duration: string; startTime: string; }) => { - const start = new Date(`${date}T${startTime}:00-07:00`); + const offset = getPacificOffset(date); + const start = new Date(`${date}T${startTime}:00-0${offset}:00`); const end = addMinutes(start, Number(duration)); const { dusk } = SunCalc.getTimes(start, ...LAT_LONG); diff --git a/app/utils.ts b/app/utils.ts index 53af0d7..bec51e9 100644 --- a/app/utils.ts +++ b/app/utils.ts @@ -32,7 +32,7 @@ export const anotherTimeFormattingFunc = (val: string | null) => { return formatTime(Number(h), m == "30"); }; -// either GMT -7 or -8 depending on the season +// 7 or 8 (from GMT) depending on the season export const getPacificOffset = (rawDate: string) => { const [year, month, day] = rawDate.split("-").map((val) => Number(val)); return new TZDate(year, month, day, "America/Los_Angeles").getTimezoneOffset() / 60;