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:
parent
208278bddb
commit
5c396e62ec
3 changed files with 21 additions and 30 deletions
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue