I want to create time slots with start,end time & also break timing.
public function getServiceScheduleSlots($duration,$break, $stTime,$enTime)
{
$start = new DateTime($stTime);
$end = new DateTime($enTime);
$interval = new DateInterval("PT" . $duration. "M");
$period = new DatePeriod($start, $duration, $end);
foreach ($period as $dt) {
$periods[] = $dt->format('H:iA');
}
return $periods;
}
For ex.,
My service start time 10:00 AM , End Time 12:00 PM.
Condition: each service time 30 min & 15 min break.
Above method returns like,
Expected results as,
I want to add break time when each period starts.
Thanks in advance.
How about this....
function getServiceScheduleSlots($duration,$break, $stTime,$enTime)
{
$start = new DateTime($stTime);
$end = new DateTime($enTime);
$interval = new DateInterval("PT" . $duration. "M");
$breakInterval = new DateInterval("PT" . $break. "M");
for ($intStart = $start;
$intStart < $end;
$intStart->add($interval)->add($breakInterval)) {
$endPeriod = clone $intStart;
$endPeriod->add($interval);
if ($endPeriod > $end) {
$endPeriod=$end;
}
$periods[] = $intStart->format('H:iA') .
' - ' .
$endPeriod->format('H:iA');
}
return $periods;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With