Skip to content

Commit

Permalink
fix: Missing date ranges when specifying a specific slot time (#13645)
Browse files Browse the repository at this point in the history
  • Loading branch information
emrysal committed Feb 12, 2024
1 parent 41046aa commit 5acb3e8
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
20 changes: 20 additions & 0 deletions packages/lib/date-ranges.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,26 @@ describe("buildDateRanges", () => {
end: dayjs("2023-06-14T16:00:00Z").tz(timeZone),
});
});
it("should return correct date ranges for specific time slot in date override", () => {
const items = [
{
date: new Date(Date.UTC(2023, 5, 13)),
startTime: new Date(Date.UTC(0, 0, 0, 9, 0)),
endTime: new Date(Date.UTC(0, 0, 0, 14, 0)),
},
];
const timeZone = "Europe/London";

const dateFrom = dayjs("2023-06-13T10:00:00Z");
const dateTo = dayjs("2023-06-13T10:30:00Z");

const results = buildDateRanges({ availability: items, timeZone, dateFrom, dateTo });

expect(results[0]).toEqual({
start: dayjs("2023-06-13T08:00:00Z").tz(timeZone),
end: dayjs("2023-06-13T13:00:00Z").tz(timeZone),
});
});
it("should return correct date ranges if date override would already already be the next day in utc timezone", () => {
const items = [
{
Expand Down
2 changes: 1 addition & 1 deletion packages/lib/date-ranges.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ export function buildDateRanges({
availability.reduce((processed: DateRange[], item) => {
if ("date" in item && !!item.date) {
const itemDateAsUtc = dayjs.utc(item.date);
if (itemDateAsUtc.isBetween(dateFrom, dateTo, null, "[]")) {
if (itemDateAsUtc.isBetween(dateFrom.startOf("day"), dateTo.endOf("day"), null, "[]")) {
processed.push(processDateOverride({ item, itemDateAsUtc, timeZone }));
}
}
Expand Down

0 comments on commit 5acb3e8

Please sign in to comment.