Test if a range intersects another range of numbers

前端 未结 6 1434
小鲜肉
小鲜肉 2021-01-07 03:41

I have 2 range of numbers:

  • $startTime to $endTime
  • $offerStartTime to $offerEndTime

6条回答
  •  旧时难觅i
    2021-01-07 03:57

    After some time I have found an efficient simple solution that seems to work (feel free to tell me if it doesn't).

    ($offerStartTime <= $startTime && $offerEndTime > $startTime) ||
    ($offerStartTime > $startTime && $offerStartTime < $endTime)
    

    I will also be looking at answers that are better than mine, so please still send me your solution.

提交回复
热议问题