Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from
Dec 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions packages/features/schedules/components/Schedule.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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]);

Expand Down
8 changes: 7 additions & 1 deletion packages/trpc/server/routers/viewer/availability.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down