fix: Missing date ranges when specifying a specific slot time (#13645)

This commit is contained in:
Alex van Andel
2024-02-12 18:25:49 +00:00
committed by GitHub
parent 41046aaf27
commit 5acb3e8f97
2 changed files with 21 additions and 1 deletions
+20
View File
@@ -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 = [
{
+1 -1
View File
@@ -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 }));
}
}