Skip to content

Advanced date override handling and timezone compatibility improvements#7

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

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

Conversation

@everettbu

@everettbu everettbu commented Jul 28, 2025

Copy link
Copy Markdown

Test 7

Summary by CodeRabbit

  • New Features

    • Improved availability checking by ensuring date overrides and working hours are accurately handled across different time zones.
    • Added support for specifying a time zone in user availability time ranges.
  • Bug Fixes

    • Fixed inconsistencies in schedule output when comparing different time zones with identical underlying UTC times.
  • Tests

    • Added a test to verify consistent scheduling results across different time zones with the same UTC intervals.

* 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>
@coderabbitai

coderabbitai Bot commented Jul 28, 2025

Copy link
Copy Markdown
Contributor

Walkthrough

The changes introduce improved timezone handling for schedule overrides and availability checks. Adjustments ensure that override times are correctly mapped between organizer and invitee timezones. Function signatures and types are updated to support timezone context, and tests are added to verify consistent schedule output across different timezones.

Changes

Cohort / File(s) Change Summary
Test: Schedule Timezone Consistency
apps/web/test/lib/getSchedule.test.ts
Added a test to verify that schedule output remains consistent across different time zones when UTC times are the same.
Slots Logic: Timezone-Aware Overrides
packages/lib/slots.ts
Modified override time calculations in getSlots to adjust for timezone differences between organizer and invitee, ensuring correct translation of override periods.
Availability Logic & Schedule Flow
packages/trpc/server/routers/viewer/slots.ts
Extended checkIfIsAvailable and getSchedule to handle timezone-aware date overrides and working hours. Updated function signatures and internal logic for consistent timezone handling in availability checks and filtering.
Types: TimeRange Extension
packages/types/schedule.d.ts
Added an optional timeZone property to the TimeRange type to support storing timezone context with time ranges.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant Server (getSchedule)
    participant SlotsLib (getSlots)
    participant Availability (checkIfIsAvailable)

    Client->>Server (getSchedule): Request schedule (with user timezones)
    Server->>SlotsLib (getSlots): Get slots (pass overrides, timezones)
    SlotsLib-->>Server (getSlots): Return slots (timezone-adjusted)
    loop For each slot
        Server->>Availability (checkIfIsAvailable): Check slot (with overrides, working hours, organizerTimeZone)
        Availability-->>Server: Slot available/unavailable
    end
    Server-->>Client: Return filtered schedule
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~35 minutes

Poem

In burrows deep, I code and hop,
Through timezones now, I never stop!
Schedules align, overrides right,
Day or night, the slots are tight.
With every test, my whiskers twitch—
Hooray for time, in every niche!
🕰️🐇

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch date-algorithm-enhanced

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@everettbu

Copy link
Copy Markdown
Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 28, 2025

Copy link
Copy Markdown
Contributor
✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 3

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c4fe69d and 3ef3284.

