From aad3988d60fa4fc6925b67f5517b6c711efe9894 Mon Sep 17 00:00:00 2001 From: Anik Dhabal Babu <81948346+anikdhabal@users.noreply.github.com> Date: Mon, 6 Jan 2025 21:00:05 +0530 Subject: [PATCH] fix: Zoho Calendar is allowing bookings during busy schedules (#18473) * fix: zoho calendar allowing to book busy schedule * Improved more readable version --------- Co-authored-by: Alex van Andel --- .../app-store/zohocalendar/lib/CalendarService.ts | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/packages/app-store/zohocalendar/lib/CalendarService.ts b/packages/app-store/zohocalendar/lib/CalendarService.ts index 0797732fe7..ab478d5d5b 100644 --- a/packages/app-store/zohocalendar/lib/CalendarService.ts +++ b/packages/app-store/zohocalendar/lib/CalendarService.ts @@ -235,6 +235,14 @@ export default class ZohoCalendarService implements Calendar { } } + private parseDateTime = (dateTimeStr: string) => { + const dateOnlyFormat = "YYYYMMDD"; + const dateTimeFormat = "YYYYMMDD[T]HHmmss[Z]"; + // Check if the string matches the date-only format (YYYYMMDDZ) or date-time format + const format = /^\d{8}Z$/.test(dateTimeStr) ? dateOnlyFormat : dateTimeFormat; + return dayjs.utc(dateTimeStr, format); + }; + private async getBusyData(dateFrom: string, dateTo: string, userEmail: string) { const query = stringify({ sdate: dateFrom, @@ -256,8 +264,8 @@ export default class ZohoCalendarService implements Calendar { .filter((freebusy: FreeBusy) => freebusy.fbtype === "busy") .map((freebusy: FreeBusy) => ({ // using dayjs utc plugin because by default, dayjs parses and displays in local time, which causes a mismatch - start: dayjs.utc(freebusy.startTime, "YYYYMMDD[T]HHmmss[Z]").toISOString(), - end: dayjs.utc(freebusy.endTime, "YYYYMMDD[T]HHmmss[Z]").toISOString(), + start: this.parseDateTime(freebusy.startTime).toISOString(), + end: this.parseDateTime(freebusy.endTime).toISOString(), })) || [] ); }