fix: correct incrementDate function in E2E tests to properly calculate next month date (#27501)

The incrementDate function was using .day() incorrectly, which sets the day
of the week for the CURRENT week rather than finding the same weekday in
the next month. This caused the function to return dates in the previous
month when the target date fell early in the week.

For example, when incrementing March 2, 2026 (Monday) by a month:
- Old behavior: April 2 (Thursday) + .day(1) = March 30 (wrong month!)
- New behavior: First Monday in April = April 6 (correct)

This bug caused flaky E2E test failures in booking-limits and duration-limits
tests because the 'year limit with multiple limits set' test would try to
book on a date that was still in the same month, which was blocked by the
month limit (3 bookings already existed in that month).

Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
Anik Dhabal Babu
2026-02-02 07:23:15 -03:00
committed by GitHub
co-authored by Devin AI
parent 8f6d580233
commit 888a8d806d
2 changed files with 18 additions and 2 deletions
+9 -1
View File
@@ -56,7 +56,15 @@ const firstMondayInBookingMonth = firstDayInBookingMonth.day(
// ensure we land on the same weekday when incrementing month
const incrementDate = (date: Dayjs, unit: dayjs.ManipulateType) => {
if (unit !== "month") return date.add(1, unit);
return date.add(1, "month").day(date.day());
// Find the first occurrence of the same weekday in the next month
// Note: .day() sets the day of the week for the CURRENT week, which can
// return a date in the previous month. Instead, we calculate the correct date.
const targetDay = date.day();
const startOfNextMonth = date.add(1, "month").startOf("month");
const firstDayOfMonth = startOfNextMonth.day();
let daysToAdd = targetDay - firstDayOfMonth;
if (daysToAdd < 0) daysToAdd += 7;
return startOfNextMonth.add(daysToAdd, "day");
};
const getLastEventUrlWithMonth = (user: Awaited<ReturnType<typeof createUserWithLimits>>, date: Dayjs) => {
+9 -1
View File
@@ -50,7 +50,15 @@ const firstMondayInBookingMonth = firstDayInBookingMonth.day(
// ensure we land on the same weekday when incrementing month
const incrementDate = (date: Dayjs, unit: dayjs.ManipulateType) => {
if (unit !== "month") return date.add(1, unit);
return date.add(1, "month").day(date.day());
// Find the first occurrence of the same weekday in the next month
// Note: .day() sets the day of the week for the CURRENT week, which can
// return a date in the previous month. Instead, we calculate the correct date.
const targetDay = date.day();
const startOfNextMonth = date.add(1, "month").startOf("month");
const firstDayOfMonth = startOfNextMonth.day();
let daysToAdd = targetDay - firstDayOfMonth;
if (daysToAdd < 0) daysToAdd += 7;
return startOfNextMonth.add(daysToAdd, "day");
};
const getLastEventUrlWithMonth = (user: Awaited<ReturnType<typeof createUserWithLimits>>, date: Dayjs) => {