penance316 / merger
Helper to merge date ranges together.
Installs: 13 278
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 3
Forks: 0
Open Issues: 0
Requires
- php: ^7.1|^8.0
Requires (Dev)
- phpunit/phpunit: ^7
README
A PHP based date merger that combines overlapping continuous date ranges.
Available via composer
composer require penance316/merger
Usage
// Each date pair should consist of [earlierDate, laterDate]. $dates = [ [new DateTime('2019-04-01'), new DateTime('2019-05-01')], [new DateTime('2019-05-01'), new DateTime('2019-06-01')], [new DateTime('2019-06-01'), new DateTime('2019-07-01')], [new DateTime('2019-07-01'), new DateTime('2019-08-01')], [new DateTime('2019-08-01'), new DateTime('2019-09-01')], ]; print_r(DateMerger::mergeRanges($dates)); // Output // Array // ( // [0] => Array // ( // [0] => DateTime Object // ( // [date] => 2019-04-01 00:00:00.000000 // [timezone_type] => 3 // [timezone] => Europe/London // ) // // [1] => DateTime Object // ( // [date] => 2019-09-01 00:00:00.000000 // [timezone_type] => 3 // [timezone] => Europe/London // ) // // ) // // )
License
MIT