Skip to content

Commit

Permalink
Implement holidays for Austria
Browse files Browse the repository at this point in the history
  • Loading branch information
felixfrey committed Jan 17, 2024
1 parent 794e044 commit 597577a
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([
'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-25',
], $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),
'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-25"
}
]
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 597577a

Please sign in to comment.