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 Czech holidays #22

Merged
merged 3 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
42 changes: 42 additions & 0 deletions src/Countries/Czechia.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

namespace Spatie\Holidays\Countries;

use Carbon\CarbonImmutable;

class Czechia extends Country
{
public function countryCode(): string
{
return 'cz';
}

protected function allHolidays(int $year): array
{
return array_merge([
'Den obnovy samostatného českého státu' => '01-01',
'Svátek práce' => '05-01',
'Den vítězství' => '05-08',
'Den slovanských věrozvěstů Cyrila a Metoděje' => '07-05',
'Den upálení mistra Jana Husa' => '07-06',
'Den české státnosti' => '09-28',
'Den vzniku samostatného československého státu' => '10-28',
'Den boje za svobodu a demokracii a Mezinárodní den studentstva' => '11-17',
'Štědrý den' => '12-24',
'1. svátek vánoční' => '12-25',
'2. svátek vánoční' => '12-26',
], $this->variableHolidays($year));
}

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

return [
'Velikonoční pondělí' => $easter->addDay(),
'Velký pátek' => $easter->subDays(2),
];
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
[
{
"name": "Den obnovy samostatn\u00e9ho \u010desk\u00e9ho st\u00e1tu",
"date": "2024-01-01"
},
{
"name": "Velk\u00fd p\u00e1tek",
"date": "2024-03-29"
},
{
"name": "Velikono\u010dn\u00ed pond\u011bl\u00ed",
"date": "2024-04-01"
},
{
"name": "Sv\u00e1tek pr\u00e1ce",
"date": "2024-05-01"
},
{
"name": "Den v\u00edt\u011bzstv\u00ed",
"date": "2024-05-08"
},
{
"name": "Den slovansk\u00fdch v\u011brozv\u011bst\u016f Cyrila a Metod\u011bje",
"date": "2024-07-05"
},
{
"name": "Den up\u00e1len\u00ed mistra Jana Husa",
"date": "2024-07-06"
},
{
"name": "Den \u010desk\u00e9 st\u00e1tnosti",
"date": "2024-09-28"
},
{
"name": "Den vzniku samostatn\u00e9ho \u010deskoslovensk\u00e9ho st\u00e1tu",
"date": "2024-10-28"
},
{
"name": "Den boje za svobodu a demokracii a Mezin\u00e1rodn\u00ed den studentstva",
"date": "2024-11-17"
},
{
"name": "\u0160t\u011bdr\u00fd den",
"date": "2024-12-24"
},
{
"name": "1. sv\u00e1tek v\u00e1no\u010dn\u00ed",
"date": "2024-12-25"
},
{
"name": "2. sv\u00e1tek v\u00e1no\u010dn\u00ed",
"date": "2024-12-26"
}
]
18 changes: 18 additions & 0 deletions tests/Countries/CzechiaTest.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 czech holidays', function () {
CarbonImmutable::setTestNowAndTimezone('2024-01-01');

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

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

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