PHP code example of spatie / holidays

1. Go to this page and download the library: Download spatie/holidays 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/ */

    

spatie / holidays example snippets


use Spatie\Holidays\Holidays;

// returns an array of Belgian holidays
// for the current year
$holidays = Holidays::for('be')->get();

use Spatie\Holidays\Holidays;
use Spatie\Holidays\Countries\Belgium;

// returns an array of Belgian holidays
// for the current year
$holidays = Holidays::for(Belgium::make())->get(); 

use Spatie\Holidays\Holidays;

// returns an array of Belgian holidays
// for the current year
$holidays = Holidays::for('be')->get();

use Spatie\Holidays\Holidays;

$holidays = Holidays::for(country: 'be', year: 2024)->get();

use Spatie\Holidays\Holidays;

$holidays = Holidays::for('be')->getInRange('2023-06-01', '2024-05-31');

$holidays = Holidays::for(country: 'be', locale: 'fr')->get();

use Spatie\Holidays\Holidays;

Holidays::for('be')->isHoliday('2024-01-01'); // true

use Spatie\Holidays\Holidays;

Holidays::for('be')->getName('2024-01-01'); // Nieuwjaar

use Spatie\Holidays\Holidays;

Holidays::has('be'); // true
Holidays::has('unknown'); // false

$holidays = Holidays::for(Germany::make('DE-BW'))->get();

class Germany extends Country
{
    protected function __construct(
        protected ?string $region = null,
    ) {
    }

    protected function allHolidays(int $year): array
    {
        // Here you can use $this->region (or other variables) to calculate holidays
    }