Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Croatian public holidays #45

Merged
merged 4 commits into from
Jan 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions src/Countries/Croatia.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

namespace Spatie\Holidays\Countries;

use Carbon\CarbonImmutable;

class Croatia extends Country
{
public function countryCode(): string
{
return 'hr';
}

/** @return array<string, CarbonImmutable|string> */
protected function allHolidays(int $year): array
{
return array_merge([
'Nova godina' => '01-01',
'Bogojavljenje' => '01-06',
'Praznik rada' => '05-01',
'Dan državnosti' => '05-30',
'Dan antifašističke borbe' => '06-22',
'Dan pobjede i domovinske zahvalnosti i Dan hrvatskih branitelja' => '08-05',
'Velika Gospa' => '08-15',
'Svi sveti' => '11-01',
'Dan sjećanja na žrtve Domovinskog rata i Dan sjećanja na žrtvu Vukovara i Škabrnje' => '11-18',
'Božić' => '12-25',
'Sveti Stjepan' => '12-26',
], $this->variableHolidays($year));
}

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

return [
'Uskrsni ponedjeljak' => $easter->addDay(),
'Tijelovo' => $easter->addDays(60),
];
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
[
{
"name": "Nova godina",
"date": "2024-01-01"
},
{
"name": "Bogojavljenje",
"date": "2024-01-06"
},
{
"name": "Uskrsni ponedjeljak",
"date": "2024-04-01"
},
{
"name": "Praznik rada",
"date": "2024-05-01"
},
{
"name": "Tijelovo",
"date": "2024-05-30"
},
{
"name": "Dan dr\u017eavnosti",
"date": "2024-05-30"
},
{
"name": "Dan antifa\u0161isti\u010dke borbe",
"date": "2024-06-22"
},
{
"name": "Dan pobjede i domovinske zahvalnosti i Dan hrvatskih branitelja",
"date": "2024-08-05"
},
{
"name": "Velika Gospa",
"date": "2024-08-15"
},
{
"name": "Svi sveti",
"date": "2024-11-01"
},
{
"name": "Dan sje\u0107anja na \u017ertve Domovinskog rata i Dan sje\u0107anja na \u017ertvu Vukovara i \u0160kabrnje",
"date": "2024-11-18"
},
{
"name": "Bo\u017ei\u0107",
"date": "2024-12-25"
},
{
"name": "Sveti Stjepan",
"date": "2024-12-26"
}
]
18 changes: 18 additions & 0 deletions tests/Countries/CroatiaTest.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 croatian holidays', function () {
CarbonImmutable::setTestNowAndTimezone('2024-01-01');

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

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

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