:date: DateTime calculations in business hours
DateTime calculations in business hours
$ composer require florianv/businessFirst you need to configure your business schedule:
…$bool = $business->within(new \DateTime('2015-05-11 10:00'));$start = new \DateTime('2015-05-11 10:00');
$end = new \DateTime('2015-05-14 10:00');
$interval = new \DateInterval('P1D');
$dates = $business->timeline($start, $end, $interval);// After that date (including it)
$nextDate = $business->closest(new \DateTime('2015-05-11 10:00'));
// Before that date (including it)
$lastDate = $business->closest(new \DateTime('2015-05-11 10:00'), Business::CLOSEST_LAST);The Business class can be serialized so it can be stored for later reuse:
$serialized = serialize($business);
$business = unserialize($serialized);If you use SpecialDay instances, you need to install the jeremeamia/superclosure library providing closure serialization:
$ composer require jeremeamia/superclosureAll classes can be encoded to JSON
$json = json_encode($business);The SpecialDay instances require a context in order extract the data from the callable.
This is automatically set to new \DateTime('now') for json_encode() call only.
No open issues yet, or sync has not completed.