fix: improve defined slot start times (#14107)
* add 15 and 5 to intervalsWithDefinedStartTimes * change slot start time logic * test if we run tests * remove unwanted changes * add tests * remove console.log --------- Co-authored-by: CarinaWolli <wollencarina@gmail.com> Co-authored-by: Joe Au-Yeung <65426560+joeauyeung@users.noreply.github.com>
This commit is contained in:
co-authored by
CarinaWolli
Joe Au-Yeung
parent
e169d9e8d1
commit
6ea13b7c9a
@@ -299,6 +299,54 @@ describe("Tests the slot logic", () => {
|
||||
expect(slots).toHaveLength(1);
|
||||
expect(slots[0].time.format()).toBe("2023-07-13T08:00:00+05:30");
|
||||
});
|
||||
|
||||
it("tests slots for 5 minute events", async () => {
|
||||
const slots = getSlots({
|
||||
inviteeDate: dayjs.tz("2023-07-13T00:00:00.000+05:30", "Europe/London"),
|
||||
frequency: 5,
|
||||
minimumBookingNotice: 0,
|
||||
eventLength: 5,
|
||||
organizerTimeZone: "Europe/London",
|
||||
dateRanges: [
|
||||
// fits 1 slot
|
||||
{
|
||||
start: dayjs.tz("2023-07-13T07:00:00.000", "Europe/London"),
|
||||
end: dayjs.tz("2023-07-13T07:05:00.000", "Europe/London"),
|
||||
},
|
||||
// fits 4 slots
|
||||
{
|
||||
start: dayjs.tz("2023-07-13T07:10:00.000", "Europe/London"),
|
||||
end: dayjs.tz("2023-07-13T07:30:00.000", "Europe/London"),
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
expect(slots).toHaveLength(5);
|
||||
});
|
||||
|
||||
it("tests slots for events with an event length that is not divisible by 5", async () => {
|
||||
const slots = getSlots({
|
||||
inviteeDate: dayjs.tz("2023-07-13T00:00:00.000+05:30", "Europe/London"),
|
||||
frequency: 8,
|
||||
minimumBookingNotice: 0,
|
||||
eventLength: 8,
|
||||
organizerTimeZone: "Europe/London",
|
||||
dateRanges: [
|
||||
{
|
||||
start: dayjs.tz("2023-07-13T07:22:00.000", "Europe/London"),
|
||||
end: dayjs.tz("2023-07-13T08:00:00.000", "Europe/London"),
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
/*
|
||||
2023-07-13T06:22:00.000Z
|
||||
2023-07-13T06:30:00.000Z
|
||||
2023-07-13T06:38:00.000Z
|
||||
2023-07-13T06:46:00.000Z
|
||||
*/
|
||||
expect(slots).toHaveLength(4);
|
||||
});
|
||||
});
|
||||
|
||||
describe("Tests the date-range slot logic with custom env variable", () => {
|
||||
|
||||
+11
-11
@@ -162,6 +162,16 @@ function buildSlotsWithDateRanges({
|
||||
offsetStart = offsetStart ? minimumOfOne(offsetStart) : 0;
|
||||
const slots: { time: Dayjs; userIds?: number[] }[] = [];
|
||||
|
||||
let interval = Number(process.env.NEXT_PUBLIC_AVAILABILITY_SCHEDULE_INTERVAL) || 1;
|
||||
const intervalsWithDefinedStartTimes = [60, 30, 20, 15, 10, 5];
|
||||
|
||||
for (let i = 0; i < intervalsWithDefinedStartTimes.length; i++) {
|
||||
if (frequency % intervalsWithDefinedStartTimes[i] === 0) {
|
||||
interval = intervalsWithDefinedStartTimes[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
dateRanges.forEach((range) => {
|
||||
const startTimeWithMinNotice = dayjs.utc().add(minimumBookingNotice, "minute");
|
||||
|
||||
@@ -169,17 +179,6 @@ function buildSlotsWithDateRanges({
|
||||
? range.start
|
||||
: startTimeWithMinNotice;
|
||||
|
||||
let interval = Number(process.env.NEXT_PUBLIC_AVAILABILITY_SCHEDULE_INTERVAL) || 15;
|
||||
|
||||
const intervalsWithDefinedStartTimes = [60, 30, 20, 10];
|
||||
|
||||
for (let i = 0; i < intervalsWithDefinedStartTimes.length; i++) {
|
||||
if (frequency % intervalsWithDefinedStartTimes[i] === 0) {
|
||||
interval = intervalsWithDefinedStartTimes[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
slotStartTime =
|
||||
slotStartTime.minute() % interval !== 0
|
||||
? slotStartTime.startOf("hour").add(Math.ceil(slotStartTime.minute() / interval) * interval, "minute")
|
||||
@@ -198,6 +197,7 @@ function buildSlotsWithDateRanges({
|
||||
slots.push({
|
||||
time: slotStartTime,
|
||||
});
|
||||
|
||||
slotStartTime = slotStartTime.add(frequency + (offsetStart ?? 0), "minutes");
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user