fix: No available users found (#13738)

* fix: No available users found

* Update getUserAvailability.ts

* Update getUserAvailability.ts

* Update handleNewBooking.ts

* Reusing the parsed dates throughout the full stack

* Fixed typo

* Added unit tests for stringToDayjs

* Fixing types

* Reverted the getSchedule utc change since that endpoint takes in UTC formatted dates but with a given timezone

* chore: Add test replicating 'no available users' error

* Test is passing

* Name clarifications

* Test clean up

* Update packages/features/bookings/lib/handleNewBooking.ts

Co-authored-by: Omar López <[email protected]>

* Update handleNewBooking.ts

* Fixed issue where date overrides ending at midnight don't allow bookings

* Removed comment

---------

Co-authored-by: Omar López <[email protected]>
This commit is contained in:
Keith WilliamsandOmar López authored and GitHub committed 2024-02-20 12:15:05 -03:00
1 parent 008e0e43a2
commit 71574488c5
4 files changed
+459 -13

No files matched your search

+26 -6
View File
@@ -77,11 +77,19 @@ export function processDateOverride({
.second(0)
.tz(timeZone, true);
const endDate = itemDateStartOfDay
.add(item.endTime.getUTCHours(), "hours")
.add(item.endTime.getUTCMinutes(), "minutes")
.second(0)
.tz(timeZone, true);
let endDate = itemDateStartOfDay;
const endTimeHours = item.endTime.getUTCHours();
const endTimeMinutes = item.endTime.getUTCMinutes();
if (endTimeHours === 23 && endTimeMinutes === 59) {
endDate = endDate.add(1, "day").tz(timeZone, true);
} else {
endDate = itemDateStartOfDay
.add(endTimeHours, "hours")
.add(endTimeMinutes, "minutes")
.second(0)
.tz(timeZone, true);
}
return {
start: startDate,
@@ -116,7 +124,19 @@ export function buildDateRanges({
availability.reduce((processed: DateRange[], item) => {
if ("date" in item && !!item.date) {
const itemDateAsUtc = dayjs.utc(item.date);
if (itemDateAsUtc.isBetween(dateFrom.startOf("day"), dateTo.endOf("day"), null, "[]")) {
// TODO: Remove the .subtract(1, "day") and .add(1, "day") part and
// refactor this to actually work with correct dates.
// As of 2024-02-20, there are mismatches between local and UTC dates for overrides
// and the dateFrom and dateTo fields, resulting in this if not returning true, which
// results in "no available users found" errors.
if (
itemDateAsUtc.isBetween(
dateFrom.subtract(1, "day").startOf("day"),
dateTo.add(1, "day").endOf("day"),
null,
"[]"
)
) {
processed.push(processDateOverride({ item, itemDateAsUtc, timeZone }));
}
}