Skip to content

Scheduling infrastructure for absolutely everyone.

fix: wrong slot starting times for half hour times zones (#10161)

Carina Wollendorfer2db4998eaa0c
diff --git a/apps/web/test/lib/getSchedule.test.ts b/apps/web/test/lib/getSchedule.test.ts
index 9c41b0682e2..05e0850197b 100644
--- a/apps/web/test/lib/getSchedule.test.ts
+++ b/apps/web/test/lib/getSchedule.test.ts
@@ -451,6 +451,7 @@ describe("getSchedule", () => {
endTime: `${plus2DateString}T18:29:59.999Z`,
timeZone: Timezones["+5:30"],
});
+
expect(scheduleForEventWith30Length).toHaveTimeSlots(
[
`04:00:00.000Z`,
@@ -484,8 +485,9 @@ describe("getSchedule", () => {
timeZone: Timezones["+5:30"],
});
// `slotInterval` takes precedence over `length`
+ // 4:30 is utc so it is 10:00 in IST
expect(scheduleForEventWith30minsLengthAndSlotInterval2hrs).toHaveTimeSlots(
- [`04:00:00.000Z`, `06:00:00.000Z`, `08:00:00.000Z`, `10:00:00.000Z`, `12:00:00.000Z`],
+ [`04:30:00.000Z`, `06:30:00.000Z`, `08:30:00.000Z`, `10:30:00.000Z`, `12:30:00.000Z`],
{
dateString: plus2DateString,
}
diff --git a/packages/lib/slots.test.ts b/packages/lib/slots.test.ts
index 0afa5ef9383..b6bff8d30f9 100644
--- a/packages/lib/slots.test.ts
+++ b/packages/lib/slots.test.ts
@@ -280,4 +280,23 @@ describe("Tests the slot logic", () => {
expect(slots[0].time.format()).toBe("2023-07-13T22:45:00+02:00");
});
+
+ it("tests slots for half hour timezones", async () => {
+ const slots = getSlots({
+ inviteeDate: dayjs.tz("2023-07-13T00:00:00.000+05:30", "Asia/Kolkata"),
+ frequency: 60,
+ minimumBookingNotice: 0,
+ eventLength: 60,
+ organizerTimeZone: "Asia/Kolkata",
+ dateRanges: [
+ {
+ start: dayjs.tz("2023-07-13T07:30:00.000", "Asia/Kolkata"),
+ end: dayjs.tz("2023-07-13T09:30:00.000", "Asia/Kolkata"),
+ },
+ ],
+ });
+
+ expect(slots).toHaveLength(1);
+ expect(slots[0].time.format()).toBe("2023-07-13T08:00:00+05:30");
+ });
});
diff --git a/packages/lib/slots.ts b/packages/lib/slots.ts
index 0911e20e670..2343e7a51a0 100644
--- a/packages/lib/slots.ts
+++ b/packages/lib/slots.ts
@@ -161,6 +161,7 @@ function buildSlotsWithDateRanges({
eventLength = minimumOfOne(eventLength);
offsetStart = offsetStart ? minimumOfOne(offsetStart) : 0;
const slots: { time: Dayjs; userIds?: number[] }[] = [];
+
dateRanges.forEach((range) => {
const startTimeWithMinNotice = dayjs.utc().add(minimumBookingNotice, "minute");
@@ -178,7 +179,7 @@ function buildSlotsWithDateRanges({
}
slotStartTime =
- slotStartTime.utc().minute() % interval !== 0
+ slotStartTime.minute() % interval !== 0
? slotStartTime.startOf("hour").add(Math.ceil(slotStartTime.minute() / interval) * interval, "minute")
: slotStartTime;