Jump to content

Check Schedule


imfromio

Recommended Posts

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?

Link to comment
Share on other sites

create table opening_hours (
  id integer not null auto_increment,
  valid_from date,
  valid_until date,
  monday varchar(32),
  tuesday varchar(32),
  wednesday varchar(32),
  thursday varchar(32),
  friday varchar(32),
  primary key (id));

 

$query = 'SELECT monday, tuesday, wednesday, thursday, friday 
FROM opening_hours 
WHERE now() BETWEEN valid_from AND valid_until';
$result = mysql_query($query);
list($monday, $tuesday, $wednesday, $thursday, $friday) = 
    myql_fetch_array($result, MYSQL_NUM)) {
//echo '<td>', $monday, '</td><td>', $tuesday, '</td><td>', $wednesday, '</td><td>',
//    $thursday, '</td><td>', $friday, '</td><td>';

 

The fields monday till friday would hold the opening hours like 17:00-24:00

Link to comment
Share on other sites

Thanks...but I don't need to create a database table.  I'm using the available_main_array to check availability.  My problem is the winter season spans two years (i.e. 11/1/09-4/30/10).  The code to check that is (I think) where I'm going wrong:

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']; }

 

Now that it's 2010, this code is saying the available dates during the winter season are 11/1/10-4/30/11.  So people trying to book dates on say 2/14/10 get an error...

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.