generated from spatie/package-skeleton-php
-
-
Notifications
You must be signed in to change notification settings - Fork 199
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from RootAccessPlease/danish-holidays
Danish holidays
- Loading branch information
Showing
3 changed files
with
111 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php | ||
|
||
namespace Spatie\Holidays\Countries; | ||
|
||
use Carbon\CarbonImmutable; | ||
|
||
class Denmark extends Country | ||
{ | ||
public function countryCode(): string | ||
{ | ||
return 'da'; | ||
} | ||
|
||
/** @return array<string, CarbonImmutable> */ | ||
protected function allHolidays(int $year): array | ||
{ | ||
return array_merge([ | ||
'Nytår' => '01-01', | ||
'Juleaften' => '12-24', | ||
'Juledag' => '12-25', | ||
'Anden Juledag' => '12-26' | ||
], $this->variableHolidays($year)); | ||
} | ||
|
||
/** @return array<string, CarbonImmutable> */ | ||
protected function variableHolidays(int $year): array | ||
{ | ||
$easter = CarbonImmutable::createFromTimestamp(easter_date($year)) | ||
->setTimezone('Europe/Copenhagen'); | ||
|
||
$holidays = [ | ||
'Påskedag' => $easter->addDay(), | ||
'Skærtorsdag' => $easter->subDays(3), | ||
'Langfredag' => $easter->subDays(2), | ||
'Anden Påskedag' => $easter->addDays(2), | ||
'Kristi Himmelfartsdag' => $easter->addDays(39), | ||
'Pinse' => $easter->addDays(49), | ||
'Anden Pinsedag' => $easter->addDays(50), | ||
]; | ||
|
||
if ($year < 2024) { | ||
$holidays['Store Bededag'] = $easter->addDays(26); | ||
} | ||
|
||
return $holidays; | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
tests/.pest/snapshots/Countries/DenmarkTest/it_can_calculate_danish_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": "Nyt\u00e5r", | ||
"date": "2024-01-01" | ||
}, | ||
{ | ||
"name": "Sk\u00e6rtorsdag", | ||
"date": "2024-03-28" | ||
}, | ||
{ | ||
"name": "Langfredag", | ||
"date": "2024-03-29" | ||
}, | ||
{ | ||
"name": "P\u00e5skedag", | ||
"date": "2024-04-01" | ||
}, | ||
{ | ||
"name": "Anden P\u00e5skedag", | ||
"date": "2024-04-02" | ||
}, | ||
{ | ||
"name": "Kristi Himmelfartsdag", | ||
"date": "2024-05-09" | ||
}, | ||
{ | ||
"name": "Pinse", | ||
"date": "2024-05-19" | ||
}, | ||
{ | ||
"name": "Anden Pinsedag", | ||
"date": "2024-05-20" | ||
}, | ||
{ | ||
"name": "Juleaften", | ||
"date": "2024-12-24" | ||
}, | ||
{ | ||
"name": "Juledag", | ||
"date": "2024-12-25" | ||
}, | ||
{ | ||
"name": "Anden Juledag", | ||
"date": "2024-12-26" | ||
} | ||
] |
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,18 @@ | ||
<?php | ||
|
||
namespace Spatie\Holidays\Tests\Countries; | ||
|
||
use Carbon\CarbonImmutable; | ||
use Spatie\Holidays\Holidays; | ||
|
||
it('can calculate danish holidays', function () { | ||
CarbonImmutable::setTestNowAndTimezone('2024-01-01'); | ||
|
||
$holidays = Holidays::for(country: 'da')->get(); | ||
|
||
expect($holidays) | ||
->toBeArray() | ||
->not()->toBeEmpty(); | ||
|
||
expect(formatDates($holidays))->toMatchSnapshot(); | ||
}); |