Skip to content

Advanced date override handling and timezone compatibility improvements#6

Open
ShashankFC wants to merge 1 commit into
date-algorithm-basefrom
date-algorithm-enhanced
Open

Advanced date override handling and timezone compatibility improvements#6
ShashankFC wants to merge 1 commit into
date-algorithm-basefrom
date-algorithm-enhanced

Conversation

@ShashankFC

Copy link
Copy Markdown

Test 7nn

Summary by CodeRabbit

  • New Features

    • Improved timezone awareness for date overrides and availability calculations
    • Added working hours validation to availability checks
    • Enhanced date override processing to properly handle timezone offsets between organizers and invitees
  • Tests

    • Added test verifying timezone consistency across schedule calculations

✏️ Tip: You can customize this high-level summary in your review settings.

nn---n*Replicated from [ai-code-review-evaluation/cal.com-coderabbit#7](https://github.com/ai-code-review-evaluation/cal.com-coderabbit/pull/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 <wollencarina@gmail.com>
@ShashankFC ShashankFC requested a review from Copilot January 30, 2026 10:17

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR enhances date override handling and timezone compatibility in the scheduling system by ensuring proper timezone conversions between organizers and invitees, and adding working hours validation to availability checks.

Changes:

  • Added timezone-aware date override processing that accounts for UTC offset differences between organizer and invitee timezones
  • Implemented working hours validation in the availability checking logic
  • Added test coverage for cross-timezone date override scenarios

Reviewed changes

Copilot reviewed 3 out of 4 changed files in this pull request and generated 5 comments.

File Description
packages/trpc/server/routers/viewer/slots.ts Added date override and working hours validation logic to checkIfIsAvailable, and ensured organizer timezone is passed through availability checks
packages/lib/slots.ts Enhanced date override processing to calculate and apply timezone offset differences between organizer and invitee
apps/web/test/lib/getSchedule.test.ts Added test case verifying timezone consistency for date overrides across different timezones

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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

Copilot AI Jan 30, 2026

Copy link

Choose a reason for hiding this comment

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

The 'end' variable calculation duplicates the 'start' calculation. It should use 'slotEndTime' instead of 'slotStartTime' to correctly represent the end of the time slot.

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

Copilot uses AI. Check for mistakes.
slotStartTime.format("YYYY MM DD")
) {
dateOverrideExist = true;
if (dayjs(date.start).add(utcOffset, "minutes") === dayjs(date.end).add(utcOffset, "minutes")) {

Copilot AI Jan 30, 2026

Copy link

Choose a reason for hiding this comment

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

This comparison uses strict equality (===) on dayjs objects, which compares object references rather than values. Use .isSame() method for proper date comparison.

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"))
) {

Copilot uses AI. Check for mistakes.
const slotEndTime = time.add(eventLength, "minutes").utc();
const slotStartTime = time.utc();

//check if date override for slot exists

Copilot AI Jan 30, 2026

Copy link

Choose a reason for hiding this comment

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

Comment should start with a space after '//' for consistency with code style conventions.

Suggested change
//check if date override for slot exists
// check if date override for slot exists

Copilot uses AI. Check for mistakes.
return true;
}

//if no date override for slot exists check if it is within normal work hours

Copilot AI Jan 30, 2026

Copy link

Choose a reason for hiding this comment

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

Comment should start with a space after '//' for consistency with code style conventions.

Copilot uses AI. Check for mistakes.
Comment on lines +107 to +123
const utcOffset = organizerTimeZone ? dayjs.tz(date.start, organizerTimeZone).utcOffset() * -1 : 0;

if (
dayjs(date.start).add(utcOffset, "minutes").format("YYYY MM DD") ===
slotStartTime.format("YYYY MM DD")
) {
dateOverrideExist = true;
if (dayjs(date.start).add(utcOffset, "minutes") === dayjs(date.end).add(utcOffset, "minutes")) {
return true;
}
if (
slotEndTime.isBefore(dayjs(date.start).add(utcOffset, "minutes")) ||
slotEndTime.isSame(dayjs(date.start).add(utcOffset, "minutes"))
) {
return true;
}
if (slotStartTime.isAfter(dayjs(date.end).add(utcOffset, "minutes"))) {

Copilot AI Jan 30, 2026

Copy link

Choose a reason for hiding this comment

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

The UTC offset calculation appears inconsistent with the approach in packages/lib/slots.ts (lines 212-214), which computes the difference between invitee and organizer offsets. Consider using a consistent approach across both files for maintainability.

Suggested change
const utcOffset = organizerTimeZone ? dayjs.tz(date.start, organizerTimeZone).utcOffset() * -1 : 0;
if (
dayjs(date.start).add(utcOffset, "minutes").format("YYYY MM DD") ===
slotStartTime.format("YYYY MM DD")
) {
dateOverrideExist = true;
if (dayjs(date.start).add(utcOffset, "minutes") === dayjs(date.end).add(utcOffset, "minutes")) {
return true;
}
if (
slotEndTime.isBefore(dayjs(date.start).add(utcOffset, "minutes")) ||
slotEndTime.isSame(dayjs(date.start).add(utcOffset, "minutes"))
) {
return true;
}
if (slotStartTime.isAfter(dayjs(date.end).add(utcOffset, "minutes"))) {
const slotStartInOrganizerTz = organizerTimeZone ? slotStartTime.tz(organizerTimeZone) : slotStartTime;
const slotEndInOrganizerTz = organizerTimeZone ? slotEndTime.tz(organizerTimeZone) : slotEndTime;
const dateStartInOrganizerTz = organizerTimeZone
? dayjs(date.start).tz(organizerTimeZone)
: dayjs(date.start).utc();
const dateEndInOrganizerTz = organizerTimeZone
? dayjs(date.end).tz(organizerTimeZone)
: dayjs(date.end).utc();
if (
dateStartInOrganizerTz.format("YYYY MM DD") ===
slotStartInOrganizerTz.format("YYYY MM DD")
) {
dateOverrideExist = true;
if (dateStartInOrganizerTz.isSame(dateEndInOrganizerTz)) {
return true;
}
if (slotEndInOrganizerTz.isBefore(dateStartInOrganizerTz) || slotEndInOrganizerTz.isSame(dateStartInOrganizerTz)) {
return true;
}
if (slotStartInOrganizerTz.isAfter(dateEndInOrganizerTz)) {

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants