Skip to content

Commit

Permalink
Address issue with inversion when date ranges are given out of order
Browse files Browse the repository at this point in the history
  • Loading branch information
emrysal committed Feb 7, 2025
1 parent 9f5fcc5 commit e62c2b5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
18 changes: 12 additions & 6 deletions packages/lib/slots.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,15 +168,21 @@ describe("Tests the date-range slot logic", () => {
});

expect(result).toHaveLength(2);
/*
});
it("finds correct slots when two unequal date ranges are given (inverse)", async () => {
const nextDay = dayjs.utc().add(1, "day").startOf("day");

TODO FIX:
// also check for order independency.
const dateRangesInverseOrder = [
// 11:15-13:00
dateRanges[1],
{
start: nextDay.hour(11).minute(15),
end: nextDay.hour(13),
},
// 11:00-13:00
dateRanges[0],
{
start: nextDay.hour(11),
end: nextDay.hour(13),
},
];

const resultInverseOrder = getSlots({
Expand All @@ -188,7 +194,7 @@ TODO FIX:
offsetStart: 0,
});

expect(resultInverseOrder).toHaveLength(2);*/
expect(resultInverseOrder).toHaveLength(2);
});

it("finds correct slots over the span of multiple days", async () => {
Expand Down
3 changes: 2 additions & 1 deletion packages/lib/slots.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,8 @@ function buildSlotsWithDateRanges({

const startTimeWithMinNotice = dayjs.utc().add(minimumBookingNotice, "minute");

dateRanges.forEach((range) => {
const orderedDateRanges = dateRanges.sort((a, b) => a.start.valueOf() - b.start.valueOf());
orderedDateRanges.forEach((range) => {
const dateYYYYMMDD = range.start.format("YYYY-MM-DD");

let slotStartTime = range.start.utc().isAfter(startTimeWithMinNotice)
Expand Down

0 comments on commit e62c2b5

Please sign in to comment.