Skip to content

Conversation

Aadhira22
Copy link

@Aadhira22 Aadhira22 commented Aug 7, 2025

I noticed that the event scheduler was allowing events to be scheduled outside of the defined working hours (8 AM to 6 PM). I modified the event creation and update logic to ensure events can only be scheduled within this time range.

This change:

  • Restricts event start and end times to be within 8 AM and 6 PM.
  • Adjusts the event times if they are outside the working hours.

Summary by CodeRabbit

  • New Features

    • Event times in the Custom Time scheduler are now automatically adjusted to stay within the configured day start (8 AM) and end (6 PM) hours.
  • Chores

    • Updated webpack development dependency to the latest version.

Copy link

vercel bot commented Aug 7, 2025

@Aadhira22 is attempting to deploy a commit to the Ansul Agrawal's projects Team on Vercel.

A member of the Team first needs to authorize it.

Copy link

coderabbitai bot commented Aug 7, 2025

Walkthrough

The update introduces a helper method to clamp event times within specified scheduler hours in the CustomTime React component, ensuring event times do not exceed set boundaries. The clamping logic is applied to event creation, updates, and movements. Additionally, the webpack development dependency is updated in package.json.

Changes

Cohort / File(s) Change Summary
Dev Dependency Update
package.json
Updated webpack version in devDependencies from ^5.95.0 to ^5.101.0.
CustomTime Event Time Clamping
src/examples/pages/Custom-Time/class-based.jsx
Added clampEventTimes method to restrict event times within scheduler hours. Integrated clamping into event creation, updates, and moves. Minor formatting and comment improvements.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant CustomTimeComponent
    participant SchedulerData
    participant ConfirmationDialog

    User->>CustomTimeComponent: Initiates event create/update/move
    CustomTimeComponent->>CustomTimeComponent: clampEventTimes(schedulerData, start, end)
    CustomTimeComponent->>ConfirmationDialog: Show confirmation with clamped times
    ConfirmationDialog-->>CustomTimeComponent: User confirms
    CustomTimeComponent->>SchedulerData: Update event with clamped times
    SchedulerData-->>CustomTimeComponent: Update state
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Poem

A bunny bounds through code so bright,
Clamping times from dawn to night.
No event may start too soon,
Nor end beyond the evening moon.
With webpack fresh and logic neat,
The scheduler’s bounds are now complete! 🐇✨

Note

🔌 MCP (Model Context Protocol) integration is now available in Early Access!

Pro users can now connect to remote MCP servers under the Integrations page to get reviews and chat conversations that understand additional development context.

✨ Finishing Touches
  • 📝 Docstrings were successfully generated. (🔄 Check again to generate docstrings again)
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 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.
  • 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.

Support

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

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.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 1cc5eaf and 096e316.

📒 Files selected for processing (2)
  • package.json (1 hunks)
  • src/examples/pages/Custom-Time/class-based.jsx (7 hunks)
🔇 Additional comments (7)
package.json (1)

93-93: Webpack version update validated

  • Confirmed that [email protected] exists and is the latest published version.
  • No moderate-or-higher security advisories were found when running npm audit (via lockfile or registry data).
  • As a minor update within the same major version, this bump should not introduce breaking changes.
src/examples/pages/Custom-Time/class-based.jsx (6)

19-20: LGTM! Clear configuration with helpful comments.

The inline comments clearly document the working hours configuration (8 AM to 6 PM), which aligns perfectly with the PR objective.


136-156: LGTM! Proper integration of time clamping in event creation.

The newEvent method correctly uses the clampEventTimes helper and applies the clamped values to both the confirmation dialog and the new event object.


158-164: LGTM! Correct implementation of clamped start time updates.

The updateEventStart method properly clamps the new start time while preserving the existing end time, and updates the scheduler with the clamped value.


166-172: LGTM! Correct implementation of clamped end time updates.

The updateEventEnd method properly clamps the new end time while preserving the existing start time, and updates the scheduler with the clamped value.


174-184: LGTM! Proper integration of time clamping in event moves.

The moveEvent method correctly applies time clamping to both start and end times when moving events, ensuring consistency with the working hours constraint.


93-97: Minor formatting improvements look good.

The removal of unnecessary parentheses in arrow functions and formatting adjustments improve code readability without affecting functionality.

Also applies to: 99-103, 121-121

