I might not be asking the right question here.
I’m retrieving bookings that have the first night and last night date and I’m trying to display on a calendar which dates are not available.
In order to get a list of booked dates, I am doing the following:
const bookedDates = bedsData?.map(({ firstNight, lastNight }) => {
const newArrivalDate = new Date(firstNight + "T00:00")
const newDepartureDate = new Date(lastNight + "T24:00")
var getDaysArray = function (start, end) {
for (
var arr = [], dt = new Date(start);
dt <= end;
dt.setDate(dt.getDate() + 1)
) {
arr.push(new Date(dt).toDateString())
}
return arr
}
var daylist = getDaysArray(newArrivalDate, newDepartureDate)
daylist?.map((v) => v)
return daylist.join(", ")
})
This returns
0: undefined
1: "Sat Feb 05 2022, Sun Feb 06 2022, Mon Feb 07 2022, Tue Feb 08 2022, Wed Feb 09 2022, Thu Feb 10 2022, Fri Feb 11 2022, Sat Feb 12 2022"
2: undefined
3: "Sat Feb 12 2022, Sun Feb 13 2022, Mon Feb 14 2022, Tue Feb 15 2022, Wed Feb 16 2022, Thu Feb 17 2022, Fri Feb 18 2022, Sat Feb 19 2022"
4: "Sat Feb 19 2022, Sun Feb 20 2022, Mon Feb 21 2022, Tue Feb 22 2022, Wed Feb 23 2022, Thu Feb 24 2022, Fri Feb 25 2022, Sat Feb 26 2022"
5: undefined
6: undefined
7: "Sat Feb 26 2022, Sun Feb 27 2022, Mon Feb 28 2022, Tue Mar 01 2022, Wed Mar 02 2022, Thu Mar 03 2022, Fri Mar 04 2022, Sat Mar 05 2022"
8: "Sat Mar 05 2022, Sun Mar 06 2022, Mon Mar 07 2022, Tue Mar 08 2022, Wed Mar 09 2022, Thu Mar 10 2022, Fri Mar 11 2022, Sat Mar 12 2022"
9: undefined
10: undefined
11: "Fri Mar 25 2022, Sat Mar 26 2022, Sun Mar 27 2022, Mon Mar 28 2022, Tue Mar 29 2022"
To show which dates are booked I’m am using
if (bookedDates.join().includes(calDates)) {
style.textDecoration = "line-through"
style.color = "rgba(0, 0, 0, 0.25)"
}

The issue I’m facing is with dates that don’t have a check out and check in on the same day. The “last day” and the “first day” of the next booking are still being included in the list of “bookedDates”. However, they need to be “available” to check out or check in still.
I hope that makes sense… pretty lost with this one!
Thanks