Extract duplicate date range helpers to shared utility

- Created getDateRange() function in utils/date.ts
- Replaced getBookableDates() and getDateRange() duplicates
- Both booking and availability pages now use shared function
- Function accepts minAdvanceDays and maxAdvanceDays as parameters
This commit is contained in:
counterweight 2025-12-21 17:54:49 +01:00
parent 208278bddb
commit 5c396e62ec
Signed by: counterweight
GPG key ID: 883EDBAA726BD96C
3 changed files with 21 additions and 30 deletions

View file

@ -46,3 +46,18 @@ export function formatDisplayDate(d: Date): string {
return d.toLocaleDateString("en-US", { weekday: "short", month: "short", day: "numeric" });
}
/**
* Get date range for booking/availability (from minAdvanceDays to maxAdvanceDays).
* Returns an array of Date objects starting from minAdvanceDays days from today.
*/
export function getDateRange(minAdvanceDays: number, maxAdvanceDays: number): Date[] {
const dates: Date[] = [];
const today = new Date();
for (let i = minAdvanceDays; i <= maxAdvanceDays; i++) {
const d = new Date(today);
d.setDate(today.getDate() + i);
dates.push(d);
}
return dates;
}