I need to get a range of hours between two given hours, with 15 minutes steps, so I get this:
"book_time_range": [
"13:00-13:15",
"13:15-13:30",
"13:30-13:45",
"13:45-14:00",
"14:00-14:15",
"14:15-14:30",
"14:30-14:45",
"14:45-15:00",
"15:00-15:15",
"15:15-15:30"
],
This is as far as I got:
public function hours_range_between_start_and_end(
$start = '13:00',
$end = '15:30',
$step = 900,
$format = 'H:i'
) {
$times_ranges = [];
$start = strtotime($start) - strtotime('TODAY');
$end = strtotime($end) - strtotime('TODAY');
foreach (range($start, $end, $step) as $increment)
{
$increment = gmdate('H:i', $increment);
list($hour, $minutes) = explode(':', $increment);
$date = new DateTime($hour . ':' . $minutes);
$times_ranges[] = $date->format($format);
}
return $times_ranges;
}
Which gives me:
"book_time_range": [
"13:00",
"13:15",
"13:30",
"13:45",
"14:00",
"14:15",
"14:30",
"14:45",
"15:00",
"15:15",
"15:30"
],
That is technically correct, but I'm getting stuck on how to work with that array to get the one I want.
Any tips? Maybe I'm approaching this incorrectly from the beginning?