I have been thinking about this task carefully. And i came up with the logic that is required to calculate whether the current time is in between 2 times. There are the following two cases to calculate that:
Case 1: The starting time is greater than the ending time
Which means the ending time must be the next day. That means that if your current time is less than the ending time OR
greater than the start time, your time is in between the two times.
Case 2: The starting time is less than the ending time
In this case, the start time and the ending time is the same day. For this, the logic that is needed is to check whether or not your time is greater than the start time AND
less than the ending time. If that's statement is true, your time is in between the two times.
I have made the following function for calculating that:
function checktime($arr,$time) {
list($h,$m)=explode(":",$time);
if(!is_array($arr[0])) {
$r1=explode(":",$arr[0]);
$r2=explode(":",$arr[1]);
if($r1[0]>$r2[0]) {
if(($h>$r1[0] || ($h==$r1[0] && $m>=$r1[1])) || ($h<$r2[0] || ($h==$r2[0] && $m<=$r2[1]))) return true;
}
else {
if(($h>$r1[0] || ($h==$r1[0] && $m>=$r1[1])) && ($h<$r2[0] || ($h==$r2[0] && $m<=$r2[1]))) return true;
}
}
}
And here are some tests, for testing the limits of the cases you gave me:
$arr=array("10:00","01:00");
echo (checktime($arr,"23:59")?"True":"False");//True
echo (checktime($arr,"12:00")?"True":"False");//True
echo (checktime($arr,"00:00")?"True":"False");//True
$arr=array("10:00","23:59");
echo (checktime($arr,"23:59")?"True":"False");//True
echo (checktime($arr,"12:00")?"True":"False");//True
echo (checktime($arr,"00:00")?"True":"False");//False
$arr=array("10:00","00:00");
echo (checktime($arr,"23:59")?"True":"False");//True
echo (checktime($arr,"12:00")?"True":"False");//True
echo (checktime($arr,"00:00")?"True":"False");//True
$arr=array("23:59","05:00");
echo (checktime($arr,"23:59")?"True":"False");//True
echo (checktime($arr,"12:00")?"True":"False");//False
echo (checktime($arr,"00:00")?"True":"False");//True
$arr=array("08:35","15:30");
echo (checktime($arr,"23:59")?"True":"False");//False
echo (checktime($arr,"12:00")?"True":"False");//True
echo (checktime($arr,"00:00")?"True":"False");//False
$arr=array("17:30","02:00");
echo (checktime($arr,"23:59")?"True":"False");//True
echo (checktime($arr,"12:00")?"True":"False");//False
echo (checktime($arr,"00:00")?"True":"False");//True
$arr=array("10:00","15:00");
echo (checktime($arr,"23:59")?"True":"False");//False
echo (checktime($arr,"12:00")?"True":"False");//True
echo (checktime($arr,"00:00")?"True":"False");//False
$arr=array("17:00","00:00");
echo (checktime($arr,"23:59")?"True":"False");//True
echo (checktime($arr,"12:00")?"True":"False");//False
echo (checktime($arr,"00:00")?"True":"False");//True