Hi,
briefly, im trying to display a range of time (like ($begins 08:00am) to ($ends 04:00pm),
by excluding one, none, or more range in 2 arrays of other times in couple ($from -> $to).
Like:8am to 4pm with steps of 20 mins, and there are, for example, 3 arrays, like
$from=array("09:00","12:00","14:00") and
$to = array("10:00","13:00","15:00"), meaning: the first range of time i want ot exclude from 8 to 4 is: from 09:00 to 10:00, and so on, -the time is never overlapped-
and im looking for something that displays :
08:00
08:20
08:40
10:00
10:20
10:40
11:00
11:20
11:40
13:00
13:20
13:40
15:00
15:20
15:40
I've used seconds from midnight, like 28800 it's 08:00, then mktime.
Here's what i triedwhich doesnt work, naturally......)
PHP Code:
<?php
$begins="28800";//08:00am
$ends="57600";// 04:00pm
$from=array("32400","43200","50400");//09:00,12:00,14:00
$to=array("36000","46800","54000"); //10:00,13:00,15:00
$step=1200;
foreach($from as $n => $f){
for($y=$begins;$y <= $ends-$step;$y++){
$v=date("H:i",mktime(0,0,$y,7,11,2004));
if ($y <= $f[$n]-$step || $y >= $to[$n]){echo $v."<br>";}
elseif($y >= $f[$n] && $y <= $to[$n]){echo"empty $n <br>";};
$y=$y+1199;//seconds, less 1 (20 minutes)
};
};
?>
it returns the (wrong) results as many times as the "count($from)"
The following does work, but jeez.......very slow and very ugly
PHP Code:
<?php
$begins="28800";//08:00am
$ends="57600";// 04:00pm
$from=array("32400","43200","50400");//09:00,12:00,14:00
$to=array("36000","46800","54000"); //10:00,13:00,15:00
$step=1200;
for($y=$begins;$y <= $ends-$step;$y++){
$v=date("H:i",mktime(0,0,$y,7,11,2004));
if (
($y <= $from[0]-$step || $y >= $to[0])&&
($y <= $from[1]-$step || $y >= $to[1])&&
($y <= $from[2]-$step || $y >= $to[2])&&
($y <= $from[3]-$step || $y >= $to[3])&&
($y <= $from[4]-$step || $y >= $to[4])&&
($y <= $from[5]-$step || $y >= $to[5])&&
($y <= $from[6]-$step || $y >= $to[6])//and so on..........zzzz
)
{echo"$v<br>";};
$y=$y+1199;//seconds, less 1 (20 minutes)
};
?>
in short i i'd like to exclude some range of time from a longer given time.
anybody merciful?