Jump to content

Need help configuring store hours


eldan88
Go to solution Solved by eldan88,

Recommended Posts

Hey Guys. I am writing a function that will output to the user if a store is open or not.

 

I wrote a fucntions named is_store_open() with a variable called $day which will have the current day of the week assigned to it.

 Lets say it is  Saturday. it finds  the case for "Saturday" and checks the opening time and closing time for Saturday.

 

The problem that I am facing, is  when the store is open past midnight on Saturday. It then won't check the case for saturday.

Instead will check the case for  Sunday. Which is not what I want, becuase it will show the store as closed when its open still open on "Saturday"

 

I wrote a function below that checks to see if the previous day closing hours are greater then the current time. If its true then return true and I guess that should fix the problem.

 

But when I wrote that it would give me an error saying that $saturday_close is undefined. I'm guessing its becuase its in a switch satement, and it does not equal to that day.

 

I'm a little bit confused on how to set this up. If anyone has a suggestion I would really apprecaite your help. Thanks!

 function is_store_open(){
  $set_time = strtotime("tomorrow"); // Lets just sat its Sunday for testing purposes
  $day =  date("l", $set_time); 
 
  $time_now =  mktime("00", "00", "00"); // Now lets say the time now is 12:00am
  
 switch ($day) {
  
  case "Saturday":
  $open = "11:00";
  $saturday_close = "1:00";
   break; 


  case "Sunday"; 
   if($saturday_close > $time_now ){//If the $monday_close hours are greater then the current time return false the store is still open
    return true;
   } else {
   $open = "2:00";
   $close = "22:00";
   }
   break;

}


 }// End of function 
 
 
 if(is_store_open()) {
   echo "Oh no! There is still a glitch in the system the store needs to remain open";
 } else {
  echo "The store is still open on Saturday";
 }
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.