Amend logic to figure out if selected slot is available (#7684)

pull/7675/head
Efraín Rochín 2023-03-13 02:59:19 -07:00 committed by GitHub
parent 02d70c63a5
commit 0871314d53
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 30 deletions

View File

@ -113,36 +113,20 @@ const isWithinAvailableHours = (
{ {
workingHours, workingHours,
organizerTimeZone, organizerTimeZone,
inviteeTimeZone,
}: { }: {
workingHours: WorkingHours[]; workingHours: WorkingHours[];
organizerTimeZone: string; organizerTimeZone: string;
inviteeTimeZone: string;
} }
) => { ) => {
const timeSlotStart = dayjs(timeSlot.start).utc(); const timeSlotStart = dayjs(timeSlot.start).utc();
const timeSlotEnd = dayjs(timeSlot.end).utc(); const timeSlotEnd = dayjs(timeSlot.end).utc();
const isOrganizerInDST = isInDST(dayjs().tz(organizerTimeZone));
const isInviteeInDST = isInDST(dayjs().tz(inviteeTimeZone));
const isOrganizerInDSTWhenSlotStart = isInDST(timeSlotStart.tz(organizerTimeZone)); const isOrganizerInDSTWhenSlotStart = isInDST(timeSlotStart.tz(organizerTimeZone));
const isInviteeInDSTWhenSlotStart = isInDST(timeSlotStart.tz(inviteeTimeZone));
const organizerDSTDifference = getDSTDifference(organizerTimeZone); const organizerDSTDifference = getDSTDifference(organizerTimeZone);
const inviteeDSTDifference = getDSTDifference(inviteeTimeZone);
const sameDSTUsers = isOrganizerInDSTWhenSlotStart === isInviteeInDSTWhenSlotStart; const getTime = (slotTime: Dayjs, minutes: number) => {
const organizerDST = isOrganizerInDST === isOrganizerInDSTWhenSlotStart; const minutesDTS = isOrganizerInDSTWhenSlotStart ? minutes - organizerDSTDifference : minutes;
const inviteeDST = isInviteeInDST === isInviteeInDSTWhenSlotStart; return slotTime.startOf("day").add(minutesDTS, "minutes");
const getTime = (slotTime: Dayjs, minutes: number) => };
slotTime
.startOf("day")
.add(
sameDSTUsers && organizerDST && inviteeDST
? minutes
: minutes -
(isOrganizerInDSTWhenSlotStart || isOrganizerInDST
? organizerDSTDifference
: inviteeDSTDifference),
"minutes"
);
for (const workingHour of workingHours) { for (const workingHour of workingHours) {
const startTime = getTime(timeSlotStart, workingHour.startTime); const startTime = getTime(timeSlotStart, workingHour.startTime);
const endTime = getTime(timeSlotEnd, workingHour.endTime); const endTime = getTime(timeSlotEnd, workingHour.endTime);
@ -298,7 +282,6 @@ async function ensureAvailableUsers(
{ {
workingHours, workingHours,
organizerTimeZone: eventType.timeZone || eventType?.schedule?.timeZone || user.timeZone, organizerTimeZone: eventType.timeZone || eventType?.schedule?.timeZone || user.timeZone,
inviteeTimeZone: input.timeZone,
} }
) )
) { ) {

View File

@ -111,7 +111,6 @@ function buildSlots({
return startOfInviteeDay.tz(inviteeTimeZone).add(minutes, "minutes"); return startOfInviteeDay.tz(inviteeTimeZone).add(minutes, "minutes");
}; };
for (const item of Object.values(slotsTimeFrameAvailable)) { for (const item of Object.values(slotsTimeFrameAvailable)) {
/* /*
* @calcom/web:dev: 2022-11-06T00:00:00-04:00 * @calcom/web:dev: 2022-11-06T00:00:00-04:00
@ -121,15 +120,10 @@ function buildSlots({
* @calcom/web:dev: 2022-11-06T03:00:00-04:00 * @calcom/web:dev: 2022-11-06T03:00:00-04:00
* ... * ...
*/ */
const slot = { slots.push({
userIds: item.userIds, userIds: item.userIds,
time: getTime(item.startTime), time: getTime(item.startTime),
}; });
// If the startOfInviteeDay has a different UTC offset than the slot, a DST change has occurred.
// As the time has now fallen backwards, or forwards; this difference -
// needs to be manually added as this is not done for us. Usually 0.
slot.time = slot.time.add(startOfInviteeDay.utcOffset() - slot.time.utcOffset(), "minutes");
slots.push(slot);
} }
return slots; return slots;
} }