@ 2014-04-20T17:03:51Z <?php
$times = array(
'mon' => '6:00 PM - 1:00 AM',
'tue' => '6:00 PM - 1:00 AM',
'wed' => '6:00 PM - 1:00 AM',
'thu' => '6:00 PM - 1:00 AM',
'fri' => '6:00 PM - 1:00 AM',
'sat' => '6:00 PM - 2:00 AM',
'sun' => '6:00 PM - 2:00 AM'
);
function compileHours($times, $timestamp) {
$times = $times[strtolower(date('D',$timestamp))];
if(!strpos($times, '-')) return array();
$hours = explode(",", $times);
$hours = array_map('explode', array_pad(array(),count($hours),'-'), $hours);
$hours = array_map('array_map', array_pad(array(),count($hours),'strtotime'), $hours, array_pad(array(),count($hours),array_pad(array(),2,$timestamp)));
end($hours);
if ($hours[key($hours)][0] > $hours[key($hours)][1]) $hours[key($hours)][1] = strtotime('+1 day', $hours[key($hours)][1]);
return $hours;
}
function isOpen($now, $times) {
$open = 0; // time until closing in seconds or 0 if closed
// merge opening hours of today and the day before
$hours = array_merge(compileHours($times, strtotime('yesterday',$now)),compileHours($times, $now));
foreach ($hours as $h) {
if ($now >= $h[0] and $now < $h[1]) {
$open = $h[1] - $now;
return $open;
}
}
return $open;
}
$now = strtotime('now');
$open = isOpen($now, $times);
if ($open == 0) {
echo "Is closed";
} else {
echo "Is open;
}
?>
Enable javascript to submit You have javascript disabled. You will not be able to edit any code.
Output for 5.4.0 - 5.4.27 Parse error: syntax error, unexpected end of file, expecting variable (T_VARIABLE) or ${ (T_DOLLAR_OPEN_CURLY_BRACES) or {$ (T_CURLY_OPEN) in /in/Sug1l on line 47
Process exited with code 255 . Output for 5.3.0 - 5.3.28 Parse error: syntax error, unexpected $end, expecting T_VARIABLE or T_DOLLAR_OPEN_CURLY_BRACES or T_CURLY_OPEN in /in/Sug1l on line 47
Process exited with code 255 . Output for 4.4.2 - 4.4.9 , 5.1.0 - 5.1.6 , 5.2.0 - 5.2.17 Parse error: syntax error, unexpected $end in /in/Sug1l on line 47
Process exited with code 255 . Output for 4.3.0 - 4.3.1 , 4.3.5 - 4.3.11 , 4.4.0 - 4.4.1 , 5.0.0 - 5.0.5 Parse error: parse error, unexpected $ in /in/Sug1l on line 47
Process exited with code 255 . Output for 4.3.2 - 4.3.4 Parse error: parse error in /in/Sug1l on line 47
Process exited with code 255 . preferences:dark mode live preview
220.53 ms | 1395 KiB | 117 Q