chore: Simplified date overrides (#10728)
* chore: Simplified date overrides * Fixed a test that had a date override that wasn't at midnight utc * Wrote test that showed a fixed Europe/Brussels * Lint fixpull/10660/head^2
parent
5a7030d277
commit
a466e71d4c
|
@ -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 = [
|
||||
{
|
||||
|
|
|
@ -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,
|
||||
};
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue