Searching for overlapping date ranges but exclusively

Hi! I’m building an app that involves booking.

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?

1 Like

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

Seems like a bug worth reporting to Bubble, it let me pick a + 1 seconds for the start date but the end date doesn’t let you pick any operators.

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.

1 Like

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.

I think most booking apps actually just book the user for 1-1:59:59 so they don’t actually have to check for any -1 +1 situations. :+1:

This topic was automatically closed after 70 days. New replies are no longer allowed.