Skip to content

Commit

Permalink
fix hours handling for when close < open
Browse files Browse the repository at this point in the history
  • Loading branch information
JoeKarow committed Feb 20, 2024
1 parent 0e5f4e9 commit df84b88
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions packages/api/router/orgHours/query.forHoursDisplay.handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,19 @@ export const forHoursDisplay = async ({ input }: TRPCHandlerParams<TForHoursDisp

const { weekYear, weekNumber } = DateTime.now()
const intervalResults = result.map(({ start, end, tz, dayIndex, ...rest }) => {
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,
Expand Down

1 comment on commit df84b88

@vercel
Copy link

@vercel vercel bot commented on df84b88 Feb 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.