generated from spatie/package-skeleton-php
-
-
Notifications
You must be signed in to change notification settings - Fork 196
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from xHeaven/feature/hungarian-holidays
Add Hungary to the supported countries
- Loading branch information
Showing
4 changed files
with
122 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<?php | ||
|
||
namespace Spatie\Holidays\Countries; | ||
|
||
use Carbon\CarbonImmutable; | ||
|
||
class Hungary extends Country | ||
{ | ||
public function countryCode(): string | ||
{ | ||
return 'hu'; | ||
} | ||
|
||
public function get(int $year): array | ||
{ | ||
$this->ensureYearCanBeCalculated($year); | ||
|
||
$fixedHolidays = $this->fixedHolidays($year); | ||
$variableHolidays = $this->variableHolidays($year); | ||
|
||
return array_merge($fixedHolidays, $variableHolidays); | ||
} | ||
|
||
/** @return array<string, CarbonImmutable> */ | ||
protected function fixedHolidays(int $year): array | ||
{ | ||
$dates = [ | ||
'Újév' => '01-01', | ||
'1848-as forradalom évfordulója' => '15-03', | ||
'A munka ünnepe' => '01-05', | ||
'Államalapítás ünnepe' => '20-08', | ||
'1956-os forradalom évfordulója' => '23-10', | ||
'Mindenszentek' => '01-11', | ||
'Karácsony' => '25-12', | ||
'Karácsony másnapja' => '26-12', | ||
]; | ||
|
||
foreach ($dates as $name => $date) { | ||
$dates[$name] = CarbonImmutable::createFromFormat('d-m-Y', "{$date}-{$year}"); | ||
} | ||
|
||
return $dates; | ||
} | ||
|
||
/** @return array<string, CarbonImmutable> */ | ||
protected function variableHolidays(int $year): array | ||
{ | ||
$easter = CarbonImmutable::createFromTimestamp(easter_date($year)) | ||
->setTimezone('Europe/Brussels'); | ||
|
||
return [ | ||
'Nagypéntek' => $easter->subDays(2), | ||
'Húsvéthétfő' => $easter->addDay(), | ||
'Pünkösdhétfő' => $easter->addDays(50), | ||
]; | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
tests/.pest/snapshots/Countries/HungaryTest/it_can_calculate_hungarian_holidays.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
[ | ||
{ | ||
"name": "\u00daj\u00e9v", | ||
"date": "01-01-2024" | ||
}, | ||
{ | ||
"name": "1848-as forradalom \u00e9vfordul\u00f3ja", | ||
"date": "15-03-2024" | ||
}, | ||
{ | ||
"name": "Nagyp\u00e9ntek", | ||
"date": "29-03-2024" | ||
}, | ||
{ | ||
"name": "H\u00fasv\u00e9th\u00e9tf\u0151", | ||
"date": "01-04-2024" | ||
}, | ||
{ | ||
"name": "A munka \u00fcnnepe", | ||
"date": "01-05-2024" | ||
}, | ||
{ | ||
"name": "P\u00fcnk\u00f6sdh\u00e9tf\u0151", | ||
"date": "20-05-2024" | ||
}, | ||
{ | ||
"name": "\u00c1llamalap\u00edt\u00e1s \u00fcnnepe", | ||
"date": "20-08-2024" | ||
}, | ||
{ | ||
"name": "1956-os forradalom \u00e9vfordul\u00f3ja", | ||
"date": "23-10-2024" | ||
}, | ||
{ | ||
"name": "Mindenszentek", | ||
"date": "01-11-2024" | ||
}, | ||
{ | ||
"name": "Kar\u00e1csony", | ||
"date": "25-12-2024" | ||
}, | ||
{ | ||
"name": "Kar\u00e1csony m\u00e1snapja", | ||
"date": "26-12-2024" | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?php | ||
|
||
namespace Spatie\Holidays\Tests\Countries; | ||
|
||
use Carbon\CarbonImmutable; | ||
use Spatie\Holidays\Holidays; | ||
|
||
it('can calculate hungarian holidays', function () { | ||
CarbonImmutable::setTestNowAndTimezone('2024-01-01'); | ||
|
||
$holidays = Holidays::get(country: 'hu'); | ||
|
||
expect($holidays)->toMatchSnapshot(); | ||
}); |