Answer the question
In order to leave comments, you need to log in
How to form overlapping periods?
Greetings!
I apologize for the appeal, I have a headache with working with dates.
I need to do the following thing: if the periods intersect, then I need to separate them.
Incoming data (for example, in reality datetime objects)
[
0 => ['openDate' => "2018-05-15", 'closeeDate' => "2018-05-30", "item" => 77],
1 => ['openDate' => "2018-05-20", 'closeeDate' => "2018-05-25", "item" => 60]
]
[
0 => ['openDate' => "2018-05-15", 'closeeDate' => "2018-05-19", "item" => 77]
1 => ['openDate' => "2018-05-20", 'closeeDate' => "2018-05-25", "item" => 60],
2 => ['openDate' => "2018-05-26", 'closeeDate' => "2018-05-30", "item" => 77],
]
Answer the question
In order to leave comments, you need to log in
another option is to collect everything in one array
initial data
$days = [2018-05-15, 2018-05-30, 2018-05-20, 2018-05-25];
then we sort in ascending order,
after which we take the first element and the second -1 day, then the second and 3-1 days, etc.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question