fix: align booking limit timezone between availability and validation (#24846)

* fix: align booking limit timezone between availability and validation

- Use eventType.schedule?.timeZone for booking limits in availability calculation
- Previously used user's timezone causing day boundary mismatch
- Add unit tests to verify timezone alignment
- Fixes issue where slots remain available after reaching booking limit

Co-Authored-By: [email protected] <[email protected]>

* Rename variable limitsTz to eventTimeZone

* update

* fix: correct timezone fallback to include user timezone without forcing UTC

- Changed fallback chain to: schedule → event → user → undefined
- Treats empty strings as missing timezones
- Does not force UTC when all timezones are missing
- Aligns with validation behavior when timezone is undefined
- Fixes getSchedule.test.ts failures

Co-Authored-By: [email protected] <[email protected]>

* Revert "fix: correct timezone fallback to include user timezone without forcing UTC"

This reverts commit 721e0bdfd7b08004e68df6bdf5b97b9bd6cf3d5c.

* test: remove complex unit tests with 'as any' casts

- Removed Booking Limits Timezone Alignment tests that required heavy mocking
- These tests relied on spying private methods and had many 'as any' casts
- Timezone alignment is already covered by integration tests in getSchedule.test.ts
- Kept BookingDateInPastError test which has no type issues

Co-Authored-By: [email protected] <[email protected]>

* address review

---------

Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
authored and GitHub committed 2025-11-04 12:13:42 +05:30
1 parent f1db27c0ad
commit 896f8dbd3d
2 files changed
+101 -2

No files matched your search

@@ -823,6 +823,7 @@ export class AvailableSlotsService {
let busyTimesFromLimitsMap: Map<number, EventBusyDetails[]> | undefined = undefined;
if (eventType && (bookingLimits || durationLimits)) {
const usersForLimits = usersWithCredentials.map((user) => ({ id: user.id, email: user.email }));
const eventTimeZone = eventType.schedule?.timeZone ?? usersWithCredentials[0]?.timeZone ?? "UTC";
busyTimesFromLimitsMap = await this.getBusyTimesFromLimitsForUsers(
usersForLimits,
bookingLimits,
@@ -831,7 +832,7 @@ export class AvailableSlotsService {
endTime,
typeof input.duration === "number" ? input.duration : undefined,
eventType,
usersWithCredentials[0]?.timeZone || "UTC",
eventTimeZone,
input.rescheduleUid || undefined
);
}
@@ -845,6 +846,7 @@ export class AvailableSlotsService {
let teamBookingLimitsMap: Map<number, EventBusyDetails[]> | undefined = undefined;
if (teamForBookingLimits && teamBookingLimits) {
const usersForTeamLimits = usersWithCredentials.map((user) => ({ id: user.id, email: user.email }));
const eventTimeZone = eventType.schedule?.timeZone ?? usersWithCredentials[0]?.timeZone ?? "UTC";
teamBookingLimitsMap = await this.getBusyTimesFromTeamLimitsForUsers(
usersForTeamLimits,
teamBookingLimits,
@@ -852,7 +854,7 @@ export class AvailableSlotsService {
endTime,
teamForBookingLimits.id,
teamForBookingLimits.includeManagedEventsInLimits,
usersWithCredentials[0]?.timeZone || "UTC",
eventTimeZone,
input.rescheduleUid || undefined
);
}