Skip to content

fix: Weekly view time slots offset and content overflow in different timezones #20570

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,17 @@ export const LargeCalendar = ({
if (!schedule) return availableTimeslots;
if (!schedule.slots) return availableTimeslots;

// Get the user's timezone
const userTimezone = dayjs.tz.guess();

for (const day in schedule.slots) {
availableTimeslots[day] = schedule.slots[day].map((slot) => {
const { time, ...rest } = slot;
// Convert UTC time to user's timezone
const slotTime = dayjs.utc(time).tz(userTimezone);
return {
start: dayjs(time).toDate(),
end: dayjs(time).add(eventDuration, "minutes").toDate(),
start: slotTime.toDate(),
end: slotTime.add(eventDuration, "minutes").toDate(),
...rest,
};
});
Expand Down
9 changes: 3 additions & 6 deletions packages/features/bookings/components/AvailableTimes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -115,24 +115,21 @@ const SlotItem = ({
const bookingData = useBookerStore((state) => state.bookingData);
const layout = useBookerStore((state) => state.layout);
const hasTimeSlots = !!seatsPerTimeSlot;

// Convert UTC time to user's timezone
const computedDateWithUsersTimezone = dayjs.utc(slot.time).tz(timezone);

const bookingFull = !!(hasTimeSlots && slot.attendees && slot.attendees >= seatsPerTimeSlot);
const isHalfFull = slot.attendees && seatsPerTimeSlot && slot.attendees / seatsPerTimeSlot >= 0.5;
const isNearlyFull = slot.attendees && seatsPerTimeSlot && slot.attendees / seatsPerTimeSlot >= 0.83;
const colorClass = isNearlyFull ? "bg-rose-600" : isHalfFull ? "bg-yellow-500" : "bg-emerald-400";

const nowDate = dayjs();
const usersTimezoneDate = nowDate.tz(timezone);

const offset = (usersTimezoneDate.utcOffset() - nowDate.utcOffset()) / 60;

const selectedTimeslot = useBookerStore((state) => state.selectedTimeslot);

const { isOverlapping, overlappingTimeEnd, overlappingTimeStart } = useCheckOverlapWithOverlay({
start: computedDateWithUsersTimezone,
selectedDuration: eventData?.length ?? 0,
offset,
offset: 0, // We don't need manual offset since we're using proper timezone conversion
});

const onButtonClick = () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,14 @@ export function useCheckOverlapWithOverlay({
overlayBusyDates.some((busyDate) => {
const busyDateStart = dayjs(busyDate.start);
const busyDateEnd = dayjs(busyDate.end);
const selectedEndTime = dayjs(start.add(offset, "hours")).add(selectedDuration ?? 0, "minute");

// Use the offset parameter if provided, otherwise use 0
const adjustedStart = offset !== 0 ? start.add(offset, "hours") : start;
const selectedEndTime = adjustedStart.add(selectedDuration ?? 0, "minute");

const isOverlapping =
(selectedEndTime.isSame(busyDateStart) || selectedEndTime.isAfter(busyDateStart)) &&
start.add(offset, "hours") < busyDateEnd &&
adjustedStart < busyDateEnd &&
selectedEndTime > busyDateStart;

overlappingTimeStart = isOverlapping ? getCurrentTime(busyDateStart.toDate()) : null;
Expand Down
24 changes: 24 additions & 0 deletions packages/features/bookings/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"extends": "@calcom/tsconfig/react-library.json",
"compilerOptions": {
"baseUrl": ".",
"paths": {
"@/*": ["./*"],
"@calcom/*": ["../../../packages/*"]
},
"resolveJsonModule": true,
"esModuleInterop": true,
"jsx": "react-jsx",
"types": ["react", "node"],
"typeRoots": ["../../../node_modules/@types", "../../../packages/types"]
},
"include": [
".",
"../../../packages/types/next-auth.d.ts",
"../../../packages/types/tanstack-table.d.ts",
"../../../packages/types/next.d.ts",
"../../../packages/types/Calendar.d.ts",
"../../../packages/types/schedule.d.ts"
],
"exclude": ["dist", "build", "node_modules", "**/*.test.*", "**/__mocks__/*", "**/__tests__/*"]
}
Loading