Scheduling infrastructure for absolutely everyone.
chore: Simplified date overrides (#10728)
Alex van Andela466e71d4c3f
diff --git a/packages/lib/date-ranges.test.ts b/packages/lib/date-ranges.test.tsindex 83dd25b8f05..1e87dd9a562 100644--- a/packages/lib/date-ranges.test.ts+++ b/packages/lib/date-ranges.test.ts@@ -117,6 +117,29 @@ describe("buildDateRanges", () => {end: dayjs("2023-06-14T21:00:00Z").tz(timeZone),});});+ it("should handle day shifts correctly", () => {+ const item = [+ {+ date: new Date(Date.UTC(2023, 7, 15)),+ startTime: new Date(Date.UTC(2023, 5, 12, 9, 0)), // 9 AM+ endTime: new Date(Date.UTC(2023, 5, 12, 17, 0)), // 5 PM+ },+ {+ date: new Date(Date.UTC(2023, 7, 15)),+ startTime: new Date(Date.UTC(2023, 5, 12, 19, 0)), // 7 PM+ endTime: new Date(Date.UTC(2023, 5, 12, 21, 0)), // 9 PM+ },+ ];++ const timeZone = "Pacific/Honolulu";++ const dateFrom = dayjs.tz("2023-08-15", "Europe/Brussels").startOf("day");+ const dateTo = dayjs.tz("2023-08-15", "Europe/Brussels").endOf("day");++ const result = buildDateRanges({ availability: item, timeZone, dateFrom, dateTo });+ // this happened only on Europe/Brussels, Europe/Amsterdam was 2023-08-15T17:00:00-10:00 (as it should be)+ expect(result[0].end.format()).not.toBe("2023-08-14T17:00:00-10:00");+ });it("should return correct date ranges with full day unavailable date override", () => {const items = [{diff --git a/packages/lib/date-ranges.ts b/packages/lib/date-ranges.tsindex 397aba2a1f6..4fd5cf2f3cd 100644--- a/packages/lib/date-ranges.ts+++ b/packages/lib/date-ranges.ts@@ -56,16 +56,23 @@ export function processWorkingHours({}export function processDateOverride({ item, timeZone }: { item: DateOverride; timeZone: string }) {- const date = dayjs.utc(item.date);-- const startTime = dayjs(item.startTime).utc().subtract(dayjs().tz(timeZone).utcOffset(), "minute");- const endTime = dayjs(item.endTime).utc().subtract(dayjs().tz(timeZone).utcOffset(), "minute");-- const diffDays = startTime.startOf("day").diff(dayjs.utc(item.startTime).startOf("day"), "day");-+ const startDate = dayjs+ .utc(item.date)+ .startOf("day")+ .add(item.startTime.getUTCHours(), "hours")+ .add(item.startTime.getUTCMinutes(), "minutes")+ .second(0)+ .tz(timeZone, true);+ const endDate = dayjs+ .utc(item.date)+ .startOf("day")+ .add(item.endTime.getUTCHours(), "hours")+ .add(item.endTime.getUTCMinutes(), "minutes")+ .second(0)+ .tz(timeZone, true);return {- start: date.add(diffDays, "day").hour(startTime.hour()).minute(startTime.minute()).second(0).tz(timeZone),- end: date.add(diffDays, "day").hour(endTime.hour()).minute(endTime.minute()).second(0).tz(timeZone),+ start: startDate,+ end: endDate,};}