From 7f5a2363f9461029bb574e328184b6b7b3c2fdd8 Mon Sep 17 00:00:00 2001 From: Nathaniel Date: Thu, 10 Feb 2022 02:34:47 +0800 Subject: [PATCH] fixed calendso busy query timezone issue (#1360) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fixed calendso busy query timezone issue * rename tz to timezone for consistency * added back missing code Co-authored-by: Alex van Andel Co-authored-by: Peer Richelsen Co-authored-by: Omar López Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com> --- .../calendar/services/BaseCalendarService.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/integrations/calendar/services/BaseCalendarService.ts b/lib/integrations/calendar/services/BaseCalendarService.ts index dbc3a7b5..2583e5b0 100644 --- a/lib/integrations/calendar/services/BaseCalendarService.ts +++ b/lib/integrations/calendar/services/BaseCalendarService.ts @@ -1,5 +1,7 @@ import { Credential } from "@prisma/client"; import dayjs from "dayjs"; +import timezone from "dayjs/plugin/timezone"; +import utc from "dayjs/plugin/utc"; import ICAL from "ical.js"; import { createEvent } from "ics"; import { @@ -24,6 +26,9 @@ import { CalendarEventType, EventBusyDate, NewCalendarEventType } from "../const import { Calendar, CalendarEvent, IntegrationCalendar } from "../interfaces/Calendar"; import { convertDate, getAttendees, getDuration } from "../utils/CalendarUtils"; +dayjs.extend(utc); +dayjs.extend(timezone); + const CALENDSO_ENCRYPTION_KEY = process.env.CALENDSO_ENCRYPTION_KEY || ""; export default abstract class BaseCalendarService implements Calendar { @@ -291,11 +296,11 @@ export default abstract class BaseCalendarService implements Calendar { vcalendar.getFirstSubcomponent("vtimezone")?.getFirstPropertyValue("tzid") || ""; const startDate = calendarTimezone - ? dayjs(event.startDate.toJSDate()).tz(calendarTimezone) + ? dayjs.tz(event.startDate.toString(), calendarTimezone) : new Date(event.startDate.toUnixTime() * 1000); const endDate = calendarTimezone - ? dayjs(event.endDate.toJSDate()).tz(calendarTimezone) + ? dayjs.tz(event.endDate.toString(), calendarTimezone) : new Date(event.endDate.toUnixTime() * 1000); return {