This package allows you to calculate with public holidays and working days in PHP based on an extension of the Carbon library.
To install this package with Composer:
composer require portavice/public-holidays-calculator
<?php
use Carbon\Carbon;
use Portavice\PublicHolidays\Carbon\Calculator;
Calculator::register(); // Register Carbon macros
Carbon::setPublicHolidays([
new FixedHoliday(1, 1), // New Year
FlexibleHoliday::EasterMonday,
]);
$jan01 = Carbon::create(2022, 1, 1);
$jan01->isWorkingDay(); // false
$dec27 = Carbon::create(2022, 12, 27);
$dec->isWorkingDay(); // true
$dec27->subWorkingDays(2); // 2022-12-22
$dec27->subWorkingDay(); // 2022-12-23
$dec27->addWorkingDay(); // 2022-12-28
$dec27->addWorkingDays(10); // 2023-01-10
- Run
composer install
to install the dependencies for PHP. - Run
composer test
to run all PHPUnit tests. - Run
composer cs
to check compliance with the code style andcomposer csfix
to fix code style violations before every commit.
PHP code MUST follow PSR-12 specification.
We use PHP_CodeSniffer for the PHP code style check.