fix: recurring events with calendar connections (#12250)

Co-authored-by: CarinaWolli <wollencarina@gmail.com>
This commit is contained in:
Carina Wollendorfer
2023-11-07 12:09:56 -03:00
committed by GitHub
co-authored by CarinaWolli
parent 13ec810cb9
commit 8b89d6635a
2 changed files with 19 additions and 22 deletions
@@ -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. ",
+18 -6
View File
@@ -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())];