Skip to content

Scheduling infrastructure for absolutely everyone.

fix: recurring events with calendar connections (#12250)

Carina Wollendorfer8b89d6635a48
diff --git a/packages/features/bookings/lib/handleNewBooking.ts b/packages/features/bookings/lib/handleNewBooking.ts
index 997b318bf4f..0684e771d97 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 9529ad7f566..61b0e56fd70 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())];