📒 Files selected for processing (4)
  • apps/web/test/lib/getSchedule.test.ts (1 hunks)
  • packages/lib/slots.ts (1 hunks)
  • packages/trpc/server/routers/viewer/slots.ts (9 hunks)
  • packages/types/schedule.d.ts (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (2)
apps/web/test/lib/getSchedule.test.ts (1)
packages/trpc/server/routers/viewer/slots.ts (1)
  • getSchedule (337-635)
packages/trpc/server/routers/viewer/slots.ts (4)
packages/dayjs/index.ts (1)
  • Dayjs (25-25)
packages/types/Calendar.d.ts (1)
  • EventBusyDate (46-50)
packages/types/schedule.d.ts (1)
  • WorkingHours (16-21)
packages/core/getUserAvailability.ts (1)
  • CurrentSeats (98-98)
🔇 Additional comments (3)
packages/types/schedule.d.ts (1)

1-6: LGTM! Good addition for timezone context.

Adding the optional timeZone property to TimeRange is a clean way to associate timezone information with date overrides. This maintains backward compatibility while enabling the timezone-aware scheduling improvements.

apps/web/test/lib/getSchedule.test.ts (1)

788-804: Good test coverage for timezone consistency.

This test effectively verifies that the schedule returns consistent UTC slots regardless of the invitee's timezone parameter, which is the expected behavior when the underlying UTC time range remains the same.

packages/trpc/server/routers/viewer/slots.ts (1)

102-136: Add null check and consider simplifying the date override logic.

The code uses organizerTimeZone without checking if it's defined. Also, the logic flow with multiple early returns is hard to follow.

Consider:

  1. Add null check for organizerTimeZone:
- const utcOffset = organizerTimeZone ? dayjs.tz(date.start, organizerTimeZone).utcOffset() * -1 : 0;
+ const utcOffset = organizerTimeZone ? -dayjs.tz(date.start, organizerTimeZone).utcOffset() : 0;
  1. Simplify the logic flow to make it more readable. The current implementation has many branches and early returns that make it difficult to understand the intended behavior.

Likely an incorrect or invalid review comment.

Comment thread packages/lib/slots.ts
Comment on lines +211 to +225
const overrides = activeOverrides.flatMap((override) => {
const organizerUtcOffset = dayjs(override.start.toString()).tz(override.timeZone).utcOffset();
const inviteeUtcOffset = dayjs(override.start.toString()).tz(timeZone).utcOffset();
const offset = inviteeUtcOffset - organizerUtcOffset;

return {
userIds: override.userId ? [override.userId] : [],
startTime:
dayjs(override.start).utc().add(offset, "minute").hour() * 60 +
dayjs(override.start).utc().add(offset, "minute").minute(),
endTime:
dayjs(override.end).utc().add(offset, "minute").hour() * 60 +
dayjs(override.end).utc().add(offset, "minute").minute(),
};
});

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Add null check for optional timeZone property.

The code accesses override.timeZone without checking if it exists, but the TimeRange type defines timeZone as optional. This could cause issues if the timezone is not provided.

Consider adding a null check or default value:

 const overrides = activeOverrides.flatMap((override) => {
-  const organizerUtcOffset = dayjs(override.start.toString()).tz(override.timeZone).utcOffset();
+  const organizerTimeZone = override.timeZone || organizerTimeZone; // Use passed organizerTimeZone as fallback
+  const organizerUtcOffset = dayjs(override.start.toString()).tz(organizerTimeZone).utcOffset();
   const inviteeUtcOffset = dayjs(override.start.toString()).tz(timeZone).utcOffset();
   const offset = inviteeUtcOffset - organizerUtcOffset;

Committable suggestion skipped: line range outside the PR's diff.

🤖 Prompt for AI Agents
In packages/lib/slots.ts around lines 211 to 225, the code accesses
override.timeZone without verifying if it exists, but timeZone is optional in
the TimeRange type. To fix this, add a null check or provide a default timezone
value when accessing override.timeZone to prevent runtime errors when it is
undefined.

Comment on lines +139 to +145
workingHours.find((workingHour) => {
if (workingHour.days.includes(slotStartTime.day())) {
const start = slotStartTime.hour() * 60 + slotStartTime.minute();
const end = slotStartTime.hour() * 60 + slotStartTime.minute();
if (start < workingHour.startTime || end > workingHour.endTime) {
return true;
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Critical bug: Incorrect end time calculation in working hours check.

The end variable is using the same calculation as start, which will always make them equal. This breaks the working hours validation logic.

Fix the calculation:

 if (workingHour.days.includes(slotStartTime.day())) {
   const start = slotStartTime.hour() * 60 + slotStartTime.minute();
-  const end = slotStartTime.hour() * 60 + slotStartTime.minute();
+  const end = slotEndTime.hour() * 60 + slotEndTime.minute();
   if (start < workingHour.startTime || end > workingHour.endTime) {
     return true;
   }
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
workingHours.find((workingHour) => {
if (workingHour.days.includes(slotStartTime.day())) {
const start = slotStartTime.hour() * 60 + slotStartTime.minute();
const end = slotStartTime.hour() * 60 + slotStartTime.minute();
if (start < workingHour.startTime || end > workingHour.endTime) {
return true;
}
workingHours.find((workingHour) => {
if (workingHour.days.includes(slotStartTime.day())) {
const start = slotStartTime.hour() * 60 + slotStartTime.minute();
const end = slotEndTime.hour() * 60 + slotEndTime.minute();
if (start < workingHour.startTime || end > workingHour.endTime) {
return true;
}
}
});
🤖 Prompt for AI Agents
In packages/trpc/server/routers/viewer/slots.ts around lines 139 to 145, the
variable 'end' is incorrectly calculated using the same expression as 'start',
causing both to be equal and breaking the working hours validation. Fix this by
calculating 'end' based on the slot end time instead of the slot start time,
ensuring it correctly represents the ending minute of the slot.

time: slot.time,
...schedule,
...availabilityCheckProps,
organizerTimeZone: schedule.timeZone,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Ensure consistent null-safety when accessing timeZone properties.

The code inconsistently handles potentially undefined timeZone values:

  • Line 492: schedule.timeZone (no null check)
  • Line 517: userSchedule.timeZone (no null check)
  • Line 585: userSchedule?.timeZone (with optional chaining)

Consider using consistent null-safety throughout:

- organizerTimeZone: schedule.timeZone,
+ organizerTimeZone: schedule.timeZone || organizerTimeZone,
- organizerTimeZone: userSchedule.timeZone,
+ organizerTimeZone: userSchedule.timeZone || organizerTimeZone,

Also applies to: 517-517, 585-585

🤖 Prompt for AI Agents
In packages/trpc/server/routers/viewer/slots.ts at lines 492, 517, and 585, the
timeZone properties are accessed inconsistently regarding null safety. To fix
this, apply optional chaining or null checks uniformly when accessing
schedule.timeZone and userSchedule.timeZone to prevent runtime errors from
undefined values. Update lines 492 and 517 to use optional chaining like line
585 for consistent null-safe access.

@github-actions

Copy link
Copy Markdown
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