From 02c180cf96d03be8d906b087bab467561b42d019 Mon Sep 17 00:00:00 2001 From: object505 Date: Fri, 19 Jan 2024 07:02:20 +0100 Subject: [PATCH 1/2] Add Macedonian holidays --- src/Countries/NorthMacedonia.php | 48 +++++++++++++++++++ .../it_can_calculate_macedonian_holidays.snap | 42 ++++++++++++++++ tests/Countries/NorthMacedoniaTest.php | 18 +++++++ 3 files changed, 108 insertions(+) create mode 100644 src/Countries/NorthMacedonia.php create mode 100644 tests/.pest/snapshots/Countries/NorthMacedoniaTest/it_can_calculate_macedonian_holidays.snap create mode 100644 tests/Countries/NorthMacedoniaTest.php diff --git a/src/Countries/NorthMacedonia.php b/src/Countries/NorthMacedonia.php new file mode 100644 index 000000000..0ab6f07a1 --- /dev/null +++ b/src/Countries/NorthMacedonia.php @@ -0,0 +1,48 @@ + '01-01', + 'Божик, првиот ден на Божик според православниот календар' => '01-07', + 'Ден на трудот' => '05-01', + 'Св. Кирил и Методиј - Ден на сесловенските просветители' => '05-24', + 'Ден на Републиката' => '08-02', + 'Ден на независноста' => '09-08', + 'Ден на народното востание' => '10-11', + 'Ден на македонската револуционерна борба' => '10-23', + 'Св. Климент Охридски' => '12-08', + ], $this->variableHolidays($year)); + } + + /** @return array */ + protected function variableHolidays(int $year): array + { + $easter = CarbonImmutable::createFromTimestamp($this->ortodoxEaster($year)) + ->setTimezone('Europe/Skopje'); + + return [ + 'Велигден, вториот ден на Велигден според православниот календар' => $easter->addDay(), + ]; + } + + protected function ortodoxEaster(int $year) + { + $timestamp = easter_date($year, CAL_EASTER_ALWAYS_JULIAN); + $daysDifference = (int)($year / 100) - (int)($year / 400) - 2; + + return strtotime("+$daysDifference days", $timestamp); + } +} diff --git a/tests/.pest/snapshots/Countries/NorthMacedoniaTest/it_can_calculate_macedonian_holidays.snap b/tests/.pest/snapshots/Countries/NorthMacedoniaTest/it_can_calculate_macedonian_holidays.snap new file mode 100644 index 000000000..dfc694191 --- /dev/null +++ b/tests/.pest/snapshots/Countries/NorthMacedoniaTest/it_can_calculate_macedonian_holidays.snap @@ -0,0 +1,42 @@ +[ + { + "name": "\u041d\u043e\u0432\u0430 \u0433\u043e\u0434\u0438\u043d\u0430", + "date": "2024-01-01" + }, + { + "name": "\u0411\u043e\u0436\u0438\u043a, \u043f\u0440\u0432\u0438\u043e\u0442 \u0434\u0435\u043d \u043d\u0430 \u0411\u043e\u0436\u0438\u043a \u0441\u043f\u043e\u0440\u0435\u0434 \u043f\u0440\u0430\u0432\u043e\u0441\u043b\u0430\u0432\u043d\u0438\u043e\u0442 \u043a\u0430\u043b\u0435\u043d\u0434\u0430\u0440", + "date": "2024-01-07" + }, + { + "name": "\u0414\u0435\u043d \u043d\u0430 \u0442\u0440\u0443\u0434\u043e\u0442", + "date": "2024-05-01" + }, + { + "name": "\u0412\u0435\u043b\u0438\u0433\u0434\u0435\u043d, \u0432\u0442\u043e\u0440\u0438\u043e\u0442 \u0434\u0435\u043d \u043d\u0430 \u0412\u0435\u043b\u0438\u0433\u0434\u0435\u043d \u0441\u043f\u043e\u0440\u0435\u0434 \u043f\u0440\u0430\u0432\u043e\u0441\u043b\u0430\u0432\u043d\u0438\u043e\u0442 \u043a\u0430\u043b\u0435\u043d\u0434\u0430\u0440", + "date": "2024-05-06" + }, + { + "name": "\u0421\u0432. \u041a\u0438\u0440\u0438\u043b \u0438 \u041c\u0435\u0442\u043e\u0434\u0438\u0458 - \u0414\u0435\u043d \u043d\u0430 \u0441\u0435\u0441\u043b\u043e\u0432\u0435\u043d\u0441\u043a\u0438\u0442\u0435 \u043f\u0440\u043e\u0441\u0432\u0435\u0442\u0438\u0442\u0435\u043b\u0438", + "date": "2024-05-24" + }, + { + "name": "\u0414\u0435\u043d \u043d\u0430 \u0420\u0435\u043f\u0443\u0431\u043b\u0438\u043a\u0430\u0442\u0430", + "date": "2024-08-02" + }, + { + "name": "\u0414\u0435\u043d \u043d\u0430 \u043d\u0435\u0437\u0430\u0432\u0438\u0441\u043d\u043e\u0441\u0442\u0430", + "date": "2024-09-08" + }, + { + "name": "\u0414\u0435\u043d \u043d\u0430 \u043d\u0430\u0440\u043e\u0434\u043d\u043e\u0442\u043e \u0432\u043e\u0441\u0442\u0430\u043d\u0438\u0435", + "date": "2024-10-11" + }, + { + "name": "\u0414\u0435\u043d \u043d\u0430 \u043c\u0430\u043a\u0435\u0434\u043e\u043d\u0441\u043a\u0430\u0442\u0430 \u0440\u0435\u0432\u043e\u043b\u0443\u0446\u0438\u043e\u043d\u0435\u0440\u043d\u0430 \u0431\u043e\u0440\u0431\u0430", + "date": "2024-10-23" + }, + { + "name": "\u0421\u0432. \u041a\u043b\u0438\u043c\u0435\u043d\u0442 \u041e\u0445\u0440\u0438\u0434\u0441\u043a\u0438", + "date": "2024-12-08" + } +] \ No newline at end of file diff --git a/tests/Countries/NorthMacedoniaTest.php b/tests/Countries/NorthMacedoniaTest.php new file mode 100644 index 000000000..b68507ff4 --- /dev/null +++ b/tests/Countries/NorthMacedoniaTest.php @@ -0,0 +1,18 @@ +get(); + + expect($holidays) + ->toBeArray() + ->not()->toBeEmpty(); + + expect(formatDates($holidays))->toMatchSnapshot(); +}); From b56fa3f616c0d807f9226d160ba08bd12abb4927 Mon Sep 17 00:00:00 2001 From: object505 Date: Fri, 19 Jan 2024 13:43:10 +0100 Subject: [PATCH 2/2] Added return type --- src/Countries/NorthMacedonia.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Countries/NorthMacedonia.php b/src/Countries/NorthMacedonia.php index 0ab6f07a1..81da2e27c 100644 --- a/src/Countries/NorthMacedonia.php +++ b/src/Countries/NorthMacedonia.php @@ -38,7 +38,7 @@ protected function variableHolidays(int $year): array ]; } - protected function ortodoxEaster(int $year) + protected function ortodoxEaster(int $year): bool|int { $timestamp = easter_date($year, CAL_EASTER_ALWAYS_JULIAN); $daysDifference = (int)($year / 100) - (int)($year / 400) - 2;