Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

kendrick's avatar

Time iteration logic

How can I iterate over a task-frame which starts at 08:00 until it reaches the max. of 14:00 including a logic with a step of 30 minutes and a 15 minutes $chill space, looped through until 14:00 to then list the task-frames as a select option within the view.

$start = $day->start; // equals 08:00
$end = $day->end; // equals 14:00

$task = '30'; // equals 30 minutes
$frame = $end - $start; // equals 6 h, 360 minutes

$amount = $frame : $task; // equals 12 without $chill space
$chill = '15'; // equals 15 minutes

$task1 = $start + $frame; // equals 08:00 - 08:30
$chill1 = $task1 + $chill; // equals 08:30 - 08:45
$task2 = $chill1 + $frame; // equals 08:45 - 09:15
$chill2 = $task2 + $chill; // equals 09:15 - 09:30
++
$task8 = $chill7 + $frame; // equals 13:15 - 13:45 
$chill8 = $task8 + $chill; // equals 13:45 - 14:00 
 

How should I start with the bridge between the Controller and View to loop over the $frame with the $task and $chill in mind?

<div class="container">
<select>
@foreach($tasks as $task)
    <option>{{$task}}</option> // should output 08:00 - 08:30, then  08:45 - 09:15 until the last 13:15 - 13:45
@endforeach
</select>
</div>

Any tips to approach the logic?

0 likes
0 replies

Please or to participate in this conversation.