Hello,
I have some code for restaurant reservations that will check to see (among other things) if the restaurant is open that day. I have a schedule of open days:
//Restuarant Open Times
$available_main_array = array(
'Summer' => array(
'start' => 'May 1',
'end' => 'October 31',
'schedule' => array(
'Sunday' => array(
array('17:00','24:00')),
'Monday' => array(
array('17:00','24:00')),
'Tuesday' => array(
array('17:00','24:00')),
'Wednesday' => array(
array('17:00','24:00')),
'Thursday' => array(
array('17:00','24:00')),
'Friday' => array(
array('17:00','24:00')),
'Saturday' => array(
array('17:00','24:00')))),
'Winter' => array(
'start' => 'November 1',
'end' => 'April 30',
'schedule' => array(
'Sunday' => array(
array('17:00','24:00')),
'Friday' => array(
array('17:00','24:00')),
'Saturday' => array(
array('17:00','24:00')))));
And these checks:
//Check Database Functions
function available($array) {
//return array('false',gmdate('g:i a',$array['etime']));
$week_schedule = availableArray($array['date']);
$schedule = $week_schedule[date('l',$array['date'])];
if(is_array($schedule)) {
foreach($schedule as $timespan) {
if(gmdate('H:i',$array['stime'])<$timespan[0]) { return array('false','Sorry, we are not available at your starting time.'); }
if(gmdate('H:i',$array['etime']-1)<$timespan[0]) { return array('false','Sorry, you cannot place an online reservation this late at night. Please call 920-854-9070 to place this reservation.'); }
}
return array('yay');
}
else { return array('false','Sorry, we are not available on that day.'); }
}
function availableArray($date) {
global $available_main_array;
foreach($available_main_array as $season_array) {
$start = $season_array['start'];
$end = $season_array['end'];
if(strtotime($end)<strtotime($start)) { $end .= ', '.(date('Y')+1); }
else { $end .= ', '.date('Y'); }
$start .= ', '.date('Y');
if($date>=strtotime($start)&&$date<=strtotime($end)) { return $season_array['schedule']; }
}
}
The problem is, any dates entered from today (in the winter season) until May 1 (the start of the summer season) return the error 'Sorry, we are not available on that day.' So I think the problem is is how I'm advancing the year (in the avaiableArray function) when the winter season goes from say 12/31/09 to 1/1/10. But for the life of me, I can't find the error in the code. Can anyone help?