I have an array of date ranges, for example:
[0] => Array ( [start_time] => 2011-10-01 00:00:00 [end_time] => 2011-10-05 00:00:00 [name] => Apples ) [1] => Array ( [start_time] => 2011-10-04 00:00:00 [end_time] => 2011-10-10 00:23:00 [name] => Oranges ) [2] => Array ( [start_time] => 2011-10-15 00:00:00 [end_time] => 2011-10-20 00:23:00 [name] => Bananas )
I try to calculate the overlap between each event and “split” this overlap into a separate element in the array, and then change the start and end times of the intersecting events accordingly so that they no longer overlap. For example, in the array above, “Apples” intersect with oranges for one day, so I would like to get an array that looks like this.
[0] => Array ( [start_time] => 2011-10-01 00:00:00 [end_time] => 2011-10-04 00:00:00 [name] => Apples ) [1] => Array ( [start_time] => 2011-10-04 00:00:00 [end_time] => 2011-10-05 00:00:00 [name] => Apples Oranges ) [2] => Array ( [start_time] => 2011-10-05 00:00:00 [end_time] => 2011-10-10 00:23:00 [name] => Oranges ) [3] => Array ( [start_time] => 2011-10-15 00:00:00 [end_time] => 2011-10-20 00:23:00 [name] => Bananas )
source share