Context: I am trying to prevent overlapping in a booking system as shown below, however books can start and end on the same time, they just cant intersect
Red = Range 1 (Existing bookings)
Blue = Range 2 (people trying to book)
S = Start time
E = End time
I have been trying to manualy do it by using and / or operators but its not really working and overlaps with doesnt allow me to have bookings start and end one after the other
For your logic start and end can be the same date, but the operator overlaps with returns true if the end of the first range is the same date as the start of the second range.
One option that you can try is using modified ranges for this logic where the end is 1 second less that the real end.
range 1 → original: 2023-08-17T10:00:00 - 2023-08-17T11:00:00, modified: 2023-08-17T10:00:00 - 2023-08-17T10:59:59
range 2 → original: 2023-08-17T11:00:00 - 2023-08-17T12:00:00, modified: 2023-08-17T11:00:00 - 2023-08-17T11:59:59
range 1 original → overlaps with → range 2 original returns true
range 1 modified-> overlaps with → range 2 modified returns false
If you use it a lot you may want to just save it in the database when you save the original date. Or you can save only the modified range and add that second back in the displayed ui. It really depends on your specific case. Play with it and see if it works for you.