fix: split time correctly if the local working hours are just across mid night (#2766)
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
This commit is contained in:
1 parent
81d917e27a
commit
0bfdf2f8ef
1 file changed
+25
-2
+25
-2
@@ -64,9 +64,32 @@ const getSlots = ({ inviteeDate, frequency, minimumBookingNotice, workingHours,
|
|||||||
const slots: Dayjs[] = [];
|
const slots: Dayjs[] = [];
|
||||||
|
|
||||||
const slotsTimeFrameAvailable = [] as Array<WorkingHoursTimeFrame>;
|
const slotsTimeFrameAvailable = [] as Array<WorkingHoursTimeFrame>;
|
||||||
|
// Here we split working hour in chunks for every frequency available that can fit in whole working hours
|
||||||
// Here we split working hour in chunks for every frequency available that can fit in whole working hour
|
const computedLocalWorkingHours: WorkingHoursTimeFrame[] = [];
|
||||||
|
let tempComputeTimeFrame: WorkingHoursTimeFrame | undefined;
|
||||||
|
const computeLength = localWorkingHours.length - 1;
|
||||||
|
const makeTimeFrame = (item: typeof localWorkingHours[0]): WorkingHoursTimeFrame => ({
|
||||||
|
startTime: item.startTime,
|
||||||
|
endTime: item.endTime,
|
||||||
|
});
|
||||||
localWorkingHours.forEach((item, index) => {
|
localWorkingHours.forEach((item, index) => {
|
||||||
|
if (!tempComputeTimeFrame) {
|
||||||
|
tempComputeTimeFrame = makeTimeFrame(item);
|
||||||
|
} else {
|
||||||
|
// please check the comment in splitAvailableTime func for the added 1 minute
|
||||||
|
if (tempComputeTimeFrame.endTime + 1 === item.startTime) {
|
||||||
|
// to deal with time that across the day, e.g. from 11:59 to to 12:01
|
||||||
|
tempComputeTimeFrame.endTime = item.endTime;
|
||||||
|
} else {
|
||||||
|
computedLocalWorkingHours.push(tempComputeTimeFrame);
|
||||||
|
tempComputeTimeFrame = makeTimeFrame(item);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (index == computeLength) {
|
||||||
|
computedLocalWorkingHours.push(tempComputeTimeFrame);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
computedLocalWorkingHours.forEach((item, index) => {
|
||||||
slotsTimeFrameAvailable.push(...splitAvailableTime(item.startTime, item.endTime, frequency, eventLength));
|
slotsTimeFrameAvailable.push(...splitAvailableTime(item.startTime, item.endTime, frequency, eventLength));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user