<?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";
}
- Output for 5.6.0 - 5.6.40, 7.0.0 - 7.0.33, 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.30, 8.2.0 - 8.2.25, 8.3.0 - 8.3.13
- Day | 00:15:00 | 23:00:00
Monday | Monday: 09:30 - 01:30 | Monday: 09:30 - 01:30
Tuesday | Monday: 09:30 - 01:30 | Tuesday: 09:30 - 01:30
Wednesday | Tuesday: 09:30 - 01:30 | Wednesday: 09:30 - 01:30
Thursday | Wednesday: 09:30 - 01:30 | Thursday: 09:30 - 01:30
Friday | Thursday: 09:30 - 01:30 | Friday: 09:30 - 23:00
Saturday | Saturday: 10:30 - 00:00 | Saturday: 10:30 - 00:00
Sunday | Sunday: 10:30 - 00:00 | Sunday: 10:30 - 00:00
preferences:
44.3 ms | 409 KiB | 5 Q