ruby - How to test whether two time ranges overlap? -
i need implement booking functionality , ensure bookings don't overlap in rails app.
the cover?
, between?
methods aren't quite need. have ensure uniqueness of time range when compared other potential ranges on same model, , efficiently.
i think can done using overlaps?
. problem returns true this:
(1..5).overlaps?(5..9) => true
if compared booking ended right when started (3:30 - 4:00
versus 4:00 - 4:30
), overlap, technically don't. problem right?
validatesoverlap seems handle issue, including edge overlap.
any suggestions?
def overlap?(x,y) (x.first - y.end) * (y.first - x.end) > 0 end
will work. problem interval
uses >=
, can see in "test if 2 date ranges overlap in ruby or rails".
Comments
Post a Comment