From a3c10d0beb491cdccd97da16f3dc0227ab20199d Mon Sep 17 00:00:00 2001 From: Alex van Andel Date: Wed, 22 Feb 2023 21:36:30 +0000 Subject: [PATCH] Amend logic to figure out the months between dates (#7289) --- apps/web/pages/[user]/calendar-cache/[month].tsx | 2 +- packages/core/CalendarManager.ts | 7 +++---- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/apps/web/pages/[user]/calendar-cache/[month].tsx b/apps/web/pages/[user]/calendar-cache/[month].tsx index d1a8bfbf54..d866b027a2 100644 --- a/apps/web/pages/[user]/calendar-cache/[month].tsx +++ b/apps/web/pages/[user]/calendar-cache/[month].tsx @@ -30,7 +30,7 @@ export const getStaticProps: GetStaticProps< }, }); const startDate = ( - dayjs(month, "YYYY-MM").isSame(dayjs(), "month") ? dayjs() : dayjs(month, "YYYY-MM") + dayjs(month, "YYYY-MM").isSame(dayjs(), "month") ? dayjs.utc() : dayjs.utc(month, "YYYY-MM") ).startOf("day"); const endDate = startDate.endOf("month"); try { diff --git a/packages/core/CalendarManager.ts b/packages/core/CalendarManager.ts index 173bca9ee1..c5172c0f61 100644 --- a/packages/core/CalendarManager.ts +++ b/packages/core/CalendarManager.ts @@ -1,4 +1,4 @@ -import { SelectedCalendar } from "@prisma/client"; +import type { SelectedCalendar } from "@prisma/client"; import _ from "lodash"; import * as process from "process"; @@ -10,7 +10,7 @@ import { WEBAPP_URL } from "@calcom/lib/constants"; import logger from "@calcom/lib/logger"; import { performance } from "@calcom/lib/server/perfObserver"; import type { CalendarEvent, EventBusyDate, NewCalendarEventType } from "@calcom/types/Calendar"; -import { CredentialPayload, CredentialWithAppName } from "@calcom/types/Credential"; +import type { CredentialPayload, CredentialWithAppName } from "@calcom/types/Credential"; import type { EventResult } from "@calcom/types/EventManager"; const log = logger.getChildLogger({ prefix: ["CalendarManager"] }); @@ -193,9 +193,8 @@ export const getBusyCalendarTimes = async ( results = await getNextCache(username, dayjs(dateFrom).format("YYYY-MM")); } else { // if dateFrom and dateTo is from different months get cache by each month - const monthsOfDiff = dayjs(dateTo).diff(dayjs(dateFrom), "month"); const months: string[] = [dayjs(dateFrom).format("YYYY-MM")]; - for (let i = 1; i <= monthsOfDiff; i++) { + for (let i = 1; dayjs(dateFrom).add(i, "month").isBefore(dateTo); i++) { months.push(dayjs(dateFrom).add(i, "month").format("YYYY-MM")); } const data: EventBusyDate[][][] = await Promise.all(months.map((month) => getNextCache(username, month)));