diff --git a/packages/lib/slots.ts b/packages/lib/slots.ts index 358bf0932a..6385ba0b93 100644 --- a/packages/lib/slots.ts +++ b/packages/lib/slots.ts @@ -42,7 +42,9 @@ const splitAvailableTime = ( const getSlots = ({ inviteeDate, frequency, minimumBookingNotice, workingHours, eventLength }: GetSlots) => { // current date in invitee tz const startDate = dayjs().add(minimumBookingNotice, "minute"); - const startOfDayUTC = dayjs.utc().startOf("day"); + // This code is ran client side, startOf() does some conversions based on the + // local tz of the client. Sometimes this shifts the day incorrectly. + const startOfDayUTC = dayjs.utc().set("hour", 0).set("minute", 0).set("second", 0); const startOfInviteeDay = inviteeDate.startOf("day"); // checks if the start date is in the past @@ -61,9 +63,20 @@ const getSlots = ({ inviteeDate, frequency, minimumBookingNotice, workingHours, startTime: /* Why? */ startOfDayUTC.add(schedule.startTime, "minute"), endTime: /* Why? */ startOfDayUTC.add(schedule.endTime, "minute"), })); - const localWorkingHours = getWorkingHours({ utcOffset: -inviteeDate.utcOffset() }, workingHoursUTC).filter( - (hours) => hours.days.includes(inviteeDate.day()) - ); + + // Dayjs does not expose the timeZone value publicly through .get("timeZone") + // instead, we as devs are required to somewhat hack our way to get the ... + // tz value as string + // eslint-disable-next-line @typescript-eslint/no-explicit-any + const timeZone: string = (inviteeDate as any)["$x"]["$timezone"]; + + const localWorkingHours = getWorkingHours( + { + // initialize current day with timeZone without conversion, just parse. + utcOffset: -dayjs.tz(dayjs(), timeZone).utcOffset(), + }, + workingHoursUTC + ).filter((hours) => hours.days.includes(inviteeDate.day())); const slots: Dayjs[] = [];