generated from spatie/package-skeleton-php
-
-
Notifications
You must be signed in to change notification settings - Fork 198
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f590204
commit d435461
Showing
7 changed files
with
171 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
||
/** @return array<string, CarbonImmutable> */ | ||
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), | ||
]; | ||
} | ||
} |
54 changes: 42 additions & 12 deletions
54
tests/.pest/snapshots/Countries/BelgiumTest/it_can_calculate_belgian_holidays.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
] |
46 changes: 46 additions & 0 deletions
46
tests/.pest/snapshots/Countries/NetherlandsTest/it_can_calculate_dutch_holidays.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
}); |