= $startmins && $currentmins <= $stopmins)
return True;
else
return False;
}
/*
* Function to determine if facility is open now
* Returns True if it is open, False if it is closed, empty string if not known
* $open_hours: value of opening_hours tag
*/
function OpenClosed ($open_hours) {
//simplest case
if ($open_hours == "24/7")
return True;
//Set up array of days as numbers - easier to compare as numbers
$weekdays = array ("mo"=>1, "tu"=>2, "we"=>3, "th"=>4, "fr"=>5, "sa"=>6, "su"=>7);
//Get today's day as a number
$today = $weekdays [strtolower (substr (date ("D"), 0, 2))];
//Default to returning False
$bOpen = False;
//If opening hours aren't specified, return empty string
if ($open_hours == "")
return "";
//Ensure $open_hours is lower case - makes life simpler
$open_hours = strtolower ($open_hours);
//split by semi-colons: each one is a set of days & times
$days = explode (";", trim ($open_hours));
//Check each set of days/times
foreach ($days as $day) {
$daytimes = explode (" ", trim ($day));
//Turn $daytimes [0] into start & end days
$dayrange = explode ("-", $daytimes [0]);
$minday = $weekdays [$dayrange [0]];
if (count ($dayrange) == 1)
//Single day, so maxday is same as minday
$maxday = $weekdays [$dayrange [0]];
else
//Two days
$maxday = $weekdays [$dayrange [1]];
//Determine if today is in the range
if ($today >= $minday && $today <= $maxday) {
//Today is in the day range - check the time
$times = explode (",", $daytimes [1]);
//Day off - specific case. Return from function immediately
if ($times [0] == "off")
return False;
if ($today == $minday && $today == $maxday) {
/*
* This is a specific day. Reset $bOpen to false,
* run CheckTime and return from function without
* further checks
*/
$bOpen = False;
//Check each time
foreach ($times as $time)
if (CheckTime ($time))
$bOpen = True;
return $bOpen;
}
else {
//Check each time
foreach ($times as $time)
if (CheckTime ($time))
$bOpen = True;
}
}
}
return $bOpen;
}
?>