portavice / public-holidays-calculator
A calculator for public holidays written in PHP
Installs: 4 416
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 1
Forks: 0
Open Issues: 0
Requires
- php: ^8.1
- ext-calendar: *
- nesbot/carbon: ^2.66.0
Requires (Dev)
- dealerdirect/phpcodesniffer-composer-installer: ^0.7.2
- phpcompatibility/php-compatibility: ^9.3.5
- phpunit/phpunit: ^10.0.18
- squizlabs/php_codesniffer: ^3.7.2
README
This package allows you to calculate with public holidays and working days in PHP based on an extension of the Carbon library.
Usage
Installation
To install this package with Composer:
composer require portavice/public-holidays-calculator
Use the Carbon
extension
<?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
Development
How to develop
- 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.
Code Style
PHP code MUST follow PSR-12 specification.
We use PHP_CodeSniffer for the PHP code style check.