From df84b8820538dec05fa75792811aed8e6a527d70 Mon Sep 17 00:00:00 2001 From: Joe Karow <58997957+JoeKarow@users.noreply.github.com> Date: Tue, 20 Feb 2024 18:35:21 -0500 Subject: [PATCH] fix hours handling for when close < open --- .../orgHours/query.forHoursDisplay.handler.ts | 25 ++++++++++--------- 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/packages/api/router/orgHours/query.forHoursDisplay.handler.ts b/packages/api/router/orgHours/query.forHoursDisplay.handler.ts index 4968b494492..99efa459438 100644 --- a/packages/api/router/orgHours/query.forHoursDisplay.handler.ts +++ b/packages/api/router/orgHours/query.forHoursDisplay.handler.ts @@ -37,18 +37,19 @@ export const forHoursDisplay = async ({ input }: TRPCHandlerParams { - const interval = Interval.fromDateTimes( - DateTime.fromJSDate(start, { zone: tz ?? 'America/New_York' }).set({ - weekday: convertToLuxonWeekday(dayIndex), - weekYear, - weekNumber, - }), - DateTime.fromJSDate(end, { zone: tz ?? 'America/New_York' }).set({ - weekday: convertToLuxonWeekday(start > end ? dayIndex + 1 : dayIndex), - weekYear, - weekNumber, - }) - ).toISO() + const shouldAddDay = start > end + + const open = DateTime.fromJSDate(start, { zone: tz ?? 'America/New_York' }).set({ + weekday: convertToLuxonWeekday(dayIndex), + weekYear, + weekNumber, + }) + const close = DateTime.fromJSDate(end, { zone: tz ?? 'America/New_York' }).set({ + weekday: convertToLuxonWeekday(shouldAddDay ? (dayIndex === 6 ? 0 : dayIndex + 1) : dayIndex), + weekYear, + weekNumber: shouldAddDay && dayIndex === 6 ? weekNumber + 1 : weekNumber, + }) + const interval = Interval.fromDateTimes(open, close).toISO() return { tz, dayIndex,