How to test whether two time ranges overlap?

大憨熊 提交于 2019-12-05 07:06:37
Robert Krzyzanowski
def overlap?(x,y)
  (x.first - y.end) * (y.first - x.end) > 0
end

will work. The problem is that Interval uses >=, as you can see in "Test if two date ranges overlap in Ruby or Rails".

For your scenario, why do we have to include end time? After all, booking is finished at that time and slot is available from that time onwards. So below should make sense.

(1...5).overlaps?(5...9)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!