Comment on lines +37 to +65
// Helper function to clamp times to 8 AM and 7 PM
clampEventTimes = (schedulerData, start, end) => {
const { dayStartFrom, dayStopTo } = schedulerData.config;
const startDate = new Date(start);
const endDate = new Date(end);

// Get the date part to preserve it
const dateStr = startDate.toISOString().split('T')[0];

// Clamp start time to 8 AM
if (startDate.getHours() < dayStartFrom) {
startDate.setHours(dayStartFrom, 0, 0, 0);
}

// Clamp end time to 7 PM
if (endDate.getHours() > dayStopTo || (endDate.getHours() === dayStopTo && endDate.getMinutes() > 0)) {
endDate.setHours(dayStopTo, 0, 0, 0);
}

// Ensure end is not before start
if (endDate < startDate) {
endDate.setTime(startDate.getTime() + 30 * 60 * 1000); // Default to 30 minutes after start
}

return {
clampedStart: `${dateStr}T${startDate.getHours().toString().padStart(2, '0')}:00:00`,
clampedEnd: `${dateStr}T${endDate.getHours().toString().padStart(2, '0')}:00:00`,
};
};
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Critical issues in time clamping logic need to be addressed.

The clampEventTimes helper method has several logical and implementation issues:

  1. Inconsistent hour boundary checking: Line 52 checks if endDate.getHours() > dayStopTo but dayStopTo is 18 (6 PM), so events ending at exactly 6 PM would be incorrectly allowed.

  2. Incomplete time preservation: The method only preserves hours but discards minutes and seconds from the original times, potentially losing precision.

  3. Timezone handling: Using new Date() constructor with ISO strings may cause timezone conversion issues.

  4. Inconsistent return format: Returns ISO-like strings but only with hour precision, not matching typical ISO format.

Apply this diff to fix the time clamping logic:

-  clampEventTimes = (schedulerData, start, end) => {
-    const { dayStartFrom, dayStopTo } = schedulerData.config;
-    const startDate = new Date(start);
-    const endDate = new Date(end);
-
-    // Get the date part to preserve it
-    const dateStr = startDate.toISOString().split('T')[0];
-
-    // Clamp start time to 8 AM
-    if (startDate.getHours() < dayStartFrom) {
-      startDate.setHours(dayStartFrom, 0, 0, 0);
-    }
-
-    // Clamp end time to 7 PM
-    if (endDate.getHours() > dayStopTo || (endDate.getHours() === dayStopTo && endDate.getMinutes() > 0)) {
-      endDate.setHours(dayStopTo, 0, 0, 0);
-    }
-
-    // Ensure end is not before start
-    if (endDate < startDate) {
-      endDate.setTime(startDate.getTime() + 30 * 60 * 1000); // Default to 30 minutes after start
-    }
-
-    return {
-      clampedStart: `${dateStr}T${startDate.getHours().toString().padStart(2, '0')}:00:00`,
-      clampedEnd: `${dateStr}T${endDate.getHours().toString().padStart(2, '0')}:00:00`,
-    };
-  };
+  clampEventTimes = (schedulerData, start, end) => {
+    const { dayStartFrom, dayStopTo } = schedulerData.config;
+    const startDate = new Date(start);
+    const endDate = new Date(end);
+
+    // Get the date part to preserve it  
+    const dateStr = startDate.toISOString().split('T')[0];
+
+    // Clamp start time to working hours start
+    if (startDate.getHours() < dayStartFrom) {
+      startDate.setHours(dayStartFrom, 0, 0, 0);
+    }
+
+    // Clamp end time to working hours end (6 PM = 18:00)
+    if (endDate.getHours() >= dayStopTo) {
+      endDate.setHours(dayStopTo - 1, 59, 59, 999); // Set to 17:59:59 for 6 PM boundary
+    }
+
+    // Ensure end is not before start
+    if (endDate <= startDate) {
+      endDate.setTime(startDate.getTime() + 30 * 60 * 1000); // Default to 30 minutes after start
+    }
+
+    return {
+      clampedStart: startDate.toISOString(),
+      clampedEnd: endDate.toISOString(),
+    };
+  };

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

🤖 Prompt for AI Agents
In src/examples/pages/Custom-Time/class-based.jsx between lines 37 and 65, the
clampEventTimes function has issues with boundary checks, time precision,
timezone handling, and return format. Fix it by adjusting the end time check to
correctly clamp events ending exactly at the boundary hour, preserve minutes and
seconds when clamping start and end times, avoid timezone conversion by
manipulating date components directly rather than relying on ISO string parsing,
and return fully formatted ISO 8601 strings including hours, minutes, and
seconds to maintain consistency and precision.

@ansulagrawal ansulagrawal self-requested a review August 8, 2025 05:40
coderabbitai bot added a commit that referenced this pull request Aug 8, 2025
Docstrings generation was requested by @ansulagrawal.

* #226 (comment)

The following files were modified:

* `src/examples/pages/Custom-Time/class-based.jsx`
Copy link

coderabbitai bot commented Aug 8, 2025

Note

Generated docstrings for this pull request at #227

Copy link

vercel bot commented Aug 14, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Project Deployment Preview Updated (UTC)
react-big-schedule Ready Preview Aug 14, 2025 1:57pm

@ansulagrawal
Copy link
Owner

@Aadhira22 I don't think this is req

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.

2 participants