判断时段是否重合
判断俩个时段是否存在交集
a1 - a2 和 b1 - b2
1、9:00 - 10:00 和 10:00 - 11:00
2、1:00 - 10:00 和 23:00 - 2:00
3、23:00 - 2:00 和 1:00 - 10:00
4、23:00 - 2:00 和 22:00 - 1:00
<?php date_default_timezone_set('PRC'); $a1 = strtotime('23:00'); $a2 = strtotime('10:00'); $b2 = strtotime('22:00'); $b1 = strtotime('09:00'); function check($a1, $a2, $b1, $b2){ if($a1 == $a2 || $b1 == $b2){ return false; } if($a1 > $a2 && $b1 < $b2) { $a2+=86400; if( ($b1<=$a2 && $b2>=$a1) || ( ($b1+86400) <= $a2 && ($b2+86400) >= $a1) ){ return true; } else { return false; } } if($a1 < $a2 && $b1 > $b2) { $b2+=86400; if( ($b1<=$a2 && $b2>=$a1) || ( $b1 <= ($a2+86400) && $b2 >= ($a1+86400) ) ){ return true; } else { return false; } } if($a1 > $a2 && $b1 > $b2) { $a2+=86400; $b2+=86400; } if($b1<=$a2 && $b2>=$a1){ return true; } return false; } $res = check($a1, $a2, $b1, $b2); var_dump($res);
看活一分钟公众号,持续订阅,更有精赞内容分享