Skip to content

feat: to enable optimized slots #16579

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

Open
wants to merge 71 commits into
base: main
Choose a base branch
from

Conversation

vijayraghav-io
Copy link
Contributor

@vijayraghav-io vijayraghav-io commented Sep 10, 2024

What does this PR do?

For the sake of demo video, availability is adjusted to simulate busy time as per examples in issue description. It should work same even with calendar busy times.

https://www.loom.com/share/8247ea087bae4aa497c48853bb2e3f8d?sid=33a96f51-1548-43d7-9b37-815d90ecc6b8

Video with calendar busy times (as per example)

https://www.loom.com/share/a9a04ee012134f31b4a5a0dfa6b2072e?sid=a4a98b11-263d-4799-875e-fe46b45ab8bf

Mandatory Tasks (DO NOT REMOVE)

  • I have self-reviewed the code (A decent size PR without self-review might be rejected).
  • -N/A - I have added a Docs issue here if this PR makes changes that would require a documentation change. If N/A, write N/A here and check the checkbox.
  • I confirm automated tests are in place that prove my fix is effective or that my feature works.

Copy link

vercel bot commented Sep 10, 2024

@vijayraghav-io is attempting to deploy a commit to the cal Team on Vercel.

A member of the Team first needs to authorize it.

@github-actions github-actions bot added ❗️ migrations contains migration files ✨ feature New feature or request labels Sep 10, 2024
@dosubot dosubot bot added the event-types area: event types, event-types label Sep 10, 2024
@graphite-app graphite-app bot added the community Created by Linear-GitHub Sync label Sep 10, 2024
@graphite-app graphite-app bot requested a review from a team September 10, 2024 19:15
Copy link

graphite-app bot commented Sep 10, 2024

Graphite Automations

"Add consumer team as reviewer" took an action on this PR • (09/10/24)

1 reviewer was added to this PR based on Keith Williams's automation.

"Add community label" took an action on this PR • (09/10/24)

1 label was added to this PR based on Keith Williams's automation.

"Add foundation team as reviewer" took an action on this PR • (09/12/24)

1 reviewer was added to this PR based on Keith Williams's automation.

slotStartTime =
slotStartTime.minute() % interval !== 0
? showOptimizedSlots
? slotStartTime.add(rangeEnd.diff(slotStartTime, "minutes") % interval, "minute")
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This ensures within a time range, always maximum available (optimum) slots are shown (without loss of any slot) And also Start of the Hour is respected.
Also , this happens only if user availability starts in minutes , say 10:10 , 10:05 (instead of 10:00 normally) and user has chosen to optimize.
For all other scenarios, the existing behaviour applies and i understand that is expected.

Copy link
Contributor

github-actions bot commented Sep 11, 2024

E2E results are ready!

Copy link
Contributor

@Amit91848 Amit91848 left a comment

Choose a reason for hiding this comment

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

Thanks for the PR @vijayraghav-io 🙌.
Haven't tested it completely yet, but code wise looks good. Can you add tests to ensure this works and won't break in the future.

@vijayraghav-io
Copy link
Contributor Author

Thanks for the PR @vijayraghav-io 🙌. Haven't tested it completely yet, but code wise looks good. Can you add tests to ensure this works and won't break in the future.

Thank you! @Amit91848 , sure will add tests.

@vijayraghav-io
Copy link
Contributor Author

@Amit91848, added tests.

Copy link
Member

@CarinaWolli CarinaWolli left a comment

Choose a reason for hiding this comment

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

This availability:
Screenshot 2024-09-12 at 10 08 19 AM

Shows the following slots:
Screenshot 2024-09-12 at 10 08 48 AM

But should be:
8:00, 9:00, 10:00, 11:00, 12:00, 13:00, 14:00

@CarinaWolli CarinaWolli added the high-risk Requires approval by Foundation team label Sep 12, 2024
@graphite-app graphite-app bot requested a review from a team September 12, 2024 14:12
@vijayraghav-io
Copy link
Contributor Author

vijayraghav-io commented Sep 12, 2024

This availability:

@CarinaWolli , handled this edge case. Also added a test case for this.

To explain the implementation -
A increment is added to the slotStartTime to adjust to be Start Of the hour,
if this increment exceeds the next Start of the hour, a condition is added to Not exceed the Start of the hour.
This should cover all cases.

Comment on lines 208 to 210
? rangeEnd.diff(slotStartTime, "minutes") % interval > interval - slotStartTime.minute()
? slotStartTime.add(interval - slotStartTime.minute(), "minute")
: slotStartTime.add(rangeEnd.diff(slotStartTime, "minutes") % interval, "minute")
Copy link
Contributor Author

@vijayraghav-io vijayraghav-io Sep 12, 2024

Choose a reason for hiding this comment

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

rangeEnd.diff(slotStartTime, "minutes") % interval - gives the remaining grace minutes available for adjustment, after consuming maximum possible slots.

Condition rangeEnd.diff(slotStartTime, "minutes") % interval > interval - slotStartTime.minute() -
After adding this grace (or free) minutes available for adjustment to slotStartTime, if result exceeds the 'next start of the hour , it is adjusted to 'start of the hour

@dosubot dosubot bot modified the milestone: v5.6 Jul 16, 2025
CarinaWolli
CarinaWolli previously approved these changes Jul 16, 2025
@CarinaWolli CarinaWolli requested a review from emrysal July 16, 2025 07:59
Copy link

delve-auditor bot commented Jul 22, 2025

No security or compliance issues detected. Reviewed everything up to 7accaf7.

Security Overview
  • 🔎 Scanned files: 16 changed file(s)
Detected Code Changes

The diff is too large to display a summary of code changes.

Reply to this PR with @delve-auditor followed by a description of what change you want and we'll auto-submit a change to this PR to implement it.

CarinaWolli
CarinaWolli previously approved these changes Jul 22, 2025
Copy link
Contributor

@Devanshusharma2005 Devanshusharma2005 left a comment

Choose a reason for hiding this comment

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

Great pr @vijayraghav-io . Can you please address the typecheck issue failing.

@vijayraghav-io
Copy link
Contributor Author

Great pr @vijayraghav-io . Can you please address the typecheck issue failing.

Thank you! 🙏 , sure will address.

@vijayraghav-io
Copy link
Contributor Author

@Devanshusharma2005 all checks are passing

@CarinaWolli
Copy link
Member

@emrysal for review, it's looking good from my side 🙏

@CarinaWolli CarinaWolli added High priority Created by Linear-GitHub Sync and removed Medium priority Created by Linear-GitHub Sync labels Aug 12, 2025
Copy link
Contributor

@volnei volnei left a comment

Choose a reason for hiding this comment

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

LGTM

@dosubot dosubot bot modified the milestones: v5.6, v5.7 Aug 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
community Created by Linear-GitHub Sync event-types area: event types, event-types ✨ feature New feature or request High priority Created by Linear-GitHub Sync high-risk Requires approval by Foundation team ❗️ migrations contains migration files ready-for-e2e 🚧 wip / in the making This is currently being worked on
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[CAL-4303] Optimized schedules
8 participants