Skip to content

Scheduling infrastructure for absolutely everyone.

Allow booking date overrides outside of working hours (#8538)

Carina Wollendorfera88eb0fdc5e9
diff --git a/packages/features/bookings/lib/handleNewBooking.ts b/packages/features/bookings/lib/handleNewBooking.ts
index 32d93194b29..338ecda022e 100644
--- a/packages/features/bookings/lib/handleNewBooking.ts
+++ b/packages/features/bookings/lib/handleNewBooking.ts
@@ -65,7 +65,7 @@ import {
import type { BufferedBusyTime } from "@calcom/types/BufferedBusyTime";
import type { AdditionalInformation, AppsStatus, CalendarEvent, Person } from "@calcom/types/Calendar";
import type { EventResult, PartialReference } from "@calcom/types/EventManager";
-import type { WorkingHours } from "@calcom/types/schedule";
+import type { WorkingHours, TimeRange as DateOverride } from "@calcom/types/schedule";
import type { EventTypeInfo } from "../../webhooks/lib/sendPayload";
import sendPayload from "../../webhooks/lib/sendPayload";
@@ -118,10 +118,14 @@ const isWithinAvailableHours = (
timeSlot: { start: ConfigType; end: ConfigType },
{
workingHours,
+ dateOverrides,
organizerTimeZone,
+ inviteeTimeZone,
}: {
workingHours: WorkingHours[];
+ dateOverrides: DateOverride[];
organizerTimeZone: string;
+ inviteeTimeZone: string;
}
) => {
const timeSlotStart = dayjs(timeSlot.start).utc();
@@ -145,6 +149,22 @@ const isWithinAvailableHours = (
return true;
}
}
+
+ // check if it is a date override
+ for (const dateOverride of dateOverrides) {
+ const utcOffSet = dayjs(dateOverride.start).tz(inviteeTimeZone).utcOffset();
+
+ const slotStart = dayjs(timeSlotStart).add(utcOffSet, "minute");
+ const slotEnd = dayjs(timeSlotEnd).add(utcOffSet, "minute");
+
+ if (
+ slotStart.isBetween(dateOverride.start, dateOverride.end) &&
+ slotEnd.isBetween(dateOverride.start, dateOverride.end)
+ ) {
+ return true;
+ }
+ }
+
log.error(
`NAUF: isWithinAvailableHours ${JSON.stringify({ ...timeSlot, organizerTimeZone, workingHours })}`
);
@@ -303,7 +323,11 @@ async function ensureAvailableUsers(
const availableUsers: IsFixedAwareUser[] = [];
/** Let's start checking for availability */
for (const user of eventType.users) {
- const { busy: bufferedBusyTimes, workingHours } = await getUserAvailability(
+ const {
+ busy: bufferedBusyTimes,
+ workingHours,
+ dateOverrides,
+ } = await getUserAvailability(
{
userId: user.id,
eventTypeId: eventType.id,
@@ -318,7 +342,9 @@ async function ensureAvailableUsers(
{ start: input.dateFrom, end: input.dateTo },
{
workingHours,
+ dateOverrides,
organizerTimeZone: eventType.timeZone || eventType?.schedule?.timeZone || user.timeZone,
+ inviteeTimeZone: input.timeZone,
}
)
) {