PHP code example of portavice / public-holidays-calculator

1. Go to this page and download the library: Download portavice/public-holidays-calculator library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

portavice / public-holidays-calculator example snippets




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