From 55f455f3df289c3b35295fe1bfd508e924f570e0 Mon Sep 17 00:00:00 2001 From: Florin Pavel Date: Tue, 23 Jan 2024 14:46:21 +0200 Subject: [PATCH] Add Romanian Holidays (#27) * add romanian holidays * add Epiphany and Saint John public holidays * fix static analysis * Fix styling * add formula to calculate the difference between Julian and Gregorian calendars * Fix styling * add the source of the orthodox easter algorithm * Fix styling * fix phpstan * remove orthodoxEaster function from Romania class --- src/Countries/Romania.php | 60 ++++++++++++++++ .../it_can_calculate_romanian_holidays.snap | 70 +++++++++++++++++++ tests/Countries/RomaniaTest.php | 19 +++++ 3 files changed, 149 insertions(+) create mode 100644 src/Countries/Romania.php create mode 100644 tests/.pest/snapshots/Countries/RomaniaTest/it_can_calculate_romanian_holidays.snap create mode 100644 tests/Countries/RomaniaTest.php diff --git a/src/Countries/Romania.php b/src/Countries/Romania.php new file mode 100644 index 000000000..c9e1775b4 --- /dev/null +++ b/src/Countries/Romania.php @@ -0,0 +1,60 @@ + */ + protected function allHolidays(int $year): array + { + return array_merge([ + 'Anul Nou' => '01-01', + 'A doua zi de Anul Nou' => '01-02', + 'Bobotează' => '01-06', + 'Sfântul Ion' => '01-07', + 'Ziua Unirii Principatelor Române' => '01-24', + 'Ziua Muncii' => '05-01', + 'Ziua Copilului' => '06-01', + 'Adormirea Maicii Domnului' => '08-15', + 'Sfântul Andrei' => '11-30', + 'Ziua Națională' => '12-01', + 'Crăciunul' => '12-25', + 'A doua zi de Crăciun' => '12-26', + ], $this->variableHolidays($year)); + } + + /** + * @return array + */ + protected function variableHolidays(int $year): array + { + $easter = $this->orthodoxEaster($year); + $easterMonday = $easter->addDay(); + $goodFriday = $easter->subDays(2); + + $pentecost = $this->orthodoxPentecost($year); + $pentecostMonday = $pentecost->addDay(); + + return [ + 'Vinerea Mare' => $goodFriday, + 'Paștele' => $easter, + 'A doua zi de Paște' => $easterMonday, + 'Rusaliile' => $pentecost, + 'A doua zi de Rusalii' => $pentecostMonday, + ]; + } + + protected function orthodoxPentecost(int $year): CarbonImmutable + { + $easter = $this->orthodoxEaster($year); + + return $easter->addDays(49); + } +} diff --git a/tests/.pest/snapshots/Countries/RomaniaTest/it_can_calculate_romanian_holidays.snap b/tests/.pest/snapshots/Countries/RomaniaTest/it_can_calculate_romanian_holidays.snap new file mode 100644 index 000000000..0c4fe65ec --- /dev/null +++ b/tests/.pest/snapshots/Countries/RomaniaTest/it_can_calculate_romanian_holidays.snap @@ -0,0 +1,70 @@ +[ + { + "name": "Anul Nou", + "date": "2024-01-01" + }, + { + "name": "A doua zi de Anul Nou", + "date": "2024-01-02" + }, + { + "name": "Boboteaz\u0103", + "date": "2024-01-06" + }, + { + "name": "Sf\u00e2ntul Ion", + "date": "2024-01-07" + }, + { + "name": "Ziua Unirii Principatelor Rom\u00e2ne", + "date": "2024-01-24" + }, + { + "name": "Ziua Muncii", + "date": "2024-05-01" + }, + { + "name": "Vinerea Mare", + "date": "2024-05-03" + }, + { + "name": "Pa\u0219tele", + "date": "2024-05-05" + }, + { + "name": "A doua zi de Pa\u0219te", + "date": "2024-05-06" + }, + { + "name": "Ziua Copilului", + "date": "2024-06-01" + }, + { + "name": "Rusaliile", + "date": "2024-06-23" + }, + { + "name": "A doua zi de Rusalii", + "date": "2024-06-24" + }, + { + "name": "Adormirea Maicii Domnului", + "date": "2024-08-15" + }, + { + "name": "Sf\u00e2ntul Andrei", + "date": "2024-11-30" + }, + { + "name": "Ziua Na\u021bional\u0103", + "date": "2024-12-01" + }, + { + "name": "Cr\u0103ciunul", + "date": "2024-12-25" + }, + { + "name": "A doua zi de Cr\u0103ciun", + "date": "2024-12-26" + } +] \ No newline at end of file diff --git a/tests/Countries/RomaniaTest.php b/tests/Countries/RomaniaTest.php new file mode 100644 index 000000000..80c177a98 --- /dev/null +++ b/tests/Countries/RomaniaTest.php @@ -0,0 +1,19 @@ +get(); + + expect($holidays) + ->toBeArray() + ->not()->toBeEmpty(); + + expect(formatDates($holidays))->toMatchSnapshot(); + +});