Skip to content

Commit

Permalink
Merge pull request #5 from RootAccessPlease/danish-holidays
Browse files Browse the repository at this point in the history
Danish holidays
  • Loading branch information
Nielsvanpach authored Jan 18, 2024
2 parents e055593 + ef4dbd9 commit 2ff8351
Show file tree
Hide file tree
Showing 3 changed files with 111 additions and 0 deletions.
47 changes: 47 additions & 0 deletions src/Countries/Denmark.php
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([

Check failure on line 17 in src/Countries/Denmark.php

View workflow job for this annotation

GitHub Actions / phpstan

Method Spatie\Holidays\Countries\Denmark::allHolidays() should return array<string, Carbon\CarbonImmutable> but returns array<string, Carbon\CarbonImmutable|string>.
'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;
}
}
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"
}
]
18 changes: 18 additions & 0 deletions tests/Countries/DenmarkTest.php
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();
});

0 comments on commit 2ff8351

Please sign in to comment.