Skip to content

Scheduling infrastructure for absolutely everyone.

fix: Check for same day, not with <= (#12167)

Alex van Andel4de142cb7c53
diff --git a/packages/features/calendars/lib/getAvailableDatesInMonth.timezone.test.ts b/packages/features/calendars/lib/getAvailableDatesInMonth.timezone.test.ts
index c8475e33119..0d8c5d10aae 100644
--- a/packages/features/calendars/lib/getAvailableDatesInMonth.timezone.test.ts
+++ b/packages/features/calendars/lib/getAvailableDatesInMonth.timezone.test.ts
@@ -1,5 +1,6 @@
import { describe, expect, test, vi } from "vitest";
+import dayjs from "@calcom/dayjs";
import { getAvailableDatesInMonth } from "@calcom/features/calendars/lib/getAvailableDatesInMonth";
import { daysInMonth, yyyymmdd } from "@calcom/lib/date-fns";
@@ -63,5 +64,22 @@ describe("Test Suite: Date Picker", () => {
vi.setSystemTime(vi.getRealSystemTime());
vi.useRealTimers();
});
+
+ test("it returns the correct responses end of month", () => {
+ // test a date at one minute past midnight, end of month.
+ // we use dayjs() as the system timezone can still modify the Date.
+ vi.useFakeTimers().setSystemTime(dayjs().endOf("month").startOf("day").add(1, "second").toDate());
+
+ const currentDate = new Date();
+ const result = getAvailableDatesInMonth({
+ browsingDate: currentDate,
+ });
+
+ expect(result).toHaveLength(1);
+
+ // Undo the forced time we applied earlier, reset to system default.
+ vi.setSystemTime(vi.getRealSystemTime());
+ vi.useRealTimers();
+ });
});
});
diff --git a/packages/features/calendars/lib/getAvailableDatesInMonth.ts b/packages/features/calendars/lib/getAvailableDatesInMonth.ts
index 8e50ef9793a..a00f83d5165 100644
--- a/packages/features/calendars/lib/getAvailableDatesInMonth.ts
+++ b/packages/features/calendars/lib/getAvailableDatesInMonth.ts
@@ -1,3 +1,4 @@
+import dayjs from "@calcom/dayjs";
import { daysInMonth, yyyymmdd } from "@calcom/lib/date-fns";
// calculate the available dates in the month:
@@ -21,7 +22,9 @@ export function getAvailableDatesInMonth({
);
for (
let date = browsingDate > minDate ? browsingDate : minDate;
- date <= lastDateOfMonth;
+ // Check if date is before the last date of the month
+ // or is the same day, in the same month, in the same year.
+ date < lastDateOfMonth || dayjs(date).isSame(lastDateOfMonth, "day");
date = new Date(date.getFullYear(), date.getMonth(), date.getDate() + 1)
) {
// intersect included dates