I am working on a booking system which works around the user selecting a time slot and I am stuck attempting to check for overlapping bookings.
I am attempting to create a function which returns all the available time slots. I have an array called bookings
which are the bookings for that day, and I have an array called slots
.
I have tried looping through the arrays and attempting this:
if (slot.start > booking.dateStart.clone().addMinutes(-30) && slot.end < booking.dateEnd.clone().addMinutes(30))
To check for any overlap, and if there is I splice the slot from the array. I need to leave a 30 minute gap between each booking so that is why I am adding minutes.
I am working on a booking system which works around the user selecting a time slot and I am stuck attempting to check for overlapping bookings.
I am attempting to create a function which returns all the available time slots. I have an array called bookings
which are the bookings for that day, and I have an array called slots
.
I have tried looping through the arrays and attempting this:
if (slot.start > booking.dateStart.clone().addMinutes(-30) && slot.end < booking.dateEnd.clone().addMinutes(30))
To check for any overlap, and if there is I splice the slot from the array. I need to leave a 30 minute gap between each booking so that is why I am adding minutes.
Share Improve this question asked Jul 20, 2014 at 20:16 user2117190user2117190 5452 gold badges6 silver badges10 bronze badges1 Answer
Reset to default 9The formula to find overlapping time periods is
start1 <= end2 && end1 >= start2
If that is true, then the periods do overlap. If you need to leave a 30 minute gap, just add that to the parison of end1
and start2
.