From 8b89d6635a48a69ebdea4bf2eb0588d627f60b10 Mon Sep 17 00:00:00 2001 From: Carina Wollendorfer <30310907+CarinaWolli@users.noreply.github.com> Date: Tue, 7 Nov 2023 10:09:56 -0500 Subject: [PATCH] fix: recurring events with calendar connections (#12250) Co-authored-by: CarinaWolli --- .../features/bookings/lib/handleNewBooking.ts | 17 +------------ packages/lib/parse-dates.ts | 24 ++++++++++++++----- 2 files changed, 19 insertions(+), 22 deletions(-) diff --git a/packages/features/bookings/lib/handleNewBooking.ts b/packages/features/bookings/lib/handleNewBooking.ts index 997b318bf4..0684e771d9 100644 --- a/packages/features/bookings/lib/handleNewBooking.ts +++ b/packages/features/bookings/lib/handleNewBooking.ts @@ -408,22 +408,7 @@ async function ensureAvailableUsers( let foundConflict = false; try { - if ( - eventType.recurringEvent && - recurringDatesInfo?.currentRecurringIndex === 0 && - recurringDatesInfo.allRecurringDates - ) { - const allBookingDates = recurringDatesInfo.allRecurringDates.map((strDate) => new Date(strDate)); - // Go through each date for the recurring event and check if each one's availability - // DONE: Decreased computational complexity from O(2^n) to O(n) by refactoring this loop to stop - // running at the first unavailable time. - let i = 0; - while (!foundConflict && i < allBookingDates.length) { - foundConflict = checkForConflicts(bufferedBusyTimes, allBookingDates[i++], duration); - } - } else { - foundConflict = checkForConflicts(bufferedBusyTimes, input.dateFrom, duration); - } + foundConflict = checkForConflicts(bufferedBusyTimes, input.dateFrom, duration); } catch { log.debug({ message: "Unable set isAvailableToBeBooked. Using true. ", diff --git a/packages/lib/parse-dates.ts b/packages/lib/parse-dates.ts index 9529ad7f56..61b0e56fd7 100644 --- a/packages/lib/parse-dates.ts +++ b/packages/lib/parse-dates.ts @@ -9,7 +9,12 @@ import { parseZone } from "./parse-zone"; type ExtraOptions = { withDefaultTimeFormat?: boolean; selectedTimeFormat?: TimeFormat }; -const processDate = (date: string | null | Dayjs, language: string, options?: ExtraOptions) => { +const processDate = ( + date: string | null | Dayjs, + language: string, + timeZone: string, + options?: ExtraOptions +) => { const parsedZone = parseZone(date); if (!parsedZone?.isValid()) return "Invalid date"; const formattedTime = parsedZone?.format( @@ -17,12 +22,19 @@ const processDate = (date: string | null | Dayjs, language: string, options?: Ex ? TimeFormat.TWELVE_HOUR : options?.selectedTimeFormat || detectBrowserTimeFormat ); - return `${formattedTime}, ${dayjs(date).toDate().toLocaleString(language, { dateStyle: "full" })}`; + return `${formattedTime}, ${dayjs(date) + .toDate() + .toLocaleString(language, { dateStyle: "full", timeZone })}`; }; -export const parseDate = (date: string | null | Dayjs, language: string, options?: ExtraOptions) => { +export const parseDate = ( + date: string | null | Dayjs, + language: string, + timeZone: string, + options?: ExtraOptions +) => { if (!date) return ["No date"]; - return processDate(date, language, options); + return processDate(date, language, timeZone, options); }; const timeOptions: Intl.DateTimeFormatOptions = { @@ -74,7 +86,7 @@ export const parseRecurringDates = ( withDefaultTimeFormat, }: { startDate: string | null | Dayjs; - timeZone?: string; + timeZone: string; recurringEvent: RecurringEvent | null; recurringCount: number; selectedTimeFormat?: TimeFormat; @@ -98,7 +110,7 @@ export const parseRecurringDates = ( }); const dateStrings = times.map((t) => { // finally; show in local timeZone again - return processDate(t.tz(timeZone), language, { selectedTimeFormat, withDefaultTimeFormat }); + return processDate(t.tz(timeZone), language, timeZone, { selectedTimeFormat, withDefaultTimeFormat }); }); return [dateStrings, times.map((t) => t.toDate())];