Skip to content

Conversation

@akshayutture-augment
Copy link

* 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.

Your free trial has ended. If you'd like to continue receiving code reviews, you can add a payment method here.

@akshayutture-augment
Copy link
Author

@greptileai

@greptile-apps
Copy link

greptile-apps bot commented Nov 14, 2025

Greptile Overview

Confidence Score: 1/5

  • This PR contains critical logic bugs that will cause incorrect slot availability calculations
  • Two critical bugs in the slot availability validation logic will cause runtime errors in availability calculations, making the scheduling system unreliable
  • Pay close attention to packages/trpc/server/routers/viewer/slots.ts - the bugs on lines 114 and 142 must be fixed before merge

Important Files Changed

File Analysis

Filename Score Overview
packages/trpc/server/routers/viewer/slots.ts 1/5 Added timezone-aware date override handling and working hours validation, but contains two critical bugs: incorrect end time calculation and broken dayjs equality check
packages/lib/slots.ts 4/5 Improved timezone handling for date overrides by calculating UTC offset differences between organizer and invitee timezones
packages/types/schedule.d.ts 5/5 Added optional timeZone field to TimeRange type to support timezone-aware date overrides
apps/web/test/lib/getSchedule.test.ts 5/5 Added test case to verify date override handling works correctly across different timezones

Sequence Diagram

sequenceDiagram
    participant Client
    participant getSchedule
    participant getUserAvailability
    participant getSlots
    participant checkIfIsAvailable

    Client->>getSchedule: request slots (eventTypeId, timeZone, dateRange)
    getSchedule->>getUserAvailability: get user availability
    getUserAvailability-->>getSchedule: return (busy, workingHours, dateOverrides, timeZone)
    
    Note over getSchedule: Flatten dateOverrides from all users<br/>and add timeZone to each override
    
    getSchedule->>getSlots: generate time slots
    Note over getSlots: Calculate timezone offset between<br/>organizer and invitee
    getSlots->>getSlots: Apply date overrides with<br/>timezone adjustments
    getSlots-->>getSchedule: return raw time slots
    
    loop For each time slot
        getSchedule->>checkIfIsAvailable: check slot availability
        Note over checkIfIsAvailable: 1. Check if date override exists<br/>2. Validate against working hours<br/>3. Check busy times
        checkIfIsAvailable-->>getSchedule: return isAvailable
    end
    
    getSchedule-->>Client: return available slots
Loading

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.

4 files reviewed, 2 comments

Edit Code Review Agent Settings | Greptile

Comment on lines +141 to +142
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: end is incorrectly set to the same value as start, causing slotEndTime to never be checked

Suggested change
const start = slotStartTime.hour() * 60 + slotStartTime.minute();
const end = slotStartTime.hour() * 60 + slotStartTime.minute();
const start = slotStartTime.hour() * 60 + slotStartTime.minute();
const end = slotEndTime.hour() * 60 + slotEndTime.minute();
Prompt To Fix With AI
This is a comment left during a code review.
Path: packages/trpc/server/routers/viewer/slots.ts
Line: 141:142

Comment:
**logic:** `end` is incorrectly set to the same value as `start`, causing `slotEndTime` to never be checked

```suggestion
        const start = slotStartTime.hour() * 60 + slotStartTime.minute();
        const end = slotEndTime.hour() * 60 + slotEndTime.minute();
```

How can I resolve this? If you propose a fix, please make it concise.

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: using === to compare dayjs objects will always return false since it compares object references, not values

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"))) {
Prompt To Fix With AI
This is a comment left during a code review.
Path: packages/trpc/server/routers/viewer/slots.ts
Line: 114:114

Comment:
**logic:** using `===` to compare dayjs objects will always return false since it compares object references, not values

```suggestion
        if (dayjs(date.start).add(utcOffset, "minutes").isSame(dayjs(date.end).add(utcOffset, "minutes"))) {
```

How can I resolve this? If you propose a fix, please make it concise.

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