我正在编写一个函数,该函数将向用户输出商店是否开放。
我写了一个名为is_store_open()的函数,它带有一个名为$day的变量,该变量将把当前星期几赋值给它。
假设今天是星期六。它查找"星期六"的箱子,并检查星期六的开门时间和关门时间。
我面临的问题是,当商店在周六午夜后还营业。这样,它就不会在星期六检查箱子了。
将检查周日的情况。这不是我想要的,因为它会显示商店关门,而它在"星期六"仍然营业
我在下面写了一个函数,检查前一天的关门时间是否大于当前时间。如果它为真,那么返回真,我想这应该可以解决问题。
但是当我写的时候,它会给我一个错误,说$saturday_close是未定义的。我猜这是因为它在一个switch语句中,并且它不等于那天。
我对如何设置这个有点困惑。如果有人有什么建议,我将非常感谢你的帮助。谢谢!
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;
}
class StoreOperationHours {
public $time_now;
public function __construct() {
//$this->time_now = mktime("2", "00", "00" ); // Now lets say the time now is 12:00am;
$this->time_now = mktime(date('H'), date('i'), date('s'));
}
public $SaturdayOpenHours = "11:00";
public $SaturdayClosingHours = "1:08:00";
public $SundayOpenHours = "11:00";
public $SundayCloseHours = "23:00";
public function IsStoreOpen() {
//$set_time = strtotime("tomorrow"); // Lets just sat its Sunday for testing purposes
$day = date("l", time());
switch ($day) {
case "Saturday":
$this->SaturdayOpenHours;
$this->SaturdayClosingHours;
break;
case "Sunday";
if(strtotime($this->SaturdayClosingHours) >= $this->time_now ){//If the $monday_close hours are greater then the current time return false the store is still open
return true;
} elseif($e) {
return false;
}
break;