Skip to content

Conversation

@everettbu
Copy link

Test 7

* fix date override for fixed round robin + time zone in date override

* check if slot is within working hours of fixed hosts

* add test for date override in different time zone

* fix date overrides for not fixed hosts (round robin)

* code clean up

* fix added test

* use the correct timezone of user for date overrides

---------

Co-authored-by: CarinaWolli <[email protected]>
Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Greptile Summary

This PR enhances timezone compatibility for date override functionality in the Cal.com scheduling system. The changes span across type definitions, slot calculation logic, and availability checking.

The core changes include:

  1. Type System Enhancement: Added an optional timeZone field to the TimeRange type in packages/types/schedule.d.ts, enabling timezone context to be stored with date overrides.

  2. Slot Calculation Improvements: Modified packages/lib/slots.ts to implement sophisticated timezone offset calculations when processing date overrides. The system now calculates the difference between organizer and invitee UTC offsets and adjusts override times accordingly.

  3. Availability Checking Logic: Enhanced packages/trpc/server/routers/viewer/slots.ts with new parameters (dateOverrides, workingHours, organizerTimeZone) to the checkIfIsAvailable function. This includes complex date override validation with timezone offset calculations and working hours validation as a fallback.

  4. Test Coverage: Added a comprehensive test case in apps/web/test/lib/getSchedule.test.ts to verify that date overrides maintain UTC consistency when requested from different timezones.

These changes address the critical need for consistent timezone handling in a global scheduling application, ensuring that availability calculations remain accurate regardless of the timezone differences between organizers and invitees. The implementation focuses on maintaining UTC consistency while properly handling timezone-specific date overrides.

Confidence score: 1/5

• This PR has critical bugs that will cause immediate production issues and should not be merged.
• The timezone calculation logic contains fundamental errors, including incomplete implementations, mathematical mistakes in UTC offset calculations, and a critical bug in working hours validation that could break availability checking.
• All modified files need significant attention, particularly packages/lib/slots.ts and packages/trpc/server/routers/viewer/slots.ts which contain the most critical issues.

4 files reviewed, 1 comment

Edit Code Review Bot Settings | Greptile

workingHours.find((workingHour) => {
if (workingHour.days.includes(slotStartTime.day())) {
const start = slotStartTime.hour() * 60 + slotStartTime.minute();
const end = slotStartTime.hour() * 60 + slotStartTime.minute();
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logic: Bug: end should use slotEndTime instead of slotStartTime. This will incorrectly validate working hours as both start and end use the same time.

Suggested change
const end = slotStartTime.hour() * 60 + slotStartTime.minute();
const end = slotEndTime.hour() * 60 + slotEndTime.minute();

slotStartTime.format("YYYY MM DD")
) {
dateOverrideExist = true;
if (dayjs(date.start).add(utcOffset, "minutes") === dayjs(date.end).add(utcOffset, "minutes")) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logic: Potential issue: Using === for dayjs comparison may not work as expected. Consider using .isSame() method instead.

Suggested change
if (dayjs(date.start).add(utcOffset, "minutes") === dayjs(date.end).add(utcOffset, "minutes")) {
if (dayjs(date.start).add(utcOffset, "minutes").isSame(dayjs(date.end).add(utcOffset, "minutes"))) {

@github-actions
Copy link
Contributor

This PR is being marked as stale due to inactivity.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants