johnykvsky/deliverycalculator

Calculate delivery date. Skip holidays and weekends. Check for different timezones

0.1.0 2020-06-03 21:39 UTC

This package is auto-updated.

Last update: 2024-04-15 03:17:44 UTC


README

Latest Version on Packagist Software License Total Downloads Build Status

Calculate delivery time - only working days, skip holidays or weekends (witch can be turned off, but by default is on).

Install

Via Composer

$ composer require johnykvsky/deliverycalculator

Should work fine on PHP 5.6, but I didn't check that. Just change required PHP version in composer.json and maybe remove dev packages.

Usage

$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

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.

Testing

$ composer test

Code checking

$ composer phpstan
$ composer phpstan-max

Security

If you discover any security related issues, please email johnykvsky@protonmail.com instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.