Nyt on lauantai 13:11 ja olemme auki!
<?php
date_default_timezone_set('Europe/Helsinki'); // timezone
$weekday = [ //AJAT SIIRRETTY -3h, huomioidaan ehtolauseessa
"Mon" => ["open"=>"00:00", "close"=>"00:00", "name"=>"maanantai"],
"Tue" => ["open"=>"00:00", "close"=>"00:00", "name"=>"tiistai"],
"Wed" => ["open"=>"08:00", "close"=>"19:00", "name"=>"keskiviikko"],
"Thu" => ["open"=>"08:00", "close"=>"19:00", "name"=>"torstai"],
"Fri" => ["open"=>"08:00", "close"=>"23:00", "name"=>"perjantai"],
"Sat" => ["open"=>"08:00", "close"=>"23:00", "name"=>"lauantai"],
"Sun" => ["open"=>"08:00", "close"=>"19:00", "name"=>"sunnuntai"],
];
$open = (date("H:i", strtotime("-3 hours")) > $weekday[date('D')]['open'] and date("H:i", strtotime("-3 hours")) < $weekday[date('D')]['close']);
if (!$open) { // JOS KIINNI ->
if (date("H:i", strtotime("-3 hours")) < $weekday[date('D')]['open']) { //SAMANA PÄIVÄNÄ
$seurauk = "tänään " . ($weekday[date('D')]['open'] + 3) . ":00!";
}
elseif (date("H:i", strtotime("-3 hours")) > $weekday[date('D')]['close']) { //SEURAAVA PVÄ
if (!($weekday[date('D', strtotime("+1 day"))]['open'] == "00:00")) {
$seurauk = $weekday[date('D', strtotime("+1 day"))]['name'] . "na " . ($weekday[date('D', strtotime("+1 day"))]['open'] +3) . ":00!";
}
else {
if (!($weekday[date('D', strtotime("+2 days"))]['open'] == "00:00")) { //SEURAAVAN JÄLKEINEN PVÄ
$seurauk = $weekday[date('D', strtotime("+2 days"))]['name'] . "na " . ($weekday[date('D', strtotime("+2 days"))]['open'] +3) . ":00!";
}
else { //SITÄKIN SEURAAVA PAKKO OLLA (vain 2 sulkupäivää putkeen) (jos muuttuu, sama ketju jatkuu, +4 days, +5 days jne)
$seurauk = $weekday[date('D', strtotime("+3 days"))]['name'] . "na " . ($weekday[date('D', strtotime("+3 days"))]['open'] +3) . ":00!";
}}}}
//JOS ERIKSEEN AUKIOLO (ei ohjelman mukainen) määrittele erikseen ->
// $seurauk = "pvänä 12:00"; // esim "tiistaina 11:00"
$auki = ($open ? "<span style=\"color:green;\">olemme auki!" : "<span style=\"color:red;\">avaamme taas " . $seurauk);
echo "Nyt on " . $weekday[date('D')]['name'] . date(' H:i ') . "ja " . $auki;
echo "</span><br />";
//TURHAT ALKAA
echo "<hr>";
show_source(__FILE__);