From 888a8d806dad73a580f4d8c4c601d58555216665 Mon Sep 17 00:00:00 2001 From: Anik Dhabal Babu <81948346+anikdhabal@users.noreply.github.com> Date: Mon, 2 Feb 2026 15:53:15 +0530 Subject: [PATCH] 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> --- apps/web/playwright/booking-limits.e2e.ts | 10 +++++++++- apps/web/playwright/duration-limits.e2e.ts | 10 +++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/apps/web/playwright/booking-limits.e2e.ts b/apps/web/playwright/booking-limits.e2e.ts index f5349aab08..c5e3da42e9 100644 --- a/apps/web/playwright/booking-limits.e2e.ts +++ b/apps/web/playwright/booking-limits.e2e.ts @@ -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>, date: Dayjs) => { diff --git a/apps/web/playwright/duration-limits.e2e.ts b/apps/web/playwright/duration-limits.e2e.ts index 5f4eaec52d..aee3ba79e5 100644 --- a/apps/web/playwright/duration-limits.e2e.ts +++ b/apps/web/playwright/duration-limits.e2e.ts @@ -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>, date: Dayjs) => {