Amend logic to calc slots time already in DST (#7792)

* amend logic to calculate DST time on buildSlots

* send start and end date in UTC

* port the logic to calc DST from buildSlots to inWithinAvailableHours
This commit is contained in:
Efraín Rochín authored and GitHub committed 2023-03-17 12:53:05 +01:00
1 parent 9ac562cfba
commit 9ba13a3f3c
3 files changed
+15 -20

No files matched your search

@@ -38,7 +38,6 @@ import { deleteScheduledSMSReminder } from "@calcom/features/ee/workflows/lib/re
import getWebhooks from "@calcom/features/webhooks/lib/getWebhooks";
import { isPrismaObjOrUndefined, parseRecurringEvent } from "@calcom/lib";
import { getVideoCallUrl } from "@calcom/lib/CalEventParser";
import { getDSTDifference, isInDST } from "@calcom/lib/date-fns";
import { getDefaultEvent, getGroupName, getUsernameList } from "@calcom/lib/defaultEvents";
import { getErrorFromUnknown } from "@calcom/lib/errors";
import getPaymentAppData from "@calcom/lib/getPaymentAppData";
@@ -125,13 +124,11 @@ const isWithinAvailableHours = (
) => {
const timeSlotStart = dayjs(timeSlot.start).utc();
const timeSlotEnd = dayjs(timeSlot.end).utc();
const isOrganizerInDSTWhenSlotStart = isInDST(timeSlotStart.tz(organizerTimeZone));
const organizerDSTDifference = getDSTDifference(organizerTimeZone);
const organizerDSTDiff =
dayjs().tz(organizerTimeZone).utcOffset() - timeSlotStart.tz(organizerTimeZone).utcOffset();
const getTime = (slotTime: Dayjs, minutes: number) =>
slotTime.startOf("day").add(minutes + organizerDSTDiff, "minutes");
const getTime = (slotTime: Dayjs, minutes: number) => {
const minutesDTS = isOrganizerInDSTWhenSlotStart ? minutes - organizerDSTDifference : minutes;
return slotTime.startOf("day").add(minutesDTS, "minutes");
};
for (const workingHour of workingHours) {
const startTime = getTime(timeSlotStart, workingHour.startTime);
const endTime = getTime(timeSlotEnd, workingHour.endTime);