Bugfix/dst available hour mismatch (#4909)
* Need to use local time, not inviteeDate * Use selected timeZone to perform localWorkingHours logic * Adding comment * More commentspull/4904/head
parent
0c4cb2e2b0
commit
ab62fc5d47
|
@ -42,7 +42,9 @@ const splitAvailableTime = (
|
||||||
const getSlots = ({ inviteeDate, frequency, minimumBookingNotice, workingHours, eventLength }: GetSlots) => {
|
const getSlots = ({ inviteeDate, frequency, minimumBookingNotice, workingHours, eventLength }: GetSlots) => {
|
||||||
// current date in invitee tz
|
// current date in invitee tz
|
||||||
const startDate = dayjs().add(minimumBookingNotice, "minute");
|
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");
|
const startOfInviteeDay = inviteeDate.startOf("day");
|
||||||
// checks if the start date is in the past
|
// 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"),
|
startTime: /* Why? */ startOfDayUTC.add(schedule.startTime, "minute"),
|
||||||
endTime: /* Why? */ startOfDayUTC.add(schedule.endTime, "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[] = [];
|
const slots: Dayjs[] = [];
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue