From 872e6d15d9f3795031e93b70c6a473f2d78fbc4d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Frano=20Bara=C4=87?= Date: Fri, 19 Jan 2024 16:19:42 +0100 Subject: [PATCH] Add support for Croatian public holidays (#45) * adds croatian holidays * stan fixes * fixed allHolidays return type --- src/Countries/Croatia.php | 43 +++++++++++++++ .../it_can_calculate_croatian_holidays.snap | 54 +++++++++++++++++++ tests/Countries/CroatiaTest.php | 18 +++++++ 3 files changed, 115 insertions(+) create mode 100644 src/Countries/Croatia.php create mode 100644 tests/.pest/snapshots/Countries/CroatiaTest/it_can_calculate_croatian_holidays.snap create mode 100644 tests/Countries/CroatiaTest.php diff --git a/src/Countries/Croatia.php b/src/Countries/Croatia.php new file mode 100644 index 000000000..d95906f74 --- /dev/null +++ b/src/Countries/Croatia.php @@ -0,0 +1,43 @@ + */ + 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 */ + protected function variableHolidays(int $year): array + { + $easter = CarbonImmutable::createFromTimestamp(easter_date($year)) + ->setTimezone('Europe/Zagreb'); + + return [ + 'Uskrsni ponedjeljak' => $easter->addDay(), + 'Tijelovo' => $easter->addDays(60), + ]; + } +} diff --git a/tests/.pest/snapshots/Countries/CroatiaTest/it_can_calculate_croatian_holidays.snap b/tests/.pest/snapshots/Countries/CroatiaTest/it_can_calculate_croatian_holidays.snap new file mode 100644 index 000000000..821ad7073 --- /dev/null +++ b/tests/.pest/snapshots/Countries/CroatiaTest/it_can_calculate_croatian_holidays.snap @@ -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" + } +] \ No newline at end of file diff --git a/tests/Countries/CroatiaTest.php b/tests/Countries/CroatiaTest.php new file mode 100644 index 000000000..a78f5258a --- /dev/null +++ b/tests/Countries/CroatiaTest.php @@ -0,0 +1,18 @@ +get(); + + expect($holidays) + ->toBeArray() + ->not()->toBeEmpty(); + + expect(formatDates($holidays))->toMatchSnapshot(); +});