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

时间:2012-07-11 08:44:23

标签: php time duration appointment timeslots

我想要的,根据我的营业时间阻止停用那些时间段计算时间段列表通过预约预约。

我已经用我的问题完成了这些事情,坚持最后一项任务,下面提到。

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个约会

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


预约-1:上午10:00至11:00(根据我的服务时间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 -

2 个答案:

答案 0 :(得分:2)

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>";

答案 1 :(得分:0)

试试这个: 1.比较第一个时段和$ appointment_start_time [0],如果第一个时段&gt; $ appointment_start_time [0] -60min,禁用时间段直到$ appointment_start_time [0]。

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

3.比较$ appointment_start_time [2]和end-time,如果end-time-120&lt; $ appointment_start_time [2],也已禁用