Skip to content

Commit

Permalink
add the Netherlands
Browse files Browse the repository at this point in the history
  • Loading branch information
Nielsvanpach committed Jan 15, 2024
1 parent f590204 commit d435461
Show file tree
Hide file tree
Showing 7 changed files with 171 additions and 16 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ At the moment only these countries are supported.
You can send a PR for yours!

- [x] Belgium
- [x] Netherlands

## Support us

Expand Down
2 changes: 1 addition & 1 deletion src/Countries/Belgium.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ protected function variableHolidays(int $year): array

return [
'Paasmaandag' => $easter->addDay(),
'OH Hemelvaart' => $easter->addDays(39),
'OLH Hemelvaart' => $easter->addDays(39),
'Pinkstermaandag' => $easter->addDays(50),
];
}
Expand Down
63 changes: 63 additions & 0 deletions src/Countries/Netherlands.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?php

namespace Spatie\Holidays\Countries;

use Carbon\CarbonImmutable;

class Netherlands extends Country
{
public function countryCode(): string
{
return 'nl';
}

public function get(int $year): array
{
$this->ensureYearCanBeCalculated($year);

$fixedHolidays = $this->fixedHolidays($year);
$variableHolidays = $this->variableHolidays($year);

return array_merge($fixedHolidays, $variableHolidays);
}

/** @return array<string, CarbonImmutable> */
protected function fixedHolidays(int $year): array
{
$dates = [
'Nieuwjaar' => '01-01',
'Bevrijdingsdag' => '01-05',
'Kerstmis' => '25-12',
'2de Kerstdag' => '26-12',
'Oudjaar' => '31-12',
];

foreach ($dates as $name => $date) {
$dates[$name] = CarbonImmutable::createFromFormat('d-m-Y', "{$date}-{$year}");
}

return $dates;

Check failure on line 39 in src/Countries/Netherlands.php

View workflow job for this annotation

GitHub Actions / phpstan

Method Spatie\Holidays\Countries\Netherlands::fixedHolidays() should return array<string, Carbon\CarbonImmutable> but returns array<string, Carbon\CarbonImmutable|string|false>.
}

/** @return array<string, CarbonImmutable> */
protected function variableHolidays(int $year): array
{
$koningsDag = CarbonImmutable::createFromFormat('d-m-Y', "27-04-{$year}");

if ($koningsDag->isSunday()) {

Check failure on line 47 in src/Countries/Netherlands.php

View workflow job for this annotation

GitHub Actions / phpstan

Cannot call method isSunday() on Carbon\CarbonImmutable|false.
$koningsDag = $koningsDag->subDay();

Check failure on line 48 in src/Countries/Netherlands.php

View workflow job for this annotation

GitHub Actions / phpstan

Cannot call method subDay() on Carbon\CarbonImmutable|false.
}

$easter = CarbonImmutable::createFromTimestamp(easter_date($year))
->setTimezone('Europe/Brussels');

return [

Check failure on line 54 in src/Countries/Netherlands.php

View workflow job for this annotation

GitHub Actions / phpstan

Method Spatie\Holidays\Countries\Netherlands::variableHolidays() should return array<string, Carbon\CarbonImmutable> but returns array<string, Carbon\CarbonImmutable|false>.
'Koningsdag' => $koningsDag,
'Goede vrijdag' => $easter->subDays(2),
'Paasmaandag' => $easter->addDay(),
'OLH Hemelvaart' => $easter->addDays(39),
'Pinksteren' => $easter->addDays(49),
'Pinkstermaandag' => $easter->addDays(50),
];
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,42 @@
{
"Nieuwjaar": "2024-01-01T00:00:00.000000Z",
"Dag van de Arbeid": "2024-05-01T00:00:00.000000Z",
"Nationale Feestdag": "2024-07-21T00:00:00.000000Z",
"OLV Hemelvaart": "2024-08-15T00:00:00.000000Z",
"Allerheiligen": "2024-11-01T00:00:00.000000Z",
"Wapenstilstand": "2024-11-11T00:00:00.000000Z",
"Kerstmis": "2024-12-25T00:00:00.000000Z",
"Paasmaandag": "2024-03-31T22:00:00.000000Z",
"OH Hemelvaart": "2024-05-08T22:00:00.000000Z",
"Pinkstermaandag": "2024-05-19T22:00:00.000000Z"
}
[
{
"name": "Nieuwjaar",
"date": "01-01-2024"
},
{
"name": "Paasmaandag",
"date": "01-04-2024"
},
{
"name": "Dag van de Arbeid",
"date": "01-05-2024"
},
{
"name": "OLH Hemelvaart",
"date": "09-05-2024"
},
{
"name": "Pinkstermaandag",
"date": "20-05-2024"
},
{
"name": "Nationale Feestdag",
"date": "21-07-2024"
},
{
"name": "OLV Hemelvaart",
"date": "15-08-2024"
},
{
"name": "Allerheiligen",
"date": "01-11-2024"
},
{
"name": "Wapenstilstand",
"date": "11-11-2024"
},
{
"name": "Kerstmis",
"date": "25-12-2024"
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
[
{
"name": "Nieuwjaar",
"date": "01-01-2024"
},
{
"name": "Goede vrijdag",
"date": "29-03-2024"
},
{
"name": "Paasmaandag",
"date": "01-04-2024"
},
{
"name": "Koningsdag",
"date": "27-04-2024"
},
{
"name": "Bevrijdingsdag",
"date": "01-05-2024"
},
{
"name": "OLH Hemelvaart",
"date": "09-05-2024"
},
{
"name": "Pinksteren",
"date": "19-05-2024"
},
{
"name": "Pinkstermaandag",
"date": "20-05-2024"
},
{
"name": "Kerstmis",
"date": "25-12-2024"
},
{
"name": "2de Kerstdag",
"date": "26-12-2024"
},
{
"name": "Oudjaar",
"date": "31-12-2024"
}
]
7 changes: 4 additions & 3 deletions tests/Countries/BelgiumTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@

use Carbon\CarbonImmutable;
use Spatie\Holidays\Countries\Belgium;
use Spatie\Holidays\Holidays;

it('can calculate belgian holidays', function () {
CarbonImmutable::setTestNowAndTimezone('2024-01-01');

$country = new Belgium();
$holidays = Holidays::get(country: 'be');

expect($country->get(2024))->toMatchSnapshot();
})->skip('The results still have timezone issues.');
expect($holidays)->toMatchSnapshot();
});
14 changes: 14 additions & 0 deletions tests/Countries/NetherlandsTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

namespace Spatie\Holidays\Tests\Countries;

use Carbon\CarbonImmutable;
use Spatie\Holidays\Holidays;

it('can calculate dutch holidays', function () {
CarbonImmutable::setTestNowAndTimezone('2024-01-01');

$holidays = Holidays::get(country: 'nl');

expect($holidays)->toMatchSnapshot();
});

0 comments on commit d435461

Please sign in to comment.