Scheduling infrastructure for absolutely everyone.
Amend logic to figure out if selected slot is available (#7684)
Efraín Rochín0871314d5304
diff --git a/packages/features/bookings/lib/handleNewBooking.ts b/packages/features/bookings/lib/handleNewBooking.tsindex bd6a977303a..477322d04b0 100644--- a/packages/features/bookings/lib/handleNewBooking.ts+++ b/packages/features/bookings/lib/handleNewBooking.ts@@ -113,36 +113,20 @@ const isWithinAvailableHours = ({workingHours,organizerTimeZone,- inviteeTimeZone,}: {workingHours: WorkingHours[];organizerTimeZone: string;- inviteeTimeZone: string;}) => {const timeSlotStart = dayjs(timeSlot.start).utc();const timeSlotEnd = dayjs(timeSlot.end).utc();- const isOrganizerInDST = isInDST(dayjs().tz(organizerTimeZone));- const isInviteeInDST = isInDST(dayjs().tz(inviteeTimeZone));const isOrganizerInDSTWhenSlotStart = isInDST(timeSlotStart.tz(organizerTimeZone));- const isInviteeInDSTWhenSlotStart = isInDST(timeSlotStart.tz(inviteeTimeZone));const organizerDSTDifference = getDSTDifference(organizerTimeZone);- const inviteeDSTDifference = getDSTDifference(inviteeTimeZone);- const sameDSTUsers = isOrganizerInDSTWhenSlotStart === isInviteeInDSTWhenSlotStart;- const organizerDST = isOrganizerInDST === isOrganizerInDSTWhenSlotStart;- const inviteeDST = isInviteeInDST === isInviteeInDSTWhenSlotStart;- const getTime = (slotTime: Dayjs, minutes: number) =>- slotTime- .startOf("day")- .add(- sameDSTUsers && organizerDST && inviteeDST- ? minutes- : minutes -- (isOrganizerInDSTWhenSlotStart || isOrganizerInDST- ? organizerDSTDifference- : inviteeDSTDifference),- "minutes"- );++ const getTime = (slotTime: Dayjs, minutes: number) => {+ const minutesDTS = isOrganizerInDSTWhenSlotStart ? minutes - organizerDSTDifference : minutes;+ return slotTime.startOf("day").add(minutesDTS, "minutes");+ };for (const workingHour of workingHours) {const startTime = getTime(timeSlotStart, workingHour.startTime);const endTime = getTime(timeSlotEnd, workingHour.endTime);@@ -298,7 +282,6 @@ async function ensureAvailableUsers({workingHours,organizerTimeZone: eventType.timeZone || eventType?.schedule?.timeZone || user.timeZone,- inviteeTimeZone: input.timeZone,})) {diff --git a/packages/lib/slots.ts b/packages/lib/slots.tsindex e34c8b24134..57cf50112b7 100644--- a/packages/lib/slots.ts+++ b/packages/lib/slots.ts@@ -111,7 +111,6 @@ function buildSlots({return startOfInviteeDay.tz(inviteeTimeZone).add(minutes, "minutes");};-for (const item of Object.values(slotsTimeFrameAvailable)) {/** @calcom/web:dev: 2022-11-06T00:00:00-04:00@@ -121,15 +120,10 @@ function buildSlots({* @calcom/web:dev: 2022-11-06T03:00:00-04:00* ...*/- const slot = {+ slots.push({userIds: item.userIds,time: getTime(item.startTime),- };- // If the startOfInviteeDay has a different UTC offset than the slot, a DST change has occurred.- // As the time has now fallen backwards, or forwards; this difference -- // needs to be manually added as this is not done for us. Usually 0.- slot.time = slot.time.add(startOfInviteeDay.utcOffset() - slot.time.utcOffset(), "minutes");- slots.push(slot);+ });}return slots;}