Skip to content

Commit

Permalink
Merge pull request #6 from felixfrey/main
Browse files Browse the repository at this point in the history
Implement holidays for Austria
  • Loading branch information
Nielsvanpach authored Jan 17, 2024
2 parents d07f5f7 + c6e4078 commit 26f476a
Show file tree
Hide file tree
Showing 3 changed files with 115 additions and 0 deletions.
43 changes: 43 additions & 0 deletions src/Countries/Austria.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

namespace Spatie\Holidays\Countries;

use Carbon\CarbonImmutable;

class Austria extends Country
{
public function countryCode(): string
{
return 'at';
}

/** @return array<string, CarbonImmutable> */
protected function allHolidays(int $year): array
{
return array_merge([

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

View workflow job for this annotation

GitHub Actions / phpstan

Method Spatie\Holidays\Countries\Austria::allHolidays() should return array<string, Carbon\CarbonImmutable> but returns array<string, Carbon\CarbonImmutable|string>.
'Neujahr' => '01-01',
'Heilige Drei Könige' => '01-06',
'Staatsfeiertag' => '05-01',
'Mariä Himmelfahrt' => '08-15',
'Nationalfeiertag' => '10-26',
'Allerheiligen' => '11-01',
'Mariä Empfängnis' => '12-08',
'Christtag' => '12-25',
'Stefanitag' => '12-26',
], $this->variableHolidays($year));
}

/** @return array<string, CarbonImmutable> */
protected function variableHolidays(int $year): array
{
$easter = CarbonImmutable::createFromTimestamp(easter_date($year))
->setTimezone('Europe/Vienna');

return [
'Ostermontag' => $easter->addDay(1),

Check failure on line 37 in src/Countries/Austria.php

View workflow job for this annotation

GitHub Actions / phpstan

Method Carbon\CarbonImmutable::addDay() invoked with 1 parameter, 0 required.
'Christi Himmelfahrt' => $easter->addDays(39),
'Pfingstmontag' => $easter->addDays(50),
'Fronleichnam' => $easter->addDays(60),
];
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
[
{
"name": "Neujahr",
"date": "2024-01-01"
},
{
"name": "Heilige Drei K\u00f6nige",
"date": "2024-01-06"
},
{
"name": "Ostermontag",
"date": "2024-04-01"
},
{
"name": "Staatsfeiertag",
"date": "2024-05-01"
},
{
"name": "Christi Himmelfahrt",
"date": "2024-05-09"
},
{
"name": "Pfingstmontag",
"date": "2024-05-20"
},
{
"name": "Fronleichnam",
"date": "2024-05-30"
},
{
"name": "Mari\u00e4 Himmelfahrt",
"date": "2024-08-15"
},
{
"name": "Nationalfeiertag",
"date": "2024-10-26"
},
{
"name": "Allerheiligen",
"date": "2024-11-01"
},
{
"name": "Mari\u00e4 Empf\u00e4ngnis",
"date": "2024-12-08"
},
{
"name": "Christtag",
"date": "2024-12-25"
},
{
"name": "Stefanitag",
"date": "2024-12-26"
}
]
18 changes: 18 additions & 0 deletions tests/Countries/AustriaTest.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 austrian holidays', function () {
CarbonImmutable::setTestNowAndTimezone('2024-01-01');

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

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

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

0 comments on commit 26f476a

Please sign in to comment.