Skip to content

Conversation

@Adrenalineren
Copy link
Contributor

@Adrenalineren Adrenalineren commented Dec 15, 2025

Resolves #21

Copilot AI review requested due to automatic review settings December 15, 2025 07:53
@vercel
Copy link

vercel bot commented Dec 15, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Review Updated (UTC)
nusc-website Ready Ready Preview, Comment Jan 13, 2026 4:33pm

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This pull request implements a weekly booking deadline restriction that prevents non-admin users from creating bookings less than 7 days in advance. Admin users are exempt from this restriction.

Key Changes:

  • Added validation logic to check booking advance notice requirements
  • Implemented admin exemption for the deadline restriction

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

const now = new Date();
const bookingDate = new Date(data.startTime);
const daysUntilBooking = Math.floor(
(bookingDate.getTime() - now.getTime()) / (1000 * 60 * 60 * 24),
Copy link

Copilot AI Dec 15, 2025

Choose a reason for hiding this comment

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

The magic number 1000 * 60 * 60 * 24 for milliseconds per day should be extracted to a named constant for better maintainability and clarity. This makes the code more readable and reduces the risk of calculation errors.

Copilot uses AI. Check for mistakes.
const daysUntilBooking = Math.floor(
(bookingDate.getTime() - now.getTime()) / (1000 * 60 * 60 * 24),
);
if (daysUntilBooking < 7) {
Copy link

Copilot AI Dec 15, 2025

Choose a reason for hiding this comment

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

The magic number 7 (representing 7 days) should be extracted to a named constant like MIN_BOOKING_ADVANCE_DAYS. This makes the requirement more explicit and easier to modify if business rules change.

Copilot uses AI. Check for mistakes.
Comment on lines 59 to 61
const daysUntilBooking = Math.floor(
(bookingDate.getTime() - now.getTime()) / (1000 * 60 * 60 * 24),
);
Copy link

Copilot AI Dec 15, 2025

Choose a reason for hiding this comment

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

The date calculation doesn't account for timezones, which can lead to inconsistent behavior. When creating Date objects without timezone specification, they use the server's local timezone, but bookings may be created by users in different timezones. This can result in incorrect day calculations. Consider using UTC methods for consistent date comparison, or ensure both dates are normalized to the same timezone before calculating the difference.

Suggested change
const daysUntilBooking = Math.floor(
(bookingDate.getTime() - now.getTime()) / (1000 * 60 * 60 * 24),
);
// Calculate difference in days using UTC to avoid timezone issues
const utcNow = Date.UTC(now.getUTCFullYear(), now.getUTCMonth(), now.getUTCDate());
const utcBooking = Date.UTC(bookingDate.getUTCFullYear(), bookingDate.getUTCMonth(), bookingDate.getUTCDate());
const daysUntilBooking = Math.floor((utcBooking - utcNow) / (1000 * 60 * 60 * 24));

Copilot uses AI. Check for mistakes.
if (token.isAdmin === false) {
const now = new Date();
const bookingDate = new Date(data.startTime);
const daysUntilBooking = Math.floor(
Copy link

Copilot AI Dec 15, 2025

Choose a reason for hiding this comment

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

The Math.floor operation can produce incorrect results for edge cases. For example, if a booking is made 6 days and 23 hours in advance, Math.floor will round down to 6 days, rejecting a booking that's nearly 7 days away. Consider using Math.ceil or adjusting the threshold to ensure the 7-day requirement is accurately enforced based on the intended business logic.

Suggested change
const daysUntilBooking = Math.floor(
const daysUntilBooking = Math.ceil(

Copilot uses AI. Check for mistakes.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copy link
Collaborator

@TheMythologist TheMythologist left a comment

Choose a reason for hiding this comment

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

Do look through the document linked in the issue #21 for more specific booking restrictions per venue. The current implementation is too basic. Also look through the comments by Copilot and address those issues

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.

Implement weekly booking restrictions

3 participants