From 0871314d5304024b48094a866dc1ffaefbd2a3c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Efra=C3=ADn=20Roch=C3=ADn?= Date: Mon, 13 Mar 2023 02:59:19 -0700 Subject: [PATCH] Amend logic to figure out if selected slot is available (#7684) --- .../features/bookings/lib/handleNewBooking.ts | 27 ++++--------------- packages/lib/slots.ts | 10 ++----- 2 files changed, 7 insertions(+), 30 deletions(-) diff --git a/packages/features/bookings/lib/handleNewBooking.ts b/packages/features/bookings/lib/handleNewBooking.ts index bd6a977303..477322d04b 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.ts index e34c8b2413..57cf50112b 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; }