我想创建带有开始、结束时间和中断开始和结束的时间段。
我已经实现了生成时间段,但在 11:10 - 11:25 之间没有休息
输入变量
$duration = 35; // how much the is the duration of a time slot
$cleanup = 0; // don't mind this
$start = '09:00'; // start time
$end = '12:00'; // end time
$break_start = '11:10'; // break start
$break_end = '11:25'; // break end
function availableSlots($duration, $cleanup, $start, $end) {
$start = new DateTime($start);
$end = new DateTime($end);
$interval = new DateInterval("PT" . $duration . "M");
$cleanupInterval = new DateInterval("PT" . $cleanup . "M");
$periods = array();
for ($intStart = $start; $intStart < $end; $intStart->add($interval)->add($cleanupInterval)) {
$endPeriod = clone $intStart;
$endPeriod->add($interval);
if ($endPeriod > $end) {
break;
}
$periods[] = $intStart->format('H:i A') . ' - ' . $endPeriod->format('H:i A');
}
return $periods;
}
函数将生成此输出:
09:00 AM - 09:35 AM
09:35 AM - 10:10 AM
10:10 AM - 10:45 AM
10:45 AM - 11:20 AM
11:20 AM - 11:55 AM
我需要实现的是上午 11:10 到上午 11:25 的休息时间,这将被排除在结果之外。
$break_start = '11:10';
$break_end = '11:25';