如何根据服务时间禁用时间段?

Posted

技术标签:

【中文标题】如何根据服务时间禁用时间段?【英文标题】:How to disabled time slots according to service time? 【发布时间】:2012-07-10 20:12:05 【问题描述】:

我只想根据我的营业时间阻止禁用那些时间段计算时间段列表预约。

我已经解决了我的问题,卡在最后一个任务上,请在下面提及。

My Service Duration = 60min.
My Today Busines Hours:
start time - 10:00 AM
end time - 3:00 PM

我已根据我今天的营业时间生成了 15 分钟的时隙列表:

$start = strtotime('10:00 AM');
$end = strtotime('3:00 PM');
for( $i = $start; $i <= $end; $i += (60*15)) 

    $slotlist[] = date('g:iA', $i);


//output
10:00AM
10:15AM
10:30AM
10:45AM
11:00AM
11:15AM
11:30AM
11:45AM
12:00PM
12:15PM
12:30PM
12:45PM
1:00PM
1:15PM
1:30PM
1:45PM
2:00PM
2:15PM
2:30PM
2:45PM
3:00PM

现在我已经预约了 3 个约会

约会 |开始时间到结束时间


Appointment-1 : 10:00 AM to 11:00 AM (根据我的服务时长60分钟) 预约 2:上午 11:15 至下午 12:15 预约 3:下午 1:00 至下午 2:00


//array of all appointment start_time
$appointment_start_time = array('10:00AM','11:15AM','1:00PM');

现在禁用那些已经预约的时间段

foreach($slotlist as $single)

    if(in_array($single, $appointment_start_time))
    
        echo "<input name=start_time type='radio' disabled  value='$single' />".$single; echo "<br>";

        $time = $single;                                                
        $event_length = 60-15;          // 60 is time duration                              
        $timestamp = strtotime("$time");                                
        $endtime = strtotime("+$event_length minutes", $timestamp);     
        $next_time = date('g:i A', $endtime);                       

        //calculate between slots (start-end time)
        $start = strtotime($single);
        $end = strtotime($next_time);
            for( $i = $start; $i <= $end; $i += (60*15)) 
            
                $list2[] = date('g:iA', $i);
            
    
    else
       
        if(in_array($single, $list2))
        
            echo "<input name=start_time type='radio' disabled  value='$single' />".$single; echo "<br>";
        
        else
           

            echo "<input name=start_time type='radio'  value='$single' />".$single; echo "<br>";
        
    



//output
10:00AM -disabled
10:15AM -disabled
10:30AM -disabled
10:45AM -disabled
11:00AM
11:15AM -disabled
11:30AM -disabled
11:45AM -disabled
12:00PM -disabled
12:15PM
12:30PM
12:45PM
1:00PM -disabled
1:15PM -disabled
1:30PM -disabled
1:45PM -disabled
2:00PM
2:15PM
2:30PM
2:45PM
3:00PM

现在要做的最后一个任务, 如何删除那些不符合服务持续时间的时间段,例如:

11:00AM (single slot b/w 2 appointment, cover only 15min)

12:15PM -
12:30PM -(3 slot b/w 2 appointment, cover only 45min)
12:45PM -

【问题讨论】:

【参考方案1】:

试试这个: 1.将第一个时隙与$appointment_start_time[0]比较,如果第一个时隙> $appointment_start_time[0]-60min,则禁用该时隙直到$appointment_start_time[0]。

2.比较 $appointment_start_time[1] 和 $appointment_start_time[0],如果持续时间 > 2 小时(您的服务持续时间 X 2),禁用 $appointment_start_time[0] 和 $appointment_start_time[1] 之间的时间段

3.比较 $appointment_start_time[2] 和 end-time,如果 end-time-120

【讨论】:

【参考方案2】:

两天过去了,我让这件事成为可能

$slottimes = 15;
$duration = 60; 
$business_start = '10:00AM';
$business_end = '3:00PM';
echo "<b>Today's Wroking Hours $business_start to $business_end</b><br>";
echo "<b>Calendar Slot(s) Time:</b> $slottimes<br>";
echo "<b>Service Duration Time:</b> $duration<br><br>";
$start = strtotime($business_start);
$end = strtotime($business_end);
/*$endtimestamp = strtotime($business_end);
$end = strtotime("-$slottimes minutes", $endtimestamp);*/
    for( $i = $start; $i <= $end; $i += (60*$slottimes)) 
    
        $slotlist[] = date('g:iA', $i);
    

echo "<b>Generate Today's Available Appointment Time(s)</b><br>";
echo "<pre>"; print_r($slotlist); echo "</pre>";

echo "<b>Today's Booked Appointment(s)</b>";
$appstarttime = array('11:00AM', '11:15AM', '1:00PM', $business_end );          //business end-time always be in array
$previoustime = NULL;
$nexttime = array($business_end);

foreach($slotlist as $single)

    if(in_array($single, $appstarttime))
    
        //calculate next time
        $time = $single;                                                
        $event_length = $duration-$slottimes;           // 60min Service duration time  - 15 slot time                          
        $timestamp = strtotime("$time");                                
        $endtime = strtotime("+$event_length minutes", $timestamp);     
        $next_time = date('g:i A', $endtime);                       

        //calculate between slots (start-end time)
        $start = strtotime($single);
        $end = strtotime($next_time);
            for( $i = $start; $i <= $end; $i += (60*$slottimes)) 
            
                $nexttime[] = date('g:iA', $i);
            



        //calculate previous time
        $time1 = $single;                                               
        $event_length1 = $duration-$slottimes;          // 60min Service duration time - 15 slot time                               
        $timestamp1 = strtotime("$time1");                              
        $endtime1 = strtotime("-$event_length1 minutes", $timestamp1);  
        $next_time1 = date('g:i A', $endtime1);                         

        //calculate between slots (start-end time)
        $start1 = strtotime($next_time1);
        $end1 = strtotime($single);
            for( $i = $start1; $i <= $end1; $i += (60*$slottimes)) 
            
                $previoustime[] = date('g:iA', $i);
            


    

echo "<br>Appointment Start Time: ";
print_r($appstarttime);
echo "<br>";

echo "<br><strong>Previous Time: </strong>";
print_r($previoustime);
echo "<br>";

echo "<br><strong>Next Time: </strong>";
print_r($nexttime);
echo "<br>";

echo "<br><strong>Merge Both Time:</strong> ";
if($previoustime && $nexttime)

    $merge = array_merge($previoustime, $nexttime);
    print_r($merge);

echo "<br>";echo "<br>";

$flag1 = 0;
$flag2 = 0;
echo "<hr><b>Today's Available Time For Appointment:</b><hr>";
foreach($slotlist as $single)

    if(in_array($single, $merge))
    
        echo "<input name=start_time type='radio' disabled  value='$single' />".$single; echo "<br>";
    
    else
    
        echo "<input name=start_time type='radio'  value='$single' />".$single; echo "<br>";
    

    if(in_array($single, $merge))
    
        $flag1 = 1;
    
    else
    
        $flag2 = 2;
    



if($flag2 != 2)
   echo "Sorry ! Today's all appointments has been booked."; 

echo "<hr>";

【讨论】:

以上是关于如何根据服务时间禁用时间段?的主要内容,如果未能解决你的问题,请参考以下文章

如何禁用使用手表循环遍历数组的可用时间?

如何根据条件禁用 TestNG 测试

如何在 iOS 中禁用来自 Web 服务调用的自动排序 JSON 字典响应

如何根据用户是不是登录启用/禁用元素?

如何在 .htaccess 文件中禁用 mod_security?

如何根据Datatables jquery中的单元格值禁用行复选框