diff --git a/lang/bosniaAndHerzegovina/en/holidays.json b/lang/bosniaAndHerzegovina/en/holidays.json new file mode 100644 index 000000000..ffab7f1a2 --- /dev/null +++ b/lang/bosniaAndHerzegovina/en/holidays.json @@ -0,0 +1,25 @@ +{ + "Nova godina - prvi dan": "New Year - first day", + "Nova godina - drugi dan": "New Year - second day", + "Badnji dan (za pravoslavce)": "Christmas Eve (Orthodox)", + "Božić (za pravoslavce)": "Christmas (Orthodox)", + "Badnji dan (za rimokatolike)": "Christmas Eve (Catholic)", + "Božić (za rimokatolike)": "Christmas (Catholic)", + "Praznik rada - prvi dan": "Labour Day - first day", + "Praznik rada - drugi dan": "Labour Day - second day", + "Veliki petak (za pravoslavce)": "Good Friday (Orthodox)", + "Veliki petak (za rimokatolike)": "Good Friday (Catholic)", + "Vaskrs (za pravoslavce)": "Easter (Orthodox)", + "Vaskrs (za rimokatolike)": "Easter (Catholic)", + "Vaskršnji ponedjeljak (za pravoslavce)": "Easter Monday (Orthodox)", + "Vaskršnji ponedjeljak (za rimokatolike)": "Easter Monday (Catholic)", + + "Dan Republike": "Republic Day", + "Dan pobjede nad fašizmom": "The day of victory over fascism", + "Dan uspostavljanja Opšteg okvirnog sporazuma za mir u BiH": "The day of establishment of the General Framework Agreement for Peace in Bosnia and Herzegovina", + + "Dan nezavisnosti Bosne i Hercegovine": "Independence Day of Bosnia And Herzegovina", + "Dan državnosti Bosne i Hercegovine": "National Day of Bosnia And Herzegovina", + + "Dan uspostavljanja Brčko distrikta": "Day of establishment of Brčko District" +} diff --git a/src/Countries/BosniaAndHerzegovina.php b/src/Countries/BosniaAndHerzegovina.php new file mode 100644 index 000000000..0e28ac74a --- /dev/null +++ b/src/Countries/BosniaAndHerzegovina.php @@ -0,0 +1,87 @@ + '01-01', + 'Nova godina - drugi dan' => '01-02', + 'Badnji dan (za pravoslavce)' => '01-06', + 'Božić (za pravoslavce)' => '01-07', + 'Praznik rada - prvi dan' => '05-01', + 'Praznik rada - drugi dan' => '05-02', + 'Badnji dan (za rimokatolike)' => '12-24', + 'Božić (za rimokatolike)' => '12-25', + ], $this->regionHolidays()); + } + + /** @return array */ + protected function regionHolidays(): array + { + return match ($this->region) { + 'ba-rs' => [ + 'Dan Republike' => '01-09', + 'Dan pobjede nad fašizmom' => '05-09', + 'Dan uspostavljanja Opšteg okvirnog sporazuma za mir u BiH' => '11-21', + ], + 'ba-fbih' => [ + 'Dan nezavisnosti Bosne i Hercegovine' => '03-01', + 'Dan državnosti Bosne i Hercegovine' => '11-25', + ], + 'ba-bd' => [ + 'Dan uspostavljanja Brčko distrikta' => '03-08', + ], + default => [], + }; + } + + /** @return array */ + public function variableHolidays(int $year): array + { + $orthodoxEaster = $this->orthodoxEaster($year); + $orthodoxGoodFriday = $orthodoxEaster->copy()->subDays(2); + $orthodoxEasterMonday = $orthodoxEaster->copy()->addDay(); + + $easter = $this->easter($year); + $goodFriday = $easter->copy()->subDays(2); + $easterMonday = $easter->copy()->addDay(); + + // TODO: Implement islamic holidays + + return [ + // Orthodox holidays + 'Vaskrs (za pravoslavce)' => $orthodoxEaster, + 'Vaskršnji ponedjeljak (za pravoslavce)' => $orthodoxEasterMonday, + 'Veliki petak (za pravoslavce)' => $orthodoxGoodFriday, + + // Catholic holidays + 'Vaskrs (za rimokatolike)' => $easter, + 'Vaskršnji ponedjeljak (za rimokatolike)' => $easterMonday, + 'Veliki petak (za rimokatolike)' => $goodFriday, + ]; + } +} diff --git a/tests/.pest/snapshots/Countries/BosniaAndHerzegovinaTest/it_can_calculate__bosnia_and_herzegovina_holidays.snap b/tests/.pest/snapshots/Countries/BosniaAndHerzegovinaTest/it_can_calculate__bosnia_and_herzegovina_holidays.snap new file mode 100644 index 000000000..c0cde7eb9 --- /dev/null +++ b/tests/.pest/snapshots/Countries/BosniaAndHerzegovinaTest/it_can_calculate__bosnia_and_herzegovina_holidays.snap @@ -0,0 +1,34 @@ +[ + { + "name": "Nova godina - prvi dan", + "date": "2024-01-01" + }, + { + "name": "Nova godina - drugi dan", + "date": "2024-01-02" + }, + { + "name": "Badnji dan (za pravoslavce)", + "date": "2024-01-06" + }, + { + "name": "Bo\u017ei\u0107 (za pravoslavce)", + "date": "2024-01-07" + }, + { + "name": "Praznik rada - prvi dan", + "date": "2024-05-01" + }, + { + "name": "Praznik rada - drugi dan", + "date": "2024-05-02" + }, + { + "name": "Badnji dan (za rimokatolike)", + "date": "2024-12-24" + }, + { + "name": "Bo\u017ei\u0107 (za rimokatolike)", + "date": "2024-12-25" + } +] \ No newline at end of file diff --git a/tests/.pest/snapshots/Countries/BosniaAndHerzegovinaTest/it_can_calculate_bosnia_and_herzegovina_holidays.snap b/tests/.pest/snapshots/Countries/BosniaAndHerzegovinaTest/it_can_calculate_bosnia_and_herzegovina_holidays.snap new file mode 100644 index 000000000..c0cde7eb9 --- /dev/null +++ b/tests/.pest/snapshots/Countries/BosniaAndHerzegovinaTest/it_can_calculate_bosnia_and_herzegovina_holidays.snap @@ -0,0 +1,34 @@ +[ + { + "name": "Nova godina - prvi dan", + "date": "2024-01-01" + }, + { + "name": "Nova godina - drugi dan", + "date": "2024-01-02" + }, + { + "name": "Badnji dan (za pravoslavce)", + "date": "2024-01-06" + }, + { + "name": "Bo\u017ei\u0107 (za pravoslavce)", + "date": "2024-01-07" + }, + { + "name": "Praznik rada - prvi dan", + "date": "2024-05-01" + }, + { + "name": "Praznik rada - drugi dan", + "date": "2024-05-02" + }, + { + "name": "Badnji dan (za rimokatolike)", + "date": "2024-12-24" + }, + { + "name": "Bo\u017ei\u0107 (za rimokatolike)", + "date": "2024-12-25" + } +] \ No newline at end of file diff --git a/tests/.pest/snapshots/Countries/BosniaAndHerzegovinaTest/it_can_translate_holidays_into_english.snap b/tests/.pest/snapshots/Countries/BosniaAndHerzegovinaTest/it_can_translate_holidays_into_english.snap new file mode 100644 index 000000000..405943f03 --- /dev/null +++ b/tests/.pest/snapshots/Countries/BosniaAndHerzegovinaTest/it_can_translate_holidays_into_english.snap @@ -0,0 +1,34 @@ +[ + { + "name": "New Year - first day", + "date": "2024-01-01" + }, + { + "name": "New Year - second day", + "date": "2024-01-02" + }, + { + "name": "Christmas Eve (Orthodox)", + "date": "2024-01-06" + }, + { + "name": "Christmas (Orthodox)", + "date": "2024-01-07" + }, + { + "name": "Labour Day - first day", + "date": "2024-05-01" + }, + { + "name": "Labour Day - second day", + "date": "2024-05-02" + }, + { + "name": "Christmas Eve (Catholic)", + "date": "2024-12-24" + }, + { + "name": "Christmas (Catholic)", + "date": "2024-12-25" + } +] \ No newline at end of file diff --git a/tests/Countries/BosniaAndHerzegovinaTest.php b/tests/Countries/BosniaAndHerzegovinaTest.php new file mode 100644 index 000000000..9dcc2cf5d --- /dev/null +++ b/tests/Countries/BosniaAndHerzegovinaTest.php @@ -0,0 +1,47 @@ +get(); + + expect($holidays) + ->toBeArray() + ->not()->toBeEmpty(); + + expect(formatDates($holidays))->toMatchSnapshot(); +}); + +it('throws an error when an invalid region is given', function () { + new BosniaAndHerzegovina('ba-xy'); +})->throws(InvalidRegion::class); + +it('can calculate victory day for republic of srpska in bosnia and herzegovina holidays', function () { + CarbonImmutable::setTestNow('2024-01-01'); + + $victoryDay = Holidays::for(BosniaAndHerzegovina::make())->isHoliday('2024-01-09'); + expect($victoryDay)->toBeFalse(); + + $victoryDayForRepublicOfSprska = Holidays::for(BosniaAndHerzegovina::make('ba-rs'))->isHoliday('2024-01-09'); + expect($victoryDayForRepublicOfSprska)->toBeTrue(); +}); + +it('can translate holidays into english', function () { + $holidays = Holidays::for(country: 'ba', locale: 'en', year: 2024)->get(); + + expect($holidays) + ->toBeArray() + ->not() + ->toBeEmpty(); + + expect(formatDates($holidays))->toMatchSnapshot(); + + expect($holidays[0]['name'])->toBe('New Year - first day'); +});