<?php
function setting($v)
{
$db = [
'opening_time_Sunday' => '10:30',
'closing_time_Sunday' => '00:00',
'opening_time_Monday' => '09:30',
'closing_time_Monday' => '01:30',
'opening_time_Tuesday' => '09:30',
'closing_time_Tuesday' => '01:30',
'opening_time_Wednesday' => '09:30',
'closing_time_Wednesday' => '01:30',
'opening_time_Thursday' => '09:30',
'closing_time_Thursday' => '01:30',
'opening_time_Friday' => '09:30',
'closing_time_Friday' => '23:00',
'opening_time_Saturday' => '10:30',
'closing_time_Saturday' => '00:00',
];
return $db[$v];
}
function Today($dateString) {
$currentDate = new \DateTimeImmutable($dateString);
if (in_array($currentDate->format('N'), [2, 3, 4, 5])) {
//check current time is not beyond the threshold
//Monday = 1 and Sunday = 7 | Thursday = 4
$closedDate = $currentDate->setTime(1, 30, 00);
if ($currentDate < $closedDate) {
//change the date to display to day prior
$currentDate = $currentDate->sub(new \DateInterval('P1D'));
}
}
$today = $currentDate->format('l');
$start = setting('opening_time_' . $today); // Select value from settings table
$end = setting('closing_time_' . $today); // Select value from settings table
return $today . ': ' . $start . " - " . $end;
}
$dates = [];
for ($i=0;$i<7;$i++) {
$date = \date_create('2018-10-08');
if ($i > 0) {
$date->modify('+' . $i . ' day');
}
$dates[$date->format('l')] = [
'00:15' => Today($date->setTime(0, 15)->format('Y-m-d H:i:s')),
'23:00' => Today($date->setTime(23, 0, 0)->format('Y-m-d H:i:s'))
];
}
echo "Day \t|\t00:15:00\t\t\t|\t23:00:00\n";
foreach($dates as $day => $times) {
echo "$day \t|\t{$times['00:15']} \t|\t{$times['23:00']}\n";
}
preferences:
22.89 ms | 405 KiB | 5 Q