这是一个商店系统。 打开和关闭JSON是
$stores_open_starts="{\"monday\":\"13:00\",\"tuesday\":false,\"wednesday\":\"15:00\",\"thursday\":false,\"friday\":false,\"saturday\":\"17:00\",\"sunday\":\"18:00\"}";
$stores_open_ends="{\"monday\":\"21:40\",\"tuesday\":false,\"wednesday\":\"15:00\",\"thursday\":false,\"friday\":false,\"saturday\":\"15:00\",\"sunday\":\"15:00\"}";
如果今天是星期一,时间是11:00 AM,那么我只想获得一个输出,那么它显示在1:00 PM。如果时间小于等于60分钟,则它将在60分钟后返回打开状态。和关闭时间一样。如果今天是星期二,则返回星期三下午3:00开放。
太复杂了。
这是我做的..如果有一天不是空白或错误,它就可以正常工作。
<?php
date_default_timezone_set('Asia/Kolkata');
$stores_open_starts="{\"monday\":\"13:00\",\"tuesday\":false,\"wednesday\":\"15:00\",\"thursday\":false,\"friday\":false,\"saturday\":\"17:00\",\"sunday\":\"18:00\"}";
$stores_open_ends="{\"monday\":\"21:40\",\"tuesday\":false,\"wednesday\":\"15:00\",\"thursday\":false,\"friday\":false,\"saturday\":\"15:00\",\"sunday\":\"15:00\"}";
$stores_open_starts=!empty($stores_open_starts)?(array)json_decode($stores_open_starts):false;
$stores_open_ends=!empty($stores_open_ends)?(array)json_decode($stores_open_ends):false;
function timeFormat($time='',$is_display=false)
{
if(empty($time)){
return false;
}
$time_format=12;
switch ($time_format){
case "12":
if ( $is_display==true){
return date("g:i A", strtotime($time));
} else return date("G:i", strtotime($time));
break;
default:
if ( $is_display==true){
return date("G:i", strtotime($time));
} else return date("G:i", strtotime($time));
break;
}
return $time;
}
$monday_open_rawtime=timeFormat($stores_open_starts['monday'],true);
$tuesday_open_rawtime=timeFormat($stores_open_starts['tuesday'],true);
$wednesday_open_rawtime=timeFormat($stores_open_starts['wednesday'],true);
$thursday_open_rawtime=timeFormat($stores_open_starts['thursday'],true);
$friday_open_rawtime=timeFormat($stores_open_starts['friday'],true);
$saturday_open_rawtime=timeFormat($stores_open_starts['saturday'],true);
$sunday_open_rawtime=timeFormat($stores_open_starts['sunday'],true);
$monday_close_rawtime=timeFormat($stores_open_ends['monday'],true);
$tuesday_close_rawtime=timeFormat($stores_open_ends['tuesday'],true);
$wednesday_close_rawtime=timeFormat($stores_open_ends['wednesday'],true);
$thursday_close_rawtime=timeFormat($stores_open_ends['thursday'],true);
$friday_close_rawtime=timeFormat($stores_open_ends['friday'],true);
$saturday_close_rawtime=timeFormat($stores_open_ends['saturday'],true);
$sunday_close_rawtime=timeFormat($stores_open_ends['sunday'],true);
$day=date("l");
//$today_bar=strtolower($day);
$today_time = date("g:i A");
$today_bar = "monday";
$datetime1 = new DateTime('tomorrow - 2day');
$prvday=$datetime1->format('l');
$day1=strtotime($today_bar);
$day2=strtotime($prvday);
$tol=$day1-$day2;
$datetime = new DateTime('tomorrow');
$nextday=$datetime->format('l');
$today_rawtime = date("g:i A");
$close_time_mins="60";
$monday_open_final_min=((round(((((strtotime($monday_open_rawtime)-strtotime($today_rawtime)) % 604800) % 86400) % 3600) / 60))+(round((((strtotime($monday_open_rawtime)-strtotime($today_rawtime)) % 604800) % 86400) / 3600)*60));
$tuesday_open_final_min=((round(((((strtotime($tuesday_open_rawtime)-strtotime($today_rawtime)) % 604800) % 86400) % 3600) / 60))+(round((((strtotime($tuesday_open_rawtime)-strtotime($today_rawtime)) % 604800) % 86400) / 3600)*60));
$wednesday_open_final_min=((round(((((strtotime($wednesday_open_rawtime)-strtotime($today_rawtime)) % 604800) % 86400) % 3600) / 60))+(round((((strtotime($wednesday_open_rawtime)-strtotime($today_rawtime)) % 604800) % 86400) / 3600)*60));
$thursday_open_final_min=((round(((((strtotime($thursday_open_rawtime)-strtotime($today_rawtime)) % 604800) % 86400) % 3600) / 60))+(round((((strtotime($thursday_open_rawtime)-strtotime($today_rawtime)) % 604800) % 86400) / 3600)*60));
$friday_open_final_min=((round(((((strtotime($friday_open_rawtime)-strtotime($today_rawtime)) % 604800) % 86400) % 3600) / 60))+(round((((strtotime($friday_open_rawtime)-strtotime($today_rawtime)) % 604800) % 86400) / 3600)*60));
$saturday_open_final_min=((round(((((strtotime($saturday_open_rawtime)-strtotime($today_rawtime)) % 604800) % 86400) % 3600) / 60))+(round((((strtotime($saturday_open_rawtime)-strtotime($today_rawtime)) % 604800) % 86400) / 3600)*60));
$sunday_open_final_min=((round(((((strtotime($sunday_open_rawtime)-strtotime($today_rawtime)) % 604800) % 86400) % 3600) / 60))+(round((((strtotime($sunday_open_rawtime)-strtotime($today_rawtime)) % 604800) % 86400) / 3600)*60));
$monday_close_final_min=((round(((((strtotime($monday_close_rawtime)-strtotime($today_rawtime)) % 604800) % 86400) % 3600) / 60))+(round((((strtotime($monday_close_rawtime)-strtotime($today_rawtime)) % 604800) % 86400) / 3600)*60));
$tuesday_close_final_min=((round(((((strtotime($tuesday_close_rawtime)-strtotime($today_rawtime)) % 604800) % 86400) % 3600) / 60))+(round((((strtotime($tuesday_close_rawtime)-strtotime($today_rawtime)) % 604800) % 86400) / 3600)*60));
$wednesday_close_final_min=((round(((((strtotime($wednesday_close_rawtime)-strtotime($today_rawtime)) % 604800) % 86400) % 3600) / 60))+(round((((strtotime($wednesday_close_rawtime)-strtotime($today_rawtime)) % 604800) % 86400) / 3600)*60));
$thursday_close_final_min=((round(((((strtotime($thursday_close_rawtime)-strtotime($today_rawtime)) % 604800) % 86400) % 3600) / 60))+(round((((strtotime($thursday_close_rawtime)-strtotime($today_rawtime)) % 604800) % 86400) / 3600)*60));
$friday_close_final_min=((round(((((strtotime($friday_close_rawtime)-strtotime($today_rawtime)) % 604800) % 86400) % 3600) / 60))+(round((((strtotime($friday_close_rawtime)-strtotime($today_rawtime)) % 604800) % 86400) / 3600)*60));
$saturday_close_final_min=((round(((((strtotime($saturday_close_rawtime)-strtotime($today_rawtime)) % 604800) % 86400) % 3600) / 60))+(round((((strtotime($saturday_close_rawtime)-strtotime($today_rawtime)) % 604800) % 86400) / 3600)*60));
$sunday_close_final_min=((round(((((strtotime($sunday_close_rawtime)-strtotime($today_rawtime)) % 604800) % 86400) % 3600) / 60))+(round((((strtotime($sunday_close_rawtime)-strtotime($today_rawtime)) % 604800) % 86400) / 3600)*60));
$monday_open_pm_final_min=((round(((((strtotime($monday_open_pm_starts)-strtotime($today_rawtime)) % 604800) % 86400) % 3600) / 60))+(round((((strtotime($monday_open_pm_starts)-strtotime($today_rawtime)) % 604800) % 86400) / 3600)*60));
$monday_close_pm_final_min=((round(((((strtotime($monday_close_pm_ends)-strtotime($today_rawtime)) % 604800) % 86400) % 3600) / 60))+(round((((strtotime($monday_close_pm_ends)-strtotime($today_rawtime)) % 604800) % 86400) / 3600)*60));
$off_day="";
if(empty($monday_open_rawtime) && !empty($tuesday_open_rawtime) && $nextday='Tuesday' && ($tol>='-518400' || $tol='0') && $tol!='0' && $tol<='0' ){
$off_day="Next Open At : ".$tuesday_open_rawtime." ,Tuesday.";
}else if(empty($tuesday_open_rawtime) && !empty($wednesday_open_rawtime) && $nextday='Wednesday' && ($tol>='-518400' || $tol='0') && $tol!='0' && $tol<='0' ){
$off_day="Next Open At : ".$wednesday_open_rawtime." ,Wednesday.";
}else if(empty($wednesday_open_rawtime) && !empty($thursday_open_rawtime) && $nextday='Thursday' && ($tol>='-518400' || $tol='0') && $tol!='0' ){
$off_day="Next Open At : ".$thursday_open_rawtime." ,Thursday.";
}else if(empty($thursday_open_rawtime) && !empty($friday_open_rawtime) && $nextday='Friday' && ($tol>='-518400' || $tol='0') && $tol!='0' ){
$off_day="Next Open At : ".$friday_open_rawtime." ,Friday.";
}else if(empty($friday_open_rawtime) && !empty($saturday_open_rawtime) && $nextday='Saturday' && ($tol>='-518400' || $tol='0') && $tol!='0'){
$off_day="Next Open At : ".$saturday_open_rawtime." ,Saturday.";
}else if(empty($saturday_open_rawtime) && !empty($sunday_open_rawtime) && $nextday='Sunday' && ($tol>='-518400' || $tol='0') && $tol!='0'){
$off_day="Next Open At : ".$sunday_open_rawtime." ,Sunday.";
}else if(empty($sunday_open_rawtime) && !empty($monday_open_rawtime) && $nextday='Monday' && ($tol>='-518400' || $tol='0') && $tol!='0'){
$off_day="Next Open At : ".$monday_open_rawtime." ,Monday.";
}
echo $off_day;
//For Monday
if(!empty($off_day)){
//echo $off_day;
//echo "l";
}else if($today_bar=='monday'){
if($today_bar='monday' && $monday_open_final_min>=$close_time_mins){
echo "Open At : ".$monday_open_rawtime." ,Today";
}else if($today_bar='monday' && $monday_open_final_min<=$close_time_mins && $monday_open_final_min>=0){
echo "Open In ".$monday_open_final_min." Mins.";
}
else if($monday_close_final_min<=$close_time_mins && $monday_close_final_min>=0 && $today_bar='monday'){
echo "Close In ".$monday_close_final_min." Mins.";
}else if ($monday_close_final_min<=0 && $today_bar!='tuesday'){
echo "Next Open At : ".$tuesday_open_rawtime." ,Tomorrow.";
}
}else if($today_bar=='tuesday'){
if($today_bar='tuesday' && $tuesday_open_final_min>=$close_time_mins){
echo "Open At : ".$tuesday_open_rawtime." ,Today";
}else if($today_bar='tuesday' && $tuesday_open_final_min<=$close_time_mins && $tuesday_open_final_min>=0){
echo "Open In ".$tuesday_open_final_min." Mins";
}
else if($tuesday_close_final_min<=$close_time_mins && $tuesday_close_final_min>=0 && $today_bar='tuesday'){
echo "Close In ".$tuesday_close_final_min." Mins";
}else if ($tuesday_close_final_min<=0 && $today_bar!='wednesday'){
echo "Next Open At : ".$wednesday_open_rawtime." ,Tomorrow";
}
}else if($today_bar=='wednesday'){
if($today_bar='wednesday' && $wednesday_open_final_min>=$close_time_mins){
echo "Open At : ".$wednesday_open_rawtime." ,Today";
}else if($today_bar='wednesday' && $wednesday_open_final_min<=$close_time_mins && $wednesday_open_final_min>=0){
echo "Open In ".$wednesday_open_final_min." Mins";
}else if($wednesday_close_final_min<=$close_time_mins && $wednesday_close_final_min>=0 && $today_bar='wednesday'){
echo "Close In ".$wednesday_close_final_min." Mins";
}else if ($wednesday_close_final_min<=0 && $today_bar!='thursday'){
echo "Next Open At : ".$thursday_open_rawtime." ,Tomorrow";
}
}else if($today_bar=='thursday'){
if($today_bar='thursday' && $thursday_open_final_min>=$close_time_mins){
echo "Open At : ".$thursday_open_rawtime." ,Today";
}else if($today_bar='thursday' && $thursday_open_final_min<=$close_time_mins && $thursday_open_final_min>=0){
echo "Open In ".$thursday_open_final_min." Mins";
}else if($thursday_close_final_min<=$close_time_mins && $thursday_close_final_min>=0 && $today_bar='thursday'){
echo "Close In ".$thursday_close_final_min." Mins";
}else if ($thursday_close_final_min<=0 && $today_bar!='friday'){
echo "Next Open At : ".$friday_open_rawtime." ,Tomorrow";
}
}else if($today_bar=='friday'){
if($today_bar='friday' && $friday_open_final_min>=$close_time_mins){
echo "Open At : ".$friday_open_rawtime." ,Today";
}else if($today_bar='friday' && $friday_open_final_min<=$close_time_mins && $friday_open_final_min>=0){
echo "Open In ".$friday_open_final_min." Mins";
}else if($friday_close_final_min<=$close_time_mins && $friday_close_final_min>=0 && $today_bar='friday'){
echo "Close In ".$friday_close_final_min." Mins";
}else if ($friday_close_final_min<=0 && $today_bar!='saturday'){
echo "Next Open At : ".$saturday_open_rawtime." ,Tomorrow";
}
}else if($today_bar=='saturday'){
if($today_bar='saturday' && $saturday_open_final_min>=$close_time_mins){
echo "Open At : ".$saturday_open_rawtime." ,Today";
}else if($today_bar='saturday' && $saturday_open_final_min<=$close_time_mins && $saturday_open_final_min>=0){
echo "Open In ".$saturday_open_final_min." Mins";
}else if($saturday_close_final_min<=$close_time_mins && $saturday_close_final_min>=0 && $today_bar='saturday'){
echo "Close In ".$saturday_close_final_min." Mins";
}else if ($saturday_close_final_min<=0 && $today_bar!='sunday'){
echo "Next Open At : ".$sunday_open_rawtime." ,Tomorrow";
}
}else if($today_bar=='sunday'){
if($today_bar='sunday' && $sunday_open_final_min>=$close_time_mins){
echo "Open At : ".$sunday_open_rawtime." ,Today";
}else if($today_bar='saturday' && $sunday_open_final_min<=$close_time_mins && $sunday_open_final_min>=0){
echo "Open In ".$sunday_open_final_min." Mins";
}else if($sunday_close_final_min<=$close_time_mins && $sunday_close_final_min>=0 && $today_bar='sunday'){
echo "Close In ".$sunday_close_final_min." Mins";
}else if ($sunday_close_final_min<=0 && $today_bar!='monday'){
echo "Next Open At : ".$monday_open_rawtime." ,Tomorrow";
}
}