如何将开放时间拆分为30分钟的块?

问题描述:

我目前正在一个应用程序预订理发师约会。我正在使用fullcalendar进行约会,我试图将工作时间分成单独的小时或00:30分钟的块。我的数据库表包含09:00至18:00的“开始”和“结束”时间。我正在考虑一段时间的循环,但现在不要如何开始。它必须是一些数组。对此有何想法?如何将开放时间拆分为30分钟的块?

Monday ['0' => '09:00', 
     '1' => '09:30', 
     '2' => '10:00', 
     ]; 
Tuesday ['0' => '09:00', 
      '1' => '09:30', 
      '2' => '10:00', 
     ]; 

Table structure Appointments Table structure Business_hours

+0

您能详细解释一下这个数据结构将如何使用吗? –

+0

客户可以预约预约时间。这些可用时间基于企业的开放时间。所以当营业时间为09:00至18:00时,应该有一个可用时间的列表,例如:09:00,9:30,10:10,10:30直到达到18:00的结束时间。当客户选择一个时间时,它不应该在可用列表中。 –

<?php 
function get_minutes ($start, $end) { 

    while (strtotime($start) <= strtotime($end)) { 
    $minutes[] = date("H:i:s", strtotime("$start")); 
    $start = date("H:i:s", strtotime("$start + 30 mins")) ;  
    } 
return $minutes; 
} 

例如

$minutes = get_minutes('08:00', '10:00'); 
foreach($minutes as $minute) { 
echo $minute .'<br />'; 
} 
?> 
+0

感谢这就是我一直在寻找的东西,它就像一个魅力。另外一个问题,我也需要一个想法来隐藏已经预订的时间。我有约会表的行:start_date,end_date像2017-06-15 13:37:00。我怎样才能隐藏预订的时间? –

+0

这里有一个假设,即数据库中的营业时间总是很长或半小时。如果营业时间可以定义为:09:15 - 17:30,那么这段代码需要处理这个边缘案例 –

+0

它的依赖于你的表结构,那么我们可以做一个查询。如果我能看到你的餐桌结构 –

如果这些被预定时隙,你会用表示时隙的数据结构更好,如:

Array('2017-01-01' => ('slot_id' => 'Dgf67654' , 
         'from' => '09:00', 
         'to' => '09:30'), 
         ('slot_id' => 'dsff7676', 
         'from' => '09:30', 
         'to' => '10:30'), 
         ... 
) 

并修改上面提出的get_minutes来生成这种结构。这种数据结构将准备使用预订代码