Jump to content

Need help configuring store hours


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
https://forums.phpfreaks.com/topic/288564-need-help-configuring-store-hours/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.