Skip to content

Scheduling infrastructure for absolutely everyone.

fix: slots ooo bug (#25878)

Udit Takkar856792e1e7cb
diff --git a/packages/features/schedules/lib/slots.test.ts b/packages/features/schedules/lib/slots.test.ts
index 1b6c5d56ca1..1187d819dba 100644
--- a/packages/features/schedules/lib/slots.test.ts
+++ b/packages/features/schedules/lib/slots.test.ts
@@ -896,4 +896,119 @@ describe("Tests the date-range slot logic with showOptimizedSlots", () => {
vi.useRealTimers();
});
+
+ it("should mark slots as away for cross-timezone OOO (Berlin OOO viewed from Kolkata)", async () => {
+ vi.setSystemTime(dayjs.utc("2024-12-20T00:00:00Z").toDate());
+
+ const datesOutOfOffice = {
+ "2024-12-22": {
+ fromUser: { id: 1, displayName: "Test User" },
+ toUser: null,
+ reason: "Holiday",
+ emoji: "πŸŽ„",
+ },
+ };
+
+ const dateRanges = [
+ {
+ start: dayjs.tz("2024-12-22T09:00:00", "Europe/Berlin"),
+ end: dayjs.tz("2024-12-22T18:00:00", "Europe/Berlin"),
+ },
+ ];
+
+ const inviteeDate = dayjs.tz("2024-12-22T13:30:00", "Asia/Kolkata");
+
+ const slots = getSlots({
+ inviteeDate,
+ frequency: 30,
+ minimumBookingNotice: 0,
+ eventLength: 30,
+ dateRanges,
+ datesOutOfOffice,
+ });
+
+ expect(slots.length).toBeGreaterThan(0);
+ slots.forEach((slot) => {
+ expect(slot.away).toBe(true);
+ expect(slot.reason).toBe("Holiday");
+ });
+
+ vi.useRealTimers();
+ });
+
+ it("should correctly handle OOO when slot time crosses UTC date boundary", async () => {
+ vi.setSystemTime(dayjs.utc("2024-12-20T00:00:00Z").toDate());
+
+ const datesOutOfOffice = {
+ "2024-12-22": {
+ fromUser: { id: 1, displayName: "Test User" },
+ toUser: null,
+ reason: "OOO",
+ emoji: "πŸ–οΈ",
+ },
+ };
+
+ const dateRanges = [
+ {
+ start: dayjs.utc("2024-12-22T22:00:00Z"),
+ end: dayjs.utc("2024-12-22T23:59:59Z"),
+ },
+ ];
+
+ const inviteeDate = dayjs.tz("2024-12-23T03:30:00", "Asia/Kolkata");
+
+ const slots = getSlots({
+ inviteeDate,
+ frequency: 30,
+ minimumBookingNotice: 0,
+ eventLength: 30,
+ dateRanges,
+ datesOutOfOffice,
+ });
+
+ expect(slots.length).toBeGreaterThan(0);
+ slots.forEach((slot) => {
+ expect(slot.away).toBe(true);
+ });
+
+ vi.useRealTimers();
+ });
+
+ it("should NOT mark slots as away when they fall outside OOO UTC date", async () => {
+ vi.setSystemTime(dayjs.utc("2024-12-20T00:00:00Z").toDate());
+
+ const datesOutOfOffice = {
+ "2024-12-22": {
+ fromUser: { id: 1, displayName: "Test User" },
+ toUser: null,
+ reason: "OOO",
+ emoji: "πŸ–οΈ",
+ },
+ };
+
+ const dateRanges = [
+ {
+ start: dayjs.utc("2024-12-21T17:00:00Z"),
+ end: dayjs.utc("2024-12-21T20:00:00Z"),
+ },
+ ];
+
+ const inviteeDate = dayjs.tz("2024-12-21T22:30:00", "Asia/Kolkata");
+
+ const slots = getSlots({
+ inviteeDate,
+ frequency: 30,
+ minimumBookingNotice: 0,
+ eventLength: 30,
+ dateRanges,
+ datesOutOfOffice,
+ });
+
+ expect(slots.length).toBeGreaterThan(0);
+ slots.forEach((slot) => {
+ expect(slot.away).toBeUndefined();
+ });
+
+ vi.useRealTimers();
+ });
});
diff --git a/packages/features/schedules/lib/slots.ts b/packages/features/schedules/lib/slots.ts
index 9884272c647..e649a6e8551 100644
--- a/packages/features/schedules/lib/slots.ts
+++ b/packages/features/schedules/lib/slots.ts
@@ -122,7 +122,6 @@ function buildSlotsWithDateRanges({
const slotBoundaries = new Map<number, true>();
orderedDateRanges.forEach((range) => {
-
let slotStartTime = range.start.utc().isAfter(startTimeWithMinNotice)
? range.start
: startTimeWithMinNotice;
@@ -181,7 +180,7 @@ function buildSlotsWithDateRanges({
}
slotBoundaries.set(slotStartTime.valueOf(), true);
- const slotDateYYYYMMDD = slotStartTime.format("YYYY-MM-DD");
+ const slotDateYYYYMMDD = slotStartTime.utc().format("YYYY-MM-DD");
const dateOutOfOfficeExists = datesOutOfOffice?.[slotDateYYYYMMDD];
let slotData: {
time: Dayjs;