I’m working on a website for a restaurant enabling users to order their meals online, pay and then just collect or have delivered. Between Monday and Fridays between the hours of 11:00:00am and 17:00:00pm selected dishes.
I’ve put together a script (below) to verify the current day and the time against the offer times. This works perfectly so far.
I was wondering if anyone can help me possibly come up with something better, perhaps more efficient/ effective or even more streamlined
<?php
$current_time = date(‘H:i:s’);
$lunch_offer_start_time = “11:00:00”;
$lunch_offer_end_time = “17:00:00”;
if(date(‘D’) == ‘Mon’ || date(‘D’) == ‘Tue’ || date(‘D’) == ‘Wed’ || date(‘D’) == ‘Thur’ || date(‘D’) == ‘Fri’) {
if (checkForLunchSpecialDaysAndHours($current_time, $lunch_offer_start_time, $lunch_offer_end_time)):
echo ‘offer, check menu’;
else:
echo ‘no offer available’;
endif;
}
function checkForLunchSpecialDaysAndHours($lunch_offer_start_time, $lunch_offer_end_time, $input) {
$offer_start_time = DateTime::createFromFormat(‘H:i:s’, $lunch_offer_start_time);
$offer_end_time = DateTime::createFromFormat(‘H:i:s’, $lunch_offer_end_time);
$i = DateTime::createFromFormat(‘H:i:s’, $input);
if ($offer_start_time > $offer_end_time)
$offer_end_time -> modify(‘+1 day’);
return ($offer_start_time <= $i && $i <= $offer_end_time) || ($offer_start_time <= $i -> modify(‘+1 day’) && $i <= $offer_end_time);
}
?>