schoppax / business-days-calculator
Business day calculation
1.0.7
2023-01-04 18:12 UTC
Requires
- php: >=7.3.0
Requires (Dev)
- php-coveralls/php-coveralls: ^1.1
- phpunit/phpunit: 6.*
This package is auto-updated.
Last update: 2025-03-04 23:22:32 UTC
README
Business Days Calculator
Install
- If you're using Composer to manage dependencies, you can use
composer require schoppax/business-days-calculator
or add to your composer.json file:
"require": {
"schoppax/business-days-calculator": "1.*",
}
Example
use \BusinessDays\Calculator; $holidays = [ new \DateTime('2000-12-31'), new \DateTime('2001-01-01') ]; $freeDays = [ new \DateTime('2000-12-28') ]; $freeWeekDays = [ Calculator::SATURDAY, Calculator::SUNDAY ]; $calculator = new Calculator(); $calculator->setFreeWeekDays($freeWeekDays); // repeat every week $calculator->setHolidays($holidays); // repeat every year $calculator->setFreeDays($freeDays); // don't repeat $result = $calculator->addBusinessDays(new \DateTime('2000-12-27', 3); // add X working days echo $result->format('Y-m-d'); // 2001-01-03 $result = $calculator->addBusinessDays(new \DateTime('2000-01-03', -3); // substract X working days echo $result->format('Y-m-d'); // 2001-12-27 $result = $calculator->getBusinessDays(new \DateTime('2000-12-27', 3); // get all X working days foreach ($result as $dt) { echo $dt->format('Y-m-d'); // 2000-12-29 / 2001-01-02 / 2001-01-03 } $result = $calculator->getBusinessDaysBetween(new \DateTime('2000-12-27', new \DateTime('2001-01-03'); foreach ($result as $dt) { echo $dt->format('Y-m-d'); // 2000-12-29 / 2001-01-02 / 2001-01-03 } echo count($result); // 3