portavice/public-holidays-calculator

A calculator for public holidays written in PHP

v1.0.0 2023-03-27 09:21 UTC

This package is auto-updated.

Last update: 2024-10-15 10:22:38 UTC


README

Latest Version on Packagist PHP from Packagist Test Status Code Style Status Total Downloads

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 and composer 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.