Delivery calculator for Laravel to calculate a date time by providing the start date time and a duration in hours
contoweb/delivery-calculator is a Laravel package for delivery calculator for laravel to calculate a date time by providing the start date time and a duration in hours.
It currently has 5 GitHub stars and 170 downloads on Packagist (latest version v2.0.2).
Install it with composer require contoweb/delivery-calculator.
Discover more Laravel packages by contoweb
or browse all Laravel packages to compare alternatives.
Last updated
Calculate a DateTime by providing a start date-time and a duration in hours considering business hours, weekends and defined holidays.
The package is available on Packagist and GitHub:
With composer
composer require contoweb/delivery-calculator
Migrate holidays table
php artisan migrate
Load the class
use Contoweb\DeliveryCalculator\DeliveryCalculator;
Initialize business hours with start (eg. 05:45) and end time (eg. 23:00)
$deliveryCalculator = new DeliveryCalculator(5, 45, 23, 0);
Function 1: Calculate a delivery DateTime by given start DateTime (Carbon date) and the delivery duration (double in hours)
$deliveryDateTime = $deliveryCalculator->getDeliveryTime(Carbon::now(), $duration);
Function 2: Given date (Carbon) is in business time?
$isBusinessTime = $deliveryCalculator->isBusinessTime(Carbon::now());
Enter a start_date (eg. 2017-12-24) and end_date (eg. 2017-12-26) into the holidays table to define holidays.
For a single holiday just enter the same date for both fields.
1.0