I'm working on a project, Where the requirement is slot based booking system
and I want to filter booked slots with carbon period
in my research I found this reference Filtering Carbon Period
public function test_slots(){
$startDate = Carbon::parse('2021-01-01 00:00:00');
$period = $startDate->toPeriod('2021-01-02 00:00:00', 60, 'minutes');
$period->prependFilter(function($date){
$start_time = $date->copy()->setTimeFromTimeString('12:00');
$end_time = $date->copy()->setTimeFromTimeString('18:00');
return $date->greaterThan($start_time) && $date->lessThan($end_time);
});
foreach($period as $slot) echo $slot->format( g i:s A') . '<br>';
}
output of code
1 00:00 PM
2 00:00 PM
3 00:00 PM
4 00:00 PM
5 00:00 PM
above method return all slots between those two timestamps but I want to remove all the slots between those two slots and return all slots which not in between both slots
I saw in this method dates copy from but I want some thing copy-exclude.
required output
6 00:00 PM
7 00:00 PM
8 00:00 PM
9 00:00 PM
10 00:00 PM
...
...
...
12 00:00 AM
above method return all slots between those two timestamps but I want to remove all the slots between those two slots and return all slots which not in between both slots
I saw in this method dates copy from but I want some thing copy-exclude.
does carbon period provide something for this purpose or should wrote custom helper ?