I have data type booking that stores startTime (date), endTime (date), and dateRange (date range). Users can create a booking which stores these fields and others, but first, we check to make sure there is no booking already between these times.
We create the ‘thing’ only when the number of bookings with dates that overlap the user’s input is 0:
However, this means that if a booking exists 9am-11am, the user cannot book 11am-1pm, they have to book 11:01am-1pm or similar. How can I make it so that bookings can exist 9am-11am and 11am-1pm for example?
I have tried running something along the lines of searching for an overlap with user’s start time input + 1 second ← range → user’s end time input - 1 second, but Bubble won’t allow this
Anyways there’s a lot of way to go about this, here’s a few:
When someone picks “1pm -2 pm” you could just book them for one second less so you are really booking them for 1pm - 1:59:59pm. Then your overlap method would work without the +1 or -1 seconds.
Or you put a custom states on the date/time pickers and workflows “When input’s value changes” and you set the Start date picker’s custom state to it’s value + 1 second. And do the same for the end date picker but do -1 seconds. Then when you check for the overlap reference the custom states instead of the direct values.
Yep, I was just writing up this workaround! I wasn’t sure if it was a bug or what.
To summarise, I create a state on each date picker - startTime+1 and endTime-1. When these values are changed, the state is set to date picker’s value +1/-1 respectively. I then run the overlap search with these constrains, so that it isn’t a problem if a booking is found that starts or ends on startTime or endTime.
So, the bookings we send to the database are still exactly 9am-10am, 10am-11am etc, and even though these mathematically overlap, we can exclude these unrealistic overlaps from the search using a state.
Yep, lots of ways to handle this issue, another is check if the range contains either date picker’s value ± 1 seconds. Two searches, one for the start and one for the end.