From d4354611d7b77b7fb318ee9073ff540601bec02b Mon Sep 17 00:00:00 2001 From: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> Date: Mon, 15 Jan 2024 11:38:25 +0100 Subject: [PATCH] add the Netherlands --- README.md | 1 + src/Countries/Belgium.php | 2 +- src/Countries/Netherlands.php | 63 +++++++++++++++++++ .../it_can_calculate_belgian_holidays.snap | 54 ++++++++++++---- .../it_can_calculate_dutch_holidays.snap | 46 ++++++++++++++ tests/Countries/BelgiumTest.php | 7 ++- tests/Countries/NetherlandsTest.php | 14 +++++ 7 files changed, 171 insertions(+), 16 deletions(-) create mode 100644 src/Countries/Netherlands.php create mode 100644 tests/.pest/snapshots/Countries/NetherlandsTest/it_can_calculate_dutch_holidays.snap create mode 100644 tests/Countries/NetherlandsTest.php diff --git a/README.md b/README.md index b78d38196..439fe988d 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/src/Countries/Belgium.php b/src/Countries/Belgium.php index e318098bb..96835ed8c 100644 --- a/src/Countries/Belgium.php +++ b/src/Countries/Belgium.php @@ -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), ]; } diff --git a/src/Countries/Netherlands.php b/src/Countries/Netherlands.php new file mode 100644 index 000000000..50a5db879 --- /dev/null +++ b/src/Countries/Netherlands.php @@ -0,0 +1,63 @@ +ensureYearCanBeCalculated($year); + + $fixedHolidays = $this->fixedHolidays($year); + $variableHolidays = $this->variableHolidays($year); + + return array_merge($fixedHolidays, $variableHolidays); + } + + /** @return array */ + 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; + } + + /** @return array */ + protected function variableHolidays(int $year): array + { + $koningsDag = CarbonImmutable::createFromFormat('d-m-Y', "27-04-{$year}"); + + if ($koningsDag->isSunday()) { + $koningsDag = $koningsDag->subDay(); + } + + $easter = CarbonImmutable::createFromTimestamp(easter_date($year)) + ->setTimezone('Europe/Brussels'); + + return [ + 'Koningsdag' => $koningsDag, + 'Goede vrijdag' => $easter->subDays(2), + 'Paasmaandag' => $easter->addDay(), + 'OLH Hemelvaart' => $easter->addDays(39), + 'Pinksteren' => $easter->addDays(49), + 'Pinkstermaandag' => $easter->addDays(50), + ]; + } +} diff --git a/tests/.pest/snapshots/Countries/BelgiumTest/it_can_calculate_belgian_holidays.snap b/tests/.pest/snapshots/Countries/BelgiumTest/it_can_calculate_belgian_holidays.snap index 8aa58f1f1..3503c4168 100644 --- a/tests/.pest/snapshots/Countries/BelgiumTest/it_can_calculate_belgian_holidays.snap +++ b/tests/.pest/snapshots/Countries/BelgiumTest/it_can_calculate_belgian_holidays.snap @@ -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" -} \ No newline at end of file +[ + { + "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" + } +] \ No newline at end of file diff --git a/tests/.pest/snapshots/Countries/NetherlandsTest/it_can_calculate_dutch_holidays.snap b/tests/.pest/snapshots/Countries/NetherlandsTest/it_can_calculate_dutch_holidays.snap new file mode 100644 index 000000000..bcf65bc05 --- /dev/null +++ b/tests/.pest/snapshots/Countries/NetherlandsTest/it_can_calculate_dutch_holidays.snap @@ -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" + } +] \ No newline at end of file diff --git a/tests/Countries/BelgiumTest.php b/tests/Countries/BelgiumTest.php index c295cbc73..cc958da07 100644 --- a/tests/Countries/BelgiumTest.php +++ b/tests/Countries/BelgiumTest.php @@ -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(); +}); diff --git a/tests/Countries/NetherlandsTest.php b/tests/Countries/NetherlandsTest.php new file mode 100644 index 000000000..d8f3a8f55 --- /dev/null +++ b/tests/Countries/NetherlandsTest.php @@ -0,0 +1,14 @@ +toMatchSnapshot(); +});