From 5b2fab2b575c608f5981541ad5ee73058703a516 Mon Sep 17 00:00:00 2001 From: Mark <14284867+xHeaven@users.noreply.github.com> Date: Wed, 17 Jan 2024 01:10:18 +0100 Subject: [PATCH 1/3] add Hungary --- src/Countries/Hungary.php | 57 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 src/Countries/Hungary.php diff --git a/src/Countries/Hungary.php b/src/Countries/Hungary.php new file mode 100644 index 000000000..0e3a1e0c1 --- /dev/null +++ b/src/Countries/Hungary.php @@ -0,0 +1,57 @@ +ensureYearCanBeCalculated($year); + + $fixedHolidays = $this->fixedHolidays($year); + $variableHolidays = $this->variableHolidays($year); + + return array_merge($fixedHolidays, $variableHolidays); + } + + /** @return array */ + 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 */ + 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), + ]; + } +} From 7f2966022b300786bce534ffa96e9f64107c311d Mon Sep 17 00:00:00 2001 From: Mark <14284867+xHeaven@users.noreply.github.com> Date: Wed, 17 Jan 2024 01:11:21 +0100 Subject: [PATCH 2/3] ignore phpstan error for return type --- phpstan-baseline.neon | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 6f8db1cb8..c3d855827 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -34,3 +34,8 @@ parameters: message: "#^Call to an undefined method Pest\\\\PendingCalls\\\\TestCall\\:\\:expect\\(\\)\\.$#" count: 1 path: tests/ArchTest.php + + - + message: "#^Method Spatie\\\\Holidays\\\\Countries\\\\Hungary\\:\\:fixedHolidays\\(\\) should return array\\ but returns array\\\\.$#" + count: 1 + path: src/Countries/Hungary.php From 9bb575fdba14f219cc0fb3adf6648a0bf1ba45c1 Mon Sep 17 00:00:00 2001 From: Mark <14284867+xHeaven@users.noreply.github.com> Date: Wed, 17 Jan 2024 01:11:34 +0100 Subject: [PATCH 3/3] add tests for Hungary --- .../it_can_calculate_hungarian_holidays.snap | 46 +++++++++++++++++++ tests/Countries/HungaryTest.php | 14 ++++++ 2 files changed, 60 insertions(+) create mode 100644 tests/.pest/snapshots/Countries/HungaryTest/it_can_calculate_hungarian_holidays.snap create mode 100644 tests/Countries/HungaryTest.php diff --git a/tests/.pest/snapshots/Countries/HungaryTest/it_can_calculate_hungarian_holidays.snap b/tests/.pest/snapshots/Countries/HungaryTest/it_can_calculate_hungarian_holidays.snap new file mode 100644 index 000000000..7422316e9 --- /dev/null +++ b/tests/.pest/snapshots/Countries/HungaryTest/it_can_calculate_hungarian_holidays.snap @@ -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" + } +] \ No newline at end of file diff --git a/tests/Countries/HungaryTest.php b/tests/Countries/HungaryTest.php new file mode 100644 index 000000000..f1fa0079e --- /dev/null +++ b/tests/Countries/HungaryTest.php @@ -0,0 +1,14 @@ +toMatchSnapshot(); +});