From 8eda30d88c8c8dbc06650e24b30e9f0ba4810515 Mon Sep 17 00:00:00 2001 From: Alex van Andel Date: Wed, 21 Dec 2022 16:13:50 +0000 Subject: [PATCH] Add 23:59 as a valid availability select option (#6137) Co-authored-by: Joe Au-Yeung <65426560+joeauyeung@users.noreply.github.com> --- .../features/schedules/components/Schedule.tsx | 16 ++++++++++++---- .../trpc/server/routers/viewer/availability.tsx | 8 +++++++- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/packages/features/schedules/components/Schedule.tsx b/packages/features/schedules/components/Schedule.tsx index c946246384..b8b92c913c 100644 --- a/packages/features/schedules/components/Schedule.tsx +++ b/packages/features/schedules/components/Schedule.tsx @@ -300,18 +300,26 @@ const useOptions = () => { const options = useMemo(() => { const end = dayjs().utc().endOf("day"); - let t: Dayjs = dayjs().utc().startOf("day"); - const options: IOption[] = []; - while (t.isBefore(end)) { + for ( + let t = dayjs().utc().startOf("day"); + t.isBefore(end); + t = t.add(INCREMENT + (!t.add(INCREMENT).isSame(t, "day") ? -1 : 0), "minutes") + ) { options.push({ value: t.toDate().valueOf(), label: dayjs(t) .utc() .format(timeFormat === 12 ? "h:mma" : "HH:mm"), }); - t = t.add(INCREMENT, "minutes"); } + // allow 23:59 + options.push({ + value: end.toDate().valueOf(), + label: dayjs(end) + .utc() + .format(timeFormat === 12 ? "h:mma" : "HH:mm"), + }); return options; }, [timeFormat]); diff --git a/packages/trpc/server/routers/viewer/availability.tsx b/packages/trpc/server/routers/viewer/availability.tsx index 11a2774025..9a9b7bcff2 100644 --- a/packages/trpc/server/routers/viewer/availability.tsx +++ b/packages/trpc/server/routers/viewer/availability.tsx @@ -84,7 +84,13 @@ export const availabilityRouter = router({ return { name: schedule.name, rawSchedule: schedule, - schedule: availability, + schedule: availability.map((a) => + a.map((startAndEnd) => ({ + ...startAndEnd, + // Turn our limited granularity into proper end of day. + end: new Date(startAndEnd.end.toISOString().replace("23:59:00.000Z", "23:59:59.999Z")), + })) + ), dateOverrides: schedule.availability.reduce((acc, override) => { // only iff future date override if (!override.date || override.date < new Date()) {