最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Intersecting time slots - Stack Overflow

programmeradmin0浏览0评论

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 badges
Add a ment  | 

1 Answer 1

Reset to default 9

The 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.

发布评论

评论列表(0)

  1. 暂无评论