Bir timerange eğer ben bir yönteme sonra yaşıyorum, kontrol edecek, bazı ücretsiz slot altına düşer.
Ben unixtime formatında ücretsiz yuvaları döndüren bir yöntem var array['from','to']. Görme gibi bir şey:
07:00 - 07:45
07:45 - 08:30
14:30 - 15:15
15:15 - 16:00
Ben verilen bir dizi bu yuvalara altına düşerse kontrol etmek istiyorum. Onlar yuvalarını örtüşüyor, ama hilarant dönemini ücretsiz yuvası yayılan olmamalıdır.
Yani geçerli aralığı:
07:00 - 07:45
07:00 - 08:30
07:10 - 08:20 // also valid
14:30 - 16:00 // also valid
Geçersiz aralık
06:00 - 16:45
15:15 - 16:10
07:00 - 16:00 //there are no ranges between 8:30 and 14:30
11:00 - 12:00
EDIT
Ne kadar var kontrol etmektir:
$startsinfreeslot=true;
$endrange=0;
foreach ($arr as $slot) {
$from=$slot['from'];
$to=$slot['to'];
if ($from==$start_date && $to==$end_date) {
// given date matches a free slot
return true;
}
if ($start_date>=$from && $start_date<$to) {
$startsinfreeslot=true;
$endrange=$to;
continue;
}
if ($startsinfreeslot) {
// we need to check if range continues
if ($endrange==$from) {
// range stops in the current range
if ($end_date<=$to) {
return true;
} else {
$endrange=$to;
continue;
}
} else {
// range doesn't continued return false
return false;
}
}
}