Add 23:59 as a valid availability select option (#6137)

Co-authored-by: Joe Au-Yeung <65426560+joeauyeung@users.noreply.github.com>
pull/6140/head
Alex van Andel 2022-12-21 16:13:50 +00:00 committed by GitHub
parent 9de19d35a8
commit 8eda30d88c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 5 deletions

View File

@ -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]);

View File

@ -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()) {