fix: hide OOO slots across timezones (#25966)

* fix: use organizer timezone

* fix: use organizer timezone

* fix: use organizer timezone

* fix type error

---------

Co-authored-by: Anik Dhabal Babu <[email protected]>
This commit is contained in:
Udit TakkarandAnik Dhabal Babu authored and GitHub committed 2025-12-19 08:12:39 -03:00
1 parent 8b13979a41
commit 68e670ae06
3 files changed
+59 -3

No files matched your search

+44 -1
View File
@@ -874,9 +874,9 @@ describe("Tests the date-range slot logic with showOptimizedSlots", () => {
},
],
datesOutOfOffice,
datesOutOfOfficeTimeZone: "UTC",
});
// Filter slots by day
const day1Slots = slots.filter((slot) => slot.time.format("YYYY-MM-DD") === "2025-11-17");
const day2Slots = slots.filter((slot) => slot.time.format("YYYY-MM-DD") === "2025-11-18");
@@ -925,6 +925,7 @@ describe("Tests the date-range slot logic with showOptimizedSlots", () => {
eventLength: 30,
dateRanges,
datesOutOfOffice,
datesOutOfOfficeTimeZone: "Europe/Berlin",
});
expect(slots.length).toBeGreaterThan(0);
@@ -1011,4 +1012,46 @@ describe("Tests the date-range slot logic with showOptimizedSlots", () => {
vi.useRealTimers();
});
it("should mark slots as away when host OOO day maps to next UTC day (LA host, Kolkata booker)", async () => {
vi.setSystemTime(dayjs.utc("2026-01-10T00:00:00Z").toDate());
const datesOutOfOffice = {
"2026-01-16": {
fromUser: { id: 1, displayName: "Host User" },
toUser: null,
reason: "OOO",
emoji: "🏖️",
},
};
const dateRanges = [
{
start: dayjs.tz("2026-01-16T16:00:00", "America/Los_Angeles"),
end: dayjs.tz("2026-01-16T17:00:00", "America/Los_Angeles"),
},
];
const inviteeDate = dayjs.tz("2026-01-17T00:00:00", "Asia/Kolkata");
const slots = getSlots({
inviteeDate,
frequency: 30,
minimumBookingNotice: 0,
eventLength: 30,
dateRanges,
datesOutOfOffice,
datesOutOfOfficeTimeZone: "America/Los_Angeles",
});
const targetSlot = slots.find(
(slot) => slot.time.tz("Asia/Kolkata").format("YYYY-MM-DD HH:mm") === "2026-01-17 05:30"
);
expect(targetSlot).toBeDefined();
expect(targetSlot?.away).toBe(true);
expect(targetSlot?.reason).toBe("OOO");
vi.useRealTimers();
});
});
+14 -2
View File
@@ -18,6 +18,7 @@ export type GetSlots = {
offsetStart?: number;
datesOutOfOffice?: IOutOfOfficeData;
showOptimizedSlots?: boolean | null;
datesOutOfOfficeTimeZone?: string;
};
export type TimeFrame = { userIds?: number[]; startTime: number; endTime: number };
@@ -76,6 +77,7 @@ function buildSlotsWithDateRanges({
offsetStart,
datesOutOfOffice,
showOptimizedSlots,
datesOutOfOfficeTimeZone,
}: {
dateRanges: DateRange[];
frequency: number;
@@ -85,6 +87,7 @@ function buildSlotsWithDateRanges({
offsetStart?: number;
datesOutOfOffice?: IOutOfOfficeData;
showOptimizedSlots?: boolean | null;
datesOutOfOfficeTimeZone?: string;
}) {
// keep the old safeguards in; may be needed.
frequency = minimumOfOne(frequency);
@@ -180,8 +183,15 @@ function buildSlotsWithDateRanges({
}
slotBoundaries.set(slotStartTime.valueOf(), true);
const slotDateYYYYMMDD = slotStartTime.utc().format("YYYY-MM-DD");
const dateOutOfOfficeExists = datesOutOfOffice?.[slotDateYYYYMMDD];
let dateOutOfOfficeExists = undefined;
if (datesOutOfOffice) {
const slotDateYYYYMMDD = datesOutOfOfficeTimeZone
? slotStartTime.tz(datesOutOfOfficeTimeZone).format("YYYY-MM-DD")
: slotStartTime.utc().format("YYYY-MM-DD");
dateOutOfOfficeExists = datesOutOfOffice?.[slotDateYYYYMMDD];
}
let slotData: {
time: Dayjs;
userIds?: number[];
@@ -228,6 +238,7 @@ const getSlots = ({
offsetStart = 0,
datesOutOfOffice,
showOptimizedSlots,
datesOutOfOfficeTimeZone,
}: GetSlots): {
time: Dayjs;
userIds?: number[];
@@ -246,6 +257,7 @@ const getSlots = ({
offsetStart,
datesOutOfOffice,
showOptimizedSlots,
datesOutOfOfficeTimeZone,
});
};
@@ -1203,6 +1203,7 @@ export class AvailableSlotsService {
frequency: eventType.slotInterval || input.duration || eventType.length,
datesOutOfOffice: !isTeamEvent ? allUsersAvailability[0]?.datesOutOfOffice : undefined,
showOptimizedSlots: eventType.showOptimizedSlots,
datesOutOfOfficeTimeZone: !isTeamEvent ? allUsersAvailability[0]?.timeZone : undefined,
});
let availableTimeSlots: typeof timeSlots = [];