PHP code example of codebros-nl / dutch-holidays

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

    

codebros-nl / dutch-holidays example snippets


use CodeBros\DutchHolidays\Facades\DutchHolidays;

// Alle feestdagen voor 2026
DutchHolidays::forYear(2026);

// Alleen wettelijke vrije dagen
DutchHolidays::officialHolidays(2026);

// Check een datum
DutchHolidays::isHoliday('2026-12-25');         // true
DutchHolidays::isWorkday('2026-05-05');         // true (default sector, geen lustrumjaar)

// Werkdag-rekenen
DutchHolidays::nextWorkday('2026-12-24');       // 2026-12-28
DutchHolidays::workdaysBetween('2026-01-01', '2026-12-31');  // ~252
DutchHolidays::addWorkdays('2026-12-24', 5);    // datum + 5 werkdagen

use CodeBros\DutchHolidays\Enums\Sector;

// Via enum (aanbevolen)
DutchHolidays::sector(Sector::Construction)->daysOff(2026);

// Of als string
DutchHolidays::sector('government')->isWorkday('2026-04-03'); // Goede Vrijdag → false

'default_sector' => Sector::Construction->value,

use CodeBros\DutchHolidays\Enums\HolidayKey;
use CodeBros\DutchHolidays\Enums\HolidayPolicy;

DutchHolidays::withPolicies([
    HolidayKey::GoodFriday->value => HolidayPolicy::Always,
    HolidayKey::LiberationDay->value => HolidayPolicy::Never,
])->forYear(2026);

use CodeBros\DutchHolidays\Facades\DutchHolidays;
use CodeBros\DutchHolidays\SectorProfile;
use CodeBros\DutchHolidays\Enums\HolidayKey;
use CodeBros\DutchHolidays\Enums\HolidayPolicy;

public function boot(): void
{
    DutchHolidays::registerSector('werkpunt_klant_a', new SectorProfile(
        name: 'Klant A — eigen cao',
        policies: [
            HolidayKey::GoodFriday->value => HolidayPolicy::Always,
            HolidayKey::LiberationDay->value => HolidayPolicy::Always,
        ],
        extraHolidays: [HolidayKey::NewYearsEve],
        description: 'Klant heeft 5 mei en Oudejaarsdag als extra vrije dag.',
    ));
}

DutchHolidays::sector('werkpunt_klant_a')->daysOff(2026);

class HolidayService
{
    public function __construct(private DutchHolidays $holidays) {}

    public function daysOffFor(Klant $klant, int $year): HolidayCollection
    {
        $policies = [];
        if ($klant->goede_vrijdag_vrij) {
            $policies[HolidayKey::GoodFriday->value] = HolidayPolicy::Always;
        }
        if ($klant->bevrijdingsdag_vrij) {
            $policies[HolidayKey::LiberationDay->value] = HolidayPolicy::Always;
        }

        return $this->holidays
            ->sector($klant->basis_sector ?? 'default')
            ->withPolicies($policies)
            ->daysOff($year);
    }
}

DutchHolidays::withExtraHolidays(
    HolidayKey::CarnivalMonday,
    HolidayKey::CarnivalTuesday,
)->forYear(2026);

// Is dit een werkdag in de huidige sector?
DutchHolidays::isWorkday('2026-05-05');

// Volgende / vorige werkdag
DutchHolidays::nextWorkday(now());
DutchHolidays::previousWorkday('2026-12-27');

// Werkdagen tellen tussen twee datums (inclusief)
DutchHolidays::workdaysBetween('2026-01-01', '2026-12-31');

// N werkdagen optellen (slaat weekenden + feestdagen over)
DutchHolidays::addWorkdays('2026-12-24', 5);
DutchHolidays::addWorkdays('2026-12-28', -2);

Carbon::today()->isDutchHoliday();          // bool
Carbon::today()->isDutchWorkday();          // bool
Carbon::today()->nextDutchWorkday();        // CarbonImmutable
Carbon::today()->previousDutchWorkday();    // CarbonImmutable
Carbon::today()->addDutchWorkdays(5);       // CarbonImmutable
Carbon::today()->dutchHoliday();            // ?Holiday

// Tussen twee datums (jaargrenzen overspannen mag)
DutchHolidays::between('2025-12-01', '2026-03-31');

// Alleen wettelijke
DutchHolidays::between('2025-12-01', '2026-03-31', officialOnly: true);

// Meerdere jaren tegelijk
$multi = DutchHolidays::forYears(2025, 2026, 2027);
$multi[2026]->official(); // HolidayCollection voor 2026

$holidays = DutchHolidays::forYear(2026);

$holidays->official();                  // alleen vrije dagen
$holidays->unofficial();                // alleen niet-vrije (Goede Vrijdag in default)
$holidays->from('2026-06-01');          // vanaf datum
$holidays->until('2026-06-30');         // tot en met datum
$holidays->byKey(HolidayKey::Christmas);
$holidays->asMap();                     // ['2026-12-25' => 'Eerste Kerstdag', ...]
$holidays->dates();                     // alleen Carbon-datums

use CodeBros\DutchHolidays\Contracts\HolidayProvider;
use CodeBros\DutchHolidays\Holiday;
use CodeBros\DutchHolidays\Enums\HolidayKey;
use Carbon\CarbonImmutable;

class CompanyClosureProvider implements HolidayProvider
{
    public function holidaysFor(int $year): array
    {
        return [
            new Holiday(
                key: HolidayKey::ChristmasEve,
                name: 'Bedrijfssluiting',
                date: CarbonImmutable::create($year, 12, 27),
                official: true,
            ),
        ];
    }

    public function name(): string
    {
        return 'company-closure';
    }
}

// Gebruik
DutchHolidays::withProvider(new CompanyClosureProvider())->daysOff(2026);
bash
php artisan vendor:publish --tag=dutch-holidays-config