fix: extra 30-minute buffer was added to 60-minute slots without it being set (#24087)

* fix: 30 min buffer added on 60 min slots

* update

* fix test

* Update restrictionSchedule.test.ts

* addressed test

* Update getSchedule.test.ts
This commit is contained in:
Anik Dhabal Babu authored and GitHub committed 2025-10-09 18:37:52 +01:00
1 parent 5aa24c8472
commit 2a23911a5b
4 files changed
+75 -80

No files matched your search

+14 -18
View File
@@ -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,
@@ -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,
});
@@ -173,13 +173,11 @@ describe("getSchedule", () => {
// - User availability: 9 AM - 5 PM London
// - Restriction: 10 AM - 6 PM Dubai
const 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 only
const 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 Kolkata
const 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 London
const 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);
});
});
+6 -1
View File
@@ -131,6 +131,11 @@ function buildSlotsWithDateRanges({
// For current day bookings, normalizing the seconds to zero to avoid issues with time calculations
slotStartTime = 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 slot
const slotBoundariesValueArray = Array.from(slotBoundaries.keys());