Scheduling infrastructure for absolutely everyone.
fix: extra 30-minute buffer was added to 60-minute slots without it being set (#24087)
Anik Dhabal Babu2a23911a5b20
diff --git a/apps/web/test/lib/getSchedule.test.ts b/apps/web/test/lib/getSchedule.test.tsindex 7494cfeca00..9229c8bbe5f 100644--- a/apps/web/test/lib/getSchedule.test.ts+++ b/apps/web/test/lib/getSchedule.test.ts@@ -1244,10 +1244,9 @@ describe("getSchedule", () => {expect(scheduleForEventWithBookingNotice13Hrs).toHaveTimeSlots([- /*`04:00:00.000Z`, `06:00:00.000Z`, - Minimum time slot is 07:30 UTC which is 13hrs from 18:30*/- `08:00:00.000Z`,- `10:00:00.000Z`,- `12:00:00.000Z`,+ /*`03:30:00.000Z`, `05:30:00.000Z`, - Minimum time slot is 07:30 UTC which is 13hrs from 18:30*/+ `07:30:00.000Z`,+ `09:30:00.000Z`,],{dateString: todayDateString,@@ -1267,10 +1266,11 @@ describe("getSchedule", () => {});expect(scheduleForEventWithBookingNotice10Hrs).toHaveTimeSlots([- /*`04:00:00.000Z`, - Minimum bookable time slot is 04:30 UTC which is 10hrs from 18:30 */- `05:00:00.000Z`,- `07:00:00.000Z`,- `09:00:00.000Z`,+ /*`03:30:00.000Z`, - Minimum bookable time slot is 04:30 UTC which is 10hrs from 18:30 */+ `04:30:00.000Z`,+ `06:30:00.000Z`,+ `08:30:00.000Z`,+ `10:30:00.000Z`,],{dateString: todayDateString,@@ -1334,11 +1334,9 @@ describe("getSchedule", () => {expect(scheduleForEventOnADayWithNonCalBooking).toHaveTimeSlots([- // `04:00:00.000Z`, // - 4 AM is booked- // `06:00:00.000Z`, // - 6 AM is not available because 08:00AM slot has a `beforeEventBuffer`- `08:00:00.000Z`, // - 8 AM is available because of availability of 06:00 - 07:59- `10:00:00.000Z`,- `12:00:00.000Z`,+ // `05:30:00.000Z`, // - 5:30 AM is not available because 08:30AM slot has a `beforeEventBuffer`+ `08:30:00.000Z`, // - 8:30 AM is available (2 PM IST)+ `10:30:00.000Z`,],{dateString: plus3DateString,@@ -1412,11 +1410,9 @@ describe("getSchedule", () => {expect(scheduleForEventOnADayWithCalBooking).toHaveTimeSlots([- // `04:00:00.000Z`, // - 4 AM is booked- // `06:00:00.000Z`, // - 6 AM is not available because of afterBuffer(120 mins) of the existing booking(4-5:59AM slot)- // `08:00:00.000Z`, // - 8 AM is not available because of beforeBuffer(120mins) of possible booking at 08:00- `10:00:00.000Z`,- `12:00:00.000Z`,+ // `05:30:00.000Z`, // - 5:30 AM is not available because of afterBuffer(120 mins) of the existing booking(4:00-5:59AM slot)+ // `08:30:00.000Z`, // - 8:30 AM is not available because of beforeBuffer(120mins) of possible booking at 08:30+ `10:30:00.000Z`,],{dateString: plus2DateString,diff --git a/apps/web/test/lib/getSchedule/futureLimit.timezone.test.ts b/apps/web/test/lib/getSchedule/futureLimit.timezone.test.tsindex 5defd710b01..c59a4fa9ede 100644--- a/apps/web/test/lib/getSchedule/futureLimit.timezone.test.ts+++ b/apps/web/test/lib/getSchedule/futureLimit.timezone.test.ts@@ -673,26 +673,26 @@ describe("getSchedule", () => {});const allTimeSlotsForToday = [- "2024-05-31T11:30:00.000Z",- "2024-06-01T04:30:00.000Z",- "2024-06-01T05:30:00.000Z",- "2024-06-01T06:30:00.000Z",- "2024-06-01T07:30:00.000Z",- "2024-06-01T08:30:00.000Z",- "2024-06-01T09:30:00.000Z",- "2024-06-01T10:30:00.000Z",+ "2024-05-31T11:00:00.000Z",+ "2024-06-01T04:00:00.000Z",+ "2024-06-01T05:00:00.000Z",+ "2024-06-01T06:00:00.000Z",+ "2024-06-01T07:00:00.000Z",+ "2024-06-01T08:00:00.000Z",+ "2024-06-01T09:00:00.000Z",+ "2024-06-01T10:00:00.000Z",];expect(scheduleForEvent).toHaveTimeSlots([- // "2024-05-30T04:30:00.000Z", // Not available as before the start of the range- "2024-05-31T04:30:00.000Z",- "2024-05-31T05:30:00.000Z",- "2024-05-31T06:30:00.000Z",- "2024-05-31T07:30:00.000Z",- "2024-05-31T08:30:00.000Z",- "2024-05-31T09:30:00.000Z",- "2024-05-31T10:30:00.000Z",+ // "2024-05-30T04:00:00.000Z", // Not available as before the start of the range+ "2024-05-31T04:00:00.000Z",+ "2024-05-31T05:00:00.000Z",+ "2024-05-31T06:00:00.000Z",+ "2024-05-31T07:00:00.000Z",+ "2024-05-31T08:00:00.000Z",+ "2024-05-31T09:00:00.000Z",+ "2024-05-31T10:00:00.000Z",],{dateString: yesterdayDateString,@@ -1634,13 +1634,13 @@ describe("getSchedule", () => {expect(scheduleForEventForPagoTz).toHaveTimeSlots([- "2024-07-25T04:30:00.000Z",- "2024-07-25T05:30:00.000Z",- "2024-07-25T06:30:00.000Z",- "2024-07-25T07:30:00.000Z",- "2024-07-25T08:30:00.000Z",- "2024-07-25T09:30:00.000Z",- "2024-07-25T10:30:00.000Z",+ "2024-07-25T04:00:00.000Z",+ "2024-07-25T05:00:00.000Z",+ "2024-07-25T06:00:00.000Z",+ "2024-07-25T07:00:00.000Z",+ "2024-07-25T08:00:00.000Z",+ "2024-07-25T09:00:00.000Z",+ "2024-07-25T10:00:00.000Z",],{// 25th timeslots are shown mostly on 24th of Pago Pago@@ -1651,14 +1651,14 @@ describe("getSchedule", () => {expect(scheduleForEventForPagoTz).toHaveTimeSlots([- "2024-07-25T11:30:00.000Z",- "2024-07-26T04:30:00.000Z",- "2024-07-26T05:30:00.000Z",- "2024-07-26T06:30:00.000Z",- "2024-07-26T07:30:00.000Z",- "2024-07-26T08:30:00.000Z",- "2024-07-26T09:30:00.000Z",- "2024-07-26T10:30:00.000Z",+ "2024-07-25T11:00:00.000Z",+ "2024-07-26T04:00:00.000Z",+ "2024-07-26T05:00:00.000Z",+ "2024-07-26T06:00:00.000Z",+ "2024-07-26T07:00:00.000Z",+ "2024-07-26T08:00:00.000Z",+ "2024-07-26T09:00:00.000Z",+ "2024-07-26T10:00:00.000Z",],{dateString: "2024-07-25",@@ -1666,7 +1666,7 @@ describe("getSchedule", () => {});- expect(scheduleForEventForPagoTz).toHaveTimeSlots(["2024-07-26T11:30:00.000Z"], {+ expect(scheduleForEventForPagoTz).toHaveTimeSlots(["2024-07-26T11:00:00.000Z"], {dateString: "2024-07-26",doExactMatch: true,});diff --git a/apps/web/test/lib/getSchedule/restrictionSchedule.test.ts b/apps/web/test/lib/getSchedule/restrictionSchedule.test.tsindex 102ce6d96a6..257fc32f66c 100644--- a/apps/web/test/lib/getSchedule/restrictionSchedule.test.ts+++ b/apps/web/test/lib/getSchedule/restrictionSchedule.test.ts@@ -173,13 +173,11 @@ describe("getSchedule", () => {// - User availability: 9 AM - 5 PM London// - Restriction: 10 AM - 6 PM Dubaiconst expectedUtcSlots = [- "2025-06-02T08:00:00.000Z", // 9 AM London, 12 PM Dubai, 1:30 PM Kolkata- "2025-06-02T09:00:00.000Z", // 10 AM London, 1 PM Dubai, 2:30 PM Kolkata- "2025-06-02T10:00:00.000Z", // 11 AM London, 2 PM Dubai, 3:30 PM Kolkata- "2025-06-02T11:00:00.000Z", // 12 PM London, 3 PM Dubai, 4:30 PM Kolkata- "2025-06-02T12:00:00.000Z", // 1 PM London, 4 PM Dubai, 5:30 PM Kolkata- "2025-06-02T13:00:00.000Z", // 2 PM London, 5 PM Dubai, 6:30 PM Kolkata- "2025-06-02T14:00:00.000Z", // 3 PM London, 6 PM Dubai, 7:30 PM Kolkata+ "2025-06-02T08:30:00.000Z", // 9:30 AM London, 12:30 PM Dubai, 2:00 PM Kolkata+ "2025-06-02T09:30:00.000Z", // 10:30 AM London, 1:30 PM Dubai, 3:00 PM Kolkata+ "2025-06-02T10:30:00.000Z", // 11:30 AM London, 2:30 PM Dubai, 4:00 PM Kolkata+ "2025-06-02T11:30:00.000Z", // 12:30 PM London, 3:30 PM Dubai, 5:00 PM Kolkata+ "2025-06-02T12:30:00.000Z", // 1:30 PM London, 4:30 PM Dubai, 6:00 PM Kolkata];expect(result).toHaveTimeSlots(expectedUtcSlots, {@@ -269,12 +267,11 @@ describe("getSchedule", () => {// - User availability: 9 AM - 5 PM London// - Restriction: 10 AM - 6 PM Dubai, weekdays onlyconst getExpectedSlotsForDate = (dateString: string) => [- `${dateString}T08:00:00.000Z`, // 9 AM London, 12 PM Dubai, 1:30 PM Kolkata- `${dateString}T09:00:00.000Z`, // 10 AM London, 1 PM Dubai, 2:30 PM Kolkata- `${dateString}T10:00:00.000Z`, // 11 AM London, 2 PM Dubai, 3:30 PM Kolkata- `${dateString}T11:00:00.000Z`, // 12 PM London, 3 PM Dubai, 4:30 PM Kolkata- `${dateString}T12:00:00.000Z`, // 1 PM London, 4 PM Dubai, 5:30 PM Kolkata- `${dateString}T13:00:00.000Z`, // 2 PM London, 5 PM Dubai, 6:30 PM Kolkata+ `${dateString}T08:30:00.000Z`, // 9:30 AM London, 12:30 PM Dubai, 2:00 PM Kolkata+ `${dateString}T09:30:00.000Z`, // 10:30 AM London, 1:30 PM Dubai, 3:00 PM Kolkata+ `${dateString}T10:30:00.000Z`, // 11:30 AM London, 2:30 PM Dubai, 4:00 PM Kolkata+ `${dateString}T11:30:00.000Z`, // 12:30 PM London, 3:30 PM Dubai, 5:00 PM Kolkata+ `${dateString}T12:30:00.000Z`, // 1:30 PM London, 4:30 PM Dubai, 6:00 PM Kolkata];// Verify weekday slots@@ -370,11 +367,10 @@ describe("getSchedule", () => {// - User availability: 9 AM - 5 PM London (1:30 PM - 9:30 PM Kolkata)// - Restriction: 10 AM - 6 PM Kolkataconst getExpectedSlotsForDate = (dateString: string) => [- `${dateString}T08:00:00.000Z`, // 1:30 PM Kolkata, 9 AM London- `${dateString}T09:00:00.000Z`, // 2:30 PM Kolkata, 10 AM London- `${dateString}T10:00:00.000Z`, // 3:30 PM Kolkata, 11 AM London- `${dateString}T11:00:00.000Z`, // 4:30 PM Kolkata, 12 PM London- `${dateString}T12:00:00.000Z`, // 5:30 PM Kolkata, 1 PM London+ `${dateString}T08:30:00.000Z`, // 2:00 PM Kolkata, 9:30 AM London+ `${dateString}T09:30:00.000Z`, // 3:00 PM Kolkata, 10:30 AM London+ `${dateString}T10:30:00.000Z`, // 4:00 PM Kolkata, 11:30 AM London+ `${dateString}T11:30:00.000Z`, // 5:00 PM Kolkata, 12:30 PM London];// Verify weekday slots@@ -453,15 +449,13 @@ describe("getSchedule", () => {// Expected slots based on user's availability: 9 AM - 5 PM Londonconst getExpectedSlotsForDate = (dateString: string) => [- `${dateString}T08:00:00.000Z`, // 9 AM London, 1:30 PM Kolkata- `${dateString}T09:00:00.000Z`, // 10 AM London, 2:30 PM Kolkata- `${dateString}T10:00:00.000Z`, // 11 AM London, 3:30 PM Kolkata- `${dateString}T11:00:00.000Z`, // 12 PM London, 4:30 PM Kolkata- `${dateString}T12:00:00.000Z`, // 1 PM London, 5:30 PM Kolkata- `${dateString}T13:00:00.000Z`, // 2 PM London, 6:30 PM Kolkata- `${dateString}T14:00:00.000Z`, // 3 PM London, 7:30 PM Kolkata- `${dateString}T15:00:00.000Z`, // 4 PM London, 8:30 PM Kolkata- `${dateString}T16:00:00.000Z`, // 5 PM London, 9:30 PM Kolkata+ `${dateString}T08:30:00.000Z`, // 9:30 AM London, 2:00 PM Kolkata+ `${dateString}T09:30:00.000Z`, // 10:30 AM London, 3:00 PM Kolkata+ `${dateString}T10:30:00.000Z`, // 11:30 AM London, 4:00 PM Kolkata+ `${dateString}T11:30:00.000Z`, // 12:30 PM London, 5:00 PM Kolkata+ `${dateString}T12:30:00.000Z`, // 1:30 PM London, 6:00 PM Kolkata+ `${dateString}T13:30:00.000Z`, // 2:30 PM London, 7:00 PM Kolkata+ `${dateString}T14:30:00.000Z`, // 3:30 PM London, 8:00 PM Kolkata];// Verify weekday slots@@ -472,8 +466,8 @@ describe("getSchedule", () => {});});- // Verify a late evening slot (8:30 PM Kolkata, 4 PM London) is present- const lateEveningSlot = `${plus2DateString}T15:00:00.000Z`;+ // Verify a late evening slot (8:00 PM Kolkata, 3:30 PM London) is present+ const lateEveningSlot = `${plus2DateString}T14:30:00.000Z`;expect(result.slots[plus2DateString].map((s) => s.time)).toContain(lateEveningSlot);});});diff --git a/packages/lib/slots.ts b/packages/lib/slots.tsindex 876f7d26f58..fdd95575698 100644--- a/packages/lib/slots.ts+++ b/packages/lib/slots.ts@@ -131,6 +131,11 @@ function buildSlotsWithDateRanges({// For current day bookings, normalizing the seconds to zero to avoid issues with time calculationsslotStartTime = slotStartTime.set("second", 0).set("millisecond", 0);++ // Convert to target timezone BEFORE checking if rounding is needed+ // This ensures we check minute alignment in the local timezone, not UTC+ // This prevents issues with half-hour offset timezones like Asia/Kolkata (GMT+5:30)+ slotStartTime = slotStartTime.tz(timeZone);if (slotStartTime.minute() % interval !== 0) {slotStartTime = getCorrectedSlotStartTime({@@ -141,7 +146,7 @@ function buildSlotsWithDateRanges({});}- slotStartTime = slotStartTime.add(offsetStart ?? 0, "minutes").tz(timeZone);+ slotStartTime = slotStartTime.add(offsetStart ?? 0, "minutes");// Find the nearest appropriate slot boundary if this time falls within an existing slotconst slotBoundariesValueArray = Array.from(slotBoundaries.keys());