Calculate delivery time - only working days, skip holidays or weekends (witch can be turned off, but by default is on).
Via Composer
$ composer require johnykvsky/deliverycalculator
$dlvCalc = new johnykvsky\Utils\DeliveryCalculator();
$provider = new johnykvsky\Utils\PolishDeliveryProvider(); //We want to ship/deliver in Poland
$dlvCalc->setShippingProvider($provider); //from Poland
$dlvCalc->setDeliveryProvider($provider); //to Poland
$result = $dlvCalc->calculateDeliveryDate(14, '2017-10-20'); //Get delivery date, shipping on 2017-10-20, deliver in 14 working days
echo $result->format('Y-m-d'); //2017-11-10
$dlvCalc = new johnykvsky\Utils\DeliveryCalculator();
$provider = new johnykvsky\Utils\PolishDeliveryProvider(); // We want to ship/deliver in Brazil
$dlvCalc->setShippingProvider($provider); // from Brazil
$dlvCalc->setDeliveryProvider($provider); // to Brazil
$result = $dlvCalc->calculateDeliveryDate(14, '2017-10-10'); //Get delivery date, shipping on 2017-10-10, deliver in 14 working days
echo $result->format('Y-m-d'); // 2017-10-31 disregarding weekends and holidays 2017-10-12
DeliveryCalculator depends on providers, however, you can create one generic provider and use it for all calculations, modifying on the fly (getters/setters) timezones, holidays and delivery-free days (ie. when client paid for delivery on sunday).
Providers has following settings:
- timezone
- holidays
- nonWorkingDays
- region
Timezone is used for proper delivery time calculation, with ie. 8h differences delivery date might skip to next day. Holidays are dates of christmas, easter and all other "officially free from work" days. NonWorkingDays are days when usually we don't deliver, like sunday. Region can be optionally set and provided with additional holidays, specific for this particular country area.
Delivery and shipping location has separate providers, witch is important, since if we want to ship tomorrow (item was sold today), but tomorrow is sunday, next day is holiday, so shipping should skip them and count from first working day.
$ composer test
If you discover any security related issues, please email [email protected] instead of using the issue tracker.
The MIT License (MIT). Please see License File for more information.