So I’ve been trying the past couple of days to do the following:
I have 2 date/time picker Inputs.
I have a booking data type, which stores bookings, each of those has start date, end date and date range.
When a user selects for example on the picker a range that let’s say 1 month, or 1 year. I want to check if this range is fully covered by the bookings or not.
Alternatively I could store availability, in hourly format, but then in this case, how do I go again from a list of date ranges (bookings) to a list of free date ranges? Booking duration varies.
You may want to look at the Date Operators. Unsure of what exactly your use case is, but it sounds like Overlaps with might be an operator you are looking for.
Takes a first range and a second range. Returns yes if the first range is contained by the second range. “Contains” means that the start of the first range is greater than or equal to the start of the second range, and the end of the first range is less than or equal to the end of the second range. So, if the two ranges are the same, then this will return yes.
Hi everyone, thanks for the comments, so I’ll give an example.
User selects from the datetime inputs a year long time frame, so let’s say from 2025-01-01 to 2025-12-31.
So we have our 1st date range of 1 year.
We also have a list of booking date ranges, 1 hour, 1 day in duration doesn’t matter. For simplicity let’s assume that all of them are already within 2025 as well. So all of them, they already overlap and are contained by the date range given by the user.
My question is how do i know, if this list of date ranges covers 2025 completely? aka the place is fully booked?
More Context: What i have is booked slots as I receive them through iCal. I iterate through each of them to save it in the database, so here maybe i can workout free dates somehow. Or I have to give up using date ranges and just create 365x24 = 8,760 datetime slots / item so i can have the full availability and subtract. It just seems excessive, there must be a simpler way to do this.