Skip to content

Commit

Permalink
fix ISO code for Denmark
Browse files Browse the repository at this point in the history
  • Loading branch information
Nielsvanpach committed Oct 1, 2024
1 parent b4bcf06 commit b988c3c
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 1 deletion.
30 changes: 30 additions & 0 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,36 @@ parameters:
count: 1
path: src/Countries/Country.php

-
message: "#^Access to undefined constant Spatie\\\\Holidays\\\\Countries\\\\Malaysia\\:\\:arafat\\.$#"
count: 1
path: src/Countries/Malaysia.php

-
message: "#^Access to undefined constant Spatie\\\\Holidays\\\\Countries\\\\Malaysia\\:\\:ashura\\.$#"
count: 1
path: src/Countries/Malaysia.php

-
message: "#^Access to undefined constant Spatie\\\\Holidays\\\\Countries\\\\Malaysia\\:\\:eidAlAdha\\.$#"
count: 1
path: src/Countries/Malaysia.php

-
message: "#^Access to undefined constant Spatie\\\\Holidays\\\\Countries\\\\Malaysia\\:\\:eidAlFitr\\.$#"
count: 1
path: src/Countries/Malaysia.php

-
message: "#^Access to undefined constant Spatie\\\\Holidays\\\\Countries\\\\Malaysia\\:\\:islamicNewYear\\.$#"
count: 1
path: src/Countries/Malaysia.php

-
message: "#^Access to undefined constant Spatie\\\\Holidays\\\\Countries\\\\Malaysia\\:\\:prophetMuhammadBirthday\\.$#"
count: 1
path: src/Countries/Malaysia.php

-
message: "#^Method Spatie\\\\Holidays\\\\Countries\\\\Morocco\\:\\:variableHolidays\\(\\) should return array\\<string, Carbon\\\\CarbonImmutable\\> but returns array\\<string, Carbon\\\\CarbonImmutable\\|null\\>\\.$#"
count: 1
Expand Down
4 changes: 4 additions & 0 deletions src/Countries/Country.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,10 @@ public static function find(string $countryCode): ?Country
{
$countryCode = strtolower($countryCode);

if ($countryCode === 'da') {
$countryCode = 'dk'; // @todo remove with new major and change the ISO code for Denmark
}

foreach (glob(__DIR__.'/../Countries/*.php') as $filename) {
if (basename($filename) === 'Country.php') {
continue;
Expand Down
2 changes: 1 addition & 1 deletion src/Countries/Denmark.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class Denmark extends Country
{
public function countryCode(): string
{
return 'da';
return 'dk';
}

protected function allHolidays(int $year): array
Expand Down
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-03-31"
},
{
"name": "Anden P\u00e5skedag",
"date": "2024-04-01"
},
{
"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"
}
]
12 changes: 12 additions & 0 deletions tests/Countries/DenmarkTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,18 @@
it('can calculate danish holidays', function () {
CarbonImmutable::setTestNow('2024-01-01');

$holidays = Holidays::for(country: 'dk')->get();

expect($holidays)
->toBeArray()
->not()->toBeEmpty();

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

it('can calculate danish holidays with the wrong ISO code', function () {
CarbonImmutable::setTestNow('2024-01-01');

$holidays = Holidays::for(country: 'da')->get();

expect($holidays)
Expand Down

0 comments on commit b988c3c

Please sign in to comment.