From b41b7d1cf4fe52d33c51f108d4ba960895826b47 Mon Sep 17 00:00:00 2001 From: Simon Barrett Date: Thu, 25 Jan 2024 17:53:52 +0000 Subject: [PATCH 001/175] add wales, england, scotland and northern ireland (#162) --- src/Countries/England.php | 11 ++ src/Countries/NorthernIreland.php | 90 ++++++++++++ src/Countries/Scotland.php | 94 +++++++++++++ src/Countries/Wales.php | 133 ++++++++++++++++++ .../it_can_calculate_holidays_for_2020.snap | 34 +++++ .../it_can_calculate_welsh_holidays.snap | 34 +++++ ..._holidays_if_christmas_is_on_a_friday.snap | 34 +++++ ...olidays_if_christmas_is_on_a_saturday.snap | 34 +++++ ..._holidays_if_christmas_is_on_a_sunday.snap | 42 ++++++ ...y_if_new_years_day_falls_on_a_weekend.snap | 34 +++++ ...can_calculate_northern_irish_for_2020.snap | 34 +++++ ...can_calculate_northern_irish_holidays.snap | 42 ++++++ ..._holidays_if_christmas_is_on_a_friday.snap | 42 ++++++ ...olidays_if_christmas_is_on_a_saturday.snap | 42 ++++++ ..._holidays_if_christmas_is_on_a_sunday.snap | 50 +++++++ ...ry_if_new_years_day_falls_on_a_friday.snap | 42 ++++++ ...y_if_new_years_day_falls_on_a_weekend.snap | 42 ++++++ .../it_can_calculate_holidays_for_2020.snap | 34 +++++ .../it_can_calculate_scottish_holidays.snap | 38 +++++ ..._holidays_if_christmas_is_on_a_friday.snap | 38 +++++ ...olidays_if_christmas_is_on_a_saturday.snap | 38 +++++ ..._holidays_if_christmas_is_on_a_sunday.snap | 46 ++++++ ...ry_if_new_years_day_falls_on_a_friday.snap | 38 +++++ ...y_if_new_years_day_falls_on_a_weekend.snap | 38 +++++ .../it_can_calculate_holidays_for_2020.snap | 34 +++++ .../it_can_calculate_welsh_holidays.snap | 34 +++++ ..._holidays_if_christmas_is_on_a_friday.snap | 34 +++++ ...olidays_if_christmas_is_on_a_saturday.snap | 34 +++++ ..._holidays_if_christmas_is_on_a_sunday.snap | 42 ++++++ ...y_if_new_years_day_falls_on_a_weekend.snap | 34 +++++ tests/Countries/EnglandTest.php | 98 +++++++++++++ tests/Countries/NorthernIrelandTest.php | 111 +++++++++++++++ tests/Countries/ScotlandTest.php | 108 ++++++++++++++ tests/Countries/WalesTest.php | 117 +++++++++++++++ 34 files changed, 1750 insertions(+) create mode 100644 src/Countries/England.php create mode 100644 src/Countries/NorthernIreland.php create mode 100644 src/Countries/Scotland.php create mode 100644 src/Countries/Wales.php create mode 100644 tests/.pest/snapshots/Countries/EnglandTest/it_can_calculate_holidays_for_2020.snap create mode 100644 tests/.pest/snapshots/Countries/EnglandTest/it_can_calculate_welsh_holidays.snap create mode 100644 tests/.pest/snapshots/Countries/EnglandTest/it_can_calculate_welsh_holidays_if_christmas_is_on_a_friday.snap create mode 100644 tests/.pest/snapshots/Countries/EnglandTest/it_can_calculate_welsh_holidays_if_christmas_is_on_a_saturday.snap create mode 100644 tests/.pest/snapshots/Countries/EnglandTest/it_can_calculate_welsh_holidays_if_christmas_is_on_a_sunday.snap create mode 100644 tests/.pest/snapshots/Countries/EnglandTest/it_returns_a_substitute_day_if_new_years_day_falls_on_a_weekend.snap create mode 100644 tests/.pest/snapshots/Countries/NorthernIrelandTest/it_can_calculate_northern_irish_for_2020.snap create mode 100644 tests/.pest/snapshots/Countries/NorthernIrelandTest/it_can_calculate_northern_irish_holidays.snap create mode 100644 tests/.pest/snapshots/Countries/NorthernIrelandTest/it_can_calculate_northern_irish_holidays_if_christmas_is_on_a_friday.snap create mode 100644 tests/.pest/snapshots/Countries/NorthernIrelandTest/it_can_calculate_northern_irish_holidays_if_christmas_is_on_a_saturday.snap create mode 100644 tests/.pest/snapshots/Countries/NorthernIrelandTest/it_can_calculate_northern_irish_holidays_if_christmas_is_on_a_sunday.snap create mode 100644 tests/.pest/snapshots/Countries/NorthernIrelandTest/it_returns_a_substitute_day_for_second_of_january_if_new_years_day_falls_on_a_friday.snap create mode 100644 tests/.pest/snapshots/Countries/NorthernIrelandTest/it_returns_a_substitute_day_if_new_years_day_falls_on_a_weekend.snap create mode 100644 tests/.pest/snapshots/Countries/ScotlandTest/it_can_calculate_holidays_for_2020.snap create mode 100644 tests/.pest/snapshots/Countries/ScotlandTest/it_can_calculate_scottish_holidays.snap create mode 100644 tests/.pest/snapshots/Countries/ScotlandTest/it_can_calculate_scottish_holidays_if_christmas_is_on_a_friday.snap create mode 100644 tests/.pest/snapshots/Countries/ScotlandTest/it_can_calculate_scottish_holidays_if_christmas_is_on_a_saturday.snap create mode 100644 tests/.pest/snapshots/Countries/ScotlandTest/it_can_calculate_scottish_holidays_if_christmas_is_on_a_sunday.snap create mode 100644 tests/.pest/snapshots/Countries/ScotlandTest/it_returns_a_substitute_day_for_second_of_january_if_new_years_day_falls_on_a_friday.snap create mode 100644 tests/.pest/snapshots/Countries/ScotlandTest/it_returns_a_substitute_day_if_new_years_day_falls_on_a_weekend.snap create mode 100644 tests/.pest/snapshots/Countries/WalesTest/it_can_calculate_holidays_for_2020.snap create mode 100644 tests/.pest/snapshots/Countries/WalesTest/it_can_calculate_welsh_holidays.snap create mode 100644 tests/.pest/snapshots/Countries/WalesTest/it_can_calculate_welsh_holidays_if_christmas_is_on_a_friday.snap create mode 100644 tests/.pest/snapshots/Countries/WalesTest/it_can_calculate_welsh_holidays_if_christmas_is_on_a_saturday.snap create mode 100644 tests/.pest/snapshots/Countries/WalesTest/it_can_calculate_welsh_holidays_if_christmas_is_on_a_sunday.snap create mode 100644 tests/.pest/snapshots/Countries/WalesTest/it_returns_a_substitute_day_if_new_years_day_falls_on_a_weekend.snap create mode 100644 tests/Countries/EnglandTest.php create mode 100644 tests/Countries/NorthernIrelandTest.php create mode 100644 tests/Countries/ScotlandTest.php create mode 100644 tests/Countries/WalesTest.php diff --git a/src/Countries/England.php b/src/Countries/England.php new file mode 100644 index 000000000..efd62adba --- /dev/null +++ b/src/Countries/England.php @@ -0,0 +1,11 @@ + */ + private function stPatricksDay(int $year): array + { + $stPatricksDay = new CarbonImmutable($year . "-03-17", 'Europe/London'); + $key = 'St Patrick\'s Day'; + + if ($stPatricksDay->isWeekend()) { + $key .= ' (substitute day)'; + $stPatricksDay = $stPatricksDay->next('monday'); + } + + return [$key => $stPatricksDay]; + } + + /** @return array */ + private function battleOfTheBoyne(int $year): array + { + $battleOfTheBoyne = new CarbonImmutable($year . "-07-12", 'Europe/London'); + $key = 'Battle of the Boyne (Orangemen\'s Day)'; + + if ($battleOfTheBoyne->isWeekend()) { + $key .= ' (substitute day)'; + $battleOfTheBoyne = $battleOfTheBoyne->next('monday'); + } + + return [$key => $battleOfTheBoyne]; + } + + /** @return array */ + protected function oneOffHolidays(int $year): array + { + return match ($year) { + 2022 => [ + 'Platinum Jubilee bank holiday' => new CarbonImmutable("2022-06-03", 'Europe/London'), + 'Bank Holiday for the State Funeral of Queen Elizabeth II' => new CarbonImmutable("2022-09-19", 'Europe/London'), + ], + default => [], + }; + } + + /** @return array */ + protected function allHolidays(int $year): array + { + $regularHolidays = array_merge( + $this->newYearsDay($year), + $this->stPatricksDay($year), + $this->earlyMayBankHoliday($year), + $this->battleOfTheBoyne($year), + [ + 'Spring bank holiday' => new CarbonImmutable("last monday of may {$year}", 'Europe/London'), + 'Summer bank holiday' => new CarbonImmutable("last monday of august {$year}", 'Europe/London'), + ], + $this->christmasDay($year), + $this->boxingDay($year), + $this->variableHolidays($year) + ); + + $oneOffHolidays = $this->oneOffHolidays($year); + + return array_merge($regularHolidays, $oneOffHolidays); + + } + + /** @return array */ + protected function variableHolidays(int $year): array + { + $easterSunday = $this->easter($year); + + $goodFriday = $easterSunday->subDays(2); + $easterMonday = $easterSunday->addDay(); + + return [ + 'Good Friday' => $goodFriday, + 'Easter Monday' => $easterMonday, + ]; + } +} diff --git a/src/Countries/Scotland.php b/src/Countries/Scotland.php new file mode 100644 index 000000000..31f5aef8c --- /dev/null +++ b/src/Countries/Scotland.php @@ -0,0 +1,94 @@ + */ + protected function secondOfJanuary(int $year): array + { + $newYearsDay = new CarbonImmutable($year . "-01-01", 'Europe/London'); + $secondOfJanuary = new CarbonImmutable($year . "-01-02", 'Europe/London'); + $key = '2nd January'; + + if ($newYearsDay->isFriday()) { + $key .= ' (substitute day)'; + $secondOfJanuary = $secondOfJanuary->next('monday'); + } + + if ($newYearsDay->isWeekend()) { + $key .= ' (substitute day)'; + $secondOfJanuary = $secondOfJanuary->next('tuesday'); + } + + return [$key => $secondOfJanuary]; + } + + /** @return array */ + private function stAndrewsDay(int $year): array + { + $stAndrewsDay = new CarbonImmutable($year . "-11-30", 'Europe/London'); + $key = 'St Andrew\'s Day'; + + if ($stAndrewsDay->isWeekend()) { + $key .= ' (substitute day)'; + $stAndrewsDay = $stAndrewsDay->next('monday'); + } + + return [$key => $stAndrewsDay]; + } + + /** @return array */ + protected function oneOffHolidays(int $year): array + { + return match ($year) { + 2022 => [ + 'Platinum Jubilee bank holiday' => new CarbonImmutable("2022-06-03", 'Europe/London'), + 'Bank Holiday for the State Funeral of Queen Elizabeth II' => new CarbonImmutable("2022-09-19", 'Europe/London'), + ], + default => [], + }; + } + + /** @return array */ + protected function allHolidays(int $year): array + { + $regularHolidays = array_merge( + $this->newYearsDay($year), + $this->secondOfJanuary($year), + $this->earlyMayBankHoliday($year), + [ + 'Spring bank holiday' => new CarbonImmutable("last monday of may {$year}", 'Europe/London'), + 'Summer bank holiday' => new CarbonImmutable("first monday of august {$year}", 'Europe/London'), + ], + $this->stAndrewsDay($year), + $this->christmasDay($year), + $this->boxingDay($year), + $this->variableHolidays($year) + ); + + $oneOffHolidays = $this->oneOffHolidays($year); + + return array_merge($regularHolidays, $oneOffHolidays); + + } + + /** @return array */ + protected function variableHolidays(int $year): array + { + $easterSunday = $this->easter($year); + + $goodFriday = $easterSunday->subDays(2); + + return [ + 'Good Friday' => $goodFriday, + ]; + } +} diff --git a/src/Countries/Wales.php b/src/Countries/Wales.php new file mode 100644 index 000000000..0a05fd29d --- /dev/null +++ b/src/Countries/Wales.php @@ -0,0 +1,133 @@ + */ + protected function christmasDay(int $year): array + { + $christmasDay = new CarbonImmutable($year . "-12-25", 'Europe/London'); + $key = 'Christmas Day'; + + if ($christmasDay->isSaturday()) { + $key .= ' (substitute day)'; + $christmasDay = $christmasDay->next('monday'); + } + + if ($christmasDay->isSunday()) { + $key .= ' (substitute day)'; + $christmasDay = $christmasDay->next('tuesday'); + } + + return [$key => $christmasDay]; + } + + /** @return array */ + protected function boxingDay(int $year): array + { + $christmasDay = new CarbonImmutable($year . "-12-25", 'Europe/London'); + $boxingDay = new CarbonImmutable($year . "-12-26", 'Europe/London'); + $key = 'Boxing Day'; + + if ($christmasDay->isFriday()) { + $key .= ' (substitute day)'; + $boxingDay = $boxingDay->next('monday'); + } + + if ($christmasDay->isSaturday()) { + $key .= ' (substitute day)'; + $boxingDay = $boxingDay->next('tuesday'); + } + + return [$key => $boxingDay]; + } + + /** @return array */ + protected function newYearsDay(int $year): array + { + $newYearsDay = new CarbonImmutable($year . "-01-01", 'Europe/London'); + $key = 'New Year\'s Day'; + + if ($newYearsDay->isWeekend()) { + $key .= ' (substitute day)'; + $newYearsDay = $newYearsDay->next('monday'); + } + + return [$key => $newYearsDay]; + } + + /** @return array */ + protected function earlyMayBankHoliday(int $year): array + { + if ($year === 2020) { + return [ + 'Early May bank holiday (VE day)' => new CarbonImmutable("2020-05-08", 'Europe/London'), + ]; + } + + if ($year === 2023) { + return [ + 'Bank holiday for the coronation of King Charles III' => new CarbonImmutable("2020-05-08", 'Europe/London'), + ]; + } + + return ['Early May bank holiday' => new CarbonImmutable("first monday of may {$year}", 'Europe/London')]; + } + + /** + * @param int $year + * @return array|CarbonImmutable[] + */ + protected function oneOffHolidays(int $year): array + { + return match ($year) { + 2022 => [ + 'Platinum Jubilee bank holiday' => new CarbonImmutable("2022-06-03", 'Europe/London'), + 'Bank Holiday for the State Funeral of Queen Elizabeth II' => new CarbonImmutable("2022-09-19", 'Europe/London'), + ], + default => [], + }; + } + + /** @return array */ + protected function allHolidays(int $year): array + { + $regularHolidays = array_merge( + $this->newYearsDay($year), + $this->earlyMayBankHoliday($year), + [ + 'Spring bank holiday' => new CarbonImmutable("last monday of may {$year}", 'Europe/London'), + 'Summer bank holiday' => new CarbonImmutable("last monday of august {$year}", 'Europe/London'), + ], + $this->christmasDay($year), + $this->boxingDay($year), + $this->variableHolidays($year) + ); + + $oneOffHolidays = $this->oneOffHolidays($year); + + return array_merge($regularHolidays, $oneOffHolidays); + } + + /** @return array */ + protected function variableHolidays(int $year): array + { + $easterSunday = $this->easter($year); + + $goodFriday = $easterSunday->subDays(2); + $easterMonday = $easterSunday->addDay(); + + return [ + 'Good Friday' => $goodFriday, + 'Easter Monday' => $easterMonday, + ]; + } +} diff --git a/tests/.pest/snapshots/Countries/EnglandTest/it_can_calculate_holidays_for_2020.snap b/tests/.pest/snapshots/Countries/EnglandTest/it_can_calculate_holidays_for_2020.snap new file mode 100644 index 000000000..144a8c9fe --- /dev/null +++ b/tests/.pest/snapshots/Countries/EnglandTest/it_can_calculate_holidays_for_2020.snap @@ -0,0 +1,34 @@ +[ + { + "name": "New Year's Day", + "date": "2020-01-01" + }, + { + "name": "Good Friday", + "date": "2020-04-10" + }, + { + "name": "Easter Monday", + "date": "2020-04-13" + }, + { + "name": "Early May bank holiday (VE day)", + "date": "2020-05-08" + }, + { + "name": "Spring bank holiday", + "date": "2020-05-25" + }, + { + "name": "Summer bank holiday", + "date": "2020-08-31" + }, + { + "name": "Christmas Day", + "date": "2020-12-25" + }, + { + "name": "Boxing Day (substitute day)", + "date": "2020-12-28" + } +] \ No newline at end of file diff --git a/tests/.pest/snapshots/Countries/EnglandTest/it_can_calculate_welsh_holidays.snap b/tests/.pest/snapshots/Countries/EnglandTest/it_can_calculate_welsh_holidays.snap new file mode 100644 index 000000000..7a2079d12 --- /dev/null +++ b/tests/.pest/snapshots/Countries/EnglandTest/it_can_calculate_welsh_holidays.snap @@ -0,0 +1,34 @@ +[ + { + "name": "New Year's Day", + "date": "2024-01-01" + }, + { + "name": "Good Friday", + "date": "2024-03-29" + }, + { + "name": "Easter Monday", + "date": "2024-04-01" + }, + { + "name": "Early May bank holiday", + "date": "2024-05-06" + }, + { + "name": "Spring bank holiday", + "date": "2024-05-27" + }, + { + "name": "Summer bank holiday", + "date": "2024-08-26" + }, + { + "name": "Christmas Day", + "date": "2024-12-25" + }, + { + "name": "Boxing Day", + "date": "2024-12-26" + } +] \ No newline at end of file diff --git a/tests/.pest/snapshots/Countries/EnglandTest/it_can_calculate_welsh_holidays_if_christmas_is_on_a_friday.snap b/tests/.pest/snapshots/Countries/EnglandTest/it_can_calculate_welsh_holidays_if_christmas_is_on_a_friday.snap new file mode 100644 index 000000000..144a8c9fe --- /dev/null +++ b/tests/.pest/snapshots/Countries/EnglandTest/it_can_calculate_welsh_holidays_if_christmas_is_on_a_friday.snap @@ -0,0 +1,34 @@ +[ + { + "name": "New Year's Day", + "date": "2020-01-01" + }, + { + "name": "Good Friday", + "date": "2020-04-10" + }, + { + "name": "Easter Monday", + "date": "2020-04-13" + }, + { + "name": "Early May bank holiday (VE day)", + "date": "2020-05-08" + }, + { + "name": "Spring bank holiday", + "date": "2020-05-25" + }, + { + "name": "Summer bank holiday", + "date": "2020-08-31" + }, + { + "name": "Christmas Day", + "date": "2020-12-25" + }, + { + "name": "Boxing Day (substitute day)", + "date": "2020-12-28" + } +] \ No newline at end of file diff --git a/tests/.pest/snapshots/Countries/EnglandTest/it_can_calculate_welsh_holidays_if_christmas_is_on_a_saturday.snap b/tests/.pest/snapshots/Countries/EnglandTest/it_can_calculate_welsh_holidays_if_christmas_is_on_a_saturday.snap new file mode 100644 index 000000000..4757ed990 --- /dev/null +++ b/tests/.pest/snapshots/Countries/EnglandTest/it_can_calculate_welsh_holidays_if_christmas_is_on_a_saturday.snap @@ -0,0 +1,34 @@ +[ + { + "name": "New Year's Day", + "date": "2021-01-01" + }, + { + "name": "Good Friday", + "date": "2021-04-02" + }, + { + "name": "Easter Monday", + "date": "2021-04-05" + }, + { + "name": "Early May bank holiday", + "date": "2021-05-03" + }, + { + "name": "Spring bank holiday", + "date": "2021-05-31" + }, + { + "name": "Summer bank holiday", + "date": "2021-08-30" + }, + { + "name": "Christmas Day (substitute day)", + "date": "2021-12-27" + }, + { + "name": "Boxing Day (substitute day)", + "date": "2021-12-28" + } +] \ No newline at end of file diff --git a/tests/.pest/snapshots/Countries/EnglandTest/it_can_calculate_welsh_holidays_if_christmas_is_on_a_sunday.snap b/tests/.pest/snapshots/Countries/EnglandTest/it_can_calculate_welsh_holidays_if_christmas_is_on_a_sunday.snap new file mode 100644 index 000000000..6448e0c3d --- /dev/null +++ b/tests/.pest/snapshots/Countries/EnglandTest/it_can_calculate_welsh_holidays_if_christmas_is_on_a_sunday.snap @@ -0,0 +1,42 @@ +[ + { + "name": "New Year's Day (substitute day)", + "date": "2022-01-03" + }, + { + "name": "Good Friday", + "date": "2022-04-15" + }, + { + "name": "Easter Monday", + "date": "2022-04-18" + }, + { + "name": "Early May bank holiday", + "date": "2022-05-02" + }, + { + "name": "Spring bank holiday", + "date": "2022-05-30" + }, + { + "name": "Platinum Jubilee bank holiday", + "date": "2022-06-03" + }, + { + "name": "Summer bank holiday", + "date": "2022-08-29" + }, + { + "name": "Bank Holiday for the State Funeral of Queen Elizabeth II", + "date": "2022-09-19" + }, + { + "name": "Boxing Day", + "date": "2022-12-26" + }, + { + "name": "Christmas Day (substitute day)", + "date": "2022-12-27" + } +] \ No newline at end of file diff --git a/tests/.pest/snapshots/Countries/EnglandTest/it_returns_a_substitute_day_if_new_years_day_falls_on_a_weekend.snap b/tests/.pest/snapshots/Countries/EnglandTest/it_returns_a_substitute_day_if_new_years_day_falls_on_a_weekend.snap new file mode 100644 index 000000000..75a852ff2 --- /dev/null +++ b/tests/.pest/snapshots/Countries/EnglandTest/it_returns_a_substitute_day_if_new_years_day_falls_on_a_weekend.snap @@ -0,0 +1,34 @@ +[ + { + "name": "New Year's Day (substitute day)", + "date": "2033-01-03" + }, + { + "name": "Good Friday", + "date": "2033-04-15" + }, + { + "name": "Easter Monday", + "date": "2033-04-18" + }, + { + "name": "Early May bank holiday", + "date": "2033-05-02" + }, + { + "name": "Spring bank holiday", + "date": "2033-05-30" + }, + { + "name": "Summer bank holiday", + "date": "2033-08-29" + }, + { + "name": "Boxing Day", + "date": "2033-12-26" + }, + { + "name": "Christmas Day (substitute day)", + "date": "2033-12-27" + } +] \ No newline at end of file diff --git a/tests/.pest/snapshots/Countries/NorthernIrelandTest/it_can_calculate_northern_irish_for_2020.snap b/tests/.pest/snapshots/Countries/NorthernIrelandTest/it_can_calculate_northern_irish_for_2020.snap new file mode 100644 index 000000000..144a8c9fe --- /dev/null +++ b/tests/.pest/snapshots/Countries/NorthernIrelandTest/it_can_calculate_northern_irish_for_2020.snap @@ -0,0 +1,34 @@ +[ + { + "name": "New Year's Day", + "date": "2020-01-01" + }, + { + "name": "Good Friday", + "date": "2020-04-10" + }, + { + "name": "Easter Monday", + "date": "2020-04-13" + }, + { + "name": "Early May bank holiday (VE day)", + "date": "2020-05-08" + }, + { + "name": "Spring bank holiday", + "date": "2020-05-25" + }, + { + "name": "Summer bank holiday", + "date": "2020-08-31" + }, + { + "name": "Christmas Day", + "date": "2020-12-25" + }, + { + "name": "Boxing Day (substitute day)", + "date": "2020-12-28" + } +] \ No newline at end of file diff --git a/tests/.pest/snapshots/Countries/NorthernIrelandTest/it_can_calculate_northern_irish_holidays.snap b/tests/.pest/snapshots/Countries/NorthernIrelandTest/it_can_calculate_northern_irish_holidays.snap new file mode 100644 index 000000000..960f4faf3 --- /dev/null +++ b/tests/.pest/snapshots/Countries/NorthernIrelandTest/it_can_calculate_northern_irish_holidays.snap @@ -0,0 +1,42 @@ +[ + { + "name": "New Year's Day", + "date": "2025-01-01" + }, + { + "name": "St Patrick's Day", + "date": "2025-03-17" + }, + { + "name": "Good Friday", + "date": "2025-04-18" + }, + { + "name": "Easter Monday", + "date": "2025-04-21" + }, + { + "name": "Early May bank holiday", + "date": "2025-05-05" + }, + { + "name": "Spring bank holiday", + "date": "2025-05-26" + }, + { + "name": "Battle of the Boyne (Orangemen's Day) (substitute day)", + "date": "2025-07-14" + }, + { + "name": "Summer bank holiday", + "date": "2025-08-25" + }, + { + "name": "Christmas Day", + "date": "2025-12-25" + }, + { + "name": "Boxing Day", + "date": "2025-12-26" + } +] \ No newline at end of file diff --git a/tests/.pest/snapshots/Countries/NorthernIrelandTest/it_can_calculate_northern_irish_holidays_if_christmas_is_on_a_friday.snap b/tests/.pest/snapshots/Countries/NorthernIrelandTest/it_can_calculate_northern_irish_holidays_if_christmas_is_on_a_friday.snap new file mode 100644 index 000000000..0e20a5c69 --- /dev/null +++ b/tests/.pest/snapshots/Countries/NorthernIrelandTest/it_can_calculate_northern_irish_holidays_if_christmas_is_on_a_friday.snap @@ -0,0 +1,42 @@ +[ + { + "name": "New Year's Day", + "date": "2020-01-01" + }, + { + "name": "St Patrick's Day", + "date": "2020-03-17" + }, + { + "name": "Good Friday", + "date": "2020-04-10" + }, + { + "name": "Easter Monday", + "date": "2020-04-13" + }, + { + "name": "Early May bank holiday (VE day)", + "date": "2020-05-08" + }, + { + "name": "Spring bank holiday", + "date": "2020-05-25" + }, + { + "name": "Battle of the Boyne (Orangemen's Day) (substitute day)", + "date": "2020-07-13" + }, + { + "name": "Summer bank holiday", + "date": "2020-08-31" + }, + { + "name": "Christmas Day", + "date": "2020-12-25" + }, + { + "name": "Boxing Day (substitute day)", + "date": "2020-12-28" + } +] \ No newline at end of file diff --git a/tests/.pest/snapshots/Countries/NorthernIrelandTest/it_can_calculate_northern_irish_holidays_if_christmas_is_on_a_saturday.snap b/tests/.pest/snapshots/Countries/NorthernIrelandTest/it_can_calculate_northern_irish_holidays_if_christmas_is_on_a_saturday.snap new file mode 100644 index 000000000..eb0db835f --- /dev/null +++ b/tests/.pest/snapshots/Countries/NorthernIrelandTest/it_can_calculate_northern_irish_holidays_if_christmas_is_on_a_saturday.snap @@ -0,0 +1,42 @@ +[ + { + "name": "New Year's Day", + "date": "2021-01-01" + }, + { + "name": "St Patrick's Day", + "date": "2021-03-17" + }, + { + "name": "Good Friday", + "date": "2021-04-02" + }, + { + "name": "Easter Monday", + "date": "2021-04-05" + }, + { + "name": "Early May bank holiday", + "date": "2021-05-03" + }, + { + "name": "Spring bank holiday", + "date": "2021-05-31" + }, + { + "name": "Battle of the Boyne (Orangemen's Day)", + "date": "2021-07-12" + }, + { + "name": "Summer bank holiday", + "date": "2021-08-30" + }, + { + "name": "Christmas Day (substitute day)", + "date": "2021-12-27" + }, + { + "name": "Boxing Day (substitute day)", + "date": "2021-12-28" + } +] \ No newline at end of file diff --git a/tests/.pest/snapshots/Countries/NorthernIrelandTest/it_can_calculate_northern_irish_holidays_if_christmas_is_on_a_sunday.snap b/tests/.pest/snapshots/Countries/NorthernIrelandTest/it_can_calculate_northern_irish_holidays_if_christmas_is_on_a_sunday.snap new file mode 100644 index 000000000..0548d752f --- /dev/null +++ b/tests/.pest/snapshots/Countries/NorthernIrelandTest/it_can_calculate_northern_irish_holidays_if_christmas_is_on_a_sunday.snap @@ -0,0 +1,50 @@ +[ + { + "name": "New Year's Day (substitute day)", + "date": "2022-01-03" + }, + { + "name": "St Patrick's Day", + "date": "2022-03-17" + }, + { + "name": "Good Friday", + "date": "2022-04-15" + }, + { + "name": "Easter Monday", + "date": "2022-04-18" + }, + { + "name": "Early May bank holiday", + "date": "2022-05-02" + }, + { + "name": "Spring bank holiday", + "date": "2022-05-30" + }, + { + "name": "Platinum Jubilee bank holiday", + "date": "2022-06-03" + }, + { + "name": "Battle of the Boyne (Orangemen's Day)", + "date": "2022-07-12" + }, + { + "name": "Summer bank holiday", + "date": "2022-08-29" + }, + { + "name": "Bank Holiday for the State Funeral of Queen Elizabeth II", + "date": "2022-09-19" + }, + { + "name": "Boxing Day", + "date": "2022-12-26" + }, + { + "name": "Christmas Day (substitute day)", + "date": "2022-12-27" + } +] \ No newline at end of file diff --git a/tests/.pest/snapshots/Countries/NorthernIrelandTest/it_returns_a_substitute_day_for_second_of_january_if_new_years_day_falls_on_a_friday.snap b/tests/.pest/snapshots/Countries/NorthernIrelandTest/it_returns_a_substitute_day_for_second_of_january_if_new_years_day_falls_on_a_friday.snap new file mode 100644 index 000000000..eb0db835f --- /dev/null +++ b/tests/.pest/snapshots/Countries/NorthernIrelandTest/it_returns_a_substitute_day_for_second_of_january_if_new_years_day_falls_on_a_friday.snap @@ -0,0 +1,42 @@ +[ + { + "name": "New Year's Day", + "date": "2021-01-01" + }, + { + "name": "St Patrick's Day", + "date": "2021-03-17" + }, + { + "name": "Good Friday", + "date": "2021-04-02" + }, + { + "name": "Easter Monday", + "date": "2021-04-05" + }, + { + "name": "Early May bank holiday", + "date": "2021-05-03" + }, + { + "name": "Spring bank holiday", + "date": "2021-05-31" + }, + { + "name": "Battle of the Boyne (Orangemen's Day)", + "date": "2021-07-12" + }, + { + "name": "Summer bank holiday", + "date": "2021-08-30" + }, + { + "name": "Christmas Day (substitute day)", + "date": "2021-12-27" + }, + { + "name": "Boxing Day (substitute day)", + "date": "2021-12-28" + } +] \ No newline at end of file diff --git a/tests/.pest/snapshots/Countries/NorthernIrelandTest/it_returns_a_substitute_day_if_new_years_day_falls_on_a_weekend.snap b/tests/.pest/snapshots/Countries/NorthernIrelandTest/it_returns_a_substitute_day_if_new_years_day_falls_on_a_weekend.snap new file mode 100644 index 000000000..f2c4691c4 --- /dev/null +++ b/tests/.pest/snapshots/Countries/NorthernIrelandTest/it_returns_a_substitute_day_if_new_years_day_falls_on_a_weekend.snap @@ -0,0 +1,42 @@ +[ + { + "name": "New Year's Day (substitute day)", + "date": "2033-01-03" + }, + { + "name": "St Patrick's Day", + "date": "2033-03-17" + }, + { + "name": "Good Friday", + "date": "2033-04-15" + }, + { + "name": "Easter Monday", + "date": "2033-04-18" + }, + { + "name": "Early May bank holiday", + "date": "2033-05-02" + }, + { + "name": "Spring bank holiday", + "date": "2033-05-30" + }, + { + "name": "Battle of the Boyne (Orangemen's Day)", + "date": "2033-07-12" + }, + { + "name": "Summer bank holiday", + "date": "2033-08-29" + }, + { + "name": "Boxing Day", + "date": "2033-12-26" + }, + { + "name": "Christmas Day (substitute day)", + "date": "2033-12-27" + } +] \ No newline at end of file diff --git a/tests/.pest/snapshots/Countries/ScotlandTest/it_can_calculate_holidays_for_2020.snap b/tests/.pest/snapshots/Countries/ScotlandTest/it_can_calculate_holidays_for_2020.snap new file mode 100644 index 000000000..144a8c9fe --- /dev/null +++ b/tests/.pest/snapshots/Countries/ScotlandTest/it_can_calculate_holidays_for_2020.snap @@ -0,0 +1,34 @@ +[ + { + "name": "New Year's Day", + "date": "2020-01-01" + }, + { + "name": "Good Friday", + "date": "2020-04-10" + }, + { + "name": "Easter Monday", + "date": "2020-04-13" + }, + { + "name": "Early May bank holiday (VE day)", + "date": "2020-05-08" + }, + { + "name": "Spring bank holiday", + "date": "2020-05-25" + }, + { + "name": "Summer bank holiday", + "date": "2020-08-31" + }, + { + "name": "Christmas Day", + "date": "2020-12-25" + }, + { + "name": "Boxing Day (substitute day)", + "date": "2020-12-28" + } +] \ No newline at end of file diff --git a/tests/.pest/snapshots/Countries/ScotlandTest/it_can_calculate_scottish_holidays.snap b/tests/.pest/snapshots/Countries/ScotlandTest/it_can_calculate_scottish_holidays.snap new file mode 100644 index 000000000..8587a1d8b --- /dev/null +++ b/tests/.pest/snapshots/Countries/ScotlandTest/it_can_calculate_scottish_holidays.snap @@ -0,0 +1,38 @@ +[ + { + "name": "New Year's Day", + "date": "2025-01-01" + }, + { + "name": "2nd January", + "date": "2025-01-02" + }, + { + "name": "Good Friday", + "date": "2025-04-18" + }, + { + "name": "Early May bank holiday", + "date": "2025-05-05" + }, + { + "name": "Spring bank holiday", + "date": "2025-05-26" + }, + { + "name": "Summer bank holiday", + "date": "2025-08-04" + }, + { + "name": "St Andrew's Day (substitute day)", + "date": "2025-12-01" + }, + { + "name": "Christmas Day", + "date": "2025-12-25" + }, + { + "name": "Boxing Day", + "date": "2025-12-26" + } +] \ No newline at end of file diff --git a/tests/.pest/snapshots/Countries/ScotlandTest/it_can_calculate_scottish_holidays_if_christmas_is_on_a_friday.snap b/tests/.pest/snapshots/Countries/ScotlandTest/it_can_calculate_scottish_holidays_if_christmas_is_on_a_friday.snap new file mode 100644 index 000000000..94688f4f9 --- /dev/null +++ b/tests/.pest/snapshots/Countries/ScotlandTest/it_can_calculate_scottish_holidays_if_christmas_is_on_a_friday.snap @@ -0,0 +1,38 @@ +[ + { + "name": "New Year's Day", + "date": "2020-01-01" + }, + { + "name": "2nd January", + "date": "2020-01-02" + }, + { + "name": "Good Friday", + "date": "2020-04-10" + }, + { + "name": "Early May bank holiday (VE day)", + "date": "2020-05-08" + }, + { + "name": "Spring bank holiday", + "date": "2020-05-25" + }, + { + "name": "Summer bank holiday", + "date": "2020-08-03" + }, + { + "name": "St Andrew's Day", + "date": "2020-11-30" + }, + { + "name": "Christmas Day", + "date": "2020-12-25" + }, + { + "name": "Boxing Day (substitute day)", + "date": "2020-12-28" + } +] \ No newline at end of file diff --git a/tests/.pest/snapshots/Countries/ScotlandTest/it_can_calculate_scottish_holidays_if_christmas_is_on_a_saturday.snap b/tests/.pest/snapshots/Countries/ScotlandTest/it_can_calculate_scottish_holidays_if_christmas_is_on_a_saturday.snap new file mode 100644 index 000000000..37cb3f2f8 --- /dev/null +++ b/tests/.pest/snapshots/Countries/ScotlandTest/it_can_calculate_scottish_holidays_if_christmas_is_on_a_saturday.snap @@ -0,0 +1,38 @@ +[ + { + "name": "New Year's Day", + "date": "2021-01-01" + }, + { + "name": "2nd January (substitute day)", + "date": "2021-01-04" + }, + { + "name": "Good Friday", + "date": "2021-04-02" + }, + { + "name": "Early May bank holiday", + "date": "2021-05-03" + }, + { + "name": "Spring bank holiday", + "date": "2021-05-31" + }, + { + "name": "Summer bank holiday", + "date": "2021-08-02" + }, + { + "name": "St Andrew's Day", + "date": "2021-11-30" + }, + { + "name": "Christmas Day (substitute day)", + "date": "2021-12-27" + }, + { + "name": "Boxing Day (substitute day)", + "date": "2021-12-28" + } +] \ No newline at end of file diff --git a/tests/.pest/snapshots/Countries/ScotlandTest/it_can_calculate_scottish_holidays_if_christmas_is_on_a_sunday.snap b/tests/.pest/snapshots/Countries/ScotlandTest/it_can_calculate_scottish_holidays_if_christmas_is_on_a_sunday.snap new file mode 100644 index 000000000..4da1e2157 --- /dev/null +++ b/tests/.pest/snapshots/Countries/ScotlandTest/it_can_calculate_scottish_holidays_if_christmas_is_on_a_sunday.snap @@ -0,0 +1,46 @@ +[ + { + "name": "New Year's Day (substitute day)", + "date": "2022-01-03" + }, + { + "name": "2nd January (substitute day)", + "date": "2022-01-04" + }, + { + "name": "Good Friday", + "date": "2022-04-15" + }, + { + "name": "Early May bank holiday", + "date": "2022-05-02" + }, + { + "name": "Spring bank holiday", + "date": "2022-05-30" + }, + { + "name": "Platinum Jubilee bank holiday", + "date": "2022-06-03" + }, + { + "name": "Summer bank holiday", + "date": "2022-08-01" + }, + { + "name": "Bank Holiday for the State Funeral of Queen Elizabeth II", + "date": "2022-09-19" + }, + { + "name": "St Andrew's Day", + "date": "2022-11-30" + }, + { + "name": "Boxing Day", + "date": "2022-12-26" + }, + { + "name": "Christmas Day (substitute day)", + "date": "2022-12-27" + } +] \ No newline at end of file diff --git a/tests/.pest/snapshots/Countries/ScotlandTest/it_returns_a_substitute_day_for_second_of_january_if_new_years_day_falls_on_a_friday.snap b/tests/.pest/snapshots/Countries/ScotlandTest/it_returns_a_substitute_day_for_second_of_january_if_new_years_day_falls_on_a_friday.snap new file mode 100644 index 000000000..37cb3f2f8 --- /dev/null +++ b/tests/.pest/snapshots/Countries/ScotlandTest/it_returns_a_substitute_day_for_second_of_january_if_new_years_day_falls_on_a_friday.snap @@ -0,0 +1,38 @@ +[ + { + "name": "New Year's Day", + "date": "2021-01-01" + }, + { + "name": "2nd January (substitute day)", + "date": "2021-01-04" + }, + { + "name": "Good Friday", + "date": "2021-04-02" + }, + { + "name": "Early May bank holiday", + "date": "2021-05-03" + }, + { + "name": "Spring bank holiday", + "date": "2021-05-31" + }, + { + "name": "Summer bank holiday", + "date": "2021-08-02" + }, + { + "name": "St Andrew's Day", + "date": "2021-11-30" + }, + { + "name": "Christmas Day (substitute day)", + "date": "2021-12-27" + }, + { + "name": "Boxing Day (substitute day)", + "date": "2021-12-28" + } +] \ No newline at end of file diff --git a/tests/.pest/snapshots/Countries/ScotlandTest/it_returns_a_substitute_day_if_new_years_day_falls_on_a_weekend.snap b/tests/.pest/snapshots/Countries/ScotlandTest/it_returns_a_substitute_day_if_new_years_day_falls_on_a_weekend.snap new file mode 100644 index 000000000..6a4fe70dd --- /dev/null +++ b/tests/.pest/snapshots/Countries/ScotlandTest/it_returns_a_substitute_day_if_new_years_day_falls_on_a_weekend.snap @@ -0,0 +1,38 @@ +[ + { + "name": "New Year's Day (substitute day)", + "date": "2033-01-03" + }, + { + "name": "2nd January (substitute day)", + "date": "2033-01-04" + }, + { + "name": "Good Friday", + "date": "2033-04-15" + }, + { + "name": "Early May bank holiday", + "date": "2033-05-02" + }, + { + "name": "Spring bank holiday", + "date": "2033-05-30" + }, + { + "name": "Summer bank holiday", + "date": "2033-08-01" + }, + { + "name": "St Andrew's Day", + "date": "2033-11-30" + }, + { + "name": "Boxing Day", + "date": "2033-12-26" + }, + { + "name": "Christmas Day (substitute day)", + "date": "2033-12-27" + } +] \ No newline at end of file diff --git a/tests/.pest/snapshots/Countries/WalesTest/it_can_calculate_holidays_for_2020.snap b/tests/.pest/snapshots/Countries/WalesTest/it_can_calculate_holidays_for_2020.snap new file mode 100644 index 000000000..144a8c9fe --- /dev/null +++ b/tests/.pest/snapshots/Countries/WalesTest/it_can_calculate_holidays_for_2020.snap @@ -0,0 +1,34 @@ +[ + { + "name": "New Year's Day", + "date": "2020-01-01" + }, + { + "name": "Good Friday", + "date": "2020-04-10" + }, + { + "name": "Easter Monday", + "date": "2020-04-13" + }, + { + "name": "Early May bank holiday (VE day)", + "date": "2020-05-08" + }, + { + "name": "Spring bank holiday", + "date": "2020-05-25" + }, + { + "name": "Summer bank holiday", + "date": "2020-08-31" + }, + { + "name": "Christmas Day", + "date": "2020-12-25" + }, + { + "name": "Boxing Day (substitute day)", + "date": "2020-12-28" + } +] \ No newline at end of file diff --git a/tests/.pest/snapshots/Countries/WalesTest/it_can_calculate_welsh_holidays.snap b/tests/.pest/snapshots/Countries/WalesTest/it_can_calculate_welsh_holidays.snap new file mode 100644 index 000000000..7a2079d12 --- /dev/null +++ b/tests/.pest/snapshots/Countries/WalesTest/it_can_calculate_welsh_holidays.snap @@ -0,0 +1,34 @@ +[ + { + "name": "New Year's Day", + "date": "2024-01-01" + }, + { + "name": "Good Friday", + "date": "2024-03-29" + }, + { + "name": "Easter Monday", + "date": "2024-04-01" + }, + { + "name": "Early May bank holiday", + "date": "2024-05-06" + }, + { + "name": "Spring bank holiday", + "date": "2024-05-27" + }, + { + "name": "Summer bank holiday", + "date": "2024-08-26" + }, + { + "name": "Christmas Day", + "date": "2024-12-25" + }, + { + "name": "Boxing Day", + "date": "2024-12-26" + } +] \ No newline at end of file diff --git a/tests/.pest/snapshots/Countries/WalesTest/it_can_calculate_welsh_holidays_if_christmas_is_on_a_friday.snap b/tests/.pest/snapshots/Countries/WalesTest/it_can_calculate_welsh_holidays_if_christmas_is_on_a_friday.snap new file mode 100644 index 000000000..144a8c9fe --- /dev/null +++ b/tests/.pest/snapshots/Countries/WalesTest/it_can_calculate_welsh_holidays_if_christmas_is_on_a_friday.snap @@ -0,0 +1,34 @@ +[ + { + "name": "New Year's Day", + "date": "2020-01-01" + }, + { + "name": "Good Friday", + "date": "2020-04-10" + }, + { + "name": "Easter Monday", + "date": "2020-04-13" + }, + { + "name": "Early May bank holiday (VE day)", + "date": "2020-05-08" + }, + { + "name": "Spring bank holiday", + "date": "2020-05-25" + }, + { + "name": "Summer bank holiday", + "date": "2020-08-31" + }, + { + "name": "Christmas Day", + "date": "2020-12-25" + }, + { + "name": "Boxing Day (substitute day)", + "date": "2020-12-28" + } +] \ No newline at end of file diff --git a/tests/.pest/snapshots/Countries/WalesTest/it_can_calculate_welsh_holidays_if_christmas_is_on_a_saturday.snap b/tests/.pest/snapshots/Countries/WalesTest/it_can_calculate_welsh_holidays_if_christmas_is_on_a_saturday.snap new file mode 100644 index 000000000..4757ed990 --- /dev/null +++ b/tests/.pest/snapshots/Countries/WalesTest/it_can_calculate_welsh_holidays_if_christmas_is_on_a_saturday.snap @@ -0,0 +1,34 @@ +[ + { + "name": "New Year's Day", + "date": "2021-01-01" + }, + { + "name": "Good Friday", + "date": "2021-04-02" + }, + { + "name": "Easter Monday", + "date": "2021-04-05" + }, + { + "name": "Early May bank holiday", + "date": "2021-05-03" + }, + { + "name": "Spring bank holiday", + "date": "2021-05-31" + }, + { + "name": "Summer bank holiday", + "date": "2021-08-30" + }, + { + "name": "Christmas Day (substitute day)", + "date": "2021-12-27" + }, + { + "name": "Boxing Day (substitute day)", + "date": "2021-12-28" + } +] \ No newline at end of file diff --git a/tests/.pest/snapshots/Countries/WalesTest/it_can_calculate_welsh_holidays_if_christmas_is_on_a_sunday.snap b/tests/.pest/snapshots/Countries/WalesTest/it_can_calculate_welsh_holidays_if_christmas_is_on_a_sunday.snap new file mode 100644 index 000000000..6448e0c3d --- /dev/null +++ b/tests/.pest/snapshots/Countries/WalesTest/it_can_calculate_welsh_holidays_if_christmas_is_on_a_sunday.snap @@ -0,0 +1,42 @@ +[ + { + "name": "New Year's Day (substitute day)", + "date": "2022-01-03" + }, + { + "name": "Good Friday", + "date": "2022-04-15" + }, + { + "name": "Easter Monday", + "date": "2022-04-18" + }, + { + "name": "Early May bank holiday", + "date": "2022-05-02" + }, + { + "name": "Spring bank holiday", + "date": "2022-05-30" + }, + { + "name": "Platinum Jubilee bank holiday", + "date": "2022-06-03" + }, + { + "name": "Summer bank holiday", + "date": "2022-08-29" + }, + { + "name": "Bank Holiday for the State Funeral of Queen Elizabeth II", + "date": "2022-09-19" + }, + { + "name": "Boxing Day", + "date": "2022-12-26" + }, + { + "name": "Christmas Day (substitute day)", + "date": "2022-12-27" + } +] \ No newline at end of file diff --git a/tests/.pest/snapshots/Countries/WalesTest/it_returns_a_substitute_day_if_new_years_day_falls_on_a_weekend.snap b/tests/.pest/snapshots/Countries/WalesTest/it_returns_a_substitute_day_if_new_years_day_falls_on_a_weekend.snap new file mode 100644 index 000000000..75a852ff2 --- /dev/null +++ b/tests/.pest/snapshots/Countries/WalesTest/it_returns_a_substitute_day_if_new_years_day_falls_on_a_weekend.snap @@ -0,0 +1,34 @@ +[ + { + "name": "New Year's Day (substitute day)", + "date": "2033-01-03" + }, + { + "name": "Good Friday", + "date": "2033-04-15" + }, + { + "name": "Easter Monday", + "date": "2033-04-18" + }, + { + "name": "Early May bank holiday", + "date": "2033-05-02" + }, + { + "name": "Spring bank holiday", + "date": "2033-05-30" + }, + { + "name": "Summer bank holiday", + "date": "2033-08-29" + }, + { + "name": "Boxing Day", + "date": "2033-12-26" + }, + { + "name": "Christmas Day (substitute day)", + "date": "2033-12-27" + } +] \ No newline at end of file diff --git a/tests/Countries/EnglandTest.php b/tests/Countries/EnglandTest.php new file mode 100644 index 000000000..366d52322 --- /dev/null +++ b/tests/Countries/EnglandTest.php @@ -0,0 +1,98 @@ +getName($testDate); + $isHoliday = Holidays::for('gb-eng')->isHoliday($testDate); + + expect($holidayName)->toBe($name)->and($isHoliday)->toBeTrue(); + +})->with([ + ['New Year\'s Day', '2024-01-01'], + ['Good Friday', '2024-03-29'], + ['Easter Monday', '2024-04-01'], + ['Early May bank holiday', '2024-05-06'], + ['Spring bank holiday', '2024-05-27'], + ['Summer bank holiday', '2024-08-26'], + ['Christmas Day', '2024-12-25'], + ['Boxing Day', '2024-12-26'], + ['New Year\'s Day', '2025-01-01'], + ['Good Friday', '2025-04-18'], + ['Easter Monday', '2025-04-21'], + ['Early May bank holiday', '2025-05-05'], + ['Spring bank holiday', '2025-05-26'], + ['Summer bank holiday', '2025-08-25'], + ['Christmas Day', '2025-12-25'], + ['Boxing Day', '2025-12-26'], + ['New Year\'s Day', '2026-01-01'], + ['Good Friday', '2026-04-03'], + ['Easter Monday', '2026-04-06'], + ['Early May bank holiday', '2026-05-04'], + ['Spring bank holiday', '2026-05-25'], + ['Summer bank holiday', '2026-08-31'], + ['Christmas Day', '2026-12-25'], + ['Boxing Day (substitute day)', '2026-12-28'], +]); + +it( 'can calculate welsh holidays', function () { + CarbonImmutable::setTestNowAndTimezone('2024-01-01'); + + $holidays = Holidays::for(country: 'gb-eng')->get(); + + expect($holidays)->toBeArray()->not()->toBeEmpty(); + expect(formatDates($holidays))->toMatchSnapshot(); + +}); + +it('returns a substitute day if new years day falls on a weekend', function () { + CarbonImmutable::setTestNowAndTimezone('2033-01-01'); + + $holidays = Holidays::for(country: 'gb-eng')->get(); + + expect($holidays)->toBeArray()->not()->toBeEmpty(); + expect(formatDates($holidays))->toMatchSnapshot(); +}); + + +it('can calculate welsh holidays if christmas is on a friday', function () { + CarbonImmutable::setTestNowAndTimezone('2020-01-01'); + + $holidays = Holidays::for(country: 'gb-eng')->get(); + + expect($holidays)->toBeArray()->not()->toBeEmpty(); + expect(formatDates($holidays))->toMatchSnapshot(); +}); + +it('can calculate welsh holidays if christmas is on a saturday', function () { + CarbonImmutable::setTestNowAndTimezone('2021-01-01'); + + $holidays = Holidays::for(country: 'gb-eng')->get(); + + expect($holidays)->toBeArray()->not()->toBeEmpty(); + expect(formatDates($holidays))->toMatchSnapshot(); +}); + +it('can calculate welsh holidays if christmas is on a sunday', function () { + CarbonImmutable::setTestNowAndTimezone('2022-01-01'); + + $holidays = Holidays::for(country: 'gb-eng')->get(); + + expect($holidays)->toBeArray()->not()->toBeEmpty(); + expect(formatDates($holidays))->toMatchSnapshot(); +}); + +it('can calculate holidays for 2020', function () { + CarbonImmutable::setTestNowAndTimezone('2020-01-01'); + + $holidays = Holidays::for(country: 'gb-eng')->get(); + + expect($holidays)->toBeArray()->not()->toBeEmpty(); + expect(formatDates($holidays))->toMatchSnapshot(); +}); diff --git a/tests/Countries/NorthernIrelandTest.php b/tests/Countries/NorthernIrelandTest.php new file mode 100644 index 000000000..a75511256 --- /dev/null +++ b/tests/Countries/NorthernIrelandTest.php @@ -0,0 +1,111 @@ +getName($testDate); + $isHoliday = Holidays::for('gb-nir')->isHoliday($testDate); + + expect($holidayName)->toBe($name)->and($isHoliday)->toBeTrue(); + +})->with([ + ['New Year\'s Day', '2024-01-01'], + ['St Patrick\'s Day (substitute day)', '2024-03-18'], + ['Good Friday', '2024-03-29'], + ['Easter Monday', '2024-04-01'], + ['Early May bank holiday', '2024-05-06'], + ['Spring bank holiday', '2024-05-27'], + ['Battle of the Boyne (Orangemen\'s Day)', '2024-07-12'], + ['Summer bank holiday', '2024-08-26'], + ['Christmas Day', '2024-12-25'], + ['Boxing Day', '2024-12-26'], + ['New Year\'s Day', '2025-01-01'], + ['St Patrick\'s Day', '2025-03-17'], + ['Good Friday', '2025-04-18'], + ['Easter Monday', '2025-04-21'], + ['Early May bank holiday', '2025-05-05'], + ['Spring bank holiday', '2025-05-26'], + ['Battle of the Boyne (Orangemen\'s Day) (substitute day)', '2025-07-14'], + ['Summer bank holiday', '2025-08-25'], + ['Christmas Day', '2025-12-25'], + ['Boxing Day', '2025-12-26'], + ['New Year\'s Day', '2026-01-01'], + ['St Patrick\'s Day', '2026-03-17'], + ['Good Friday', '2026-04-03'], + ['Easter Monday', '2026-04-06'], + ['Early May bank holiday', '2026-05-04'], + ['Spring bank holiday', '2026-05-25'], + ['Battle of the Boyne (Orangemen\'s Day) (substitute day)', '2026-07-13'], + ['Summer bank holiday', '2026-08-31'], + ['Christmas Day', '2026-12-25'], + ['Boxing Day (substitute day)', '2026-12-28'], + +]); + +it( 'can calculate northern irish holidays', function () { + CarbonImmutable::setTestNowAndTimezone('2025-01-01'); + + $holidays = Holidays::for(country: 'gb-nir')->get(); + + expect($holidays)->toBeArray()->not()->toBeEmpty() + ->and(formatDates($holidays))->toMatchSnapshot(); + +}); + +it('returns a substitute day if new years day falls on a weekend', function () { + CarbonImmutable::setTestNowAndTimezone('2033-01-01'); + + $holidays = Holidays::for(country: 'gb-nir')->get(); + + expect($holidays)->toBeArray()->not()->toBeEmpty() + ->and(formatDates($holidays))->toMatchSnapshot(); +}); + +it('returns a substitute day for second of january if new years day falls on a friday', function () { + CarbonImmutable::setTestNowAndTimezone('2021-01-01'); + + $holidays = Holidays::for(country: 'gb-nir')->get(); + + expect($holidays)->toBeArray()->not()->toBeEmpty() + ->and(formatDates($holidays))->toMatchSnapshot(); +}); + +it('can calculate northern irish holidays if christmas is on a friday', function () { + CarbonImmutable::setTestNowAndTimezone('2020-01-01'); + + $holidays = Holidays::for(country: 'gb-nir')->get(); + + expect($holidays)->toBeArray()->not()->toBeEmpty() + ->and(formatDates($holidays))->toMatchSnapshot(); +}); + +it('can calculate northern irish holidays if christmas is on a saturday', function () { + CarbonImmutable::setTestNowAndTimezone('2021-01-01'); + + $holidays = Holidays::for(country: 'gb-nir')->get(); + + expect($holidays)->toBeArray()->not()->toBeEmpty() + ->and(formatDates($holidays))->toMatchSnapshot(); +}); + +it('can calculate northern irish holidays if christmas is on a sunday', function () { + CarbonImmutable::setTestNowAndTimezone('2022-01-01'); + + $holidays = Holidays::for(country: 'gb-nir')->get(); + + expect($holidays)->toBeArray()->not()->toBeEmpty() + ->and(formatDates($holidays))->toMatchSnapshot(); +}); + +it('can calculate northern irish for 2020', function () { + CarbonImmutable::setTestNowAndTimezone('2020-01-01'); + + $holidays = Holidays::for(country: 'gb-eng')->get(); + + expect($holidays)->toBeArray()->not()->toBeEmpty() + ->and(formatDates($holidays))->toMatchSnapshot(); +}); diff --git a/tests/Countries/ScotlandTest.php b/tests/Countries/ScotlandTest.php new file mode 100644 index 000000000..17e50cb71 --- /dev/null +++ b/tests/Countries/ScotlandTest.php @@ -0,0 +1,108 @@ +getName($testDate); + $isHoliday = Holidays::for('gb-sct')->isHoliday($testDate); + + expect($holidayName)->toBe($name)->and($isHoliday)->toBeTrue(); + +})->with([ + ['New Year\'s Day', '2024-01-01'], + ['2nd January', '2024-01-02'], + ['Good Friday', '2024-03-29'], + ['Early May bank holiday', '2024-05-06'], + ['Spring bank holiday', '2024-05-27'], + ['Summer bank holiday', '2024-08-05'], + ['St Andrew\'s Day (substitute day)', '2024-12-02'], + ['Christmas Day', '2024-12-25'], + ['Boxing Day', '2024-12-26'], + ['New Year\'s Day', '2025-01-01'], + ['2nd January', '2025-01-02'], + ['Good Friday', '2025-04-18'], + ['Early May bank holiday', '2025-05-05'], + ['Spring bank holiday', '2025-05-26'], + ['Summer bank holiday', '2025-08-04'], + ['St Andrew\'s Day (substitute day)', '2025-12-01'], + ['Christmas Day', '2025-12-25'], + ['Boxing Day', '2025-12-26'], + ['New Year\'s Day', '2026-01-01'], + ['2nd January', '2026-01-02'], + ['Good Friday', '2026-04-03'], + ['Early May bank holiday', '2026-05-04'], + ['Spring bank holiday', '2026-05-25'], + ['Summer bank holiday', '2026-08-03'], + ['St Andrew\'s Day', '2026-11-30'], + ['Christmas Day', '2026-12-25'], + ['Boxing Day (substitute day)', '2026-12-28'], +]); + + +it( 'can calculate scottish holidays', function () { + CarbonImmutable::setTestNowAndTimezone('2025-01-01'); + + $holidays = Holidays::for(country: 'gb-sct')->get(); + + expect($holidays)->toBeArray()->not()->toBeEmpty() + ->and(formatDates($holidays))->toMatchSnapshot(); + +}); + +it('returns a substitute day if new years day falls on a weekend', function () { + CarbonImmutable::setTestNowAndTimezone('2033-01-01'); + + $holidays = Holidays::for(country: 'gb-sct')->get(); + + expect($holidays)->toBeArray()->not()->toBeEmpty() + ->and(formatDates($holidays))->toMatchSnapshot(); +}); + +it('returns a substitute day for second of january if new years day falls on a friday', function () { + CarbonImmutable::setTestNowAndTimezone('2021-01-01'); + + $holidays = Holidays::for(country: 'gb-sct')->get(); + + expect($holidays)->toBeArray()->not()->toBeEmpty() + ->and(formatDates($holidays))->toMatchSnapshot(); +}); + +it('can calculate scottish holidays if christmas is on a friday', function () { + CarbonImmutable::setTestNowAndTimezone('2020-01-01'); + + $holidays = Holidays::for(country: 'gb-sct')->get(); + + expect($holidays)->toBeArray()->not()->toBeEmpty() + ->and(formatDates($holidays))->toMatchSnapshot(); +}); + +it('can calculate scottish holidays if christmas is on a saturday', function () { + CarbonImmutable::setTestNowAndTimezone('2021-01-01'); + + $holidays = Holidays::for(country: 'gb-sct')->get(); + + expect($holidays)->toBeArray()->not()->toBeEmpty() + ->and(formatDates($holidays))->toMatchSnapshot(); +}); + +it('can calculate scottish holidays if christmas is on a sunday', function () { + CarbonImmutable::setTestNowAndTimezone('2022-01-01'); + + $holidays = Holidays::for(country: 'gb-sct')->get(); + + expect($holidays)->toBeArray()->not()->toBeEmpty() + ->and(formatDates($holidays))->toMatchSnapshot(); +}); + +it('can calculate holidays for 2020', function () { + CarbonImmutable::setTestNowAndTimezone('2020-01-01'); + + $holidays = Holidays::for(country: 'gb-eng')->get(); + + expect($holidays)->toBeArray()->not()->toBeEmpty() + ->and(formatDates($holidays))->toMatchSnapshot(); +}); diff --git a/tests/Countries/WalesTest.php b/tests/Countries/WalesTest.php new file mode 100644 index 000000000..ac009897b --- /dev/null +++ b/tests/Countries/WalesTest.php @@ -0,0 +1,117 @@ +getName($testDate); + $isHoliday = Holidays::for('gb-cym')->isHoliday($testDate); + + expect($holidayName)->toBe($name)->and($isHoliday)->toBeTrue(); + +})->with([ + ['New Year\'s Day', '2024-01-01'], + ['Good Friday', '2024-03-29'], + ['Easter Monday', '2024-04-01'], + ['Early May bank holiday', '2024-05-06'], + ['Spring bank holiday', '2024-05-27'], + ['Summer bank holiday', '2024-08-26'], + ['Christmas Day', '2024-12-25'], + ['Boxing Day', '2024-12-26'], + ['New Year\'s Day', '2025-01-01'], + ['Good Friday', '2025-04-18'], + ['Easter Monday', '2025-04-21'], + ['Early May bank holiday', '2025-05-05'], + ['Spring bank holiday', '2025-05-26'], + ['Summer bank holiday', '2025-08-25'], + ['Christmas Day', '2025-12-25'], + ['Boxing Day', '2025-12-26'], + ['New Year\'s Day', '2026-01-01'], + ['Good Friday', '2026-04-03'], + ['Easter Monday', '2026-04-06'], + ['Early May bank holiday', '2026-05-04'], + ['Spring bank holiday', '2026-05-25'], + ['Summer bank holiday', '2026-08-31'], + ['Christmas Day', '2026-12-25'], + ['Boxing Day (substitute day)', '2026-12-28'], +]); + +it('calculates welsh easter holidays by date', function (string $name, string $date) { + + $testDate = CarbonImmutable::parse($date); + + $holidayName = Holidays::for('gb-cym')->getName($testDate); + $isHoliday = Holidays::for('gb-cym')->isHoliday($testDate); + + expect($holidayName)->toBe($name)->and($isHoliday)->toBeTrue(); + +})->with([ + ['Good Friday', '2024-03-29'], + ['Easter Monday', '2024-04-01'], + ['Good Friday', '2025-04-18'], + ['Easter Monday', '2025-04-21'], + ['Good Friday', '2026-04-03'], + ['Easter Monday', '2026-04-06'], +]); + +it( 'can calculate welsh holidays', function () { + CarbonImmutable::setTestNowAndTimezone('2024-01-01'); + + $holidays = Holidays::for(country: 'gb-cym')->get(); + + expect($holidays)->toBeArray()->not()->toBeEmpty(); + expect(formatDates($holidays))->toMatchSnapshot(); + +}); + +it('returns a substitute day if new years day falls on a weekend', function () { + CarbonImmutable::setTestNowAndTimezone('2033-01-01'); + + $holidays = Holidays::for(country: 'gb-cym')->get(); + + expect($holidays)->toBeArray()->not()->toBeEmpty(); + expect(formatDates($holidays))->toMatchSnapshot(); +}); + + +it('can calculate welsh holidays if christmas is on a friday', function () { + CarbonImmutable::setTestNowAndTimezone('2020-01-01'); + + $holidays = Holidays::for(country: 'gb-cym')->get(); + + expect($holidays)->toBeArray()->not()->toBeEmpty(); + expect(formatDates($holidays))->toMatchSnapshot(); +}); + +it('can calculate welsh holidays if christmas is on a saturday', function () { + CarbonImmutable::setTestNowAndTimezone('2021-01-01'); + + $holidays = Holidays::for(country: 'gb-cym')->get(); + + expect($holidays)->toBeArray()->not()->toBeEmpty(); + expect(formatDates($holidays))->toMatchSnapshot(); +}); + +it('can calculate welsh holidays if christmas is on a sunday', function () { + CarbonImmutable::setTestNowAndTimezone('2022-01-01'); + + $holidays = Holidays::for(country: 'gb-cym')->get(); + + expect($holidays)->toBeArray()->not()->toBeEmpty(); + expect(formatDates($holidays))->toMatchSnapshot(); +}); + +it('can calculate holidays for 2020', function () { + CarbonImmutable::setTestNowAndTimezone('2020-01-01'); + + $holidays = Holidays::for(country: 'gb-cym')->get(); + + expect($holidays)->toBeArray()->not()->toBeEmpty(); + expect(formatDates($holidays))->toMatchSnapshot(); +}); + From 938b22a5d18f43602af3bbe57926bf4c02493e2a Mon Sep 17 00:00:00 2001 From: Nielsvanpach Date: Thu, 25 Jan 2024 17:54:13 +0000 Subject: [PATCH 002/175] Fix styling --- src/Countries/NorthernIreland.php | 8 ++++---- src/Countries/Scotland.php | 10 +++++----- src/Countries/Wales.php | 17 ++++++++--------- tests/Countries/EnglandTest.php | 5 +---- tests/Countries/NorthernIrelandTest.php | 2 +- tests/Countries/ScotlandTest.php | 3 +-- tests/Countries/WalesTest.php | 6 +----- 7 files changed, 21 insertions(+), 30 deletions(-) diff --git a/src/Countries/NorthernIreland.php b/src/Countries/NorthernIreland.php index 6f489cff6..889fa513e 100644 --- a/src/Countries/NorthernIreland.php +++ b/src/Countries/NorthernIreland.php @@ -14,7 +14,7 @@ public function countryCode(): string /** @return array */ private function stPatricksDay(int $year): array { - $stPatricksDay = new CarbonImmutable($year . "-03-17", 'Europe/London'); + $stPatricksDay = new CarbonImmutable($year.'-03-17', 'Europe/London'); $key = 'St Patrick\'s Day'; if ($stPatricksDay->isWeekend()) { @@ -28,7 +28,7 @@ private function stPatricksDay(int $year): array /** @return array */ private function battleOfTheBoyne(int $year): array { - $battleOfTheBoyne = new CarbonImmutable($year . "-07-12", 'Europe/London'); + $battleOfTheBoyne = new CarbonImmutable($year.'-07-12', 'Europe/London'); $key = 'Battle of the Boyne (Orangemen\'s Day)'; if ($battleOfTheBoyne->isWeekend()) { @@ -44,8 +44,8 @@ protected function oneOffHolidays(int $year): array { return match ($year) { 2022 => [ - 'Platinum Jubilee bank holiday' => new CarbonImmutable("2022-06-03", 'Europe/London'), - 'Bank Holiday for the State Funeral of Queen Elizabeth II' => new CarbonImmutable("2022-09-19", 'Europe/London'), + 'Platinum Jubilee bank holiday' => new CarbonImmutable('2022-06-03', 'Europe/London'), + 'Bank Holiday for the State Funeral of Queen Elizabeth II' => new CarbonImmutable('2022-09-19', 'Europe/London'), ], default => [], }; diff --git a/src/Countries/Scotland.php b/src/Countries/Scotland.php index 31f5aef8c..09e2ea097 100644 --- a/src/Countries/Scotland.php +++ b/src/Countries/Scotland.php @@ -14,8 +14,8 @@ public function countryCode(): string /** @return array */ protected function secondOfJanuary(int $year): array { - $newYearsDay = new CarbonImmutable($year . "-01-01", 'Europe/London'); - $secondOfJanuary = new CarbonImmutable($year . "-01-02", 'Europe/London'); + $newYearsDay = new CarbonImmutable($year.'-01-01', 'Europe/London'); + $secondOfJanuary = new CarbonImmutable($year.'-01-02', 'Europe/London'); $key = '2nd January'; if ($newYearsDay->isFriday()) { @@ -34,7 +34,7 @@ protected function secondOfJanuary(int $year): array /** @return array */ private function stAndrewsDay(int $year): array { - $stAndrewsDay = new CarbonImmutable($year . "-11-30", 'Europe/London'); + $stAndrewsDay = new CarbonImmutable($year.'-11-30', 'Europe/London'); $key = 'St Andrew\'s Day'; if ($stAndrewsDay->isWeekend()) { @@ -50,8 +50,8 @@ protected function oneOffHolidays(int $year): array { return match ($year) { 2022 => [ - 'Platinum Jubilee bank holiday' => new CarbonImmutable("2022-06-03", 'Europe/London'), - 'Bank Holiday for the State Funeral of Queen Elizabeth II' => new CarbonImmutable("2022-09-19", 'Europe/London'), + 'Platinum Jubilee bank holiday' => new CarbonImmutable('2022-06-03', 'Europe/London'), + 'Bank Holiday for the State Funeral of Queen Elizabeth II' => new CarbonImmutable('2022-09-19', 'Europe/London'), ], default => [], }; diff --git a/src/Countries/Wales.php b/src/Countries/Wales.php index 0a05fd29d..7468ba889 100644 --- a/src/Countries/Wales.php +++ b/src/Countries/Wales.php @@ -14,7 +14,7 @@ public function countryCode(): string /** @return array */ protected function christmasDay(int $year): array { - $christmasDay = new CarbonImmutable($year . "-12-25", 'Europe/London'); + $christmasDay = new CarbonImmutable($year.'-12-25', 'Europe/London'); $key = 'Christmas Day'; if ($christmasDay->isSaturday()) { @@ -33,8 +33,8 @@ protected function christmasDay(int $year): array /** @return array */ protected function boxingDay(int $year): array { - $christmasDay = new CarbonImmutable($year . "-12-25", 'Europe/London'); - $boxingDay = new CarbonImmutable($year . "-12-26", 'Europe/London'); + $christmasDay = new CarbonImmutable($year.'-12-25', 'Europe/London'); + $boxingDay = new CarbonImmutable($year.'-12-26', 'Europe/London'); $key = 'Boxing Day'; if ($christmasDay->isFriday()) { @@ -53,7 +53,7 @@ protected function boxingDay(int $year): array /** @return array */ protected function newYearsDay(int $year): array { - $newYearsDay = new CarbonImmutable($year . "-01-01", 'Europe/London'); + $newYearsDay = new CarbonImmutable($year.'-01-01', 'Europe/London'); $key = 'New Year\'s Day'; if ($newYearsDay->isWeekend()) { @@ -69,13 +69,13 @@ protected function earlyMayBankHoliday(int $year): array { if ($year === 2020) { return [ - 'Early May bank holiday (VE day)' => new CarbonImmutable("2020-05-08", 'Europe/London'), + 'Early May bank holiday (VE day)' => new CarbonImmutable('2020-05-08', 'Europe/London'), ]; } if ($year === 2023) { return [ - 'Bank holiday for the coronation of King Charles III' => new CarbonImmutable("2020-05-08", 'Europe/London'), + 'Bank holiday for the coronation of King Charles III' => new CarbonImmutable('2020-05-08', 'Europe/London'), ]; } @@ -83,15 +83,14 @@ protected function earlyMayBankHoliday(int $year): array } /** - * @param int $year * @return array|CarbonImmutable[] */ protected function oneOffHolidays(int $year): array { return match ($year) { 2022 => [ - 'Platinum Jubilee bank holiday' => new CarbonImmutable("2022-06-03", 'Europe/London'), - 'Bank Holiday for the State Funeral of Queen Elizabeth II' => new CarbonImmutable("2022-09-19", 'Europe/London'), + 'Platinum Jubilee bank holiday' => new CarbonImmutable('2022-06-03', 'Europe/London'), + 'Bank Holiday for the State Funeral of Queen Elizabeth II' => new CarbonImmutable('2022-09-19', 'Europe/London'), ], default => [], }; diff --git a/tests/Countries/EnglandTest.php b/tests/Countries/EnglandTest.php index 366d52322..ee3d22e80 100644 --- a/tests/Countries/EnglandTest.php +++ b/tests/Countries/EnglandTest.php @@ -1,8 +1,6 @@ get(); @@ -60,7 +58,6 @@ expect(formatDates($holidays))->toMatchSnapshot(); }); - it('can calculate welsh holidays if christmas is on a friday', function () { CarbonImmutable::setTestNowAndTimezone('2020-01-01'); diff --git a/tests/Countries/NorthernIrelandTest.php b/tests/Countries/NorthernIrelandTest.php index a75511256..11266d3af 100644 --- a/tests/Countries/NorthernIrelandTest.php +++ b/tests/Countries/NorthernIrelandTest.php @@ -46,7 +46,7 @@ ]); -it( 'can calculate northern irish holidays', function () { +it('can calculate northern irish holidays', function () { CarbonImmutable::setTestNowAndTimezone('2025-01-01'); $holidays = Holidays::for(country: 'gb-nir')->get(); diff --git a/tests/Countries/ScotlandTest.php b/tests/Countries/ScotlandTest.php index 17e50cb71..f8aa5d926 100644 --- a/tests/Countries/ScotlandTest.php +++ b/tests/Countries/ScotlandTest.php @@ -42,8 +42,7 @@ ['Boxing Day (substitute day)', '2026-12-28'], ]); - -it( 'can calculate scottish holidays', function () { +it('can calculate scottish holidays', function () { CarbonImmutable::setTestNowAndTimezone('2025-01-01'); $holidays = Holidays::for(country: 'gb-sct')->get(); diff --git a/tests/Countries/WalesTest.php b/tests/Countries/WalesTest.php index ac009897b..2e840357b 100644 --- a/tests/Countries/WalesTest.php +++ b/tests/Countries/WalesTest.php @@ -1,8 +1,6 @@ get(); @@ -78,7 +76,6 @@ expect(formatDates($holidays))->toMatchSnapshot(); }); - it('can calculate welsh holidays if christmas is on a friday', function () { CarbonImmutable::setTestNowAndTimezone('2020-01-01'); @@ -114,4 +111,3 @@ expect($holidays)->toBeArray()->not()->toBeEmpty(); expect(formatDates($holidays))->toMatchSnapshot(); }); - From f5acb1e04c021a4396eb7faf389bcd02537aa662 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Reyes=20Galgani?= Date: Fri, 26 Jan 2024 05:13:07 -0500 Subject: [PATCH 003/175] Add Chile Holidays (#88) * Add Chile Holidays * Update Chile.php * Update Chile.php --- src/Countries/Chile.php | 47 +++++++++++++ .../it_can_calculate_chile_holidays.snap | 70 +++++++++++++++++++ tests/Countries/ChileTest.php | 18 +++++ 3 files changed, 135 insertions(+) create mode 100644 src/Countries/Chile.php create mode 100644 tests/.pest/snapshots/Countries/ChileTest/it_can_calculate_chile_holidays.snap create mode 100644 tests/Countries/ChileTest.php diff --git a/src/Countries/Chile.php b/src/Countries/Chile.php new file mode 100644 index 000000000..37e0f7255 --- /dev/null +++ b/src/Countries/Chile.php @@ -0,0 +1,47 @@ + '01-01', + 'Viernes Santo' => '03-29', + 'Sábado Santo' => '03-30', + 'Día del Trabajador' => '05-01', + 'Día de las Glorias Navales' => '05-21', + 'Día Nacional de los Pueblos Indígenas' => '06-20', + 'San Pedro y San Pablo' => '06-29', + 'Día de la Virgen del Carmen' => '07-16', + 'Asunción de la Virgen' => '08-15', + 'Independencia Nacional' => '09-18', + 'Día de las Glorias del Ejército' => '09-19', + 'Feriado añadido de Fiestas Patrias' => '09-20', + 'Encuentro de Dos Mundos' => '10-12', + 'Día de las Iglesias Evangélicas' => '10-31', + 'Día de Todos los Santos' => '11-01', + 'Inmaculada Concepción' => '12-08', + 'Navidad' => '12-25', + ]; + } + + protected function variableHolidays(int $year): array + { + $easter = CarbonImmutable::createFromTimestamp(easter_date($year)) + ->setTimezone('America/Santiago'); + + return [ + 'Jueves santo' => $easter->subDays(3), + 'Viernes santo' => $easter->subDays(2), + ]; + } +} diff --git a/tests/.pest/snapshots/Countries/ChileTest/it_can_calculate_chile_holidays.snap b/tests/.pest/snapshots/Countries/ChileTest/it_can_calculate_chile_holidays.snap new file mode 100644 index 000000000..88339584a --- /dev/null +++ b/tests/.pest/snapshots/Countries/ChileTest/it_can_calculate_chile_holidays.snap @@ -0,0 +1,70 @@ +[ + { + "name": "A\u00f1o Nuevo", + "date": "2024-01-01" + }, + { + "name": "Viernes Santo", + "date": "2024-03-29" + }, + { + "name": "S\u00e1bado Santo", + "date": "2024-03-30" + }, + { + "name": "D\u00eda del Trabajador", + "date": "2024-05-01" + }, + { + "name": "D\u00eda de las Glorias Navales", + "date": "2024-05-21" + }, + { + "name": "D\u00eda Nacional de los Pueblos Ind\u00edgenas", + "date": "2024-06-20" + }, + { + "name": "San Pedro y San Pablo", + "date": "2024-06-29" + }, + { + "name": "D\u00eda de la Virgen del Carmen", + "date": "2024-07-16" + }, + { + "name": "Asunci\u00f3n de la Virgen", + "date": "2024-08-15" + }, + { + "name": "Independencia Nacional", + "date": "2024-09-18" + }, + { + "name": "D\u00eda de las Glorias del Ej\u00e9rcito", + "date": "2024-09-19" + }, + { + "name": "Feriado a\u00f1adido de Fiestas Patrias", + "date": "2024-09-20" + }, + { + "name": "Encuentro de Dos Mundos", + "date": "2024-10-12" + }, + { + "name": "D\u00eda de las Iglesias Evang\u00e9licas", + "date": "2024-10-31" + }, + { + "name": "D\u00eda de Todos los Santos", + "date": "2024-11-01" + }, + { + "name": "Inmaculada Concepci\u00f3n", + "date": "2024-12-08" + }, + { + "name": "Navidad", + "date": "2024-12-25" + } +] \ No newline at end of file diff --git a/tests/Countries/ChileTest.php b/tests/Countries/ChileTest.php new file mode 100644 index 000000000..aed6f880f --- /dev/null +++ b/tests/Countries/ChileTest.php @@ -0,0 +1,18 @@ +get(); + + expect($holidays) + ->toBeArray() + ->not()->toBeEmpty(); + + expect(formatDates($holidays))->toMatchSnapshot(); +}); From 664960223d4a8f1d2e85933dd4e8e01e9dc16a96 Mon Sep 17 00:00:00 2001 From: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> Date: Fri, 26 Jan 2024 11:14:03 +0100 Subject: [PATCH 004/175] cleanup Chile --- src/Countries/Chile.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Countries/Chile.php b/src/Countries/Chile.php index 37e0f7255..d4ee5a343 100644 --- a/src/Countries/Chile.php +++ b/src/Countries/Chile.php @@ -34,10 +34,10 @@ protected function allHolidays(int $year): array ]; } + /** @return array */ protected function variableHolidays(int $year): array { - $easter = CarbonImmutable::createFromTimestamp(easter_date($year)) - ->setTimezone('America/Santiago'); + $easter = $this->easter($year); return [ 'Jueves santo' => $easter->subDays(3), From 0ed82081a7602cf507480d8cbc3b045ed13def39 Mon Sep 17 00:00:00 2001 From: PhilN8 <85251946+PhilN8@users.noreply.github.com> Date: Sat, 27 Jan 2024 13:03:10 +0300 Subject: [PATCH 005/175] Added Kenyan holidays (#69) * feat: kenyan holidays added * added Utamaduni Day and Easter holidays * fix:phpstan errors * fix: removed buggy line --- src/Countries/Kenya.php | 39 +++++++++++++++++ .../it_can_calculate_kenyan_holidays.snap | 42 +++++++++++++++++++ tests/Countries/KenyaTest.php | 18 ++++++++ 3 files changed, 99 insertions(+) create mode 100644 src/Countries/Kenya.php create mode 100644 tests/.pest/snapshots/Countries/KenyaTest/it_can_calculate_kenyan_holidays.snap create mode 100644 tests/Countries/KenyaTest.php diff --git a/src/Countries/Kenya.php b/src/Countries/Kenya.php new file mode 100644 index 000000000..f4c506648 --- /dev/null +++ b/src/Countries/Kenya.php @@ -0,0 +1,39 @@ + "01-01", + "Labour" => "05-01", + "Madaraka" => "06-01", + "Utamaduni" => "10-10", + "Mashujaa" => "10-20", + "Jamhuri" => "12-01", + "Christmas" => "12-25", + "Boxing" => "12-26", + ], $this->variableHolidays($year)); + } + + /** @return array */ + protected function variableHolidays(int $year): array + { + $easter = CarbonImmutable::createFromTimestamp(easter_date($year)) + ->setTimezone('Africa/Nairobi'); + + return [ + "Good Friday" => $easter->subDays(2), + "Easter Monday" => $easter->addDay(), + ]; + } +} diff --git a/tests/.pest/snapshots/Countries/KenyaTest/it_can_calculate_kenyan_holidays.snap b/tests/.pest/snapshots/Countries/KenyaTest/it_can_calculate_kenyan_holidays.snap new file mode 100644 index 000000000..8ca55adb8 --- /dev/null +++ b/tests/.pest/snapshots/Countries/KenyaTest/it_can_calculate_kenyan_holidays.snap @@ -0,0 +1,42 @@ +[ + { + "name": "New Year's", + "date": "2024-01-01" + }, + { + "name": "Good Friday", + "date": "2024-03-29" + }, + { + "name": "Easter Monday", + "date": "2024-04-01" + }, + { + "name": "Labour", + "date": "2024-05-01" + }, + { + "name": "Madaraka", + "date": "2024-06-01" + }, + { + "name": "Utamaduni", + "date": "2024-10-10" + }, + { + "name": "Mashujaa", + "date": "2024-10-20" + }, + { + "name": "Jamhuri", + "date": "2024-12-01" + }, + { + "name": "Christmas", + "date": "2024-12-25" + }, + { + "name": "Boxing", + "date": "2024-12-26" + } +] \ No newline at end of file diff --git a/tests/Countries/KenyaTest.php b/tests/Countries/KenyaTest.php new file mode 100644 index 000000000..96d17cdf3 --- /dev/null +++ b/tests/Countries/KenyaTest.php @@ -0,0 +1,18 @@ +get(); + + expect($holidays) + ->toBeArray() + ->not()->toBeEmpty(); + + expect(formatDates($holidays))->toMatchSnapshot(); +}); From db1952bafe266ef6393d223ac444130e02605cf6 Mon Sep 17 00:00:00 2001 From: Nielsvanpach Date: Sat, 27 Jan 2024 10:03:27 +0000 Subject: [PATCH 006/175] Fix styling --- src/Countries/Kenya.php | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/Countries/Kenya.php b/src/Countries/Kenya.php index f4c506648..82a7ad3d8 100644 --- a/src/Countries/Kenya.php +++ b/src/Countries/Kenya.php @@ -14,14 +14,14 @@ public function countryCode(): string protected function allHolidays(int $year): array { return array_merge([ - "New Year's" => "01-01", - "Labour" => "05-01", - "Madaraka" => "06-01", - "Utamaduni" => "10-10", - "Mashujaa" => "10-20", - "Jamhuri" => "12-01", - "Christmas" => "12-25", - "Boxing" => "12-26", + "New Year's" => '01-01', + 'Labour' => '05-01', + 'Madaraka' => '06-01', + 'Utamaduni' => '10-10', + 'Mashujaa' => '10-20', + 'Jamhuri' => '12-01', + 'Christmas' => '12-25', + 'Boxing' => '12-26', ], $this->variableHolidays($year)); } @@ -32,8 +32,8 @@ protected function variableHolidays(int $year): array ->setTimezone('Africa/Nairobi'); return [ - "Good Friday" => $easter->subDays(2), - "Easter Monday" => $easter->addDay(), + 'Good Friday' => $easter->subDays(2), + 'Easter Monday' => $easter->addDay(), ]; } } From 81f1927b06a0991e21b0e335e597355498cae19c Mon Sep 17 00:00:00 2001 From: Kevin Bui Date: Sat, 27 Jan 2024 21:20:13 +1100 Subject: [PATCH 007/175] Add vietnamese holidays (#115) * add Vietnamese holidays according to the standard calendar. * include Vietnamese holidays according to Chinese Calendar. * refactor the a Chinese calendar trait. * update the Lunar New Year's Eve. * re-add snapshots for countries other than Vietnam. * use Vietnamese to name the holidays, English names commented. * For Vietnam, use the country code of vn instead of vi. * refactor according to PHPStan. * specify a type for the $timezone parameter. * Refactor according to PHPStan. * In Vietnam, a day before or after the Independence Day can be a public holiday. * work out some logics to calculate the extra day off for Independence Day. * add a few test cases to make sure the Lunar New Year holiday in Vietnam is calculated correctly. * Add test cases for the holiday of independence. * add doc blocks. * remove empty line. * rename an instance variable. * add two more days to the Lunar Year Year holiday. * refactor from Y/m/d to Y-m-d for Chinese Calendar. * add a few more test cases for Lunar New Year. * refactor the Lunar New Year holiday. * refactor and add a few more test cases. * add translations for vietnam --- lang/vietnam/en/holidays.json | 16 +++ src/Calendars/ChineseCalendar.php | 39 ++++++ src/Countries/Vietnam.php | 117 ++++++++++++++++++ .../it_can_calculate_vietnamese_holidays.snap | 54 ++++++++ tests/Countries/VietnamTest.php | 57 +++++++++ 5 files changed, 283 insertions(+) create mode 100644 lang/vietnam/en/holidays.json create mode 100644 src/Calendars/ChineseCalendar.php create mode 100644 src/Countries/Vietnam.php create mode 100644 tests/.pest/snapshots/Countries/VietnamTest/it_can_calculate_vietnamese_holidays.snap create mode 100644 tests/Countries/VietnamTest.php diff --git a/lang/vietnam/en/holidays.json b/lang/vietnam/en/holidays.json new file mode 100644 index 000000000..b074514b0 --- /dev/null +++ b/lang/vietnam/en/holidays.json @@ -0,0 +1,16 @@ +{ + "Tết Dương Lịch":"New Year's Day", + "Ngày Hai Mươi Chín Tết":"12-29 the previous year (in Chinese Calendar)", + "Ngày Ba Mươi Tết":"Lunar New Year's Eve (12-30 in Chinese Calendar)", + "Mùng Một Tết Âm Lịch":"Lunar New Year Day 1", + "Mùng Hai Tết Âm Lịch":"Lunar New Year Day 2", + "Mùng Ba Tết Âm Lịch":"Lunar New Year Day 3", + "Mùng Bốn Tết Âm Lịch":"Lunar New Year Day 4", + "Mùng Năm Tết Âm Lịch":"Lunar New Year Day 5", + "Ngày Giỗ Tổ Hùng Vương":"Hung Kings' Festival", + "Ngày Giải Phóng Miền Nam, Thống Nhất Đất Nước":"Day of Southern Liberation and National Reunification", + "Ngày Quốc Tế Lao Động":"Labour Day", + "Ngày Trước Quốc Khánh":"The Day Before Independence Day", + "Ngày Quốc Khánh":"Independence Day", + "Ngày Sau Quốc Khánh":"The Day After Independence Day" +} \ No newline at end of file diff --git a/src/Calendars/ChineseCalendar.php b/src/Calendars/ChineseCalendar.php new file mode 100644 index 000000000..5ce9996bb --- /dev/null +++ b/src/Calendars/ChineseCalendar.php @@ -0,0 +1,39 @@ +asianTimezone = $asianTimezone; + + return $this; + } + + protected function chineseToGregorianDate(string $input, int $year): CarbonImmutable + { + $timestamp = (int) $this->getFormatter()->parse($year . '-' . $input); + + return (new CarbonImmutable()) + ->setTimeStamp($timestamp) + ->setTimezone(new DateTimeZone($this->asianTimezone)); + } + + protected function getFormatter(): IntlDateFormatter + { + return new IntlDateFormatter( + locale: 'zh-CN@calendar=chinese', + dateType: IntlDateFormatter::SHORT, + timeType: IntlDateFormatter::NONE, + timezone: $this->asianTimezone, + calendar: IntlDateFormatter::TRADITIONAL + ); + } +} \ No newline at end of file diff --git a/src/Countries/Vietnam.php b/src/Countries/Vietnam.php new file mode 100644 index 000000000..e99f75919 --- /dev/null +++ b/src/Countries/Vietnam.php @@ -0,0 +1,117 @@ + '01-01', + // Day of Southern Liberation and National Reunification + 'Ngày Giải Phóng Miền Nam, Thống Nhất Đất Nước' => '04-30', + // Labour Day + 'Ngày Quốc Tế Lao Động' => '05-01', + // Independence Day + 'Ngày Quốc Khánh' => '09-02', + ], $this->variableHolidays($year)); + } + + /** @return array */ + protected function variableHolidays(int $year): array + { + $this->setTimezoneForChineseCalendar('Asia/Ho_Chi_Minh'); + + return array_merge( + $this->getHungKingsFestival($year), + $this->getLunarNewYearHoliday($year), + $this->getTheExtraDayForIndependenceDay($year), + ); + } + + /** @return array */ + protected function getHungKingsFestival(int $year): array + { + return [ + // Hung Kings' Festival + 'Ngày Giỗ Tổ Hùng Vương' => $this->chineseToGregorianDate('03-10', $year), + ]; + } + + /** @return array */ + protected function getLunarNewYearHoliday(int $year): array + { + $firstOfJanInChineseCalendar = $this->chineseToGregorianDate('01-01', $year); + + return [ + // 12-29 the previous year (in Chinese Calendar) + 'Ngày Hai Mươi Chín Tết' => $firstOfJanInChineseCalendar->subDays(2), + // Lunar New Year's Eve (12-30 in Chinese Calendar) + 'Ngày Ba Mươi Tết' => $firstOfJanInChineseCalendar->subDay(), + // Lunar New Year Day 1 + 'Mùng Một Tết Âm Lịch' => $firstOfJanInChineseCalendar, + // Lunar New Year Day 2 + 'Mùng Hai Tết Âm Lịch' => $firstOfJanInChineseCalendar->addDay(), + // Lunar New Year Day 3 + 'Mùng Ba Tết Âm Lịch' => $firstOfJanInChineseCalendar->addDays(2), + // Lunar New Year Day 4 + 'Mùng Bốn Tết Âm Lịch' => $firstOfJanInChineseCalendar->addDays(3), + // Lunar New Year Day 5 + 'Mùng Năm Tết Âm Lịch' => $firstOfJanInChineseCalendar->addDays(4), + ]; + } + + /** @return array */ + protected function getTheExtraDayForIndependenceDay(int $year): array + { + if ($year < 2021) { + return []; + } + + $independenceDay = CarbonImmutable::parse("$year-09-02") + ->setTimeZone("Asia/Ho_Chi_Minh"); + + if ($independenceDay->dayOfWeek == CarbonImmutable::MONDAY) { + return ['Ngày Sau Quốc Khánh' => $independenceDay->addDay()]; + } + + if ($independenceDay->dayOfWeek == CarbonImmutable::TUESDAY) { + return ['Ngày Trước Quốc Khánh' => $independenceDay->subDay()]; + } + + if ($independenceDay->dayOfWeek == CarbonImmutable::WEDNESDAY) { + return ['Ngày Trước Quốc Khánh' => $independenceDay->subDay()]; + } + + if ($independenceDay->dayOfWeek == CarbonImmutable::THURSDAY) { + return ['Ngày Sau Quốc Khánh' => $independenceDay->addDay()]; + } + + if ($independenceDay->dayOfWeek == CarbonImmutable::FRIDAY) { + return ['Ngày Trước Quốc Khánh' => $independenceDay->subDay()]; + } + + if ($independenceDay->dayOfWeek == CarbonImmutable::SATURDAY) { + return ['Ngày Trước Quốc Khánh' => $independenceDay->subDay()]; + } + + if ($independenceDay->dayOfWeek == CarbonImmutable::SUNDAY) { + return ['Ngày Sau Quốc Khánh' => $independenceDay->addDays(2)]; + } + + return []; + } +} diff --git a/tests/.pest/snapshots/Countries/VietnamTest/it_can_calculate_vietnamese_holidays.snap b/tests/.pest/snapshots/Countries/VietnamTest/it_can_calculate_vietnamese_holidays.snap new file mode 100644 index 000000000..3b7cc36f9 --- /dev/null +++ b/tests/.pest/snapshots/Countries/VietnamTest/it_can_calculate_vietnamese_holidays.snap @@ -0,0 +1,54 @@ +[ + { + "name": "T\u1ebft D\u01b0\u01a1ng L\u1ecbch", + "date": "2024-01-01" + }, + { + "name": "Ng\u00e0y Hai M\u01b0\u01a1i Ch\u00edn T\u1ebft", + "date": "2024-02-08" + }, + { + "name": "Ng\u00e0y Ba M\u01b0\u01a1i T\u1ebft", + "date": "2024-02-09" + }, + { + "name": "M\u00f9ng M\u1ed9t T\u1ebft \u00c2m L\u1ecbch", + "date": "2024-02-10" + }, + { + "name": "M\u00f9ng Hai T\u1ebft \u00c2m L\u1ecbch", + "date": "2024-02-11" + }, + { + "name": "M\u00f9ng Ba T\u1ebft \u00c2m L\u1ecbch", + "date": "2024-02-12" + }, + { + "name": "M\u00f9ng B\u1ed1n T\u1ebft \u00c2m L\u1ecbch", + "date": "2024-02-13" + }, + { + "name": "M\u00f9ng N\u0103m T\u1ebft \u00c2m L\u1ecbch", + "date": "2024-02-14" + }, + { + "name": "Ng\u00e0y Gi\u1ed7 T\u1ed5 H\u00f9ng V\u01b0\u01a1ng", + "date": "2024-04-18" + }, + { + "name": "Ng\u00e0y Gi\u1ea3i Ph\u00f3ng Mi\u1ec1n Nam, Th\u1ed1ng Nh\u1ea5t \u0110\u1ea5t N\u01b0\u1edbc", + "date": "2024-04-30" + }, + { + "name": "Ng\u00e0y Qu\u1ed1c T\u1ebf Lao \u0110\u1ed9ng", + "date": "2024-05-01" + }, + { + "name": "Ng\u00e0y Qu\u1ed1c Kh\u00e1nh", + "date": "2024-09-02" + }, + { + "name": "Ng\u00e0y Sau Qu\u1ed1c Kh\u00e1nh", + "date": "2024-09-03" + } +] \ No newline at end of file diff --git a/tests/Countries/VietnamTest.php b/tests/Countries/VietnamTest.php new file mode 100644 index 000000000..edb13028d --- /dev/null +++ b/tests/Countries/VietnamTest.php @@ -0,0 +1,57 @@ +get(); + + expect($holidays) + ->toBeArray() + ->not()->toBeEmpty(); + + expect(formatDates($holidays))->toMatchSnapshot(); +}); + +it('can calculate the Lunar New Year holiday', function ($year, $expectedHoliday) { + CarbonImmutable::setTestNowAndTimezone("{$year}-01-01", 'Asia/Ho_Chi_Minh'); + + $holidays = Holidays::for(country: 'vn')->get(); + + expect($holidays) + ->toBeArray() + ->not()->toBeEmpty(); + + $lunarNewYearHoliday = array_map(fn ($date) => $date['date'], formatDates($holidays)); + + expect($lunarNewYearHoliday)->toContain(...$expectedHoliday); +})->with([ + ['year' => 2023, 'expected_holiday' => ['2023-01-20', '2023-01-21', '2023-01-22', '2023-01-23', '2023-01-24', '2023-01-25', '2023-01-26']], + ['year' => 2022, 'expected_holiday' => ['2022-01-30', '2022-01-31', '2022-02-01', '2022-02-02', '2022-02-03', '2022-02-04', '2022-02-05']], + ['year' => 2021, 'expected_holiday' => ['2021-02-10', '2021-02-11', '2021-02-12', '2021-02-13', '2021-02-14', '2021-02-15', '2021-02-16']], + ['year' => 2020, 'expected_holiday' => ['2020-01-23', '2020-01-24', '2020-01-25', '2020-01-26', '2020-01-27', '2020-01-28', '2020-01-29']], + ['year' => 2019, 'expected_holiday' => ['2019-02-03', '2019-02-04', '2019-02-05', '2019-02-06', '2019-02-07', '2019-02-08', '2019-02-08']], +]); + +it('can calculate the holiday of independence', function ($year, $expectedHoliday) { + CarbonImmutable::setTestNowAndTimezone("{$year}-01-01", 'Asia/Ho_Chi_Minh'); + + $holidays = Holidays::for(country: 'vn')->get(); + + expect($holidays) + ->toBeArray() + ->not()->toBeEmpty(); + + $dates = array_map(fn ($date) => $date['date'], formatDates($holidays)); + + expect($dates)->toContain(...$expectedHoliday); +})->with([ + ['year' => 2023, 'expected_holiday' => ['2023-09-01', '2023-09-02']], + ['year' => 2022, 'expected_holiday' => ['2022-09-01', '2022-09-02']], + ['year' => 2021, 'expected_holiday' => ['2021-09-02', '2021-09-03']], +]); From 1ecaacbd7a1be274471f59db1fc5a6e11aaa7a21 Mon Sep 17 00:00:00 2001 From: Nielsvanpach Date: Sat, 27 Jan 2024 10:20:32 +0000 Subject: [PATCH 008/175] Fix styling --- src/Calendars/ChineseCalendar.php | 6 +++--- src/Countries/Vietnam.php | 6 ++---- tests/Countries/VietnamTest.php | 1 - 3 files changed, 5 insertions(+), 8 deletions(-) diff --git a/src/Calendars/ChineseCalendar.php b/src/Calendars/ChineseCalendar.php index 5ce9996bb..a19f4d019 100644 --- a/src/Calendars/ChineseCalendar.php +++ b/src/Calendars/ChineseCalendar.php @@ -19,8 +19,8 @@ public function setTimezoneForChineseCalendar(string $asianTimezone): static protected function chineseToGregorianDate(string $input, int $year): CarbonImmutable { - $timestamp = (int) $this->getFormatter()->parse($year . '-' . $input); - + $timestamp = (int) $this->getFormatter()->parse($year.'-'.$input); + return (new CarbonImmutable()) ->setTimeStamp($timestamp) ->setTimezone(new DateTimeZone($this->asianTimezone)); @@ -36,4 +36,4 @@ protected function getFormatter(): IntlDateFormatter calendar: IntlDateFormatter::TRADITIONAL ); } -} \ No newline at end of file +} diff --git a/src/Countries/Vietnam.php b/src/Countries/Vietnam.php index e99f75919..8f1c9841d 100644 --- a/src/Countries/Vietnam.php +++ b/src/Countries/Vietnam.php @@ -3,8 +3,6 @@ namespace Spatie\Holidays\Countries; use Carbon\CarbonImmutable; -use DateTimeZone; -use IntlDateFormatter; use Spatie\Holidays\Calendars\ChineseCalendar; class Vietnam extends Country @@ -54,7 +52,7 @@ protected function getHungKingsFestival(int $year): array /** @return array */ protected function getLunarNewYearHoliday(int $year): array { - $firstOfJanInChineseCalendar = $this->chineseToGregorianDate('01-01', $year); + $firstOfJanInChineseCalendar = $this->chineseToGregorianDate('01-01', $year); return [ // 12-29 the previous year (in Chinese Calendar) @@ -82,7 +80,7 @@ protected function getTheExtraDayForIndependenceDay(int $year): array } $independenceDay = CarbonImmutable::parse("$year-09-02") - ->setTimeZone("Asia/Ho_Chi_Minh"); + ->setTimeZone('Asia/Ho_Chi_Minh'); if ($independenceDay->dayOfWeek == CarbonImmutable::MONDAY) { return ['Ngày Sau Quốc Khánh' => $independenceDay->addDay()]; diff --git a/tests/Countries/VietnamTest.php b/tests/Countries/VietnamTest.php index edb13028d..d05a4ea4c 100644 --- a/tests/Countries/VietnamTest.php +++ b/tests/Countries/VietnamTest.php @@ -3,7 +3,6 @@ namespace Spatie\Holidays\Tests\Countries; use Carbon\CarbonImmutable; -use Spatie\Holidays\Countries\Vietnam; use Spatie\Holidays\Holidays; it('can calculate vietnamese holidays', function () { From 7e912ad1192c4d9df97fd1921417609bc45ac915 Mon Sep 17 00:00:00 2001 From: Arne Breitsprecher Date: Sat, 27 Jan 2024 11:20:44 +0100 Subject: [PATCH 009/175] Germany: Adding local for EN, FR, NL (#183) * Adding germany local for EN, FR, NL * Adding test for local support * Update tests/Countries/GermanyTest.php --------- Co-authored-by: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> --- lang/germany/en/holidays.json | 21 +++++++++++++++++++++ lang/germany/fr/holidays.json | 21 +++++++++++++++++++++ lang/germany/nl/holidays.json | 21 +++++++++++++++++++++ tests/Countries/GermanyTest.php | 15 +++++++++++++++ 4 files changed, 78 insertions(+) create mode 100644 lang/germany/en/holidays.json create mode 100644 lang/germany/fr/holidays.json create mode 100644 lang/germany/nl/holidays.json diff --git a/lang/germany/en/holidays.json b/lang/germany/en/holidays.json new file mode 100644 index 000000000..4202f709f --- /dev/null +++ b/lang/germany/en/holidays.json @@ -0,0 +1,21 @@ +{ + "Neujahr": "New Year", + "Heilige Drei Könige": "Epiphany", + "Tag der Arbeit": "Labour Day", + "Himmelfahrt": "Ascension Day", + "Pfingstmontag": "Whit Monday", + "Pfingstsonntag": "Whit Sunday", + "Fronleichnam": "Corpus Christi", + "Mariä Himmelfahrt": "Assumption of Mary", + "Tag der Deutschen Einheit": "German Unity Day", + "Reformationstag": "Reformation Day", + "Allerheiligen": "All Saints' Day", + "Buß- und Bettag": "Repentance and Prayer Day", + "1. Weihnachtstag": "Christmas Day", + "2. Weihnachtstag": "Second Day of Christmas", + "Ostermontag": "Easter Monday", + "Karfreitag": "Good Friday", + "Ostersonntag": "Easter Sunday", + "Internationaler Frauentag": "International Women's Day", + "Weltkindertag": "World Children's Day" +} \ No newline at end of file diff --git a/lang/germany/fr/holidays.json b/lang/germany/fr/holidays.json new file mode 100644 index 000000000..e260be7f5 --- /dev/null +++ b/lang/germany/fr/holidays.json @@ -0,0 +1,21 @@ +{ + "Neujahr": "Jour de l'An", + "Heilige Drei Könige": "Épiphanie", + "Tag der Arbeit": "Fête du Travail", + "Himmelfahrt": "Ascension", + "Pfingstmontag": "Lundi de Pentecôte", + "Pfingstsonntag": "Dimanche de Pentecôte", + "Fronleichnam": "Fête-Dieu", + "Mariä Himmelfahrt": "Assomption", + "Tag der Deutschen Einheit": "Jour de l'Unité allemande", + "Reformationstag": "Fête de la Réformation", + "Allerheiligen": "Toussaint", + "Buß- und Bettag": "Jour de pénitence et de prières", + "1. Weihnachtstag": "Noël", + "2. Weihnachtstag": "Lendemain de Noël", + "Ostermontag": "Lundi de Pâques", + "Karfreitag": "Vendredi Saint", + "Ostersonntag": "Dimanche de Pâques", + "Internationaler Frauentag": "Journée internationale des femmes", + "Weltkindertag": "Journée de l'enfance" +} \ No newline at end of file diff --git a/lang/germany/nl/holidays.json b/lang/germany/nl/holidays.json new file mode 100644 index 000000000..98f8a17cb --- /dev/null +++ b/lang/germany/nl/holidays.json @@ -0,0 +1,21 @@ +{ + "Neujahr": "Nieuwjaar", + "Heilige Drei Könige": "Driekoningen", + "Tag der Arbeit": "Dag van de Arbeid", + "Himmelfahrt": "Hemelvaart", + "Pfingstmontag": "Tweede pinksterdag", + "Pfingstsonntag": "Eerste Pinksterdag", + "Fronleichnam": "Sacramentsdag", + "Mariä Himmelfahrt": "Mariahemelvaart", + "Tag der Deutschen Einheit": "Dag van de Duitse eenheid", + "Reformationstag": "Hervormingsdag", + "Allerheiligen": "Allerheiligen", + "Buß- und Bettag": "Boete- en Biddag", + "1. Weihnachtstag": "Eerste kerstdag", + "2. Weihnachtstag": "Tweede kerstdag", + "Ostermontag": "Tweede paasdag", + "Karfreitag": "Goede Vrijdag", + "Ostersonntag": "Eerste paasdag", + "Internationaler Frauentag": "Internationale vrouwendag", + "Weltkindertag": "Kinderdag" +} \ No newline at end of file diff --git a/tests/Countries/GermanyTest.php b/tests/Countries/GermanyTest.php index b6a4f710f..9ae4e1489 100644 --- a/tests/Countries/GermanyTest.php +++ b/tests/Countries/GermanyTest.php @@ -4,6 +4,7 @@ use Carbon\CarbonImmutable; use Spatie\Holidays\Countries\Germany; +use Spatie\Holidays\Exceptions\InvalidLocale; use Spatie\Holidays\Holidays; it('can calculate german holidays', function () { @@ -78,3 +79,17 @@ ['SH', 10], ['TH', 11]] ); + +it('can calculate german holidays in local', function (string $locale, string $newYearsDayName) { + CarbonImmutable::setTestNow('2024-01-01'); + $result = Holidays::for(country: 'de', year: 2024, locale: $locale)->get(); + + expect($result)->toBeArray(); + expect($result[0]['name'])->toBe($newYearsDayName); +})->with( + [ + ['en','New Year'], + ['nl','Nieuwjaar'], + ['fr','Jour de l\'An'] + ] +); \ No newline at end of file From 57ff3b24e279c239998e8e7c1c28571bd89bbceb Mon Sep 17 00:00:00 2001 From: Nielsvanpach Date: Sat, 27 Jan 2024 10:21:03 +0000 Subject: [PATCH 010/175] Fix styling --- tests/Countries/GermanyTest.php | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/tests/Countries/GermanyTest.php b/tests/Countries/GermanyTest.php index 9ae4e1489..24f2aa199 100644 --- a/tests/Countries/GermanyTest.php +++ b/tests/Countries/GermanyTest.php @@ -4,7 +4,6 @@ use Carbon\CarbonImmutable; use Spatie\Holidays\Countries\Germany; -use Spatie\Holidays\Exceptions\InvalidLocale; use Spatie\Holidays\Holidays; it('can calculate german holidays', function () { @@ -88,8 +87,8 @@ expect($result[0]['name'])->toBe($newYearsDayName); })->with( [ - ['en','New Year'], - ['nl','Nieuwjaar'], - ['fr','Jour de l\'An'] + ['en', 'New Year'], + ['nl', 'Nieuwjaar'], + ['fr', 'Jour de l\'An'], ] -); \ No newline at end of file +); From 9bb7bb2d487f75d56ac00ed29d0e5e2f875d6e61 Mon Sep 17 00:00:00 2001 From: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> Date: Sat, 27 Jan 2024 11:26:45 +0100 Subject: [PATCH 011/175] ChineseCalendar changes --- src/Calendars/ChineseCalendar.php | 10 +++++----- src/Countries/Vietnam.php | 17 +++++++++-------- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/src/Calendars/ChineseCalendar.php b/src/Calendars/ChineseCalendar.php index a19f4d019..689b26874 100644 --- a/src/Calendars/ChineseCalendar.php +++ b/src/Calendars/ChineseCalendar.php @@ -8,11 +8,11 @@ trait ChineseCalendar { - protected string $asianTimezone = 'Asia/Shanghai'; + protected string $chineseCalendarTimezone = 'Asia/Shanghai'; - public function setTimezoneForChineseCalendar(string $asianTimezone): static + public function setChineseCalendarTimezone(string $chineseCalendarTimezone): static { - $this->asianTimezone = $asianTimezone; + $this->chineseCalendarTimezone = $chineseCalendarTimezone; return $this; } @@ -23,7 +23,7 @@ protected function chineseToGregorianDate(string $input, int $year): CarbonImmut return (new CarbonImmutable()) ->setTimeStamp($timestamp) - ->setTimezone(new DateTimeZone($this->asianTimezone)); + ->setTimezone(new DateTimeZone($this->chineseCalendarTimezone)); } protected function getFormatter(): IntlDateFormatter @@ -32,7 +32,7 @@ protected function getFormatter(): IntlDateFormatter locale: 'zh-CN@calendar=chinese', dateType: IntlDateFormatter::SHORT, timeType: IntlDateFormatter::NONE, - timezone: $this->asianTimezone, + timezone: $this->chineseCalendarTimezone, calendar: IntlDateFormatter::TRADITIONAL ); } diff --git a/src/Countries/Vietnam.php b/src/Countries/Vietnam.php index 8f1c9841d..76ae6f1b5 100644 --- a/src/Countries/Vietnam.php +++ b/src/Countries/Vietnam.php @@ -3,6 +3,7 @@ namespace Spatie\Holidays\Countries; use Carbon\CarbonImmutable; +use Carbon\CarbonInterface; use Spatie\Holidays\Calendars\ChineseCalendar; class Vietnam extends Country @@ -31,7 +32,7 @@ protected function allHolidays(int $year): array /** @return array */ protected function variableHolidays(int $year): array { - $this->setTimezoneForChineseCalendar('Asia/Ho_Chi_Minh'); + $this->setChineseCalendarTimezone('Asia/Ho_Chi_Minh'); return array_merge( $this->getHungKingsFestival($year), @@ -82,31 +83,31 @@ protected function getTheExtraDayForIndependenceDay(int $year): array $independenceDay = CarbonImmutable::parse("$year-09-02") ->setTimeZone('Asia/Ho_Chi_Minh'); - if ($independenceDay->dayOfWeek == CarbonImmutable::MONDAY) { + if ($independenceDay->dayOfWeek === CarbonInterface::MONDAY) { return ['Ngày Sau Quốc Khánh' => $independenceDay->addDay()]; } - if ($independenceDay->dayOfWeek == CarbonImmutable::TUESDAY) { + if ($independenceDay->dayOfWeek === CarbonInterface::TUESDAY) { return ['Ngày Trước Quốc Khánh' => $independenceDay->subDay()]; } - if ($independenceDay->dayOfWeek == CarbonImmutable::WEDNESDAY) { + if ($independenceDay->dayOfWeek === CarbonInterface::WEDNESDAY) { return ['Ngày Trước Quốc Khánh' => $independenceDay->subDay()]; } - if ($independenceDay->dayOfWeek == CarbonImmutable::THURSDAY) { + if ($independenceDay->dayOfWeek === CarbonInterface::THURSDAY) { return ['Ngày Sau Quốc Khánh' => $independenceDay->addDay()]; } - if ($independenceDay->dayOfWeek == CarbonImmutable::FRIDAY) { + if ($independenceDay->dayOfWeek === CarbonInterface::FRIDAY) { return ['Ngày Trước Quốc Khánh' => $independenceDay->subDay()]; } - if ($independenceDay->dayOfWeek == CarbonImmutable::SATURDAY) { + if ($independenceDay->dayOfWeek === CarbonInterface::SATURDAY) { return ['Ngày Trước Quốc Khánh' => $independenceDay->subDay()]; } - if ($independenceDay->dayOfWeek == CarbonImmutable::SUNDAY) { + if ($independenceDay->dayOfWeek === CarbonInterface::SUNDAY) { return ['Ngày Sau Quốc Khánh' => $independenceDay->addDays(2)]; } From 40048aa869ee512531a542b780ff6b18c99febd9 Mon Sep 17 00:00:00 2001 From: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> Date: Sat, 27 Jan 2024 11:29:53 +0100 Subject: [PATCH 012/175] fix failing tests --- tests/Countries/VietnamTest.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/Countries/VietnamTest.php b/tests/Countries/VietnamTest.php index d05a4ea4c..a83eb01fc 100644 --- a/tests/Countries/VietnamTest.php +++ b/tests/Countries/VietnamTest.php @@ -6,7 +6,7 @@ use Spatie\Holidays\Holidays; it('can calculate vietnamese holidays', function () { - CarbonImmutable::setTestNowAndTimezone('2024-01-01', 'Asia/Ho_Chi_Minh'); + CarbonImmutable::setTestNow('2024-01-01'); $holidays = Holidays::for(country: 'vn')->get(); @@ -18,7 +18,7 @@ }); it('can calculate the Lunar New Year holiday', function ($year, $expectedHoliday) { - CarbonImmutable::setTestNowAndTimezone("{$year}-01-01", 'Asia/Ho_Chi_Minh'); + CarbonImmutable::setTestNow("{$year}-01-01"); $holidays = Holidays::for(country: 'vn')->get(); @@ -38,7 +38,7 @@ ]); it('can calculate the holiday of independence', function ($year, $expectedHoliday) { - CarbonImmutable::setTestNowAndTimezone("{$year}-01-01", 'Asia/Ho_Chi_Minh'); + CarbonImmutable::setTestNow("{$year}-01-01"); $holidays = Holidays::for(country: 'vn')->get(); From 3b1c0bd9384bef35a050e75f7345a2808323934f Mon Sep 17 00:00:00 2001 From: Takeshi Yu Date: Sat, 27 Jan 2024 18:57:08 +0800 Subject: [PATCH 013/175] Support for Taiwan holidays (#124) * support Taiwan holidays * Refactor lunarCalendar method to handle parsing errors * Update variableHolidays to correctly return converted dates * Refactor variableHolidays to combine array_map and array_filter * use the Taiwanese language to label the holiday --------- Co-authored-by: Takeshi Yu --- composer.json | 4 +- src/Countries/Taiwan.php | 63 +++++++++++++++++++ .../it_can_calculate_taiwan_holidays.snap | 38 +++++++++++ tests/Countries/TaiwanTest.php | 19 ++++++ 4 files changed, 122 insertions(+), 2 deletions(-) create mode 100644 src/Countries/Taiwan.php create mode 100644 tests/.pest/snapshots/Countries/TaiwanTest/it_can_calculate_taiwan_holidays.snap create mode 100644 tests/Countries/TaiwanTest.php diff --git a/composer.json b/composer.json index 8e0f585dc..d51ff2f1e 100644 --- a/composer.json +++ b/composer.json @@ -21,8 +21,8 @@ ], "require": { "php": "^8.1", - "nesbot/carbon": "^2.72.1", - "ext-calendar": "*" + "ext-intl": "*", + "nesbot/carbon": "^2.72.1" }, "require-dev": { "laravel/pint": "^1.0", diff --git a/src/Countries/Taiwan.php b/src/Countries/Taiwan.php new file mode 100644 index 000000000..804c06424 --- /dev/null +++ b/src/Countries/Taiwan.php @@ -0,0 +1,63 @@ + '01-01', + '228和平紀念日' => '02-28', + '兒童節' => '04-04', + '雙十國慶' => '10-10', + ], $this->variableHolidays($year)); + } + + /** @return array */ + protected function variableHolidays(int $year): array + { + return array_filter(array_map(fn ($date) => $this->lunarCalendar($date, $year), [ + '農曆春節-正月初一' => '01-01', + '農曆春節-正月初二' => '01-02', + '農曆春節-正月初三' => '01-03', + '端午節' => '05-05', + '中秋節' => '08-15', + ])); + } + + protected function lunarCalendar(string $input, int $year): ?string + { + $formatter = new IntlDateFormatter( + locale: 'zh-TW@calendar=chinese', + dateType: IntlDateFormatter::SHORT, + timeType: IntlDateFormatter::NONE, + timezone: $this->timezone, + calendar: IntlDateFormatter::TRADITIONAL + ); + + $lunarDateStr = $year . '-' . $input; + $parsedTimestamp = $formatter->parse($lunarDateStr); + + if ($parsedTimestamp === false) { + return null; + } + + $dateTime = new DateTime; + $dateTime->setTimestamp($parsedTimestamp); + $dateTime->setTimezone(new DateTimeZone($this->timezone)); + + return $dateTime->format('m-d'); + } +} diff --git a/tests/.pest/snapshots/Countries/TaiwanTest/it_can_calculate_taiwan_holidays.snap b/tests/.pest/snapshots/Countries/TaiwanTest/it_can_calculate_taiwan_holidays.snap new file mode 100644 index 000000000..637abf2c6 --- /dev/null +++ b/tests/.pest/snapshots/Countries/TaiwanTest/it_can_calculate_taiwan_holidays.snap @@ -0,0 +1,38 @@ +[ + { + "name": "\u5143\u65e6", + "date": "2024-01-01" + }, + { + "name": "\u8fb2\u66c6\u6625\u7bc0-\u6b63\u6708\u521d\u4e00", + "date": "2024-02-10" + }, + { + "name": "\u8fb2\u66c6\u6625\u7bc0-\u6b63\u6708\u521d\u4e8c", + "date": "2024-02-11" + }, + { + "name": "\u8fb2\u66c6\u6625\u7bc0-\u6b63\u6708\u521d\u4e09", + "date": "2024-02-12" + }, + { + "name": "228\u548c\u5e73\u7d00\u5ff5\u65e5", + "date": "2024-02-28" + }, + { + "name": "\u5152\u7ae5\u7bc0", + "date": "2024-04-04" + }, + { + "name": "\u7aef\u5348\u7bc0", + "date": "2024-06-10" + }, + { + "name": "\u4e2d\u79cb\u7bc0", + "date": "2024-09-17" + }, + { + "name": "\u96d9\u5341\u570b\u6176", + "date": "2024-10-10" + } +] \ No newline at end of file diff --git a/tests/Countries/TaiwanTest.php b/tests/Countries/TaiwanTest.php new file mode 100644 index 000000000..75c7b6906 --- /dev/null +++ b/tests/Countries/TaiwanTest.php @@ -0,0 +1,19 @@ +get(); + + expect($holidays) + ->toBeArray() + ->not()->toBeEmpty(); + + expect(formatDates($holidays))->toMatchSnapshot(); + +}); From d04df737ab7ed0e6c24019b042060f87ccba546c Mon Sep 17 00:00:00 2001 From: Nielsvanpach Date: Sat, 27 Jan 2024 10:57:27 +0000 Subject: [PATCH 014/175] Fix styling --- src/Countries/Taiwan.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Countries/Taiwan.php b/src/Countries/Taiwan.php index 804c06424..762c2c892 100644 --- a/src/Countries/Taiwan.php +++ b/src/Countries/Taiwan.php @@ -47,7 +47,7 @@ protected function lunarCalendar(string $input, int $year): ?string calendar: IntlDateFormatter::TRADITIONAL ); - $lunarDateStr = $year . '-' . $input; + $lunarDateStr = $year.'-'.$input; $parsedTimestamp = $formatter->parse($lunarDateStr); if ($parsedTimestamp === false) { From a3d0e1f685deb1a91fc37f8bce79615255e2ba09 Mon Sep 17 00:00:00 2001 From: Arne Breitsprecher Date: Sat, 27 Jan 2024 16:45:52 +0100 Subject: [PATCH 015/175] Update region parameter in country constructor to a working example (#184) --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 508e61d5b..69240bf97 100644 --- a/README.md +++ b/README.md @@ -128,13 +128,13 @@ In case your country has specific rules for calculating holidays, for example region specific holidays, you can pass this to the constructor of your country class. ```php -$holidays = Holidays::for(Austria::make(region: 'de-bw'))->get(); +$holidays = Holidays::for(Germany::make(region: 'DE-BW'))->get(); ``` -The value, `de-bw`, will be passed to the region parameter of the constructor of a country. +The value, `DE-BW`, will be passed to the region parameter of the constructor of a country. ```php -class Austria extends Country +class Germany extends Country { protected function __construct( protected ?string $region = null, From 4c5ff964e6af9a7c53906ead846029d136618afd Mon Sep 17 00:00:00 2001 From: Martin Welte Date: Sat, 27 Jan 2024 16:48:37 +0100 Subject: [PATCH 016/175] Draft: Add Support for Switzerland (#49) * feat: add switzerland * test: add switzerland test * feat: add region and translation Support * test: update tests * test: add snapshots * feat: add translations for switzerland * feat: update switzerland to use global languages * test: update Switzerland tests --- lang/switzerland/de/holidays.json | 18 + lang/switzerland/fr/holidays.json | 18 + lang/switzerland/it/holidays.json | 18 + src/Countries/Switzerland.php | 316 ++++++++++++++++++ src/Exceptions/InvalidRegion.php | 18 + .../it_can_calculate_swiss_holidays.snap | 38 +++ ..._holidays_for_a_specified_region__zh_.snap | 38 +++ ..._translate_swiss_holidays_into_french.snap | 38 +++ ...translate_swiss_holidays_into_italian.snap | 38 +++ tests/Countries/SwitzerlandTest.php | 58 ++++ 10 files changed, 598 insertions(+) create mode 100644 lang/switzerland/de/holidays.json create mode 100644 lang/switzerland/fr/holidays.json create mode 100644 lang/switzerland/it/holidays.json create mode 100644 src/Countries/Switzerland.php create mode 100644 src/Exceptions/InvalidRegion.php create mode 100644 tests/.pest/snapshots/Countries/SwitzerlandTest/it_can_calculate_swiss_holidays.snap create mode 100644 tests/.pest/snapshots/Countries/SwitzerlandTest/it_can_get_swiss_holidays_for_a_specified_region__zh_.snap create mode 100644 tests/.pest/snapshots/Countries/SwitzerlandTest/it_can_translate_swiss_holidays_into_french.snap create mode 100644 tests/.pest/snapshots/Countries/SwitzerlandTest/it_can_translate_swiss_holidays_into_italian.snap create mode 100644 tests/Countries/SwitzerlandTest.php diff --git a/lang/switzerland/de/holidays.json b/lang/switzerland/de/holidays.json new file mode 100644 index 000000000..c294fd7b8 --- /dev/null +++ b/lang/switzerland/de/holidays.json @@ -0,0 +1,18 @@ +{ + "Neujahr": "Neujahr", + "Berchtoldstag": "Berchtoldstag", + "Heilige Drei Könige": "Heilige Drei Könige", + "Josefstag": "Josefstag", + "Karfreitag": "Karfreitag", + "Ostermontag": "Ostermontag", + "Tag der Arbeit": "Tag der Arbeit", + "Auffahrt": "Auffahrt", + "Pfingstmontag": "Pfingstmontag", + "Fronleichnam": "Fronleichnam", + "Bundesfeier": "Bundesfeier", + "Maria Himmelfahrt": "Maria Himmelfahrt", + "Allerheiligen": "Allerheiligen", + "Maria Empfängnis": "Maria Empfängnis", + "Weihnachtstag": "Weihnachtstag", + "Stephanstag": "Stephanstag" +} diff --git a/lang/switzerland/fr/holidays.json b/lang/switzerland/fr/holidays.json new file mode 100644 index 000000000..0fe65215c --- /dev/null +++ b/lang/switzerland/fr/holidays.json @@ -0,0 +1,18 @@ +{ + "Neujahr": "Nouvel An", + "Berchtoldstag": "Saint-Berthold", + "Heilige Drei Könige": "Épiphanie", + "Josefstag": "Saint-Joseph", + "Karfreitag": "Vendredi saint", + "Ostermontag": "Lundi de Pâques", + "Tag der Arbeit": "Fête du travail", + "Auffahrt": "Ascension", + "Pfingstmontag": "Lundi de Pentecôte", + "Fronleichnam": "Fête-Dieu", + "Bundesfeier": "Fête nationale", + "Maria Himmelfahrt": "Assomption", + "Allerheiligen": "Toussaint", + "Maria Empfängnis": "Immaculée Conception", + "Weihnachtstag": "Noël", + "Stephanstag": "Saint-Étienne" +} diff --git a/lang/switzerland/it/holidays.json b/lang/switzerland/it/holidays.json new file mode 100644 index 000000000..e7a30514c --- /dev/null +++ b/lang/switzerland/it/holidays.json @@ -0,0 +1,18 @@ +{ + "Neujahr": "Capodanno", + "Berchtoldstag": "San Silvestro", + "Heilige Drei Könige": "Epifania", + "Josefstag": "San Giuseppe", + "Karfreitag": "Venerdì Santo", + "Ostermontag": "Lunedì di Pasqua", + "Tag der Arbeit": "Festa del lavoro", + "Auffahrt": "Ascensione", + "Pfingstmontag": "Lunedì di Pentecoste", + "Fronleichnam": "Corpus Domini", + "Bundesfeier": "Festa nazionale", + "Maria Himmelfahrt": "Assunzione", + "Allerheiligen": "Ognissanti", + "Maria Empfängnis": "Immacolata Concezione", + "Weihnachtstag": "Natale", + "Stephanstag": "Santo Stefano" +} diff --git a/src/Countries/Switzerland.php b/src/Countries/Switzerland.php new file mode 100644 index 000000000..6259e3d9b --- /dev/null +++ b/src/Countries/Switzerland.php @@ -0,0 +1,316 @@ + + */ + public function regionalHolidays(int $year): array + { + if ($this->region === null) { + return []; + } + + $easter = $this->easter($year); + + $sharedHolidays = [ + self::NEW_YEAR => '01-01', + self::ASCENSION_DAY => $easter->addDays(39), + self::FEDERAL_CELEBRATION => '08-01', + self::CHRISTMAS_DAY => '12-25', + ]; + + $regionallyDifferentHolidays = [ + self::SECOND_JANUARY => '01-02', + self::THREE_KINGS => '01-06', + self::DAY_OF_JOSEPH => '03-19', + self::GOOD_FRIDAY => $easter->subDays(2), + self::EASTER_MONDAY => $easter->addDay(), + self::LABOR_DAY => '05-01', + self::WHIT_MONDAY => $easter->addDays(50), + self::CORPUS_CHRISTI => $easter->addDays(60), + self::ASSUMPTION_DAY => '08-15', + self::ALL_SAINTS_DAY => '11-01', + self::IMMACULATE_CONCEPTION => '12-08', + self::ST_STEPHENS_DAY => '12-26', + ]; + + $currentRegion = match($this->region) { + 'ch-ag' => [ + self::GOOD_FRIDAY, + ], + 'ch-ar' => [ + self::GOOD_FRIDAY, + self::EASTER_MONDAY, + self::WHIT_MONDAY, + self::ST_STEPHENS_DAY, + ], + 'ch-ai' => [ + self::GOOD_FRIDAY, + self::EASTER_MONDAY, + self::WHIT_MONDAY, + self::CORPUS_CHRISTI, + self::ST_STEPHENS_DAY, + ], + 'ch-bl' => [ + self::GOOD_FRIDAY, + self::EASTER_MONDAY, + self::LABOR_DAY, + self::WHIT_MONDAY, + self::ST_STEPHENS_DAY, + ], + 'ch-bs' => [ + self::GOOD_FRIDAY, + self::EASTER_MONDAY, + self::LABOR_DAY, + self::WHIT_MONDAY, + self::ST_STEPHENS_DAY, + ], + 'ch-be' => [ + self::SECOND_JANUARY, + self::GOOD_FRIDAY, + self::EASTER_MONDAY, + self::WHIT_MONDAY, + self::ST_STEPHENS_DAY, + ], + 'ch-fr' => [ + self::GOOD_FRIDAY, + ], + 'ch-ge' => [ + self::GOOD_FRIDAY, + self::EASTER_MONDAY, + self::WHIT_MONDAY, + ], + 'ch-gl' => [ + self::GOOD_FRIDAY, + self::EASTER_MONDAY, + self::ALL_SAINTS_DAY, + self::IMMACULATE_CONCEPTION, + ], + 'ch-gr' => [ + self::GOOD_FRIDAY, + self::EASTER_MONDAY, + self::WHIT_MONDAY, + self::ST_STEPHENS_DAY, + ], + 'ch-ju' => [ + self::GOOD_FRIDAY, + self::EASTER_MONDAY, + self::LABOR_DAY, + self::WHIT_MONDAY, + self::CORPUS_CHRISTI, + ], + 'ch-lu' => [ + self::GOOD_FRIDAY, + self::CORPUS_CHRISTI, + self::ASSUMPTION_DAY, + self::ALL_SAINTS_DAY, + self::ST_STEPHENS_DAY, + ], + 'ch-ne' => [ + self::GOOD_FRIDAY, + self::LABOR_DAY, + ], + 'ch-nw' => [ + self::GOOD_FRIDAY, + self::CORPUS_CHRISTI, + self::ASSUMPTION_DAY, + self::ALL_SAINTS_DAY, + self::IMMACULATE_CONCEPTION, + ], + 'ch-ow' => [ + self::GOOD_FRIDAY, + self::CORPUS_CHRISTI, + self::ASSUMPTION_DAY, + self::ALL_SAINTS_DAY, + self::IMMACULATE_CONCEPTION, + ], + 'ch-sh' => [ + self::GOOD_FRIDAY, + self::EASTER_MONDAY, + self::WHIT_MONDAY, + self::ST_STEPHENS_DAY, + ], + 'ch-sz' => [ + self::DAY_OF_JOSEPH, + self::GOOD_FRIDAY, + self::CORPUS_CHRISTI, + self::ASSUMPTION_DAY, + self::ALL_SAINTS_DAY, + ], + 'ch-so' => [ + self::GOOD_FRIDAY, + ], + 'ch-sg' => [ + self::GOOD_FRIDAY, + self::EASTER_MONDAY, + self::WHIT_MONDAY, + self::ALL_SAINTS_DAY, + self::ST_STEPHENS_DAY, + ], + 'ch-ti' => [ + self::THREE_KINGS, + self::EASTER_MONDAY, + self::ASSUMPTION_DAY, + self::ALL_SAINTS_DAY, + self::ST_STEPHENS_DAY, + ], + 'ch-tg' => [ + self::SECOND_JANUARY, + self::GOOD_FRIDAY, + self::EASTER_MONDAY, + self::WHIT_MONDAY, + self::ST_STEPHENS_DAY, + ], + 'ch-ur' => [ + self::GOOD_FRIDAY, + self::CORPUS_CHRISTI, + self::ASSUMPTION_DAY, + self::ALL_SAINTS_DAY, + self::IMMACULATE_CONCEPTION, + ], + 'ch-vd' => [ + self::SECOND_JANUARY, + self::GOOD_FRIDAY, + self::EASTER_MONDAY, + self::WHIT_MONDAY, + ], + 'ch-vs' => [ + self::DAY_OF_JOSEPH, + self::CORPUS_CHRISTI, + self::ASSUMPTION_DAY, + self::ALL_SAINTS_DAY, + self::IMMACULATE_CONCEPTION, + ], + 'ch-zg' => [ + self::GOOD_FRIDAY, + self::CORPUS_CHRISTI, + self::ASSUMPTION_DAY, + self::ALL_SAINTS_DAY, + self::IMMACULATE_CONCEPTION, + ], + 'ch-zh' => [ + self::GOOD_FRIDAY, + self::EASTER_MONDAY, + self::LABOR_DAY, + self::WHIT_MONDAY, + self::ST_STEPHENS_DAY, + ], + default => [], + }; + + $regionalHolidays = array_filter( + $regionallyDifferentHolidays, + fn ($key) => in_array($key, $currentRegion), + ARRAY_FILTER_USE_KEY + ); + + return array_merge($regionalHolidays, $sharedHolidays); + } + + protected function allHolidays(int $year): array + { + if($this->region !== null) { + return $this->regionalHolidays($year); + } + + return array_merge([ + self::NEW_YEAR => '01-01', + self::SECOND_JANUARY => '01-02', + self::FEDERAL_CELEBRATION => '08-01', + self::CHRISTMAS_DAY => '12-25', + self::ST_STEPHENS_DAY => '12-26', + ], $this->variableHolidays($year)); + } + + /** @return array */ + protected function variableHolidays(int $year): array + { + $easter = $this->easter($year); + + return [ + self::GOOD_FRIDAY => $easter->subDays(2), + self::EASTER_MONDAY => $easter->addDay(), + self::ASCENSION_DAY => $easter->addDays(39), + self::WHIT_MONDAY => $easter->addDays(50), + ]; + } +} diff --git a/src/Exceptions/InvalidRegion.php b/src/Exceptions/InvalidRegion.php new file mode 100644 index 000000000..7941fe2b5 --- /dev/null +++ b/src/Exceptions/InvalidRegion.php @@ -0,0 +1,18 @@ +get(); + + expect($holidays) + ->toBeArray() + ->not()->toBeEmpty(); + + expect(formatDates($holidays))->toMatchSnapshot(); +}); + +it('can get swiss holidays for a specified region (zh)', function() { + CarbonImmutable::setTestNowAndTimezone('2024-01-01'); + + $switzerland = new Switzerland(region: 'ch-zh'); + + $holidays = Holidays::for($switzerland)->get(); + + expect($holidays) + ->toBeArray() + ->not()->toBeEmpty(); + + expect(formatDates($holidays))->toMatchSnapshot(); +}); + +it('throws an error when an invalid region is given', function () { + new Switzerland('ch-xx'); +})->throws(InvalidRegion::class); + +it('can translate swiss holidays into french', function() { + $holidays = Holidays::for(country: 'ch', locale: 'fr', year: 2024)->get(); + + expect($holidays) + ->toBeArray() + ->not()->toBeEmpty(); + + expect(formatDates($holidays))->toMatchSnapshot(); +}); + +it('can translate swiss holidays into italian', function() { + $holidays = Holidays::for(country: 'ch', locale: 'it', year: 2024)->get(); + + expect($holidays) + ->toBeArray() + ->not()->toBeEmpty(); + + expect(formatDates($holidays))->toMatchSnapshot(); +}); From bd6d672ee3dbd307c04558756de4b33e7ca3e581 Mon Sep 17 00:00:00 2001 From: Nielsvanpach Date: Sat, 27 Jan 2024 15:48:59 +0000 Subject: [PATCH 017/175] Fix styling --- src/Countries/Switzerland.php | 6 +++--- tests/Countries/SwitzerlandTest.php | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Countries/Switzerland.php b/src/Countries/Switzerland.php index 6259e3d9b..94d52f8c9 100644 --- a/src/Countries/Switzerland.php +++ b/src/Countries/Switzerland.php @@ -70,7 +70,7 @@ class Switzerland extends Country public function __construct(protected ?string $region = null) { - if ($region !== null && !in_array($region, self::REGIONS)) { + if ($region !== null && ! in_array($region, self::REGIONS)) { throw InvalidRegion::unsupportedRegion($region); } } @@ -113,7 +113,7 @@ public function regionalHolidays(int $year): array self::ST_STEPHENS_DAY => '12-26', ]; - $currentRegion = match($this->region) { + $currentRegion = match ($this->region) { 'ch-ag' => [ self::GOOD_FRIDAY, ], @@ -288,7 +288,7 @@ public function regionalHolidays(int $year): array protected function allHolidays(int $year): array { - if($this->region !== null) { + if ($this->region !== null) { return $this->regionalHolidays($year); } diff --git a/tests/Countries/SwitzerlandTest.php b/tests/Countries/SwitzerlandTest.php index 1b3ba626a..0e4a97f41 100644 --- a/tests/Countries/SwitzerlandTest.php +++ b/tests/Countries/SwitzerlandTest.php @@ -19,7 +19,7 @@ expect(formatDates($holidays))->toMatchSnapshot(); }); -it('can get swiss holidays for a specified region (zh)', function() { +it('can get swiss holidays for a specified region (zh)', function () { CarbonImmutable::setTestNowAndTimezone('2024-01-01'); $switzerland = new Switzerland(region: 'ch-zh'); @@ -37,7 +37,7 @@ new Switzerland('ch-xx'); })->throws(InvalidRegion::class); -it('can translate swiss holidays into french', function() { +it('can translate swiss holidays into french', function () { $holidays = Holidays::for(country: 'ch', locale: 'fr', year: 2024)->get(); expect($holidays) @@ -47,7 +47,7 @@ expect(formatDates($holidays))->toMatchSnapshot(); }); -it('can translate swiss holidays into italian', function() { +it('can translate swiss holidays into italian', function () { $holidays = Holidays::for(country: 'ch', locale: 'it', year: 2024)->get(); expect($holidays) From db113b099a332fe21037118d1c8ee32303d0fdb4 Mon Sep 17 00:00:00 2001 From: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> Date: Sat, 27 Jan 2024 16:49:40 +0100 Subject: [PATCH 018/175] undo code styling on PRs --- .github/workflows/fix-php-code-style-issues.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/fix-php-code-style-issues.yml b/.github/workflows/fix-php-code-style-issues.yml index 99b82e963..30e62c774 100644 --- a/.github/workflows/fix-php-code-style-issues.yml +++ b/.github/workflows/fix-php-code-style-issues.yml @@ -1,6 +1,6 @@ name: Fix PHP code style issues -on: [push, pull_request] +on: [push] permissions: contents: write From d6701a68bcbab45098dd17cd87590b2fd7bd44a7 Mon Sep 17 00:00:00 2001 From: Alpha Olomi Date: Sat, 27 Jan 2024 18:59:52 +0300 Subject: [PATCH 019/175] Add Tanzania national and religious holiday (#98) * Add Tanzania national and religious holiday Co-Authored-By: Michael Omakei <48096457+omakei@users.noreply.github.com> * feat: revise religious Holidays Co-Authored-By: Michael Omakei <48096457+omakei@users.noreply.github.com> --------- Co-authored-by: Michael Omakei <48096457+omakei@users.noreply.github.com> --- src/Countries/Tanzania.php | 64 +++++++++++++++++++ .../it_can_calculate_tanzania_holidays.snap | 54 ++++++++++++++++ tests/Countries/TanzaniaTest.php | 18 ++++++ 3 files changed, 136 insertions(+) create mode 100644 src/Countries/Tanzania.php create mode 100644 tests/.pest/snapshots/Countries/TanzaniaTest/it_can_calculate_tanzania_holidays.snap create mode 100644 tests/Countries/TanzaniaTest.php diff --git a/src/Countries/Tanzania.php b/src/Countries/Tanzania.php new file mode 100644 index 000000000..05e16186a --- /dev/null +++ b/src/Countries/Tanzania.php @@ -0,0 +1,64 @@ + '01-01', + 'Labor Day' => '05-01', + 'Saba Saba Day' => '07-07', + 'Farmers Day (Nane Nane Day)' => '08-08', + 'Christmas Day' => '12-25', + 'Boxing Day' => '12-26' + ], $this->variableHolidays($year)); + } + + /** @return array */ + protected function variableHolidays(int $year): array + { + $easter = $this->easter($year); + + $variable_holidays = [ + 'Easter Monday' => $easter->addDay(), + 'Good Friday' => $easter->addDays(-2), + ]; + + // Zanzibar Revolutionary Day celebrations started in 1964 + if ($year >= 1964) { + $variable_holidays['Zanzibar Revolutionary Day'] = '01-12'; + } + + // Karume Day celebrations started in 1973 + if ($year >= 1973) { + $variable_holidays['Karume Day'] = '04-07'; + } + + // 'Union Day celebrations started in 1964 + if ($year >= 1964) { + $variable_holidays['Union Day'] = '04-26'; + } + + // Nyerere Day day celebrations started in 2000 + if ($year >= 2000) { + $variable_holidays['Nyerere Day'] = '10-14'; + } + + // Independence Day celebrations started in 1961 + if ($year >= 1961) { + $variable_holidays['Independence Day'] = '12-09'; + } + + return $variable_holidays; + } +} diff --git a/tests/.pest/snapshots/Countries/TanzaniaTest/it_can_calculate_tanzania_holidays.snap b/tests/.pest/snapshots/Countries/TanzaniaTest/it_can_calculate_tanzania_holidays.snap new file mode 100644 index 000000000..d1d187c0d --- /dev/null +++ b/tests/.pest/snapshots/Countries/TanzaniaTest/it_can_calculate_tanzania_holidays.snap @@ -0,0 +1,54 @@ +[ + { + "name": "New Year's Day", + "date": "2024-01-01" + }, + { + "name": "Zanzibar Revolutionary Day", + "date": "2024-01-12" + }, + { + "name": "Good Friday", + "date": "2024-03-29" + }, + { + "name": "Easter Monday", + "date": "2024-04-01" + }, + { + "name": "Karume Day", + "date": "2024-04-07" + }, + { + "name": "Union Day", + "date": "2024-04-26" + }, + { + "name": "Labor Day", + "date": "2024-05-01" + }, + { + "name": "Saba Saba Day", + "date": "2024-07-07" + }, + { + "name": "Farmers Day (Nane Nane Day)", + "date": "2024-08-08" + }, + { + "name": "Nyerere Day", + "date": "2024-10-14" + }, + { + "name": "Independence Day", + "date": "2024-12-09" + }, + { + "name": "Christmas Day", + "date": "2024-12-25" + }, + { + "name": "Boxing Day", + "date": "2024-12-26" + } +] \ No newline at end of file diff --git a/tests/Countries/TanzaniaTest.php b/tests/Countries/TanzaniaTest.php new file mode 100644 index 000000000..69777866b --- /dev/null +++ b/tests/Countries/TanzaniaTest.php @@ -0,0 +1,18 @@ +get(); + + expect($holidays) + ->toBeArray() + ->not()->toBeEmpty(); + + expect(formatDates($holidays))->toMatchSnapshot(); +}); From 6e152ff4c77e4584a020259e0299af35e0f73756 Mon Sep 17 00:00:00 2001 From: Nielsvanpach Date: Sat, 27 Jan 2024 16:00:12 +0000 Subject: [PATCH 020/175] Fix styling --- src/Countries/Tanzania.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Countries/Tanzania.php b/src/Countries/Tanzania.php index 05e16186a..7b318534a 100644 --- a/src/Countries/Tanzania.php +++ b/src/Countries/Tanzania.php @@ -3,7 +3,6 @@ namespace Spatie\Holidays\Countries; use Carbon\CarbonImmutable; -use IntlCalendar; class Tanzania extends Country { @@ -20,7 +19,7 @@ protected function allHolidays(int $year): array 'Saba Saba Day' => '07-07', 'Farmers Day (Nane Nane Day)' => '08-08', 'Christmas Day' => '12-25', - 'Boxing Day' => '12-26' + 'Boxing Day' => '12-26', ], $this->variableHolidays($year)); } From 1d6fdabb246d1190809fc7cea1c5de12ec25e4d2 Mon Sep 17 00:00:00 2001 From: Raiquen Guidotti Date: Mon, 29 Jan 2024 10:08:27 +0100 Subject: [PATCH 021/175] Switzerland: add missing holidays to "ch-ur" region (#191) * style: rename holidays variable names of Switzerland for consistency and correctness * feat: add missing holiday to ch-zh * feat: add missing holidays to ch-ur --- lang/switzerland/de/holidays.json | 1 + lang/switzerland/fr/holidays.json | 1 + lang/switzerland/it/holidays.json | 1 + src/Countries/Switzerland.php | 91 ++++++++++--------- ..._holidays_for_a_specified_region__zh_.snap | 4 + 5 files changed, 57 insertions(+), 41 deletions(-) diff --git a/lang/switzerland/de/holidays.json b/lang/switzerland/de/holidays.json index c294fd7b8..f59358468 100644 --- a/lang/switzerland/de/holidays.json +++ b/lang/switzerland/de/holidays.json @@ -11,6 +11,7 @@ "Fronleichnam": "Fronleichnam", "Bundesfeier": "Bundesfeier", "Maria Himmelfahrt": "Maria Himmelfahrt", + "Buss- und Bettag" : "Buss- und Bettag", "Allerheiligen": "Allerheiligen", "Maria Empfängnis": "Maria Empfängnis", "Weihnachtstag": "Weihnachtstag", diff --git a/lang/switzerland/fr/holidays.json b/lang/switzerland/fr/holidays.json index 0fe65215c..28a04b822 100644 --- a/lang/switzerland/fr/holidays.json +++ b/lang/switzerland/fr/holidays.json @@ -11,6 +11,7 @@ "Fronleichnam": "Fête-Dieu", "Bundesfeier": "Fête nationale", "Maria Himmelfahrt": "Assomption", + "Buss- und Bettag": "Jeûne fédéral", "Allerheiligen": "Toussaint", "Maria Empfängnis": "Immaculée Conception", "Weihnachtstag": "Noël", diff --git a/lang/switzerland/it/holidays.json b/lang/switzerland/it/holidays.json index e7a30514c..e62ec667e 100644 --- a/lang/switzerland/it/holidays.json +++ b/lang/switzerland/it/holidays.json @@ -11,6 +11,7 @@ "Fronleichnam": "Corpus Domini", "Bundesfeier": "Festa nazionale", "Maria Himmelfahrt": "Assunzione", + "Buss- und Bettag": "Digiuno federale", "Allerheiligen": "Ognissanti", "Maria Empfängnis": "Immacolata Concezione", "Weihnachtstag": "Natale", diff --git a/src/Countries/Switzerland.php b/src/Countries/Switzerland.php index 94d52f8c9..662860019 100644 --- a/src/Countries/Switzerland.php +++ b/src/Countries/Switzerland.php @@ -36,19 +36,19 @@ class Switzerland extends Country 'ch-zh', ]; - private const NEW_YEAR = 'Neujahr'; + private const NEW_YEARS_DAY = 'Neujahr'; - private const SECOND_JANUARY = 'Berchtoldstag'; + private const BERCHTOLDS_DAY = 'Berchtoldstag'; - private const THREE_KINGS = 'Heilige Drei Könige'; + private const THREE_KINGS_DAY = 'Heilige Drei Könige'; - private const DAY_OF_JOSEPH = 'Josefstag'; + private const SAINT_JOSEPHS_DAY = 'Josefstag'; private const GOOD_FRIDAY = 'Karfreitag'; private const EASTER_MONDAY = 'Ostermontag'; - private const LABOR_DAY = 'Tag der Arbeit'; + private const LABOUR_DAY = 'Tag der Arbeit'; private const ASCENSION_DAY = 'Auffahrt'; @@ -56,17 +56,19 @@ class Switzerland extends Country private const CORPUS_CHRISTI = 'Fronleichnam'; - private const FEDERAL_CELEBRATION = 'Bundesfeier'; + private const SWISS_NATIONAL_HOLIDAY = 'Bundesfeier'; private const ASSUMPTION_DAY = 'Maria Himmelfahrt'; + private const FEDERAL_DAY_OF_THANKSGIVING_REPENTANCE_AND_PRAYER = "Buss- und Bettag"; + private const ALL_SAINTS_DAY = 'Allerheiligen'; private const IMMACULATE_CONCEPTION = 'Maria Empfängnis'; private const CHRISTMAS_DAY = 'Weihnachtstag'; - private const ST_STEPHENS_DAY = 'Stephanstag'; + private const SAINT_STEPHENS_DAY = 'Stephanstag'; public function __construct(protected ?string $region = null) { @@ -92,25 +94,26 @@ public function regionalHolidays(int $year): array $easter = $this->easter($year); $sharedHolidays = [ - self::NEW_YEAR => '01-01', + self::NEW_YEARS_DAY => '01-01', self::ASCENSION_DAY => $easter->addDays(39), - self::FEDERAL_CELEBRATION => '08-01', + self::SWISS_NATIONAL_HOLIDAY => '08-01', self::CHRISTMAS_DAY => '12-25', ]; $regionallyDifferentHolidays = [ - self::SECOND_JANUARY => '01-02', - self::THREE_KINGS => '01-06', - self::DAY_OF_JOSEPH => '03-19', + self::BERCHTOLDS_DAY => '01-02', + self::THREE_KINGS_DAY => '01-06', + self::SAINT_JOSEPHS_DAY => '03-19', self::GOOD_FRIDAY => $easter->subDays(2), self::EASTER_MONDAY => $easter->addDay(), - self::LABOR_DAY => '05-01', + self::LABOUR_DAY => '05-01', self::WHIT_MONDAY => $easter->addDays(50), self::CORPUS_CHRISTI => $easter->addDays(60), self::ASSUMPTION_DAY => '08-15', + self::FEDERAL_DAY_OF_THANKSGIVING_REPENTANCE_AND_PRAYER => new CarbonImmutable('third sunday of September '.$year, 'Europe/Zurich'), self::ALL_SAINTS_DAY => '11-01', self::IMMACULATE_CONCEPTION => '12-08', - self::ST_STEPHENS_DAY => '12-26', + self::SAINT_STEPHENS_DAY => '12-26', ]; $currentRegion = match ($this->region) { @@ -121,35 +124,35 @@ public function regionalHolidays(int $year): array self::GOOD_FRIDAY, self::EASTER_MONDAY, self::WHIT_MONDAY, - self::ST_STEPHENS_DAY, + self::SAINT_STEPHENS_DAY, ], 'ch-ai' => [ self::GOOD_FRIDAY, self::EASTER_MONDAY, self::WHIT_MONDAY, self::CORPUS_CHRISTI, - self::ST_STEPHENS_DAY, + self::SAINT_STEPHENS_DAY, ], 'ch-bl' => [ self::GOOD_FRIDAY, self::EASTER_MONDAY, - self::LABOR_DAY, + self::LABOUR_DAY, self::WHIT_MONDAY, - self::ST_STEPHENS_DAY, + self::SAINT_STEPHENS_DAY, ], 'ch-bs' => [ self::GOOD_FRIDAY, self::EASTER_MONDAY, - self::LABOR_DAY, + self::LABOUR_DAY, self::WHIT_MONDAY, - self::ST_STEPHENS_DAY, + self::SAINT_STEPHENS_DAY, ], 'ch-be' => [ - self::SECOND_JANUARY, + self::BERCHTOLDS_DAY, self::GOOD_FRIDAY, self::EASTER_MONDAY, self::WHIT_MONDAY, - self::ST_STEPHENS_DAY, + self::SAINT_STEPHENS_DAY, ], 'ch-fr' => [ self::GOOD_FRIDAY, @@ -169,12 +172,12 @@ public function regionalHolidays(int $year): array self::GOOD_FRIDAY, self::EASTER_MONDAY, self::WHIT_MONDAY, - self::ST_STEPHENS_DAY, + self::SAINT_STEPHENS_DAY, ], 'ch-ju' => [ self::GOOD_FRIDAY, self::EASTER_MONDAY, - self::LABOR_DAY, + self::LABOUR_DAY, self::WHIT_MONDAY, self::CORPUS_CHRISTI, ], @@ -183,11 +186,11 @@ public function regionalHolidays(int $year): array self::CORPUS_CHRISTI, self::ASSUMPTION_DAY, self::ALL_SAINTS_DAY, - self::ST_STEPHENS_DAY, + self::SAINT_STEPHENS_DAY, ], 'ch-ne' => [ self::GOOD_FRIDAY, - self::LABOR_DAY, + self::LABOUR_DAY, ], 'ch-nw' => [ self::GOOD_FRIDAY, @@ -207,10 +210,10 @@ public function regionalHolidays(int $year): array self::GOOD_FRIDAY, self::EASTER_MONDAY, self::WHIT_MONDAY, - self::ST_STEPHENS_DAY, + self::SAINT_STEPHENS_DAY, ], 'ch-sz' => [ - self::DAY_OF_JOSEPH, + self::SAINT_JOSEPHS_DAY, self::GOOD_FRIDAY, self::CORPUS_CHRISTI, self::ASSUMPTION_DAY, @@ -224,37 +227,42 @@ public function regionalHolidays(int $year): array self::EASTER_MONDAY, self::WHIT_MONDAY, self::ALL_SAINTS_DAY, - self::ST_STEPHENS_DAY, + self::SAINT_STEPHENS_DAY, ], 'ch-ti' => [ - self::THREE_KINGS, + self::THREE_KINGS_DAY, self::EASTER_MONDAY, self::ASSUMPTION_DAY, self::ALL_SAINTS_DAY, - self::ST_STEPHENS_DAY, + self::SAINT_STEPHENS_DAY, ], 'ch-tg' => [ - self::SECOND_JANUARY, + self::BERCHTOLDS_DAY, self::GOOD_FRIDAY, self::EASTER_MONDAY, self::WHIT_MONDAY, - self::ST_STEPHENS_DAY, + self::SAINT_STEPHENS_DAY, ], 'ch-ur' => [ + self::THREE_KINGS_DAY, + self::SAINT_JOSEPHS_DAY, self::GOOD_FRIDAY, + self::EASTER_MONDAY, + self::WHIT_MONDAY, self::CORPUS_CHRISTI, self::ASSUMPTION_DAY, self::ALL_SAINTS_DAY, self::IMMACULATE_CONCEPTION, + self::SAINT_STEPHENS_DAY ], 'ch-vd' => [ - self::SECOND_JANUARY, + self::BERCHTOLDS_DAY, self::GOOD_FRIDAY, self::EASTER_MONDAY, self::WHIT_MONDAY, ], 'ch-vs' => [ - self::DAY_OF_JOSEPH, + self::SAINT_JOSEPHS_DAY, self::CORPUS_CHRISTI, self::ASSUMPTION_DAY, self::ALL_SAINTS_DAY, @@ -270,9 +278,10 @@ public function regionalHolidays(int $year): array 'ch-zh' => [ self::GOOD_FRIDAY, self::EASTER_MONDAY, - self::LABOR_DAY, + self::LABOUR_DAY, self::WHIT_MONDAY, - self::ST_STEPHENS_DAY, + self::FEDERAL_DAY_OF_THANKSGIVING_REPENTANCE_AND_PRAYER, + self::SAINT_STEPHENS_DAY, ], default => [], }; @@ -293,11 +302,11 @@ protected function allHolidays(int $year): array } return array_merge([ - self::NEW_YEAR => '01-01', - self::SECOND_JANUARY => '01-02', - self::FEDERAL_CELEBRATION => '08-01', + self::NEW_YEARS_DAY => '01-01', + self::BERCHTOLDS_DAY => '01-02', + self::SWISS_NATIONAL_HOLIDAY => '08-01', self::CHRISTMAS_DAY => '12-25', - self::ST_STEPHENS_DAY => '12-26', + self::SAINT_STEPHENS_DAY => '12-26', ], $this->variableHolidays($year)); } diff --git a/tests/.pest/snapshots/Countries/SwitzerlandTest/it_can_get_swiss_holidays_for_a_specified_region__zh_.snap b/tests/.pest/snapshots/Countries/SwitzerlandTest/it_can_get_swiss_holidays_for_a_specified_region__zh_.snap index f4b753733..f594ea470 100644 --- a/tests/.pest/snapshots/Countries/SwitzerlandTest/it_can_get_swiss_holidays_for_a_specified_region__zh_.snap +++ b/tests/.pest/snapshots/Countries/SwitzerlandTest/it_can_get_swiss_holidays_for_a_specified_region__zh_.snap @@ -27,6 +27,10 @@ "name": "Bundesfeier", "date": "2024-08-01" }, + { + "name": "Buss- und Bettag", + "date": "2024-09-15" + }, { "name": "Weihnachtstag", "date": "2024-12-25" From e9445b09a49c45dc447e88a3757a049e21293dc1 Mon Sep 17 00:00:00 2001 From: Nielsvanpach Date: Mon, 29 Jan 2024 09:08:45 +0000 Subject: [PATCH 022/175] Fix styling --- src/Countries/Switzerland.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Countries/Switzerland.php b/src/Countries/Switzerland.php index 662860019..c2e9d157c 100644 --- a/src/Countries/Switzerland.php +++ b/src/Countries/Switzerland.php @@ -60,7 +60,7 @@ class Switzerland extends Country private const ASSUMPTION_DAY = 'Maria Himmelfahrt'; - private const FEDERAL_DAY_OF_THANKSGIVING_REPENTANCE_AND_PRAYER = "Buss- und Bettag"; + private const FEDERAL_DAY_OF_THANKSGIVING_REPENTANCE_AND_PRAYER = 'Buss- und Bettag'; private const ALL_SAINTS_DAY = 'Allerheiligen'; @@ -253,7 +253,7 @@ public function regionalHolidays(int $year): array self::ASSUMPTION_DAY, self::ALL_SAINTS_DAY, self::IMMACULATE_CONCEPTION, - self::SAINT_STEPHENS_DAY + self::SAINT_STEPHENS_DAY, ], 'ch-vd' => [ self::BERCHTOLDS_DAY, From 34f55ba5befada5a8d2c29ade9b83bcabe244e45 Mon Sep 17 00:00:00 2001 From: Arne Breitsprecher Date: Mon, 29 Jan 2024 10:12:19 +0100 Subject: [PATCH 023/175] Germany: Setting some historical holidays (#188) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Update region parameter in country constructor to a working example * Update German holiday date in test case for buß/bettag to correct date * German unity day in 1990 changed * phpstan * Adding DE-BY: Joseftag and DE-BE: Victory in Europe Day --- lang/germany/en/holidays.json | 3 ++- lang/germany/fr/holidays.json | 3 ++- lang/germany/nl/holidays.json | 3 ++- src/Countries/Germany.php | 28 +++++++++++++++++++--------- tests/Countries/GermanyTest.php | 25 ++++++++++++++++++++++++- 5 files changed, 49 insertions(+), 13 deletions(-) diff --git a/lang/germany/en/holidays.json b/lang/germany/en/holidays.json index 4202f709f..e2431c7e6 100644 --- a/lang/germany/en/holidays.json +++ b/lang/germany/en/holidays.json @@ -17,5 +17,6 @@ "Karfreitag": "Good Friday", "Ostersonntag": "Easter Sunday", "Internationaler Frauentag": "International Women's Day", - "Weltkindertag": "World Children's Day" + "Weltkindertag": "World Children's Day", + "Tag der Befreiung": "Victory in Europe Day" } \ No newline at end of file diff --git a/lang/germany/fr/holidays.json b/lang/germany/fr/holidays.json index e260be7f5..db6056a12 100644 --- a/lang/germany/fr/holidays.json +++ b/lang/germany/fr/holidays.json @@ -17,5 +17,6 @@ "Karfreitag": "Vendredi Saint", "Ostersonntag": "Dimanche de Pâques", "Internationaler Frauentag": "Journée internationale des femmes", - "Weltkindertag": "Journée de l'enfance" + "Weltkindertag": "Journée de l'enfance", + "Tag der Befreiung": "Fête de la Victoire" } \ No newline at end of file diff --git a/lang/germany/nl/holidays.json b/lang/germany/nl/holidays.json index 98f8a17cb..3ef5bc24e 100644 --- a/lang/germany/nl/holidays.json +++ b/lang/germany/nl/holidays.json @@ -17,5 +17,6 @@ "Karfreitag": "Goede Vrijdag", "Ostersonntag": "Eerste paasdag", "Internationaler Frauentag": "Internationale vrouwendag", - "Weltkindertag": "Kinderdag" + "Weltkindertag": "Kinderdag", + "Tag der Befreiung": "Bevrijdingsdag" } \ No newline at end of file diff --git a/src/Countries/Germany.php b/src/Countries/Germany.php index 6bdc0da33..e0b61f282 100644 --- a/src/Countries/Germany.php +++ b/src/Countries/Germany.php @@ -27,6 +27,11 @@ private function getRepentanceAndPrayerDay(int $year): string protected function historicalHolidays(int $year): array { $historicalHolidays = []; + if ($year >= 1954 && $year <= 1990) { + $historicalHolidays['Tag der deutschen Einheit'] = '06-17'; + } else { + $historicalHolidays['Tag der deutschen Einheit'] = '10-03'; + } if ($year >= 1990 && $year <= 1994) { $historicalHolidays['Buß- und Bettag'] = $this->getRepentanceAndPrayerDay($year); } @@ -43,7 +48,6 @@ protected function allHolidays(int $year): array return array_merge([ 'Neujahr' => '01-01', - 'Tag der deutschen Einheit' => '10-03', 'Tag der Arbeit' => '05-01', '1. Weihnachtstag' => '12-25', '2. Weihnachtstag' => '12-26', @@ -77,23 +81,29 @@ protected function regionHolidays(int $year): array 'Allerheiligen' => '11-01', ]; case 'DE-BY': - return [ + $byHolidays = [ 'Heilige Drei Könige' => '01-06', 'Fronleichnam' => $easter->addDays(60), 'Allerheiligen' => '11-01', 'Mariä Himmelfahrt' => '08-15', ]; + if ($year >= 1948 && $year <= 1969) { + $byHolidays['Josefstag'] = '03-19'; + } + + return $byHolidays; case 'DE-BE': + $beHolidays = [ + ]; if ($year >= 2019) { - return [ - 'Internationaler Frauentag' => '03-08', - ]; - } else { - return [ - - ]; + $beHolidays['Internationaler Frauentag'] = '03-08'; + } + if ($year === 2020) { + $beHolidays['Tag der Befreiung'] = '05-08'; } + + return $beHolidays; case 'DE-BB': if ($year >= 1991) { return [ diff --git a/tests/Countries/GermanyTest.php b/tests/Countries/GermanyTest.php index 24f2aa199..a1e77616e 100644 --- a/tests/Countries/GermanyTest.php +++ b/tests/Countries/GermanyTest.php @@ -18,7 +18,22 @@ expect(formatDates($holidays))->toMatchSnapshot(); }); +it('can calculate german historical unity day in year 1990', function () { + CarbonImmutable::setTestNow('1990-01-01'); + + $holiday = Holidays::for('de')->isHoliday('1990-06-17'); + + expect($holiday)->toBeTrue(); + +}); +it('can calculate german unity day in year 1990', function () { + CarbonImmutable::setTestNow('2024-01-01'); + + $holiday = Holidays::for('de')->isHoliday('2024-10-03'); + expect($holiday)->toBeTrue(); + +}); it('can calculate german historical reformationstag in year 2017', function () { CarbonImmutable::setTestNow('2017-01-01'); @@ -39,7 +54,15 @@ it('can calculate german buß- und bettag in year 1990', function () { CarbonImmutable::setTestNow('1990-01-01'); - $holiday = Holidays::for('de')->isHoliday('1990-10-03'); + $holiday = Holidays::for('de')->isHoliday('1990-11-21'); + + expect($holiday)->toBeTrue(); + +}); +it('can calculate german berlin holiday Victory in Europe Day in year 2020', function () { + CarbonImmutable::setTestNow('2020-01-01'); + + $holiday = Holidays::for(Germany::make('DE-BE'))->isHoliday('2020-05-08'); expect($holiday)->toBeTrue(); From 17c78494a6114ec5b2a1ab671838836fb1fd5d4c Mon Sep 17 00:00:00 2001 From: Biswajit Biswas Date: Tue, 30 Jan 2024 14:41:11 +0600 Subject: [PATCH 024/175] feat: Add Bangla language support for Bangladeshi holidays (#182) * feat: Add Bangla language support for Bangladeshi holidays * fix: Return Bengali Names in English by default insted Bangla font * fix: Unit testing --- lang/bangladesh/bn/holidays.json | 10 ++++++ lang/bangladesh/en/holidays.json | 10 ++++++ ...lculate_bangladesh_holidays_in_Bangla.snap | 34 +++++++++++++++++++ ...culate_bangladesh_holidays_in_English.snap | 34 +++++++++++++++++++ tests/Countries/BangladeshTest.php | 24 +++++++++++++ 5 files changed, 112 insertions(+) create mode 100644 lang/bangladesh/bn/holidays.json create mode 100644 lang/bangladesh/en/holidays.json create mode 100644 tests/.pest/snapshots/Countries/BangladeshTest/it_can_calculate_bangladesh_holidays_in_Bangla.snap create mode 100644 tests/.pest/snapshots/Countries/BangladeshTest/it_can_calculate_bangladesh_holidays_in_English.snap diff --git a/lang/bangladesh/bn/holidays.json b/lang/bangladesh/bn/holidays.json new file mode 100644 index 000000000..069f2d940 --- /dev/null +++ b/lang/bangladesh/bn/holidays.json @@ -0,0 +1,10 @@ +{ + "International Mother Language Day": "Antorjatik Matribhasha Dibos", + "Birthday of Sheikh Mujibur Rahman": "Shekh Mujibur Rahmaner Jonmodin", + "Independence Day": "Swadhinota Dibos", + "Bengali New Year": "Bangla Noboborsho", + "May Day": "Antorjatik Shrom Dibos", + "National Mourning Day": "Jatiyo Shok Dibos", + "Victory Day": "Bijoy Dibos", + "Christmas Day": "Borodin" +} diff --git a/lang/bangladesh/en/holidays.json b/lang/bangladesh/en/holidays.json new file mode 100644 index 000000000..456af3986 --- /dev/null +++ b/lang/bangladesh/en/holidays.json @@ -0,0 +1,10 @@ +{ + "International Mother Language Day": "International Mother Language Day", + "Birthday of Sheikh Mujibur Rahman": "Birthday of Sheikh Mujibur Rahman", + "Independence Day": "Independence Day", + "Bengali New Year": "Bengali New Year", + "May Day": "May Day", + "National Mourning Day": "National Mourning Day", + "Victory Day": "Victory Day", + "Christmas Day": "Christmas Day" +} diff --git a/tests/.pest/snapshots/Countries/BangladeshTest/it_can_calculate_bangladesh_holidays_in_Bangla.snap b/tests/.pest/snapshots/Countries/BangladeshTest/it_can_calculate_bangladesh_holidays_in_Bangla.snap new file mode 100644 index 000000000..285dbbc3c --- /dev/null +++ b/tests/.pest/snapshots/Countries/BangladeshTest/it_can_calculate_bangladesh_holidays_in_Bangla.snap @@ -0,0 +1,34 @@ +[ + { + "name": "Antorjatik Matribhasha Dibos", + "date": "2024-02-21" + }, + { + "name": "Shekh Mujibur Rahmaner Jonmodin", + "date": "2024-03-17" + }, + { + "name": "Swadhinota Dibos", + "date": "2024-03-26" + }, + { + "name": "Bangla Noboborsho", + "date": "2024-04-14" + }, + { + "name": "Antorjatik Shrom Dibos", + "date": "2024-05-01" + }, + { + "name": "Jatiyo Shok Dibos", + "date": "2024-08-15" + }, + { + "name": "Bijoy Dibos", + "date": "2024-12-16" + }, + { + "name": "Borodin", + "date": "2024-12-25" + } +] \ No newline at end of file diff --git a/tests/.pest/snapshots/Countries/BangladeshTest/it_can_calculate_bangladesh_holidays_in_English.snap b/tests/.pest/snapshots/Countries/BangladeshTest/it_can_calculate_bangladesh_holidays_in_English.snap new file mode 100644 index 000000000..f5a0e91db --- /dev/null +++ b/tests/.pest/snapshots/Countries/BangladeshTest/it_can_calculate_bangladesh_holidays_in_English.snap @@ -0,0 +1,34 @@ +[ + { + "name": "International Mother Language Day", + "date": "2024-02-21" + }, + { + "name": "Birthday of Sheikh Mujibur Rahman", + "date": "2024-03-17" + }, + { + "name": "Independence Day", + "date": "2024-03-26" + }, + { + "name": "Bengali New Year", + "date": "2024-04-14" + }, + { + "name": "May Day", + "date": "2024-05-01" + }, + { + "name": "National Mourning Day", + "date": "2024-08-15" + }, + { + "name": "Victory Day", + "date": "2024-12-16" + }, + { + "name": "Christmas Day", + "date": "2024-12-25" + } +] \ No newline at end of file diff --git a/tests/Countries/BangladeshTest.php b/tests/Countries/BangladeshTest.php index d978a795d..51f7e40f5 100644 --- a/tests/Countries/BangladeshTest.php +++ b/tests/Countries/BangladeshTest.php @@ -16,3 +16,27 @@ expect(formatDates($holidays))->toMatchSnapshot(); }); + +it('can calculate bangladesh holidays in English', function () { + CarbonImmutable::setTestNow('2024-01-01'); + + $holidays = Holidays::for(country: 'bd', locale: 'en')->get(); + + expect($holidays) + ->toBeArray() + ->not()->toBeEmpty(); + + expect(formatDates($holidays))->toMatchSnapshot(); +}); + +it('can calculate bangladesh holidays in Bangla', function () { + CarbonImmutable::setTestNow('2024-01-01'); + + $holidays = Holidays::for(country: 'bd', locale: 'bn')->get(); + + expect($holidays) + ->toBeArray() + ->not()->toBeEmpty(); + + expect(formatDates($holidays))->toMatchSnapshot(); +}); From 363585142b25a5eb3356ed9b0f81a6a3c5549ada Mon Sep 17 00:00:00 2001 From: AditiAld Date: Tue, 30 Jan 2024 15:58:57 +0700 Subject: [PATCH 025/175] add indonesia holiday (#66) * add indonesia holiday * (fix): remove docblock * fix(test): variable holidays * fix(docblock): variableHolidays docblock * refactor(variableHolidays): get easter date from the parent class * fix(variableHolidays): easter date * feat(holiday): add chinese new year holiday to indonesia * fix(IndonesiaTest) --- src/Countries/Indonesia.php | 40 +++++++++++++++++++ .../it_can_calculate_indonesia_holidays.snap | 38 ++++++++++++++++++ tests/Countries/IndonesiaTest.php | 18 +++++++++ 3 files changed, 96 insertions(+) create mode 100644 src/Countries/Indonesia.php create mode 100644 tests/.pest/snapshots/Countries/IndonesiaTest/it_can_calculate_indonesia_holidays.snap create mode 100644 tests/Countries/IndonesiaTest.php diff --git a/src/Countries/Indonesia.php b/src/Countries/Indonesia.php new file mode 100644 index 000000000..ef19d1d17 --- /dev/null +++ b/src/Countries/Indonesia.php @@ -0,0 +1,40 @@ + '01-01', + 'Hari Buruh Internasional' => '05-01', + 'Hari Lahir Pancasila' => '06-01', + 'Hari Kemerdekaan' => '08-17', + 'Hari Raya Natal' => '12-25', + ], $this->variableHolidays($year)); + } + + /** @return array */ + protected function variableHolidays(int $year): array + { + $easter = $this->easter($year); + + return [ + 'Tahun Baru Imlek' => $this->chineseToGregorianDate('01-01', $year), + 'Jumat Agung' => $easter->subDays(2), + 'Hari Paskah' => $easter, + 'Kenaikan Yesus Kristus' => $easter->addDays(39), + ]; + } +} diff --git a/tests/.pest/snapshots/Countries/IndonesiaTest/it_can_calculate_indonesia_holidays.snap b/tests/.pest/snapshots/Countries/IndonesiaTest/it_can_calculate_indonesia_holidays.snap new file mode 100644 index 000000000..f8c9dd8c1 --- /dev/null +++ b/tests/.pest/snapshots/Countries/IndonesiaTest/it_can_calculate_indonesia_holidays.snap @@ -0,0 +1,38 @@ +[ + { + "name": "Tahun Baru", + "date": "2024-01-01" + }, + { + "name": "Tahun Baru Imlek", + "date": "2024-02-10" + }, + { + "name": "Jumat Agung", + "date": "2024-03-29" + }, + { + "name": "Hari Paskah", + "date": "2024-03-31" + }, + { + "name": "Hari Buruh Internasional", + "date": "2024-05-01" + }, + { + "name": "Kenaikan Yesus Kristus", + "date": "2024-05-09" + }, + { + "name": "Hari Lahir Pancasila", + "date": "2024-06-01" + }, + { + "name": "Hari Kemerdekaan", + "date": "2024-08-17" + }, + { + "name": "Hari Raya Natal", + "date": "2024-12-25" + } +] \ No newline at end of file diff --git a/tests/Countries/IndonesiaTest.php b/tests/Countries/IndonesiaTest.php new file mode 100644 index 000000000..9cc85dcc7 --- /dev/null +++ b/tests/Countries/IndonesiaTest.php @@ -0,0 +1,18 @@ +get(); + + expect($holidays) + ->toBeArray() + ->not()->toBeEmpty(); + + expect(formatDates($holidays))->toMatchSnapshot(); +}); From 6c3395e7f4f9b25b22afbcab3e8583fe75fdec0b Mon Sep 17 00:00:00 2001 From: Nielsvanpach Date: Tue, 30 Jan 2024 08:59:54 +0000 Subject: [PATCH 026/175] Update CHANGELOG --- CHANGELOG.md | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 326828cd5..192aa09a3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,42 @@ All notable changes to `holidays` will be documented in this file. +## 1.4.0 - 2024-01-30 + +### What's Changed + +* Add Montenegro holidays by @Rkishahaha in https://github.com/spatie/holidays/pull/171 +* Add Angola Holidays by @monteirofutila in https://github.com/spatie/holidays/pull/89 +* add wales, england, scotland and northern ireland by @SimonBarrettACT in https://github.com/spatie/holidays/pull/162 +* Add Chile Holidays by @AndresReyesDev in https://github.com/spatie/holidays/pull/88 +* Added Kenyan holidays by @PhilN8 in https://github.com/spatie/holidays/pull/69 +* Add vietnamese holidays by @kevinb1989 in https://github.com/spatie/holidays/pull/115 +* Germany: Adding local for EN, FR, NL by @arnebr in https://github.com/spatie/holidays/pull/183 +* Support for Taiwan holidays by @takeshiyu in https://github.com/spatie/holidays/pull/124 +* Fixing README.md to update region parameter in country constructor to a working example by @arnebr in https://github.com/spatie/holidays/pull/184 +* Draft: Add Support for Switzerland by @Martin-Welte in https://github.com/spatie/holidays/pull/49 +* Add Tanzania national holiday by @alphaolomi in https://github.com/spatie/holidays/pull/98 +* Switzerland: add missing holidays to "ch-ur" region by @Kenny1291 in https://github.com/spatie/holidays/pull/191 +* Germany: Setting some historical holidays by @arnebr in https://github.com/spatie/holidays/pull/188 +* feat: Add Bangla language support for Bangladeshi holidays by @jfBiswajit in https://github.com/spatie/holidays/pull/182 +* add indonesia holiday by @ddouble-d in https://github.com/spatie/holidays/pull/66 + +### New Contributors + +* @Rkishahaha made their first contribution in https://github.com/spatie/holidays/pull/171 +* @monteirofutila made their first contribution in https://github.com/spatie/holidays/pull/89 +* @SimonBarrettACT made their first contribution in https://github.com/spatie/holidays/pull/162 +* @AndresReyesDev made their first contribution in https://github.com/spatie/holidays/pull/88 +* @PhilN8 made their first contribution in https://github.com/spatie/holidays/pull/69 +* @kevinb1989 made their first contribution in https://github.com/spatie/holidays/pull/115 +* @takeshiyu made their first contribution in https://github.com/spatie/holidays/pull/124 +* @alphaolomi made their first contribution in https://github.com/spatie/holidays/pull/98 +* @Kenny1291 made their first contribution in https://github.com/spatie/holidays/pull/191 +* @jfBiswajit made their first contribution in https://github.com/spatie/holidays/pull/182 +* @ddouble-d made their first contribution in https://github.com/spatie/holidays/pull/66 + +**Full Changelog**: https://github.com/spatie/holidays/compare/1.3.0...1.4.0 + ## 1.3.0 - 2024-01-25 ### What's Changed From 6fde494086a7624a09e42fa83639674c8d6e98cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20B=C3=B8ndergaard?= Date: Tue, 30 Jan 2024 16:14:14 +0100 Subject: [PATCH 027/175] Fix easter sunday and monday (#197) --- src/Countries/Denmark.php | 4 ++-- .../DenmarkTest/it_can_calculate_danish_holidays.snap | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Countries/Denmark.php b/src/Countries/Denmark.php index ee68d1d74..3d4e091eb 100644 --- a/src/Countries/Denmark.php +++ b/src/Countries/Denmark.php @@ -27,10 +27,10 @@ protected function variableHolidays(int $year): array $easter = $this->easter($year); $holidays = [ - 'Påskedag' => $easter->addDay(), 'Skærtorsdag' => $easter->subDays(3), 'Langfredag' => $easter->subDays(2), - 'Anden Påskedag' => $easter->addDays(2), + 'Påskedag' => $easter, + 'Anden Påskedag' => $easter->addDay(), 'Kristi Himmelfartsdag' => $easter->addDays(39), 'Pinse' => $easter->addDays(49), 'Anden Pinsedag' => $easter->addDays(50), diff --git a/tests/.pest/snapshots/Countries/DenmarkTest/it_can_calculate_danish_holidays.snap b/tests/.pest/snapshots/Countries/DenmarkTest/it_can_calculate_danish_holidays.snap index b19f23c2d..705cd12ee 100644 --- a/tests/.pest/snapshots/Countries/DenmarkTest/it_can_calculate_danish_holidays.snap +++ b/tests/.pest/snapshots/Countries/DenmarkTest/it_can_calculate_danish_holidays.snap @@ -13,11 +13,11 @@ }, { "name": "P\u00e5skedag", - "date": "2024-04-01" + "date": "2024-03-31" }, { "name": "Anden P\u00e5skedag", - "date": "2024-04-02" + "date": "2024-04-01" }, { "name": "Kristi Himmelfartsdag", From feda8ec11b9a960748512d8dc7524da8bb455de5 Mon Sep 17 00:00:00 2001 From: MirilTerolli Date: Wed, 31 Jan 2024 14:31:59 -0500 Subject: [PATCH 028/175] Albanian National Holidays (#157) * Albanian National Holidays - Add Albanian national holidays including tentative dates for islamic holidays that are TBD. - Test coverage. * Albanian National Holidays - Add test coverage for holidays with standard dates. * Enhancements - Add empty line in the end of the testing file. * Enhancements - Fix empty line warning in the end of the file. * Fixes - Fix php stan error. * Fix holiday TYPO. * Language support - Translation for German, English, Spanish, French, Greek, Italian, Portughese, Russian, Turkish. * Filter out some variable holidays when they are not set for the given year. --------- Co-authored-by: Miril Terolli --- src/Countries/Albania.php | 88 +++++++++++++ src/lang/albania/de/holidays.json | 15 +++ src/lang/albania/en/holidays.json | 15 +++ src/lang/albania/es/holidays.json | 15 +++ src/lang/albania/fr/holidays.json | 16 +++ src/lang/albania/gr/holidays.json | 15 +++ src/lang/albania/it/holidays.json | 15 +++ src/lang/albania/pt/holidays.json | 15 +++ src/lang/albania/ru/holidays.json | 15 +++ src/lang/albania/tr/holidays.json | 15 +++ .../it_can_calculate_albanian_holidays.snap | 54 ++++++++ tests/Countries/AlbaniaTest.php | 123 ++++++++++++++++++ 12 files changed, 401 insertions(+) create mode 100644 src/Countries/Albania.php create mode 100644 src/lang/albania/de/holidays.json create mode 100644 src/lang/albania/en/holidays.json create mode 100644 src/lang/albania/es/holidays.json create mode 100644 src/lang/albania/fr/holidays.json create mode 100644 src/lang/albania/gr/holidays.json create mode 100644 src/lang/albania/it/holidays.json create mode 100644 src/lang/albania/pt/holidays.json create mode 100644 src/lang/albania/ru/holidays.json create mode 100644 src/lang/albania/tr/holidays.json create mode 100644 tests/.pest/snapshots/Countries/AlbaniaTest/it_can_calculate_albanian_holidays.snap create mode 100644 tests/Countries/AlbaniaTest.php diff --git a/src/Countries/Albania.php b/src/Countries/Albania.php new file mode 100644 index 000000000..42ad87619 --- /dev/null +++ b/src/Countries/Albania.php @@ -0,0 +1,88 @@ + '01-01', + 'Dita e Verës' => '03-14', + 'Dita e Sulltan Nevruzit' => '03-22', + 'Dita Ndërkombëtare e Punëtorëve' => '05-01', + 'Dita e Shenjtërimit të Shenjt Terezës' => '09-05', + 'Dita e Pavarësisë' => '11-28', + 'Dita e Çlirimit' => '11-29', + 'Dita Kombëtare e Rinisë' => '12-08', + 'Krishtlindja' => '12-25', + ], $this->variableHolidays($year)); + } + + /** @return array */ + protected function variableHolidays(int $year): array + { + return array_filter([ + 'E diela e Pashkëve Katolike' => $this->easter($year), + 'E diela e Pashkëve Ortodokse' => $this->orthodoxEaster($year), + 'Dita e Bajramit të Madh' => $this->getEidAlFitrHoliday($year), + 'Dita e Kurban Bajramit' => $this->getEidAlAdhaHoliday($year), + ]); + } + + /** + * + */ + private function getEidAlFitrHoliday(int $year): ?string + { + /** + * Provided until 2034 by qppstudio.net. + * https://www.qppstudio.net/global-holidays-observances/eid-al-fitr-end-of-ramadan.htm + */ + return match ($year) { + 2024 => '04-10', + 2025 => '03-30', + 2026 => '03-20', + 2027 => '03-09', + 2028 => '02-26', + 2029 => '02-14', + 2030 => '02-04', + 2031 => '01-24', + 2032 => '01-14', + 2033 => '01-02', + 2034 => '12-12', + default => null // Holiday is variable; requires ongoing maintenance. + }; + } + + private function getEidAlAdhaHoliday(int $year): ?string + { + /** + * Tentative dates. + * Provided until 2034 by timeanddate.com. + * https://www.timeanddate.com/holidays/us/eid-al-adha + */ + return match ($year) { + 2024 => '06-17', + 2025 => '06-07', + 2026 => '05-27', + 2027 => '05-17', + 2028 => '05-05', + 2029 => '04-24', + 2030 => '04-14', + 2031 => '04-03', + 2032 => '03-22', + 2033 => '03-12', + 2034 => '03-01', + default => null // Holiday is variable; requires ongoing maintenance. + }; + } + +} diff --git a/src/lang/albania/de/holidays.json b/src/lang/albania/de/holidays.json new file mode 100644 index 000000000..ec5d24885 --- /dev/null +++ b/src/lang/albania/de/holidays.json @@ -0,0 +1,15 @@ +{ + "Viti i Ri": "Neujahr", + "Dita e Verës": "Sommertag", + "Dita e Sulltan Nevruzit": "Tag des Sultan Nevruz", + "Dita Ndërkombëtare e Punëtorëve": "Tag der Arbeit", + "Dita e Shenjtërimit të Shenjt Terezës": "Tag der Heiligsprechung der Heiligen Teresa", + "Dita e Pavarësisë": "Unabhängigkeitstag", + "Dita e Çlirimit": "Befreiungstag", + "Dita Kombëtare e Rinisë": "Nationaler Jugendtag", + "Krishtlindja": "Weihnachten", + "E diela e Pashkëve Katolike": "Katholischer Ostersonntag", + "E diela e Pashkëve Ortodokse": "Orthodoxer Ostersonntag", + "Dita e Bajramit të Madh": "Eid al-Fitr", + "Dita e Kurban Bajramit": "Eid al-Adha" +} diff --git a/src/lang/albania/en/holidays.json b/src/lang/albania/en/holidays.json new file mode 100644 index 000000000..df15b5c2f --- /dev/null +++ b/src/lang/albania/en/holidays.json @@ -0,0 +1,15 @@ +{ + "Viti i Ri": "New Year's Day", + "Dita e Verës": "Summer Day", + "Dita e Sulltan Nevruzit": "Sultan Nevruz Day", + "Dita Ndërkombëtare e Punëtorëve": "International Workers' Day", + "Dita e Shenjtërimit të Shenjt Terezës": "Saint Teresa Canonization Day", + "Dita e Pavarësisë": "Independence Day", + "Dita e Çlirimit": "Liberation Day", + "Dita Kombëtare e Rinisë": "National Youth Day", + "Krishtlindja": "Christmas", + "E diela e Pashkëve Katolike": "Catholic Easter Sunday", + "E diela e Pashkëve Ortodokse": "Orthodox Easter Sunday", + "Dita e Bajramit të Madh": "Eid al-Fitr", + "Dita e Kurban Bajramit": "Eid al-Adha" +} diff --git a/src/lang/albania/es/holidays.json b/src/lang/albania/es/holidays.json new file mode 100644 index 000000000..713b70def --- /dev/null +++ b/src/lang/albania/es/holidays.json @@ -0,0 +1,15 @@ +{ + "Viti i Ri": "Año Nuevo", + "Dita e Verës": "Día del Verano", + "Dita e Sulltan Nevruzit": "Día del Sultan Nevruz", + "Dita Ndërkombëtare e Punëtorëve": "Día Internacional de los Trabajadores", + "Dita e Shenjtërimit të Shenjt Terezës": "Día de la Canonización de Santa Teresa", + "Dita e Pavarësisë": "Día de la Independencia", + "Dita e Çlirimit": "Día de la Liberación", + "Dita Kombëtare e Rinisë": "Día Nacional de la Juventud", + "Krishtlindja": "Navidad", + "E diela e Pashkëve Katolike": "Domingo de Pascua Católica", + "E diela e Pashkëve Ortodokse": "Domingo de Pascua Ortodoxa", + "Dita e Bajramit të Madh": "Eid al-Fitr", + "Dita e Kurban Bajramit": "Eid al-Adha" +} diff --git a/src/lang/albania/fr/holidays.json b/src/lang/albania/fr/holidays.json new file mode 100644 index 000000000..e2a7f2f05 --- /dev/null +++ b/src/lang/albania/fr/holidays.json @@ -0,0 +1,16 @@ +{ + "Viti i Ri": "Jour de l'An", + "Dita e Verës": "Jour de l'Été", + "Dita e Sulltan Nevruzit": "Jour du Sultan Nevruz", + "Dita Ndërkombëtare e Punëtorëve": "Fête du Travail", + "Dita e Shenjtërimit të Shenjt Terezës": "Jour de la Canonisation de Sainte Teresa", + "Dita e Pavarësisë": "Jour de l'Indépendance", + "Dita e Çlirimit": "Jour de la Libération", + "Dita Kombëtare e Rinisë": "Journée nationale de la jeunesse", + "Krishtlindja": "Noël", + "E diela e Pashkëve Katolike": "Dimanche de Pâques catholique", + "E diela e Pashkëve Ortodokse": "Dimanche de Pâques orthodoxe", + "Dita e Bajramit të Madh": "Aïd al-Fitr", + "Dita e Kurban Bajramit": "Aïd al-Adha" +} + diff --git a/src/lang/albania/gr/holidays.json b/src/lang/albania/gr/holidays.json new file mode 100644 index 000000000..a2e5d28e5 --- /dev/null +++ b/src/lang/albania/gr/holidays.json @@ -0,0 +1,15 @@ +{ + "Viti i Ri": "Πρωτοχρονιά (Protochroniá)", + "Dita e Verës": "Ημέρα του Καλοκαιριού (Iméra tou Kalokairioú)", + "Dita e Sulltan Nevruzit": "Ημέρα του Σουλτάν Nevruz (Iméra tou Soúltan Nevruz)", + "Dita Ndërkombëtare e Punëtorëve": "Διεθνής Ημέρα των Εργαζομένων (Diethnís Iméra ton Ergazoménon)", + "Dita e Shenjtërimit të Shenjt Terezës": "Ημέρα Κανονισμού της Αγίας Τερέζας (Iméra Kanonismoú tis Agías Terézas)", + "Dita e Pavarësisë": "Ημέρα Ανεξαρτησίας (Iméra Anexartisías)", + "Dita e Çlirimit": "Ημέρα Απελευθέρωσης (Iméra Apelafthéroses)", + "Dita Kombëtare e Rinisë": "Εθνική Ημέρα της Νεολαίας (Ethnikí Iméra tis Neoléas)", + "Krishtlindja": "Χριστούγεννα (Christoúgenna)", + "E diela e Pashkëve Katolike": "Κυριακή του Καθολικού Πάσχα (Kyriakí tou Katholikoú Páscha)", + "E diela e Pashkëve Ortodokse": "Κυριακή του Ορθόδοξου Πάσχα (Kyriakí tou Orthódoksi Páscha)", + "Dita e Bajramit të Madh": "Ημέρα του Μεγάλου Βαϊράμ (Iméra tou Megálou Vaïrám)", + "Dita e Kurban Bajramit": "Ημέρα του Κουρμπάν Βαϊράμ (Iméra tou Kourbán Vaïrám)" +} diff --git a/src/lang/albania/it/holidays.json b/src/lang/albania/it/holidays.json new file mode 100644 index 000000000..4e192da2a --- /dev/null +++ b/src/lang/albania/it/holidays.json @@ -0,0 +1,15 @@ +{ + "Viti i Ri": "Capodanno", + "Dita e Verës": "Giorno d'Estate", + "Dita e Sulltan Nevruzit": "Giorno del Sultano Nevruz", + "Dita Ndërkombëtare e Punëtorëve": "Festa dei Lavoratori", + "Dita e Shenjtërimit të Shenjt Terezës": "Giorno della Canonizzazione di Santa Teresa", + "Dita e Pavarësisë": "Giorno dell'Indipendenza", + "Dita e Çlirimit": "Giorno della Liberazione", + "Dita Kombëtare e Rinisë": "Giornata Nazionale della Gioventù", + "Krishtlindja": "Natale", + "E diela e Pashkëve Katolike": "Domenica di Pasqua Cattolica", + "E diela e Pashkëve Ortodokse": "Domenica di Pasqua Ortodossa", + "Dita e Bajramit të Madh": "Eid al-Fitr", + "Dita e Kurban Bajramit": "Eid al-Adha" +} diff --git a/src/lang/albania/pt/holidays.json b/src/lang/albania/pt/holidays.json new file mode 100644 index 000000000..dc3fce2f3 --- /dev/null +++ b/src/lang/albania/pt/holidays.json @@ -0,0 +1,15 @@ +{ + "Viti i Ri": "Ano Novo", + "Dita e Verës": "Dia do Verão", + "Dita e Sulltan Nevruzit": "Dia do Sultão Nevruz", + "Dita Ndërkombëtare e Punëtorëve": "Dia Internacional dos Trabalhadores", + "Dita e Shenjtërimit të Shenjt Terezës": "Dia da Canonização de Santa Teresa", + "Dita e Pavarësisë": "Dia da Independência", + "Dita e Çlirimit": "Dia da Libertação", + "Dita Kombëtare e Rinisë": "Dia Nacional da Juventude", + "Krishtlindja": "Natal", + "E diela e Pashkëve Katolike": "Domingo de Páscoa Católico", + "E diela e Pashkëve Ortodokse": "Domingo de Páscoa Ortodoxo", + "Dita e Bajramit të Madh": "Eid al-Fitr", + "Dita e Kurban Bajramit": "Eid al-Adha" +} diff --git a/src/lang/albania/ru/holidays.json b/src/lang/albania/ru/holidays.json new file mode 100644 index 000000000..2eb3f356d --- /dev/null +++ b/src/lang/albania/ru/holidays.json @@ -0,0 +1,15 @@ +{ + "Viti i Ri": "Новий рік", + "Dita e Verës": "День літа", + "Dita e Sulltan Nevruzit": "День Султана Невруза", + "Dita Ndërkombëtare e Punëtorëve": "Міжнародний день праці", + "Dita e Shenjtërimit të Shenjt Terezës": "День канонізації Святої Терези", + "Dita e Pavarësisë": "День Незалежності", + "Dita e Çlirimit": "День Визволення", + "Dita Kombëtare e Rinisë": "Національний день молоді", + "Krishtlindja": "Різдво", + "E diela e Pashkëve Katolike": "Католицька неділя Великодня", + "E diela e Pashkëve Ortodokse": "Православна неділя Великодня", + "Dita e Bajramit të Madh": "Байрам", + "Dita e Kurban Bajramit": "Курбан-байрам" +} diff --git a/src/lang/albania/tr/holidays.json b/src/lang/albania/tr/holidays.json new file mode 100644 index 000000000..ede076e01 --- /dev/null +++ b/src/lang/albania/tr/holidays.json @@ -0,0 +1,15 @@ +{ + "Viti i Ri": "Yılbaşı", + "Dita e Verës": "Yaz Günü", + "Dita e Sulltan Nevruzit": "Sultan Nevruz Günü", + "Dita Ndërkombëtare e Punëtorëve": "Uluslararası İşçi Günü", + "Dita e Shenjtërimit të Shenjt Terezës": "Azize Teresa'nın Kanonizasyon Günü", + "Dita e Pavarësisë": "Bağımsızlık Günü", + "Dita e Çlirimit": "Kurtuluş Günü", + "Dita Kombëtare e Rinisë": "Ulusal Gençlik Günü", + "Krishtlindja": "Noel", + "E diela e Pashkëve Katolike": "Katolik Paskalya Pazarı", + "E diela e Pashkëve Ortodokse": "Ortodoks Paskalya Pazarı", + "Dita e Bajramit të Madh": "Ramazan Bayramı", + "Dita e Kurban Bajramit": "Kurban Bayramı" +} diff --git a/tests/.pest/snapshots/Countries/AlbaniaTest/it_can_calculate_albanian_holidays.snap b/tests/.pest/snapshots/Countries/AlbaniaTest/it_can_calculate_albanian_holidays.snap new file mode 100644 index 000000000..49c936114 --- /dev/null +++ b/tests/.pest/snapshots/Countries/AlbaniaTest/it_can_calculate_albanian_holidays.snap @@ -0,0 +1,54 @@ +[ + { + "name": "Viti i Ri", + "date": "2024-01-01" + }, + { + "name": "Dita e Ver\u00ebs", + "date": "2024-03-14" + }, + { + "name": "Dita e Sulltan Nevruzit", + "date": "2024-03-22" + }, + { + "name": "E diela e Pashk\u00ebve Katolike", + "date": "2024-03-31" + }, + { + "name": "Dita e Bajramit t\u00eb Madh", + "date": "2024-04-10" + }, + { + "name": "Dita Nd\u00ebrkomb\u00ebtare e Pun\u00ebtor\u00ebve", + "date": "2024-05-01" + }, + { + "name": "E diela e Pashk\u00ebve Ortodokse", + "date": "2024-05-05" + }, + { + "name": "Dita e Kurban Bajramit", + "date": "2024-06-17" + }, + { + "name": "Dita e Shenjt\u00ebrimit t\u00eb Shenjt Terez\u00ebs", + "date": "2024-09-05" + }, + { + "name": "Dita e Pavar\u00ebsis\u00eb", + "date": "2024-11-28" + }, + { + "name": "Dita e \u00c7lirimit", + "date": "2024-11-29" + }, + { + "name": "Dita Komb\u00ebtare e Rinis\u00eb", + "date": "2024-12-08" + }, + { + "name": "Krishtlindja", + "date": "2024-12-25" + } +] \ No newline at end of file diff --git a/tests/Countries/AlbaniaTest.php b/tests/Countries/AlbaniaTest.php new file mode 100644 index 000000000..e068877b7 --- /dev/null +++ b/tests/Countries/AlbaniaTest.php @@ -0,0 +1,123 @@ +get(); + expect($holidays) + ->toBeArray() + ->not()->toBeEmpty(); + + expect(formatDates($holidays))->toMatchSnapshot(); +}); + + +it('does not return a holiday falsely', function() use ($holiday) { + $dateInstance = CarbonImmutable::createFromDate('2024-01-03'); + $holiday = Holidays::for(country: 'al'); + + $isHoliday = $holiday->isHoliday($dateInstance); + expect($isHoliday)->toBeFalse(); + + $holidayName = $holiday->getName($dateInstance); + expect($holidayName)->toBeNull(); +}); + +describe('national holidays with standard dates', function() { + $holiday = Holidays::for(country: 'al'); + + it('can calculate the `Viti i Ri` holiday as expected', function() use ($holiday) { + $dateInstance = CarbonImmutable::createFromDate('2024-01-01'); + + $isHoliday = $holiday->isHoliday($dateInstance); + expect($isHoliday)->toBeTrue(); + + $holidayName = $holiday->getName($dateInstance); + expect($holidayName)->toBe('Viti i Ri'); + }); + + it('can calculate the `Dita e Verës` holiday as expected', function() use ($holiday) { + $dateInstance = CarbonImmutable::createFromDate('2024-03-14'); + + $isHoliday = $holiday->isHoliday($dateInstance); + expect($isHoliday)->toBeTrue(); + + $holidayName = $holiday->getName($dateInstance); + expect($holidayName)->toBe('Dita e Verës'); + }); + + it('can calculate the `Dita e Sulltan Nevruzit` holiday as expected', function() use ($holiday) { + $dateInstance = CarbonImmutable::createFromDate('2024-03-22'); + + $isHoliday = $holiday->isHoliday($dateInstance); + expect($isHoliday)->toBeTrue(); + + $holidayName = $holiday->getName($dateInstance); + expect($holidayName)->toBe('Dita e Sulltan Nevruzit'); + }); + + it('can calculate the `Dita Ndërkombëtare e Punëtorëve` holiday as expected', function() use ($holiday) { + $dateInstance = CarbonImmutable::createFromDate('2024-05-01'); + + $isHoliday = $holiday->isHoliday($dateInstance); + expect($isHoliday)->toBeTrue(); + + $holidayName = $holiday->getName($dateInstance); + expect($holidayName)->toBe('Dita Ndërkombëtare e Punëtorëve'); + }); + + it('can calculate the `Dita e Shenjtërimit të Shenjt Terezës` holiday as expected', function() use ($holiday) { + $dateInstance = CarbonImmutable::createFromDate('2024-09-05'); + + $isHoliday = $holiday->isHoliday($dateInstance); + expect($isHoliday)->toBeTrue(); + + $holidayName = $holiday->getName($dateInstance); + expect($holidayName)->toBe('Dita e Shenjtërimit të Shenjt Terezës'); + }); + + it('can calculate the `Dita e Pavarësisë` holiday as expected', function() use ($holiday) { + $dateInstance = CarbonImmutable::createFromDate('2024-11-28'); + + $isHoliday = $holiday->isHoliday($dateInstance); + expect($isHoliday)->toBeTrue(); + + $holidayName = $holiday->getName($dateInstance); + expect($holidayName)->toBe('Dita e Pavarësisë'); + }); + + it('can calculate the `Dita e Çlirimit` holiday as expected', function() use ($holiday) { + $dateInstance = CarbonImmutable::createFromDate('2024-11-29'); + + $isHoliday = $holiday->isHoliday($dateInstance); + expect($isHoliday)->toBeTrue(); + + $holidayName = $holiday->getName($dateInstance); + expect($holidayName)->toBe('Dita e Çlirimit'); + }); + + it('can calculate the `Dita Kombëtare e Rinisë` holiday as expected', function() use ($holiday) { + $dateInstance = CarbonImmutable::createFromDate('2024-12-08'); + + $isHoliday = $holiday->isHoliday($dateInstance); + expect($isHoliday)->toBeTrue(); + + $holidayName = $holiday->getName($dateInstance); + expect($holidayName)->toBe('Dita Kombëtare e Rinisë'); + }); + + it('can calculate the `Krishtlindja` holiday as expected', function() use ($holiday) { + $dateInstance = CarbonImmutable::createFromDate('2024-12-25'); + + $isHoliday = $holiday->isHoliday($dateInstance); + expect($isHoliday)->toBeTrue(); + + $holidayName = $holiday->getName($dateInstance); + expect($holidayName)->toBe('Krishtlindja'); + }); + }); From 5d5ad2485b4b8c5ce058e40b074be1169e833cdd Mon Sep 17 00:00:00 2001 From: Nielsvanpach Date: Wed, 31 Jan 2024 19:32:20 +0000 Subject: [PATCH 029/175] Fix styling --- src/Countries/Albania.php | 4 -- tests/Countries/AlbaniaTest.php | 79 ++++++++++++++++----------------- 2 files changed, 39 insertions(+), 44 deletions(-) diff --git a/src/Countries/Albania.php b/src/Countries/Albania.php index 42ad87619..2d7424dbf 100644 --- a/src/Countries/Albania.php +++ b/src/Countries/Albania.php @@ -37,9 +37,6 @@ protected function variableHolidays(int $year): array ]); } - /** - * - */ private function getEidAlFitrHoliday(int $year): ?string { /** @@ -84,5 +81,4 @@ private function getEidAlAdhaHoliday(int $year): ?string default => null // Holiday is variable; requires ongoing maintenance. }; } - } diff --git a/tests/Countries/AlbaniaTest.php b/tests/Countries/AlbaniaTest.php index e068877b7..461e5e126 100644 --- a/tests/Countries/AlbaniaTest.php +++ b/tests/Countries/AlbaniaTest.php @@ -16,108 +16,107 @@ expect(formatDates($holidays))->toMatchSnapshot(); }); - -it('does not return a holiday falsely', function() use ($holiday) { +it('does not return a holiday falsely', function () use ($holiday) { $dateInstance = CarbonImmutable::createFromDate('2024-01-03'); $holiday = Holidays::for(country: 'al'); $isHoliday = $holiday->isHoliday($dateInstance); expect($isHoliday)->toBeFalse(); - + $holidayName = $holiday->getName($dateInstance); expect($holidayName)->toBeNull(); }); -describe('national holidays with standard dates', function() { +describe('national holidays with standard dates', function () { $holiday = Holidays::for(country: 'al'); - it('can calculate the `Viti i Ri` holiday as expected', function() use ($holiday) { + it('can calculate the `Viti i Ri` holiday as expected', function () use ($holiday) { $dateInstance = CarbonImmutable::createFromDate('2024-01-01'); - + $isHoliday = $holiday->isHoliday($dateInstance); expect($isHoliday)->toBeTrue(); - + $holidayName = $holiday->getName($dateInstance); expect($holidayName)->toBe('Viti i Ri'); }); - - it('can calculate the `Dita e Verës` holiday as expected', function() use ($holiday) { + + it('can calculate the `Dita e Verës` holiday as expected', function () use ($holiday) { $dateInstance = CarbonImmutable::createFromDate('2024-03-14'); - + $isHoliday = $holiday->isHoliday($dateInstance); expect($isHoliday)->toBeTrue(); - + $holidayName = $holiday->getName($dateInstance); expect($holidayName)->toBe('Dita e Verës'); }); - - it('can calculate the `Dita e Sulltan Nevruzit` holiday as expected', function() use ($holiday) { + + it('can calculate the `Dita e Sulltan Nevruzit` holiday as expected', function () use ($holiday) { $dateInstance = CarbonImmutable::createFromDate('2024-03-22'); - + $isHoliday = $holiday->isHoliday($dateInstance); expect($isHoliday)->toBeTrue(); - + $holidayName = $holiday->getName($dateInstance); expect($holidayName)->toBe('Dita e Sulltan Nevruzit'); }); - - it('can calculate the `Dita Ndërkombëtare e Punëtorëve` holiday as expected', function() use ($holiday) { + + it('can calculate the `Dita Ndërkombëtare e Punëtorëve` holiday as expected', function () use ($holiday) { $dateInstance = CarbonImmutable::createFromDate('2024-05-01'); - + $isHoliday = $holiday->isHoliday($dateInstance); expect($isHoliday)->toBeTrue(); - + $holidayName = $holiday->getName($dateInstance); expect($holidayName)->toBe('Dita Ndërkombëtare e Punëtorëve'); }); - - it('can calculate the `Dita e Shenjtërimit të Shenjt Terezës` holiday as expected', function() use ($holiday) { + + it('can calculate the `Dita e Shenjtërimit të Shenjt Terezës` holiday as expected', function () use ($holiday) { $dateInstance = CarbonImmutable::createFromDate('2024-09-05'); - + $isHoliday = $holiday->isHoliday($dateInstance); expect($isHoliday)->toBeTrue(); - + $holidayName = $holiday->getName($dateInstance); expect($holidayName)->toBe('Dita e Shenjtërimit të Shenjt Terezës'); }); - - it('can calculate the `Dita e Pavarësisë` holiday as expected', function() use ($holiday) { + + it('can calculate the `Dita e Pavarësisë` holiday as expected', function () use ($holiday) { $dateInstance = CarbonImmutable::createFromDate('2024-11-28'); - + $isHoliday = $holiday->isHoliday($dateInstance); expect($isHoliday)->toBeTrue(); - + $holidayName = $holiday->getName($dateInstance); expect($holidayName)->toBe('Dita e Pavarësisë'); }); - - it('can calculate the `Dita e Çlirimit` holiday as expected', function() use ($holiday) { + + it('can calculate the `Dita e Çlirimit` holiday as expected', function () use ($holiday) { $dateInstance = CarbonImmutable::createFromDate('2024-11-29'); - + $isHoliday = $holiday->isHoliday($dateInstance); expect($isHoliday)->toBeTrue(); - + $holidayName = $holiday->getName($dateInstance); expect($holidayName)->toBe('Dita e Çlirimit'); }); - - it('can calculate the `Dita Kombëtare e Rinisë` holiday as expected', function() use ($holiday) { + + it('can calculate the `Dita Kombëtare e Rinisë` holiday as expected', function () use ($holiday) { $dateInstance = CarbonImmutable::createFromDate('2024-12-08'); - + $isHoliday = $holiday->isHoliday($dateInstance); expect($isHoliday)->toBeTrue(); - + $holidayName = $holiday->getName($dateInstance); expect($holidayName)->toBe('Dita Kombëtare e Rinisë'); }); - - it('can calculate the `Krishtlindja` holiday as expected', function() use ($holiday) { + + it('can calculate the `Krishtlindja` holiday as expected', function () use ($holiday) { $dateInstance = CarbonImmutable::createFromDate('2024-12-25'); - + $isHoliday = $holiday->isHoliday($dateInstance); expect($isHoliday)->toBeTrue(); - + $holidayName = $holiday->getName($dateInstance); expect($holidayName)->toBe('Krishtlindja'); }); - }); +}); From b21b11d90dcc0e1781b5aa537e1d6549e78c0418 Mon Sep 17 00:00:00 2001 From: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> Date: Wed, 31 Jan 2024 20:36:16 +0100 Subject: [PATCH 030/175] cleanup Albania --- src/Countries/Albania.php | 9 +++++---- src/Exceptions/InvalidYear.php | 5 +++++ tests/Countries/AlbaniaTest.php | 2 +- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/Countries/Albania.php b/src/Countries/Albania.php index 2d7424dbf..dd0e05d32 100644 --- a/src/Countries/Albania.php +++ b/src/Countries/Albania.php @@ -3,6 +3,7 @@ namespace Spatie\Holidays\Countries; use Carbon\CarbonImmutable; +use Spatie\Holidays\Exceptions\InvalidYear; class Albania extends Country { @@ -37,7 +38,7 @@ protected function variableHolidays(int $year): array ]); } - private function getEidAlFitrHoliday(int $year): ?string + private function getEidAlFitrHoliday(int $year): string { /** * Provided until 2034 by qppstudio.net. @@ -55,11 +56,11 @@ private function getEidAlFitrHoliday(int $year): ?string 2032 => '01-14', 2033 => '01-02', 2034 => '12-12', - default => null // Holiday is variable; requires ongoing maintenance. + default => throw InvalidYear::range('Albania', 2024, 2034), }; } - private function getEidAlAdhaHoliday(int $year): ?string + private function getEidAlAdhaHoliday(int $year): string { /** * Tentative dates. @@ -78,7 +79,7 @@ private function getEidAlAdhaHoliday(int $year): ?string 2032 => '03-22', 2033 => '03-12', 2034 => '03-01', - default => null // Holiday is variable; requires ongoing maintenance. + default => throw InvalidYear::range('Albania', 2024, 2034), }; } } diff --git a/src/Exceptions/InvalidYear.php b/src/Exceptions/InvalidYear.php index bea3dcbb1..0eac2b9e1 100644 --- a/src/Exceptions/InvalidYear.php +++ b/src/Exceptions/InvalidYear.php @@ -15,4 +15,9 @@ public static function yearTooHigh(): self { return new self('Holidays can only be calculated for years before 2038.'); } + + public static function range(string $country, int $start, int $end): self + { + return new self("Only years between {$start} and {$end} are supported for {$country}."); + } } diff --git a/tests/Countries/AlbaniaTest.php b/tests/Countries/AlbaniaTest.php index 461e5e126..0cc1bf411 100644 --- a/tests/Countries/AlbaniaTest.php +++ b/tests/Countries/AlbaniaTest.php @@ -16,7 +16,7 @@ expect(formatDates($holidays))->toMatchSnapshot(); }); -it('does not return a holiday falsely', function () use ($holiday) { +it('does not return a holiday falsely', function () { $dateInstance = CarbonImmutable::createFromDate('2024-01-03'); $holiday = Holidays::for(country: 'al'); From b57af78f87c25e05f0665943eb9c878a82f55b2f Mon Sep 17 00:00:00 2001 From: Orane Edwards Date: Wed, 31 Jan 2024 14:42:17 -0500 Subject: [PATCH 031/175] Add holidays for Jamaica (#185) * Add Jamaican holidays * Add observed holidays for Jamaica. * Php Stan flagged error. Changed how date is created. * Remove unnecessary test for Ash Wednesday. * Remove timezone specification. --- src/Countries/Jamaica.php | 84 +++++++++++++++++++ .../it_can_calculate_jamaican_holidays.snap | 42 ++++++++++ tests/Countries/JamaicaTest.php | 34 ++++++++ 3 files changed, 160 insertions(+) create mode 100644 src/Countries/Jamaica.php create mode 100644 tests/.pest/snapshots/Countries/JamaicaTest/it_can_calculate_jamaican_holidays.snap create mode 100644 tests/Countries/JamaicaTest.php diff --git a/src/Countries/Jamaica.php b/src/Countries/Jamaica.php new file mode 100644 index 000000000..a6c955580 --- /dev/null +++ b/src/Countries/Jamaica.php @@ -0,0 +1,84 @@ +fixedHolidays(), + $this->variableHolidays($year), + $this->observedHolidays($year) + ); + + return $holidays; + } + + /** @return array */ + protected function fixedHolidays(): array + { + $holidays = [ + 'New Year\'s Day' => '01-01', + 'Labour Day' => '05-23', + 'Emancipation Day' => '08-01', + 'Independence Day' => '08-06', + 'Christmas Day' => '12-25', + 'Boxing Day' => '12-26', + ]; + + return $holidays; + } + + /** @return array */ + protected function variableHolidays(int $year): array + { + $easter = $this->easter($year); + $heroesDay = new CarbonImmutable("third monday of October $year"); + + return [ + 'Ash Wednesday' => $easter->subDays(46), + 'Good Friday' => $easter->subDays(2), + 'Easter Monday' => $easter->addDay(), + 'National Heroes Day' => $heroesDay, + ]; + } + + /** @return array */ + protected function observedHolidays(int $year): array + { + + $observedHolidays = []; + + foreach ($this->fixedHolidays() as $name => $date) { + $date = CarbonImmutable::parse("$year-$date"); + + // If any holiday falls on a Sunday, then it is observed on Monday + if($date->dayOfWeek === 0) { + $observedHolidays["{$name} Observed"] = $date->next(CarbonImmutable::MONDAY); + } + + // If Labour Day falls on a Saturday, then it is observed on Monday + if($name == 'Labour Day' && $date->dayOfWeek === 6) { + $observedHolidays["{$name} Observed"] = $date->next(CarbonImmutable::MONDAY); + } + + // If Boxing Day falls on a Monday, then it is observed on Tuesday (Christmas Day is observed on Monday) + // https://jis.gov.jm/observance-public-holidays-christmas-day-monday-december-26th-boxing-day-tuesday-december-27th/ + if ($name == 'Boxing Day' && $date->dayOfWeek === 1) { + $observedHolidays["{$name} Observed"] = $date->next(CarbonImmutable::TUESDAY); + } + } + + return $observedHolidays; + } +} diff --git a/tests/.pest/snapshots/Countries/JamaicaTest/it_can_calculate_jamaican_holidays.snap b/tests/.pest/snapshots/Countries/JamaicaTest/it_can_calculate_jamaican_holidays.snap new file mode 100644 index 000000000..3d71e806c --- /dev/null +++ b/tests/.pest/snapshots/Countries/JamaicaTest/it_can_calculate_jamaican_holidays.snap @@ -0,0 +1,42 @@ +[ + { + "name": "New Year's Day", + "date": "2024-01-01" + }, + { + "name": "Ash Wednesday", + "date": "2024-02-14" + }, + { + "name": "Good Friday", + "date": "2024-03-29" + }, + { + "name": "Easter Monday", + "date": "2024-04-01" + }, + { + "name": "Labour Day", + "date": "2024-05-23" + }, + { + "name": "Emancipation Day", + "date": "2024-08-01" + }, + { + "name": "Independence Day", + "date": "2024-08-06" + }, + { + "name": "National Heroes Day", + "date": "2024-10-21" + }, + { + "name": "Christmas Day", + "date": "2024-12-25" + }, + { + "name": "Boxing Day", + "date": "2024-12-26" + } +] \ No newline at end of file diff --git a/tests/Countries/JamaicaTest.php b/tests/Countries/JamaicaTest.php new file mode 100644 index 000000000..1ea7b0237 --- /dev/null +++ b/tests/Countries/JamaicaTest.php @@ -0,0 +1,34 @@ +get(); + + expect($holidays) + ->toBeArray() + ->not()->toBeEmpty(); + + expect(formatDates($holidays))->toMatchSnapshot(); +}); + +it('can calculate observed holidays based on year', function () { + + // Check for Observed New Year's Day + $holidays = Holidays::for(country: 'jm', year: 2023)->get(); + expect(array_search('New Year\'s Day Observed', array_column($holidays, 'name')))->toBeInt(); + + // Check for Observed Labour Day + $holidays = Holidays::for(country: 'jm', year: 2020)->get(); + expect(array_search('Labour Day Observed', array_column($holidays, 'name')))->toBeInt(); + + // Check that there is no Observerd New Year's Day + $holidays = Holidays::for(country: 'jm', year: 2024)->get(); + expect(array_search('Labour Day Observed', array_column($holidays, 'name')))->toBeFalse(); + +}); From 96395a14fe63e3656ba5e5cd86eaa3df3694ad59 Mon Sep 17 00:00:00 2001 From: Nielsvanpach Date: Wed, 31 Jan 2024 19:42:38 +0000 Subject: [PATCH 032/175] Fix styling --- src/Countries/Jamaica.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/Countries/Jamaica.php b/src/Countries/Jamaica.php index a6c955580..e9b3af3d4 100644 --- a/src/Countries/Jamaica.php +++ b/src/Countries/Jamaica.php @@ -3,7 +3,6 @@ namespace Spatie\Holidays\Countries; use Carbon\CarbonImmutable; -use Carbon\CarbonInterface; class Jamaica extends Country { @@ -63,12 +62,12 @@ protected function observedHolidays(int $year): array $date = CarbonImmutable::parse("$year-$date"); // If any holiday falls on a Sunday, then it is observed on Monday - if($date->dayOfWeek === 0) { + if ($date->dayOfWeek === 0) { $observedHolidays["{$name} Observed"] = $date->next(CarbonImmutable::MONDAY); } // If Labour Day falls on a Saturday, then it is observed on Monday - if($name == 'Labour Day' && $date->dayOfWeek === 6) { + if ($name == 'Labour Day' && $date->dayOfWeek === 6) { $observedHolidays["{$name} Observed"] = $date->next(CarbonImmutable::MONDAY); } From 60df0844a3dd83923e2d6b483d45012180ecf7c2 Mon Sep 17 00:00:00 2001 From: Peter Sowah Date: Wed, 31 Jan 2024 19:45:26 +0000 Subject: [PATCH 033/175] Add public holidays for Ghana (#175) * add Ghana holidays * add iterable type to variableHolidays method * Update src/Countries/Ghana.php Co-authored-by: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> * clean --------- Co-authored-by: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> --- src/Countries/Ghana.php | 39 +++++++++++++++++ ...te_Ghana_date_based_regional_holidays.snap | 42 ++++++++++++++++++ ...te_Ghana_easter_based_region_holidays.snap | 42 ++++++++++++++++++ .../it_can_calculate_Ghana_holidays.snap | 42 ++++++++++++++++++ tests/Countries/GhanaTest.php | 43 +++++++++++++++++++ 5 files changed, 208 insertions(+) create mode 100644 src/Countries/Ghana.php create mode 100644 tests/.pest/snapshots/Countries/GhanaTest/it_can_calculate_Ghana_date_based_regional_holidays.snap create mode 100644 tests/.pest/snapshots/Countries/GhanaTest/it_can_calculate_Ghana_easter_based_region_holidays.snap create mode 100644 tests/.pest/snapshots/Countries/GhanaTest/it_can_calculate_Ghana_holidays.snap create mode 100644 tests/Countries/GhanaTest.php diff --git a/src/Countries/Ghana.php b/src/Countries/Ghana.php new file mode 100644 index 000000000..2a32685ca --- /dev/null +++ b/src/Countries/Ghana.php @@ -0,0 +1,39 @@ + '01-01', + 'Constitution Day' => '01-07', + 'Independence Day' => '03-06', + 'May Day' => '05-01', + 'Founder\'s Day' => '08-04', + 'Kwame Nkrumah Memorial Day' => '09-21', + 'Christmas Day' => '12-25', + 'Boxing Day' => '12-26', + ], $this->variableHolidays($year)); + } + + /** @return array */ + protected function variableHolidays(int $year): array + { + $easter = $this->easter($year); + + return [ + 'Good Friday' => $easter->subDays(2), + 'Easter Monday' => $easter->addDay(), + ]; + } +} diff --git a/tests/.pest/snapshots/Countries/GhanaTest/it_can_calculate_Ghana_date_based_regional_holidays.snap b/tests/.pest/snapshots/Countries/GhanaTest/it_can_calculate_Ghana_date_based_regional_holidays.snap new file mode 100644 index 000000000..3d29c9e8f --- /dev/null +++ b/tests/.pest/snapshots/Countries/GhanaTest/it_can_calculate_Ghana_date_based_regional_holidays.snap @@ -0,0 +1,42 @@ +[ + { + "name": "New Year's Day", + "date": "2024-01-01" + }, + { + "name": "Constitution Day", + "date": "2024-01-07" + }, + { + "name": "Independence Day", + "date": "2024-03-06" + }, + { + "name": "Good Friday", + "date": "2024-03-29" + }, + { + "name": "Easter Monday", + "date": "2024-04-01" + }, + { + "name": "May Day", + "date": "2024-05-01" + }, + { + "name": "Founder's Day", + "date": "2024-08-04" + }, + { + "name": "Kwame Nkrumah Memorial Day", + "date": "2024-09-21" + }, + { + "name": "Christmas Day", + "date": "2024-12-25" + }, + { + "name": "Boxing Day", + "date": "2024-12-26" + } +] \ No newline at end of file diff --git a/tests/.pest/snapshots/Countries/GhanaTest/it_can_calculate_Ghana_easter_based_region_holidays.snap b/tests/.pest/snapshots/Countries/GhanaTest/it_can_calculate_Ghana_easter_based_region_holidays.snap new file mode 100644 index 000000000..3d29c9e8f --- /dev/null +++ b/tests/.pest/snapshots/Countries/GhanaTest/it_can_calculate_Ghana_easter_based_region_holidays.snap @@ -0,0 +1,42 @@ +[ + { + "name": "New Year's Day", + "date": "2024-01-01" + }, + { + "name": "Constitution Day", + "date": "2024-01-07" + }, + { + "name": "Independence Day", + "date": "2024-03-06" + }, + { + "name": "Good Friday", + "date": "2024-03-29" + }, + { + "name": "Easter Monday", + "date": "2024-04-01" + }, + { + "name": "May Day", + "date": "2024-05-01" + }, + { + "name": "Founder's Day", + "date": "2024-08-04" + }, + { + "name": "Kwame Nkrumah Memorial Day", + "date": "2024-09-21" + }, + { + "name": "Christmas Day", + "date": "2024-12-25" + }, + { + "name": "Boxing Day", + "date": "2024-12-26" + } +] \ No newline at end of file diff --git a/tests/.pest/snapshots/Countries/GhanaTest/it_can_calculate_Ghana_holidays.snap b/tests/.pest/snapshots/Countries/GhanaTest/it_can_calculate_Ghana_holidays.snap new file mode 100644 index 000000000..3d29c9e8f --- /dev/null +++ b/tests/.pest/snapshots/Countries/GhanaTest/it_can_calculate_Ghana_holidays.snap @@ -0,0 +1,42 @@ +[ + { + "name": "New Year's Day", + "date": "2024-01-01" + }, + { + "name": "Constitution Day", + "date": "2024-01-07" + }, + { + "name": "Independence Day", + "date": "2024-03-06" + }, + { + "name": "Good Friday", + "date": "2024-03-29" + }, + { + "name": "Easter Monday", + "date": "2024-04-01" + }, + { + "name": "May Day", + "date": "2024-05-01" + }, + { + "name": "Founder's Day", + "date": "2024-08-04" + }, + { + "name": "Kwame Nkrumah Memorial Day", + "date": "2024-09-21" + }, + { + "name": "Christmas Day", + "date": "2024-12-25" + }, + { + "name": "Boxing Day", + "date": "2024-12-26" + } +] \ No newline at end of file diff --git a/tests/Countries/GhanaTest.php b/tests/Countries/GhanaTest.php new file mode 100644 index 000000000..78f05a44b --- /dev/null +++ b/tests/Countries/GhanaTest.php @@ -0,0 +1,43 @@ +get(); + + expect($holidays) + ->toBeArray() + ->not()->toBeEmpty(); + + expect(formatDates($holidays))->toMatchSnapshot(); +}); + +it('can calculate Ghana easter based region holidays', function () { + CarbonImmutable::setTestNowAndTimezone('2024-01-01'); + + $holidays = Holidays::for(country: 'gh')->get(); + + expect($holidays) + ->toBeArray() + ->not()->toBeEmpty(); + + expect(formatDates($holidays))->toMatchSnapshot(); +}); + +it('can calculate Ghana date based regional holidays', function () { + CarbonImmutable::setTestNowAndTimezone('2024-01-01'); + + $holidays = Holidays::for(country: 'gh')->get(); + + expect($holidays) + ->toBeArray() + ->not()->toBeEmpty(); + + expect(formatDates($holidays))->toMatchSnapshot(); +}); From 089c5cc271ed359cabd8e7fe7a456fabfa51d15f Mon Sep 17 00:00:00 2001 From: Nielsvanpach Date: Wed, 31 Jan 2024 19:45:46 +0000 Subject: [PATCH 034/175] Fix styling --- src/Countries/Ghana.php | 1 - tests/Countries/GhanaTest.php | 1 - 2 files changed, 2 deletions(-) diff --git a/src/Countries/Ghana.php b/src/Countries/Ghana.php index 2a32685ca..03342516c 100644 --- a/src/Countries/Ghana.php +++ b/src/Countries/Ghana.php @@ -6,7 +6,6 @@ class Ghana extends Country { - public function countryCode(): string { return 'gh'; diff --git a/tests/Countries/GhanaTest.php b/tests/Countries/GhanaTest.php index 78f05a44b..3a02ed9d3 100644 --- a/tests/Countries/GhanaTest.php +++ b/tests/Countries/GhanaTest.php @@ -3,7 +3,6 @@ namespace Spatie\Holidays\Tests\Countries; use Carbon\CarbonImmutable; -use Spatie\Holidays\Countries\France; use Spatie\Holidays\Holidays; it('can calculate Ghana holidays', function () { From adf73ed2dd5799cc841c90ef5aa013b01d40f357 Mon Sep 17 00:00:00 2001 From: Jure Filipic Date: Wed, 31 Jan 2024 21:01:00 +0100 Subject: [PATCH 035/175] Support for Slovenian langage second PR after rebase problem (#139) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Jure Filipič --- src/Countries/Slovenia.php | 42 +++++++++++++++ .../it_can_calculate_slovenian_holidays.snap | 54 +++++++++++++++++++ tests/Countries/SloveniaTest.php | 18 +++++++ 3 files changed, 114 insertions(+) create mode 100644 src/Countries/Slovenia.php create mode 100644 tests/.pest/snapshots/Countries/SloveniaTest/it_can_calculate_slovenian_holidays.snap create mode 100644 tests/Countries/SloveniaTest.php diff --git a/src/Countries/Slovenia.php b/src/Countries/Slovenia.php new file mode 100644 index 000000000..1ed8f5c7d --- /dev/null +++ b/src/Countries/Slovenia.php @@ -0,0 +1,42 @@ + '01-01', // New Year's Day + 'Novo leto 2' => '01-02', // New Year's Day, yes it's a second day + 'Prešernov dan, slovenski kulturni praznik' => '08-02', // Prešeren Day, Slovenian Cultural Holiday + 'Dan upora proti okupatorju' => '04-27', // Day of Uprising Against Occupation + 'Praznik dela' => '05-01', // Labour Day + 'Praznik dela 2' => '05-02', // Labour Day, yes it's a second day + 'Dan državnosti' => '06-25', // Statehood Day + 'Marijino vnebovzetje' => '08-15', // Assumption of Mary + 'Dan reformacije' => '10-31', // Reformation Day + 'Dan spomina na mrtve' => '11-01', // Remembrance Day + 'Božič' => '12-25', // Christmas Day + 'Dan samostojnosti in enotnosti' => '12-26', // Independence and Unity Day + ], $this->variableHolidays($year)); + } + + /** @return array */ + protected function variableHolidays(int $year): array + { + $easter = $this->easter($year); + + return [ + 'Velikonočni ponedeljek' => $easter->addDay(), // Easter Monday + ]; + } +} diff --git a/tests/.pest/snapshots/Countries/SloveniaTest/it_can_calculate_slovenian_holidays.snap b/tests/.pest/snapshots/Countries/SloveniaTest/it_can_calculate_slovenian_holidays.snap new file mode 100644 index 000000000..b869f39b7 --- /dev/null +++ b/tests/.pest/snapshots/Countries/SloveniaTest/it_can_calculate_slovenian_holidays.snap @@ -0,0 +1,54 @@ +[ + { + "name": "Novo leto", + "date": "2024-01-01" + }, + { + "name": "Novo leto 2", + "date": "2024-01-02" + }, + { + "name": "Velikono\u010dni ponedeljek", + "date": "2024-04-01" + }, + { + "name": "Dan upora proti okupatorju", + "date": "2024-04-27" + }, + { + "name": "Praznik dela", + "date": "2024-05-01" + }, + { + "name": "Praznik dela 2", + "date": "2024-05-02" + }, + { + "name": "Dan dr\u017eavnosti", + "date": "2024-06-25" + }, + { + "name": "Pre\u0161ernov dan, slovenski kulturni praznik", + "date": "2024-08-02" + }, + { + "name": "Marijino vnebovzetje", + "date": "2024-08-15" + }, + { + "name": "Dan reformacije", + "date": "2024-10-31" + }, + { + "name": "Dan spomina na mrtve", + "date": "2024-11-01" + }, + { + "name": "Bo\u017ei\u010d", + "date": "2024-12-25" + }, + { + "name": "Dan samostojnosti in enotnosti", + "date": "2024-12-26" + } +] \ No newline at end of file diff --git a/tests/Countries/SloveniaTest.php b/tests/Countries/SloveniaTest.php new file mode 100644 index 000000000..d12319061 --- /dev/null +++ b/tests/Countries/SloveniaTest.php @@ -0,0 +1,18 @@ +get(); + + expect($holidays) + ->toBeArray() + ->not()->toBeEmpty(); + + expect(formatDates($holidays))->toMatchSnapshot(); +}); From 30690720a4d7d69d7751d01595bfc032a3dc24dd Mon Sep 17 00:00:00 2001 From: Nielsvanpach Date: Wed, 31 Jan 2024 20:01:21 +0000 Subject: [PATCH 036/175] Fix styling --- src/Countries/Slovenia.php | 4 ++-- tests/Countries/SloveniaTest.php | 12 ++++++------ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/Countries/Slovenia.php b/src/Countries/Slovenia.php index 1ed8f5c7d..4f2171d50 100644 --- a/src/Countries/Slovenia.php +++ b/src/Countries/Slovenia.php @@ -14,7 +14,7 @@ public function countryCode(): string protected function allHolidays(int $year): array { - return array_merge([ + return array_merge([ 'Novo leto' => '01-01', // New Year's Day 'Novo leto 2' => '01-02', // New Year's Day, yes it's a second day 'Prešernov dan, slovenski kulturni praznik' => '08-02', // Prešeren Day, Slovenian Cultural Holiday @@ -33,7 +33,7 @@ protected function allHolidays(int $year): array /** @return array */ protected function variableHolidays(int $year): array { - $easter = $this->easter($year); + $easter = $this->easter($year); return [ 'Velikonočni ponedeljek' => $easter->addDay(), // Easter Monday diff --git a/tests/Countries/SloveniaTest.php b/tests/Countries/SloveniaTest.php index d12319061..0dc846a6e 100644 --- a/tests/Countries/SloveniaTest.php +++ b/tests/Countries/SloveniaTest.php @@ -6,13 +6,13 @@ use Spatie\Holidays\Holidays; it('can calculate slovenian holidays', function () { - CarbonImmutable::setTestNowAndTimezone('2024-01-01'); + CarbonImmutable::setTestNowAndTimezone('2024-01-01'); - $holidays = Holidays::for(country: 'si')->get(); + $holidays = Holidays::for(country: 'si')->get(); - expect($holidays) - ->toBeArray() - ->not()->toBeEmpty(); + expect($holidays) + ->toBeArray() + ->not()->toBeEmpty(); - expect(formatDates($holidays))->toMatchSnapshot(); + expect(formatDates($holidays))->toMatchSnapshot(); }); From 8d7932e724c7939cb069f34df13d0dd8261ba1d8 Mon Sep 17 00:00:00 2001 From: vkosachev Date: Wed, 31 Jan 2024 22:08:48 +0200 Subject: [PATCH 037/175] Add Moldavian Holidays (#95) * Add Moldavian Holidays * Add Moldavian Holidays * change location for tests * updating the snapshots * Remove custom algorithm and use built in "orthodoxEater() method." * update from upstream --------- Co-authored-by: Vitaliy Kosachev --- src/Countries/Moldova.php | 40 ++++++++++++++ .../it_can_calculate_moldavian_holidays.snap | 54 +++++++++++++++++++ tests/Countries/MoldovaTest.php | 19 +++++++ 3 files changed, 113 insertions(+) create mode 100644 src/Countries/Moldova.php create mode 100644 tests/.pest/snapshots/Countries/MoldovaTest/it_can_calculate_moldavian_holidays.snap create mode 100644 tests/Countries/MoldovaTest.php diff --git a/src/Countries/Moldova.php b/src/Countries/Moldova.php new file mode 100644 index 000000000..0e7d3d47b --- /dev/null +++ b/src/Countries/Moldova.php @@ -0,0 +1,40 @@ + '01-01', + 'Crăciunul pe stil vechi' => '01-07', + 'A doua zi de Crăciun pe stil vechi' => '01-08', + 'Ziua Internațională a Femeii' => '03-08', + 'Ziua Muncii' => '05-01', + 'Ziua Europei' => '05-09', + 'Ziua Internațională a Copilului' => '06-01', + 'Ziua Independenței' => '08-27', + 'Ziua Limbii Române' => '08-31', + 'Crăciunul pe stil nou' => '12-25', + ], $this->variableHolidays($year)); + } + + /** @return array */ + protected function variableHolidays(int $year): array + { + $easter = $this->orthodoxEaster($year); + return [ + 'Prima zi de Paște' => $easter, + 'A doua zi de Paște' => $easter->addDay(), + 'Paștele Blajinilor' => $easter->addDays(8), + ]; + } +} diff --git a/tests/.pest/snapshots/Countries/MoldovaTest/it_can_calculate_moldavian_holidays.snap b/tests/.pest/snapshots/Countries/MoldovaTest/it_can_calculate_moldavian_holidays.snap new file mode 100644 index 000000000..9d18ecd37 --- /dev/null +++ b/tests/.pest/snapshots/Countries/MoldovaTest/it_can_calculate_moldavian_holidays.snap @@ -0,0 +1,54 @@ +[ + { + "name": "Anul Nou", + "date": "2024-01-01" + }, + { + "name": "Cr\u0103ciunul pe stil vechi", + "date": "2024-01-07" + }, + { + "name": "A doua zi de Cr\u0103ciun pe stil vechi", + "date": "2024-01-08" + }, + { + "name": "Ziua Interna\u021bional\u0103 a Femeii", + "date": "2024-03-08" + }, + { + "name": "Ziua Muncii", + "date": "2024-05-01" + }, + { + "name": "Prima zi de Pa\u0219te", + "date": "2024-05-05" + }, + { + "name": "A doua zi de Pa\u0219te", + "date": "2024-05-06" + }, + { + "name": "Ziua Europei", + "date": "2024-05-09" + }, + { + "name": "Pa\u0219tele Blajinilor", + "date": "2024-05-13" + }, + { + "name": "Ziua Interna\u021bional\u0103 a Copilului", + "date": "2024-06-01" + }, + { + "name": "Ziua Independen\u021bei", + "date": "2024-08-27" + }, + { + "name": "Ziua Limbii Rom\u00e2ne", + "date": "2024-08-31" + }, + { + "name": "Cr\u0103ciunul pe stil nou", + "date": "2024-12-25" + } +] \ No newline at end of file diff --git a/tests/Countries/MoldovaTest.php b/tests/Countries/MoldovaTest.php new file mode 100644 index 000000000..02ac0db64 --- /dev/null +++ b/tests/Countries/MoldovaTest.php @@ -0,0 +1,19 @@ +get(); + + expect($holidays) + ->toBeArray() + ->not()->toBeEmpty(); + + expect(formatDates($holidays))->toMatchSnapshot(); + +}); From 976518c67ff6049f045853b163367e57b91248af Mon Sep 17 00:00:00 2001 From: Nielsvanpach Date: Wed, 31 Jan 2024 20:09:20 +0000 Subject: [PATCH 038/175] Fix styling --- src/Countries/Moldova.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Countries/Moldova.php b/src/Countries/Moldova.php index 0e7d3d47b..aadae2468 100644 --- a/src/Countries/Moldova.php +++ b/src/Countries/Moldova.php @@ -30,7 +30,8 @@ protected function allHolidays(int $year): array /** @return array */ protected function variableHolidays(int $year): array { - $easter = $this->orthodoxEaster($year); + $easter = $this->orthodoxEaster($year); + return [ 'Prima zi de Paște' => $easter, 'A doua zi de Paște' => $easter->addDay(), From c2ce9ce0b70b1cae5f1e556b32916388abe550e0 Mon Sep 17 00:00:00 2001 From: Michael Nabil <46572405+michaelnabil230@users.noreply.github.com> Date: Wed, 31 Jan 2024 22:20:19 +0200 Subject: [PATCH 039/175] Add `Egypt` Holidays (#35) * Add `Egypt` Holidays * Clean * Fix * Update src/Countries/Egypt.php Co-authored-by: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> * Fix test * Added a translation --------- Co-authored-by: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> --- lang/egypt/ar/holidays.json | 23 +++++ src/Countries/Egypt.php | 47 ++++++++++ .../it_can_calculate_egypt_holidays.snap | 86 +++++++++++++++++++ tests/Countries/EgyptTest.php | 17 ++++ 4 files changed, 173 insertions(+) create mode 100644 lang/egypt/ar/holidays.json create mode 100644 src/Countries/Egypt.php create mode 100644 tests/.pest/snapshots/Countries/EgyptTest/it_can_calculate_egypt_holidays.snap create mode 100644 tests/Countries/EgyptTest.php diff --git a/lang/egypt/ar/holidays.json b/lang/egypt/ar/holidays.json new file mode 100644 index 000000000..2ca7af8d3 --- /dev/null +++ b/lang/egypt/ar/holidays.json @@ -0,0 +1,23 @@ +{ + "New Year\n's Day": "يوم رأس السنة", + "Coptic Christmas": "عيد الميلاد القبطي", + "Revolution Day January 25": "عيد ثورة 25 يناير", + "March Equinox": "اعتدال مارس", + "Sinai Liberation": "تحرير سيناء", + "Labor": "العمل", + "Coptic Good": "الصالح القبطي", + "Coptic Holy": "المقدس القبطي", + "Coptic Easter": "عيد الفصح القبطي", + "Spring Festival": "مهرجان الربيع", + "June Solstice": "انقلاب يونيو", + "June 30 Revolution": "ثورة 30 يونيو", + "Day off for June 30 Revolution": "يوم عطلة بمناسبة ثورة 30 يونيو", + "Revolution Day July 23": "عيد ثورة 23 يوليو", + "Day off for Revolution Day July 23": "يوم عطلة بمناسبة عيد ثورة 23 يوليو", + "Flooding of the Nile": "فيضان النيل", + "Nayrouz": "النيروز", + "September Equinox": "الاعتدال في سبتمبر", + "Armed Forces": "القوات المسلحة", + "Day off for Armed Forces": "يوم عطلة للقوات المسلحة", + "December Solstice": "الانقلاب الشمسي في ديسمبر" +} \ No newline at end of file diff --git a/src/Countries/Egypt.php b/src/Countries/Egypt.php new file mode 100644 index 000000000..4154b53f4 --- /dev/null +++ b/src/Countries/Egypt.php @@ -0,0 +1,47 @@ + '01-01', + 'Coptic Christmas' => '01-07', + 'Revolution Day January 25' => '01-25', + 'March Equinox' => '03-20', + 'Sinai Liberation' => '04-25', + 'Labor' => '05-01', + 'Coptic Good' => '05-03', + 'Coptic Holy' => '05-04', + 'Coptic Easter' => '05-05', + 'Spring Festival' => '05-06', + 'June Solstice' => '06-20', + 'June 30 Revolution' => '06-30', + 'Day off for June 30 Revolution' => '07-04', + 'Revolution Day July 23' => '07-23', + 'Day off for Revolution Day July 23' => '07-25', + 'Flooding of the Nile' => '08-15', + 'Nayrouz' => '09-11', + 'September Equinox' => '09-22', + 'Armed Forces' => '10-06', + 'Day off for Armed Forces' => '10-10', + 'December Solstice' => '12-21', + ], $this->variableHolidays($year)); + } + + /** @return array */ + protected function variableHolidays(int $year): array + { + // The variable holidays all follow the lunar calendar, so their dates are not confirmed. + return []; + } +} diff --git a/tests/.pest/snapshots/Countries/EgyptTest/it_can_calculate_egypt_holidays.snap b/tests/.pest/snapshots/Countries/EgyptTest/it_can_calculate_egypt_holidays.snap new file mode 100644 index 000000000..97a3a8144 --- /dev/null +++ b/tests/.pest/snapshots/Countries/EgyptTest/it_can_calculate_egypt_holidays.snap @@ -0,0 +1,86 @@ +[ + { + "name": "New Year's Day", + "date": "2024-01-01" + }, + { + "name": "Coptic Christmas", + "date": "2024-01-07" + }, + { + "name": "Revolution Day January 25", + "date": "2024-01-25" + }, + { + "name": "March Equinox", + "date": "2024-03-20" + }, + { + "name": "Sinai Liberation", + "date": "2024-04-25" + }, + { + "name": "Labor", + "date": "2024-05-01" + }, + { + "name": "Coptic Good", + "date": "2024-05-03" + }, + { + "name": "Coptic Holy", + "date": "2024-05-04" + }, + { + "name": "Coptic Easter", + "date": "2024-05-05" + }, + { + "name": "Spring Festival", + "date": "2024-05-06" + }, + { + "name": "June Solstice", + "date": "2024-06-20" + }, + { + "name": "June 30 Revolution", + "date": "2024-06-30" + }, + { + "name": "Day off for June 30 Revolution", + "date": "2024-07-04" + }, + { + "name": "Revolution Day July 23", + "date": "2024-07-23" + }, + { + "name": "Day off for Revolution Day July 23", + "date": "2024-07-25" + }, + { + "name": "Flooding of the Nile", + "date": "2024-08-15" + }, + { + "name": "Nayrouz", + "date": "2024-09-11" + }, + { + "name": "September Equinox", + "date": "2024-09-22" + }, + { + "name": "Armed Forces", + "date": "2024-10-06" + }, + { + "name": "Day off for Armed Forces", + "date": "2024-10-10" + }, + { + "name": "December Solstice", + "date": "2024-12-21" + } +] \ No newline at end of file diff --git a/tests/Countries/EgyptTest.php b/tests/Countries/EgyptTest.php new file mode 100644 index 000000000..24f5d9ea5 --- /dev/null +++ b/tests/Countries/EgyptTest.php @@ -0,0 +1,17 @@ +get(); + + expect($holidays) + ->toBeArray() + ->not()->toBeEmpty() + ->and(formatDates($holidays))->toMatchSnapshot(); +}); From c7b2e09a84a53baa07c76c0c96c6d85590452b87 Mon Sep 17 00:00:00 2001 From: Ye Thu Soe Date: Thu, 1 Feb 2024 02:53:39 +0630 Subject: [PATCH 040/175] add myanmar holidays (#29) * add myanmar holidays * test: update myanmar holidays * fix: remove unnecessary attribute declared --------- Co-authored-by: yethusoe91 <> --- src/Countries/Myanmar.php | 42 ++++++++ .../it_can_calculate_myanmar_holidays.snap | 102 ++++++++++++++++++ tests/Countries/MyanmarTest.php | 21 ++++ 3 files changed, 165 insertions(+) create mode 100644 src/Countries/Myanmar.php create mode 100644 tests/.pest/snapshots/Countries/MyanmarTest/it_can_calculate_myanmar_holidays.snap create mode 100644 tests/Countries/MyanmarTest.php diff --git a/src/Countries/Myanmar.php b/src/Countries/Myanmar.php new file mode 100644 index 000000000..7e7a79b74 --- /dev/null +++ b/src/Countries/Myanmar.php @@ -0,0 +1,42 @@ + '01-04', + 'ကရင်နှစ်သစ်ကူးနေ့' => '01-11', + 'ပြည်ထောင်စုနေ့' => '02-12', + 'တောင်သူလယ်သမားနေ့' => '03-02', + 'တပေါင်းလပြည့်နေ့' => '03-24', + 'တပ်မတော်နေ့' => '03-27', + 'မြန်မာနှစ်သစ်ကူးရုံးပိတ်ရက် ၁' => '04-13', + 'မြန်မာနှစ်သစ်ကူးရုံးပိတ်ရက် ၂' => '04-14', + 'မြန်မာနှစ်သစ်ကူးရုံးပိတ်ရက် ၃' => '04-15', + 'မြန်မာနှစ်သစ်ကူးရုံးပိတ်ရက် ၄' => '04-16', + 'မြန်မာနှစ်သစ်ကူးရုံးပိတ်ရက် ၅' => '04-17', + 'မြန်မာနှစ်သစ်ကူးရုံးပိတ်ရက် ၆' => '04-18', + 'မြန်မာနှစ်သစ်ကူးရုံးပိတ်ရက် ၇' => '04-19', + 'မြန်မာနှစ်သစ်ကူးရုံးပိတ်ရက် ၈' => '04-20', + 'မြန်မာနှစ်သစ်ကူးရုံးပိတ်ရက် ၉' => '04-21', + 'အလုပ်သမားနေ့' => '05-01', + 'ကဆုန်လပြည့်နေ့' => '05-22', + 'အာဇာနည်နေ့' => '07-19', + 'ဝါဆိုလပြည့်နေ့' => '07-20', + 'သီတင်းကျွတ်ရုံးပိတ်ရက် ၁' => '10-16', + 'သီတင်းကျွတ်ရုံးပိတ်ရက် ၂' => '10-17', + 'သီတင်းကျွတ်ရုံးပိတ်ရက် ၃' => '10-18', + 'တန်ဆောင်မုန်းလပြည့်နေ့' => '11-15', + 'အမျိုးသားအောင်ပွဲနေ့' => '11-25', + 'ခရစ်စမတ်နေ့' => '12-25', + ]; + } +} diff --git a/tests/.pest/snapshots/Countries/MyanmarTest/it_can_calculate_myanmar_holidays.snap b/tests/.pest/snapshots/Countries/MyanmarTest/it_can_calculate_myanmar_holidays.snap new file mode 100644 index 000000000..e0da2f2a4 --- /dev/null +++ b/tests/.pest/snapshots/Countries/MyanmarTest/it_can_calculate_myanmar_holidays.snap @@ -0,0 +1,102 @@ +[ + { + "name": "\u101c\u103d\u1010\u103a\u101c\u1015\u103a\u101b\u1031\u1038\u1014\u1031\u1037", + "date": "2024-01-04" + }, + { + "name": "\u1000\u101b\u1004\u103a\u1014\u103e\u1005\u103a\u101e\u1005\u103a\u1000\u1030\u1038\u1014\u1031\u1037", + "date": "2024-01-11" + }, + { + "name": "\u1015\u103c\u100a\u103a\u1011\u1031\u102c\u1004\u103a\u1005\u102f\u1014\u1031\u1037", + "date": "2024-02-12" + }, + { + "name": "\u1010\u1031\u102c\u1004\u103a\u101e\u1030\u101c\u101a\u103a\u101e\u1019\u102c\u1038\u1014\u1031\u1037", + "date": "2024-03-02" + }, + { + "name": "\u1010\u1015\u1031\u102b\u1004\u103a\u1038\u101c\u1015\u103c\u100a\u1037\u103a\u1014\u1031\u1037", + "date": "2024-03-24" + }, + { + "name": "\u1010\u1015\u103a\u1019\u1010\u1031\u102c\u103a\u1014\u1031\u1037", + "date": "2024-03-27" + }, + { + "name": "\u1019\u103c\u1014\u103a\u1019\u102c\u1014\u103e\u1005\u103a\u101e\u1005\u103a\u1000\u1030\u1038\u101b\u102f\u1036\u1038\u1015\u102d\u1010\u103a\u101b\u1000\u103a \u1041", + "date": "2024-04-13" + }, + { + "name": "\u1019\u103c\u1014\u103a\u1019\u102c\u1014\u103e\u1005\u103a\u101e\u1005\u103a\u1000\u1030\u1038\u101b\u102f\u1036\u1038\u1015\u102d\u1010\u103a\u101b\u1000\u103a \u1042", + "date": "2024-04-14" + }, + { + "name": "\u1019\u103c\u1014\u103a\u1019\u102c\u1014\u103e\u1005\u103a\u101e\u1005\u103a\u1000\u1030\u1038\u101b\u102f\u1036\u1038\u1015\u102d\u1010\u103a\u101b\u1000\u103a \u1043", + "date": "2024-04-15" + }, + { + "name": "\u1019\u103c\u1014\u103a\u1019\u102c\u1014\u103e\u1005\u103a\u101e\u1005\u103a\u1000\u1030\u1038\u101b\u102f\u1036\u1038\u1015\u102d\u1010\u103a\u101b\u1000\u103a \u1044", + "date": "2024-04-16" + }, + { + "name": "\u1019\u103c\u1014\u103a\u1019\u102c\u1014\u103e\u1005\u103a\u101e\u1005\u103a\u1000\u1030\u1038\u101b\u102f\u1036\u1038\u1015\u102d\u1010\u103a\u101b\u1000\u103a \u1045", + "date": "2024-04-17" + }, + { + "name": "\u1019\u103c\u1014\u103a\u1019\u102c\u1014\u103e\u1005\u103a\u101e\u1005\u103a\u1000\u1030\u1038\u101b\u102f\u1036\u1038\u1015\u102d\u1010\u103a\u101b\u1000\u103a \u1046", + "date": "2024-04-18" + }, + { + "name": "\u1019\u103c\u1014\u103a\u1019\u102c\u1014\u103e\u1005\u103a\u101e\u1005\u103a\u1000\u1030\u1038\u101b\u102f\u1036\u1038\u1015\u102d\u1010\u103a\u101b\u1000\u103a \u1047", + "date": "2024-04-19" + }, + { + "name": "\u1019\u103c\u1014\u103a\u1019\u102c\u1014\u103e\u1005\u103a\u101e\u1005\u103a\u1000\u1030\u1038\u101b\u102f\u1036\u1038\u1015\u102d\u1010\u103a\u101b\u1000\u103a \u1048", + "date": "2024-04-20" + }, + { + "name": "\u1019\u103c\u1014\u103a\u1019\u102c\u1014\u103e\u1005\u103a\u101e\u1005\u103a\u1000\u1030\u1038\u101b\u102f\u1036\u1038\u1015\u102d\u1010\u103a\u101b\u1000\u103a \u1049", + "date": "2024-04-21" + }, + { + "name": "\u1021\u101c\u102f\u1015\u103a\u101e\u1019\u102c\u1038\u1014\u1031\u1037", + "date": "2024-05-01" + }, + { + "name": "\u1000\u1006\u102f\u1014\u103a\u101c\u1015\u103c\u100a\u1037\u103a\u1014\u1031\u1037", + "date": "2024-05-22" + }, + { + "name": "\u1021\u102c\u1007\u102c\u1014\u100a\u103a\u1014\u1031\u1037", + "date": "2024-07-19" + }, + { + "name": "\u101d\u102b\u1006\u102d\u102f\u101c\u1015\u103c\u100a\u1037\u103a\u1014\u1031\u1037", + "date": "2024-07-20" + }, + { + "name": "\u101e\u102e\u1010\u1004\u103a\u1038\u1000\u103b\u103d\u1010\u103a\u101b\u102f\u1036\u1038\u1015\u102d\u1010\u103a\u101b\u1000\u103a \u1041", + "date": "2024-10-16" + }, + { + "name": "\u101e\u102e\u1010\u1004\u103a\u1038\u1000\u103b\u103d\u1010\u103a\u101b\u102f\u1036\u1038\u1015\u102d\u1010\u103a\u101b\u1000\u103a \u1042", + "date": "2024-10-17" + }, + { + "name": "\u101e\u102e\u1010\u1004\u103a\u1038\u1000\u103b\u103d\u1010\u103a\u101b\u102f\u1036\u1038\u1015\u102d\u1010\u103a\u101b\u1000\u103a \u1043", + "date": "2024-10-18" + }, + { + "name": "\u1010\u1014\u103a\u1006\u1031\u102c\u1004\u103a\u1019\u102f\u1014\u103a\u1038\u101c\u1015\u103c\u100a\u1037\u103a\u1014\u1031\u1037", + "date": "2024-11-15" + }, + { + "name": "\u1021\u1019\u103b\u102d\u102f\u1038\u101e\u102c\u1038\u1021\u1031\u102c\u1004\u103a\u1015\u103d\u1032\u1014\u1031\u1037", + "date": "2024-11-25" + }, + { + "name": "\u1001\u101b\u1005\u103a\u1005\u1019\u1010\u103a\u1014\u1031\u1037", + "date": "2024-12-25" + } +] \ No newline at end of file diff --git a/tests/Countries/MyanmarTest.php b/tests/Countries/MyanmarTest.php new file mode 100644 index 000000000..cee3463f1 --- /dev/null +++ b/tests/Countries/MyanmarTest.php @@ -0,0 +1,21 @@ +get(); + + $result = Holidays::for('mm')->getName(CarbonImmutable::parse('2024-12-25')); + + expect($result)->toBe('ခရစ်စမတ်နေ့'); + + $result = Holidays::for('mm')->getName(CarbonImmutable::parse('2024-01-02')); + expect($result)->toBeNull(); + + expect(formatDates($holidays))->toMatchSnapshot(); + +}); From e2889785b61c13b426ebd889ef35693446d7d4b6 Mon Sep 17 00:00:00 2001 From: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> Date: Wed, 31 Jan 2024 21:22:05 +0100 Subject: [PATCH 041/175] cleanup exceptions --- src/Countries/Country.php | 4 ++-- src/Countries/SriLanka.php | 4 ++-- src/Countries/Switzerland.php | 2 +- .../{UnsupportedCountry.php => InvalidCountry.php} | 4 ++-- src/Exceptions/InvalidRegion.php | 7 +------ tests/Countries/SriLankaTest.php | 4 ++-- tests/HolidaysTest.php | 4 ++-- 7 files changed, 12 insertions(+), 17 deletions(-) rename src/Exceptions/{UnsupportedCountry.php => InvalidCountry.php} (59%) diff --git a/src/Countries/Country.php b/src/Countries/Country.php index 9e9a85533..9934a7972 100644 --- a/src/Countries/Country.php +++ b/src/Countries/Country.php @@ -5,7 +5,7 @@ use Carbon\CarbonImmutable; use Spatie\Holidays\Concerns\Translatable; use Spatie\Holidays\Exceptions\InvalidYear; -use Spatie\Holidays\Exceptions\UnsupportedCountry; +use Spatie\Holidays\Exceptions\InvalidCountry; abstract class Country { @@ -93,7 +93,7 @@ public static function findOrFail(string $countryCode): Country $country = self::find($countryCode); if (! $country) { - throw UnsupportedCountry::make($countryCode); + throw InvalidCountry::notFound($countryCode); } return $country; diff --git a/src/Countries/SriLanka.php b/src/Countries/SriLanka.php index a94f46cdf..10413e49d 100644 --- a/src/Countries/SriLanka.php +++ b/src/Countries/SriLanka.php @@ -2,7 +2,7 @@ namespace Spatie\Holidays\Countries; -use Spatie\Holidays\Exceptions\UnsupportedCountry; +use Spatie\Holidays\Exceptions\InvalidCountry; class SriLanka extends Country { @@ -16,6 +16,6 @@ protected function allHolidays(int $year): array // Sri lanka has a committee that decides the holidays for the year // instead of following a full moon calendar. - throw UnsupportedCountry::make($this->countryCode()); + throw InvalidCountry::notFound($this->countryCode()); } } diff --git a/src/Countries/Switzerland.php b/src/Countries/Switzerland.php index c2e9d157c..d4d710689 100644 --- a/src/Countries/Switzerland.php +++ b/src/Countries/Switzerland.php @@ -73,7 +73,7 @@ class Switzerland extends Country public function __construct(protected ?string $region = null) { if ($region !== null && ! in_array($region, self::REGIONS)) { - throw InvalidRegion::unsupportedRegion($region); + throw InvalidRegion::notFound($region); } } diff --git a/src/Exceptions/UnsupportedCountry.php b/src/Exceptions/InvalidCountry.php similarity index 59% rename from src/Exceptions/UnsupportedCountry.php rename to src/Exceptions/InvalidCountry.php index 79bcabb34..451910b25 100644 --- a/src/Exceptions/UnsupportedCountry.php +++ b/src/Exceptions/InvalidCountry.php @@ -4,9 +4,9 @@ use RuntimeException; -class UnsupportedCountry extends RuntimeException +class InvalidCountry extends RuntimeException { - public static function make(string $countryCode): self + public static function notFound(string $countryCode): self { return new self("Country code `{$countryCode}` is not supported."); } diff --git a/src/Exceptions/InvalidRegion.php b/src/Exceptions/InvalidRegion.php index 7941fe2b5..d27ed70d7 100644 --- a/src/Exceptions/InvalidRegion.php +++ b/src/Exceptions/InvalidRegion.php @@ -6,13 +6,8 @@ class InvalidRegion extends RuntimeException { - public static function unsupportedRegion(string $region): self + public static function notFound(string $region): self { return new self("Region '$region' is not supported."); } - - public static function unsupportedLocale(string $locale): self - { - return new self("Locale '$locale' is not supported."); - } } diff --git a/tests/Countries/SriLankaTest.php b/tests/Countries/SriLankaTest.php index ab8eefe4a..5989f52e3 100644 --- a/tests/Countries/SriLankaTest.php +++ b/tests/Countries/SriLankaTest.php @@ -2,9 +2,9 @@ namespace Spatie\Holidays\Tests\Countries; -use Spatie\Holidays\Exceptions\UnsupportedCountry; +use Spatie\Holidays\Exceptions\InvalidCountry; use Spatie\Holidays\Holidays; it('cannot calculate sri lanka holidays', function () { Holidays::for(country: 'lk')->get(); -})->throws(UnsupportedCountry::class); +})->throws(InvalidCountry::class); diff --git a/tests/HolidaysTest.php b/tests/HolidaysTest.php index c09d7db67..c5a462123 100644 --- a/tests/HolidaysTest.php +++ b/tests/HolidaysTest.php @@ -5,7 +5,7 @@ use Spatie\Holidays\Countries\Netherlands; use Spatie\Holidays\Exceptions\InvalidLocale; use Spatie\Holidays\Exceptions\InvalidYear; -use Spatie\Holidays\Exceptions\UnsupportedCountry; +use Spatie\Holidays\Exceptions\InvalidCountry; use Spatie\Holidays\Holidays; it('can get all holidays of the current year', function () { @@ -43,7 +43,7 @@ it('cannot get all holidays of an unknown country code', function () { Holidays::for(country: 'unknown'); -})->throws(UnsupportedCountry::class); +})->throws(InvalidCountry::class); it('cannot get holidays for years before 1970', function () { Holidays::for(country: 'be', year: 1969)->get(); From 0ee271a4f1cc4edcee0d0ef5e524b5875a3ff4f5 Mon Sep 17 00:00:00 2001 From: Nielsvanpach Date: Wed, 31 Jan 2024 20:24:24 +0000 Subject: [PATCH 042/175] Fix styling --- src/Countries/Country.php | 2 +- tests/HolidaysTest.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Countries/Country.php b/src/Countries/Country.php index 9934a7972..538b89675 100644 --- a/src/Countries/Country.php +++ b/src/Countries/Country.php @@ -4,8 +4,8 @@ use Carbon\CarbonImmutable; use Spatie\Holidays\Concerns\Translatable; -use Spatie\Holidays\Exceptions\InvalidYear; use Spatie\Holidays\Exceptions\InvalidCountry; +use Spatie\Holidays\Exceptions\InvalidYear; abstract class Country { diff --git a/tests/HolidaysTest.php b/tests/HolidaysTest.php index c5a462123..99f8a792a 100644 --- a/tests/HolidaysTest.php +++ b/tests/HolidaysTest.php @@ -3,9 +3,9 @@ use Carbon\CarbonImmutable; use Spatie\Holidays\Countries\Belgium; use Spatie\Holidays\Countries\Netherlands; +use Spatie\Holidays\Exceptions\InvalidCountry; use Spatie\Holidays\Exceptions\InvalidLocale; use Spatie\Holidays\Exceptions\InvalidYear; -use Spatie\Holidays\Exceptions\InvalidCountry; use Spatie\Holidays\Holidays; it('can get all holidays of the current year', function () { From e30a34d631b24cd7981b55a7c7a759a2d64d4311 Mon Sep 17 00:00:00 2001 From: Joshua Paul <52431939+cybernerdie@users.noreply.github.com> Date: Wed, 31 Jan 2024 21:31:16 +0100 Subject: [PATCH 043/175] Added support for holidays in Nigeria (#10) * Added support for holidays in Nigeria * fix name of the test case * remove children's day from list of official holiday * fix code styling issues * Update src/Countries/Nigeria.php --------- Co-authored-by: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> --- src/Countries/Nigeria.php | 36 +++++++++++++++++++ .../it_can_calculate_nigerian_holidays.snap | 34 ++++++++++++++++++ tests/Countries/NigeriaTest.php | 18 ++++++++++ 3 files changed, 88 insertions(+) create mode 100644 src/Countries/Nigeria.php create mode 100644 tests/.pest/snapshots/Countries/NigeriaTest/it_can_calculate_nigerian_holidays.snap create mode 100644 tests/Countries/NigeriaTest.php diff --git a/src/Countries/Nigeria.php b/src/Countries/Nigeria.php new file mode 100644 index 000000000..21ead05d6 --- /dev/null +++ b/src/Countries/Nigeria.php @@ -0,0 +1,36 @@ + "01-01", + 'Worker\'s Day' => "05-01", + 'Democracy Day' => "06-12", + 'Independence Day' => "10-01", + 'Christmas Day' => "12-25", + 'Boxing Day' => "12-26", + ], $this->variableHolidays($year)); + } + + /** @return array */ + protected function variableHolidays(int $year): array + { + $easter = $this->easter($year); + + return [ + 'Good Friday' => $easter->subDays(2), + 'Easter Monday' => $easter->addDay(), + ]; + } +} diff --git a/tests/.pest/snapshots/Countries/NigeriaTest/it_can_calculate_nigerian_holidays.snap b/tests/.pest/snapshots/Countries/NigeriaTest/it_can_calculate_nigerian_holidays.snap new file mode 100644 index 000000000..ee5d39b48 --- /dev/null +++ b/tests/.pest/snapshots/Countries/NigeriaTest/it_can_calculate_nigerian_holidays.snap @@ -0,0 +1,34 @@ +[ + { + "name": "New Year's Day", + "date": "2024-01-01" + }, + { + "name": "Good Friday", + "date": "2024-03-29" + }, + { + "name": "Easter Monday", + "date": "2024-04-01" + }, + { + "name": "Worker's Day", + "date": "2024-05-01" + }, + { + "name": "Democracy Day", + "date": "2024-06-12" + }, + { + "name": "Independence Day", + "date": "2024-10-01" + }, + { + "name": "Christmas Day", + "date": "2024-12-25" + }, + { + "name": "Boxing Day", + "date": "2024-12-26" + } +] \ No newline at end of file diff --git a/tests/Countries/NigeriaTest.php b/tests/Countries/NigeriaTest.php new file mode 100644 index 000000000..8fdb2a32a --- /dev/null +++ b/tests/Countries/NigeriaTest.php @@ -0,0 +1,18 @@ +get(); + + expect($holidays) + ->toBeArray() + ->not()->toBeEmpty(); + + expect(formatDates($holidays))->toMatchSnapshot(); +}); From 914ae68e4dd979172182fb60058ae914db12c0f8 Mon Sep 17 00:00:00 2001 From: Nielsvanpach Date: Wed, 31 Jan 2024 20:31:34 +0000 Subject: [PATCH 044/175] Fix styling --- src/Countries/Nigeria.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Countries/Nigeria.php b/src/Countries/Nigeria.php index 21ead05d6..7721b0d06 100644 --- a/src/Countries/Nigeria.php +++ b/src/Countries/Nigeria.php @@ -14,12 +14,12 @@ public function countryCode(): string protected function allHolidays(int $year): array { return array_merge([ - 'New Year\'s Day' => "01-01", - 'Worker\'s Day' => "05-01", - 'Democracy Day' => "06-12", - 'Independence Day' => "10-01", - 'Christmas Day' => "12-25", - 'Boxing Day' => "12-26", + 'New Year\'s Day' => '01-01', + 'Worker\'s Day' => '05-01', + 'Democracy Day' => '06-12', + 'Independence Day' => '10-01', + 'Christmas Day' => '12-25', + 'Boxing Day' => '12-26', ], $this->variableHolidays($year)); } From 9896b2f30228cb25cf605ef81d2dcd60e996c48f Mon Sep 17 00:00:00 2001 From: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> Date: Thu, 1 Feb 2024 10:37:25 +0100 Subject: [PATCH 045/175] remove timezones --- src/Countries/Australia.php | 2 +- src/Countries/Greece.php | 2 +- src/Countries/Japan.php | 12 ++++-------- src/Countries/Kenya.php | 3 +-- src/Countries/Montenegro.php | 2 +- src/Countries/Vietnam.php | 3 +-- 6 files changed, 9 insertions(+), 15 deletions(-) diff --git a/src/Countries/Australia.php b/src/Countries/Australia.php index 0b43bae4e..3de478baa 100644 --- a/src/Countries/Australia.php +++ b/src/Countries/Australia.php @@ -30,7 +30,7 @@ protected function allHolidays(int $year): array /** @return array */ protected function variableHolidays(int $year): array { - $easter = $this->easter($year)->setTimezone('Australia/Sydney'); + $easter = $this->easter($year); return [ 'Good Friday' => $easter->subDays(2), diff --git a/src/Countries/Greece.php b/src/Countries/Greece.php index 1b206e007..5a0b0a450 100644 --- a/src/Countries/Greece.php +++ b/src/Countries/Greece.php @@ -30,7 +30,7 @@ protected function allHolidays(int $year): array protected function variableHolidays(int $year): array { // OrthodoxEaster needs to setTimezone - $orthodoxEaster = $this->orthodoxEaster($year)->setTimezone('Europe/Athens'); + $orthodoxEaster = $this->orthodoxEaster($year); $cleanMonday = $orthodoxEaster->copy()->subDays(48); $megaliParaskevi = $orthodoxEaster->copy()->subDays(2); $megaloSavvato = $orthodoxEaster->copy()->subDays(1); diff --git a/src/Countries/Japan.php b/src/Countries/Japan.php index 38b1bc7d5..a15d890c5 100644 --- a/src/Countries/Japan.php +++ b/src/Countries/Japan.php @@ -33,17 +33,13 @@ protected function allHolidays(int $year): array /** @return array */ protected function variableHolidays(int $year): array { - $comingOfAgeDay = (new CarbonImmutable("second monday of january $year")) // Coming of Age Day - ->setTimezone('Asia/Tokyo'); + $comingOfAgeDay = (new CarbonImmutable("second monday of january $year"))->startOfDay(); - $oceansDay = (new CarbonImmutable("third monday of july $year")) // Ocean's Day - ->setTimezone('Asia/Tokyo'); + $oceansDay = (new CarbonImmutable("third monday of july $year"))->startOfDay(); - $respectForTheAgedDay = (new CarbonImmutable("third monday of september $year")) // Respect for the Aged Day - ->setTimezone('Asia/Tokyo'); + $respectForTheAgedDay = (new CarbonImmutable("third monday of september $year"))->startOfDay(); - $sportsDay = (new CarbonImmutable("second monday of october $year")) // Sports Day - ->setTimezone('Asia/Tokyo'); + $sportsDay = (new CarbonImmutable("second monday of october $year"))->startOfDay(); $holidays = [ '成人の日' => $comingOfAgeDay, diff --git a/src/Countries/Kenya.php b/src/Countries/Kenya.php index 82a7ad3d8..86e95b704 100644 --- a/src/Countries/Kenya.php +++ b/src/Countries/Kenya.php @@ -28,8 +28,7 @@ protected function allHolidays(int $year): array /** @return array */ protected function variableHolidays(int $year): array { - $easter = CarbonImmutable::createFromTimestamp(easter_date($year)) - ->setTimezone('Africa/Nairobi'); + $easter = $this->easter($year); return [ 'Good Friday' => $easter->subDays(2), diff --git a/src/Countries/Montenegro.php b/src/Countries/Montenegro.php index 2423f1e81..b653d4a4f 100644 --- a/src/Countries/Montenegro.php +++ b/src/Countries/Montenegro.php @@ -36,7 +36,7 @@ public function allHolidays(int $year): array public function variableHolidays(int $year): array { // Orthodox Easter calculation needs to be in the same timezone as the country - $orthodoxEaster = $this->orthodoxEaster($year)->setTimezone('Europe/Podgorica'); + $orthodoxEaster = $this->orthodoxEaster($year); $goodFriday = $orthodoxEaster->copy()->subDays(2); $orthodoxEasterMonday = $orthodoxEaster->copy()->addDay(); diff --git a/src/Countries/Vietnam.php b/src/Countries/Vietnam.php index 76ae6f1b5..7d6504047 100644 --- a/src/Countries/Vietnam.php +++ b/src/Countries/Vietnam.php @@ -80,8 +80,7 @@ protected function getTheExtraDayForIndependenceDay(int $year): array return []; } - $independenceDay = CarbonImmutable::parse("$year-09-02") - ->setTimeZone('Asia/Ho_Chi_Minh'); + $independenceDay = CarbonImmutable::parse("$year-09-02")->startOfDay(); if ($independenceDay->dayOfWeek === CarbonInterface::MONDAY) { return ['Ngày Sau Quốc Khánh' => $independenceDay->addDay()]; From 6c140a5336c51f4162cb93c764c4168df452f369 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9as=20Lundgren?= <1066486+adevade@users.noreply.github.com> Date: Thu, 1 Feb 2024 10:39:09 +0100 Subject: [PATCH 046/175] Add support for Swedish holidays (#199) * Add support for Swedish holidays * Remove timezones --- src/Countries/Sweden.php | 57 +++++++++++++++++++ .../it_can_calculate_swedish_holidays.snap | 54 ++++++++++++++++++ tests/Countries/SwedenTest.php | 18 ++++++ 3 files changed, 129 insertions(+) create mode 100644 src/Countries/Sweden.php create mode 100644 tests/.pest/snapshots/Countries/SwedenTest/it_can_calculate_swedish_holidays.snap create mode 100644 tests/Countries/SwedenTest.php diff --git a/src/Countries/Sweden.php b/src/Countries/Sweden.php new file mode 100644 index 000000000..dc4a5b888 --- /dev/null +++ b/src/Countries/Sweden.php @@ -0,0 +1,57 @@ + '01-01', + 'Trettondedag jul' => '01-06', + 'Första maj' => '05-1', + 'Nationaldagen' => '06-6', + 'Juldagen' => '12-25', + 'Annandag jul' => '12-26', + ], $this->variableHolidays($year)); + } + + /** @return array */ + protected function variableHolidays(int $year): array + { + $easter = $this->easter($year); + + /** @var CarbonImmutable $midsummerDay */ + $midsummerDay = CarbonImmutable::createFromFormat('Y-m-d', "{$year}-06-20"); + + if (! $midsummerDay->isSaturday()) { + $midsummerDay = $midsummerDay->next(CarbonImmutable::SATURDAY); + } + + /** @var CarbonImmutable $halloween */ + $halloween = CarbonImmutable::createFromFormat('Y-m-d', "{$year}-10-31"); + + if (! $halloween->isSaturday()) { + $halloween = $halloween->next(CarbonImmutable::SATURDAY); + } + + return [ + 'Långfredagen' => $easter->subDays(2), + 'Påskdagen' => $easter, + 'Annandag påsk' => $easter->addDay(), + 'Kristi himmelsfärdsdag' => $easter->addDays(39), + 'Pingstdagen' => $easter->addDays(49), + 'Midsommardagen' => $midsummerDay->day > 26 + ? $midsummerDay->subWeek() + : $midsummerDay, + 'Alla helgons dag' => $halloween, + ]; + } +} diff --git a/tests/.pest/snapshots/Countries/SwedenTest/it_can_calculate_swedish_holidays.snap b/tests/.pest/snapshots/Countries/SwedenTest/it_can_calculate_swedish_holidays.snap new file mode 100644 index 000000000..c22a86d64 --- /dev/null +++ b/tests/.pest/snapshots/Countries/SwedenTest/it_can_calculate_swedish_holidays.snap @@ -0,0 +1,54 @@ +[ + { + "name": "Ny\u00e5rsdagen", + "date": "2024-01-01" + }, + { + "name": "Trettondedag jul", + "date": "2024-01-06" + }, + { + "name": "L\u00e5ngfredagen", + "date": "2024-03-29" + }, + { + "name": "P\u00e5skdagen", + "date": "2024-03-31" + }, + { + "name": "Annandag p\u00e5sk", + "date": "2024-04-01" + }, + { + "name": "F\u00f6rsta maj", + "date": "2024-05-01" + }, + { + "name": "Kristi himmelsf\u00e4rdsdag", + "date": "2024-05-09" + }, + { + "name": "Pingstdagen", + "date": "2024-05-19" + }, + { + "name": "Nationaldagen", + "date": "2024-06-06" + }, + { + "name": "Midsommardagen", + "date": "2024-06-22" + }, + { + "name": "Alla helgons dag", + "date": "2024-11-02" + }, + { + "name": "Juldagen", + "date": "2024-12-25" + }, + { + "name": "Annandag jul", + "date": "2024-12-26" + } +] \ No newline at end of file diff --git a/tests/Countries/SwedenTest.php b/tests/Countries/SwedenTest.php new file mode 100644 index 000000000..5505f368d --- /dev/null +++ b/tests/Countries/SwedenTest.php @@ -0,0 +1,18 @@ +get(); + + expect($holidays) + ->toBeArray() + ->not()->toBeEmpty(); + + expect(formatDates($holidays))->toMatchSnapshot(); +}); From 32a94ff790adf31c3058d72a3e4d75634d01b8b2 Mon Sep 17 00:00:00 2001 From: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> Date: Thu, 1 Feb 2024 10:45:07 +0100 Subject: [PATCH 047/175] fixes for Sweden --- phpstan-baseline.neon | 5 +++++ src/Countries/Sweden.php | 11 +++++------ 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index ec51df55b..b253bace3 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -25,6 +25,11 @@ parameters: count: 1 path: src/Countries/Country.php + - + message: "#^Cannot call method startOfDay\\(\\) on Carbon\\\\CarbonImmutable\\|false\\.$#" + count: 2 + path: src/Countries/Sweden.php + - message: "#^Cannot call method setTimeStamp\\(\\) on DateTime\\|false\\.$#" count: 1 diff --git a/src/Countries/Sweden.php b/src/Countries/Sweden.php index dc4a5b888..e16eae6eb 100644 --- a/src/Countries/Sweden.php +++ b/src/Countries/Sweden.php @@ -3,6 +3,7 @@ namespace Spatie\Holidays\Countries; use Carbon\CarbonImmutable; +use Carbon\CarbonInterface; class Sweden extends Country { @@ -28,18 +29,16 @@ protected function variableHolidays(int $year): array { $easter = $this->easter($year); - /** @var CarbonImmutable $midsummerDay */ - $midsummerDay = CarbonImmutable::createFromFormat('Y-m-d', "{$year}-06-20"); + $midsummerDay = CarbonImmutable::createFromFormat('Y-m-d', "{$year}-06-20")->startOfDay(); if (! $midsummerDay->isSaturday()) { - $midsummerDay = $midsummerDay->next(CarbonImmutable::SATURDAY); + $midsummerDay = $midsummerDay->next(CarbonInterface::SATURDAY); } - /** @var CarbonImmutable $halloween */ - $halloween = CarbonImmutable::createFromFormat('Y-m-d', "{$year}-10-31"); + $halloween = CarbonImmutable::createFromFormat('Y-m-d', "{$year}-10-31")->startOfDay(); if (! $halloween->isSaturday()) { - $halloween = $halloween->next(CarbonImmutable::SATURDAY); + $halloween = $halloween->next(CarbonInterface::SATURDAY); } return [ From d99af11b2b3a1fe59fa4b009e33cceaa0e8c3b82 Mon Sep 17 00:00:00 2001 From: Ali Salehi <111766206+alisalehi1380@users.noreply.github.com> Date: Thu, 1 Feb 2024 13:23:27 +0330 Subject: [PATCH 048/175] Add National and Revolutionary Iran Holidays (#146) * Add Iran Holidays * Add(lang): Iran Holidays * Fix(Countries): remove `variableHolidays` func | rename Iran Holidays to persian * Add(test): can calculate iran holidays in local | Change setTestNowAndTimezone to setTestNow --- lang/Iran/en/holidays.json | 12 ++++++ lang/Iran/fa/holidays.json | 12 ++++++ src/Countries/Iran.php | 29 +++++++++++++ .../it_can_calculate_iran_holidays.snap | 42 +++++++++++++++++++ tests/Countries/IranTest.php | 31 ++++++++++++++ 5 files changed, 126 insertions(+) create mode 100644 lang/Iran/en/holidays.json create mode 100644 lang/Iran/fa/holidays.json create mode 100644 src/Countries/Iran.php create mode 100644 tests/.pest/snapshots/Countries/IranTest/it_can_calculate_iran_holidays.snap create mode 100644 tests/Countries/IranTest.php diff --git a/lang/Iran/en/holidays.json b/lang/Iran/en/holidays.json new file mode 100644 index 000000000..d8ede9c05 --- /dev/null +++ b/lang/Iran/en/holidays.json @@ -0,0 +1,12 @@ +{ + "پیروزی انقلاب اسلامی پنجاه و هفت": "Anniversary of Islamic Revolution Day", + "روز ملی شدن صنعت نفت": "Nationalization of Oil Industry Day", + "نخستین روز نوروز": "Nowruz First Day", + "دومین روز نوروز": "Nowruz Second Day", + "سومین روز نوروز": "Nowruz Third Day", + "چهارمین روز نوروز": "Nowruz Fourth Day", + "روز جمهوری اسلامی": "Islamic Republic Day", + "سیزده بدر": "Sizdah Bedar", + "رحلت روح\u200Cالله خمینی": "Death of Khomeini Day", + "قیام ۱۵ خرداد": "Revolt of Khordad 15 Day" +} \ No newline at end of file diff --git a/lang/Iran/fa/holidays.json b/lang/Iran/fa/holidays.json new file mode 100644 index 000000000..a8f7a256b --- /dev/null +++ b/lang/Iran/fa/holidays.json @@ -0,0 +1,12 @@ +{ + "پیروزی انقلاب اسلامی پنجاه و هفت": "پیروزی انقلاب اسلامی پنجاه و هفت", + "روز ملی شدن صنعت نفت": "روز ملی شدن صنعت نفت", + "نخستین روز نوروز": "نخستین روز نوروز", + "دومین روز نوروز": "دومین روز نوروز", + "سومین روز نوروز": "سومین روز نوروز", + "چهارمین روز نوروز": "چهارمین روز نوروز", + "روز جمهوری اسلامی": "روز جمهوری اسلامی", + "سیزده بدر": "سیزده بدر", + "رحلت روح\u200Cالله خمینی": "رحلت روح\u200Cالله خمینی", + "قیام ۱۵ خرداد": "قیام ۱۵ خرداد" +} \ No newline at end of file diff --git a/src/Countries/Iran.php b/src/Countries/Iran.php new file mode 100644 index 000000000..981f5e618 --- /dev/null +++ b/src/Countries/Iran.php @@ -0,0 +1,29 @@ + '02-11', + 'روز ملی شدن صنعت نفت' => '03-19', + 'نخستین روز نوروز' => '03-20', + 'دومین روز نوروز' => '03-21', + 'سومین روز نوروز' => '03-22', + 'چهارمین روز نوروز' => '03-23', + 'روز جمهوری اسلامی' => '03-31', + 'سیزده بدر' => '04-01', + 'رحلت روح‌الله خمینی' => '06-03', + 'قیام ۱۵ خرداد' => '06-04', + ]; + } +} \ No newline at end of file diff --git a/tests/.pest/snapshots/Countries/IranTest/it_can_calculate_iran_holidays.snap b/tests/.pest/snapshots/Countries/IranTest/it_can_calculate_iran_holidays.snap new file mode 100644 index 000000000..9309cbd09 --- /dev/null +++ b/tests/.pest/snapshots/Countries/IranTest/it_can_calculate_iran_holidays.snap @@ -0,0 +1,42 @@ +[ + { + "name": "\u067e\u06cc\u0631\u0648\u0632\u06cc \u0627\u0646\u0642\u0644\u0627\u0628 \u0627\u0633\u0644\u0627\u0645\u06cc \u067e\u0646\u062c\u0627\u0647 \u0648 \u0647\u0641\u062a", + "date": "2024-02-11" + }, + { + "name": "\u0631\u0648\u0632 \u0645\u0644\u06cc \u0634\u062f\u0646 \u0635\u0646\u0639\u062a \u0646\u0641\u062a", + "date": "2024-03-19" + }, + { + "name": "\u0646\u062e\u0633\u062a\u06cc\u0646 \u0631\u0648\u0632 \u0646\u0648\u0631\u0648\u0632", + "date": "2024-03-20" + }, + { + "name": "\u062f\u0648\u0645\u06cc\u0646 \u0631\u0648\u0632 \u0646\u0648\u0631\u0648\u0632", + "date": "2024-03-21" + }, + { + "name": "\u0633\u0648\u0645\u06cc\u0646 \u0631\u0648\u0632 \u0646\u0648\u0631\u0648\u0632", + "date": "2024-03-22" + }, + { + "name": "\u0686\u0647\u0627\u0631\u0645\u06cc\u0646 \u0631\u0648\u0632 \u0646\u0648\u0631\u0648\u0632", + "date": "2024-03-23" + }, + { + "name": "\u0631\u0648\u0632 \u062c\u0645\u0647\u0648\u0631\u06cc \u0627\u0633\u0644\u0627\u0645\u06cc", + "date": "2024-03-31" + }, + { + "name": "\u0633\u06cc\u0632\u062f\u0647 \u0628\u062f\u0631", + "date": "2024-04-01" + }, + { + "name": "\u0631\u062d\u0644\u062a \u0631\u0648\u062d\u200c\u0627\u0644\u0644\u0647 \u062e\u0645\u06cc\u0646\u06cc", + "date": "2024-06-03" + }, + { + "name": "\u0642\u06cc\u0627\u0645 \u06f1\u06f5 \u062e\u0631\u062f\u0627\u062f", + "date": "2024-06-04" + } +] \ No newline at end of file diff --git a/tests/Countries/IranTest.php b/tests/Countries/IranTest.php new file mode 100644 index 000000000..7ceb54944 --- /dev/null +++ b/tests/Countries/IranTest.php @@ -0,0 +1,31 @@ +get(); + + expect($holidays) + ->toBeArray() + ->not()->toBeEmpty(); + + expect(formatDates($holidays))->toMatchSnapshot(); +}); + +it('can calculate iran holidays in local', function (string $locale, string $newYearsDayName) { + CarbonImmutable::setTestNow('2024-01-01'); + $result = Holidays::for(country: 'ir', year: null, locale: $locale)->get(); + + expect($result)->toBeArray(); + expect($result[7]['name'])->toBe($newYearsDayName); +})->with( + [ + ['en', 'Sizdah Bedar'], + ['fa', 'سیزده بدر'], + ] +); \ No newline at end of file From d8214608fe6aa0b44f6060ffba79c816f9e94032 Mon Sep 17 00:00:00 2001 From: Nielsvanpach Date: Thu, 1 Feb 2024 09:53:48 +0000 Subject: [PATCH 049/175] Fix styling --- src/Countries/Iran.php | 6 ++---- tests/Countries/IranTest.php | 10 +++++----- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/src/Countries/Iran.php b/src/Countries/Iran.php index 981f5e618..a70be6c58 100644 --- a/src/Countries/Iran.php +++ b/src/Countries/Iran.php @@ -2,15 +2,13 @@ namespace Spatie\Holidays\Countries; -use Carbon\CarbonImmutable; - class Iran extends Country { public function countryCode(): string { return 'ir'; } - + protected function allHolidays(int $year): array { return [ @@ -26,4 +24,4 @@ protected function allHolidays(int $year): array 'قیام ۱۵ خرداد' => '06-04', ]; } -} \ No newline at end of file +} diff --git a/tests/Countries/IranTest.php b/tests/Countries/IranTest.php index 7ceb54944..0c5c23f04 100644 --- a/tests/Countries/IranTest.php +++ b/tests/Countries/IranTest.php @@ -7,20 +7,20 @@ it('can calculate iran holidays', function () { CarbonImmutable::setTestNow('2024-01-01'); - + $holidays = Holidays::for(country: 'ir')->get(); - + expect($holidays) ->toBeArray() ->not()->toBeEmpty(); - + expect(formatDates($holidays))->toMatchSnapshot(); }); it('can calculate iran holidays in local', function (string $locale, string $newYearsDayName) { CarbonImmutable::setTestNow('2024-01-01'); $result = Holidays::for(country: 'ir', year: null, locale: $locale)->get(); - + expect($result)->toBeArray(); expect($result[7]['name'])->toBe($newYearsDayName); })->with( @@ -28,4 +28,4 @@ ['en', 'Sizdah Bedar'], ['fa', 'سیزده بدر'], ] -); \ No newline at end of file +); From 984b4114f83fd561d2eb689e4519b8c906cf4247 Mon Sep 17 00:00:00 2001 From: Nielsvanpach Date: Thu, 1 Feb 2024 09:54:47 +0000 Subject: [PATCH 050/175] Update CHANGELOG --- CHANGELOG.md | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 192aa09a3..54aaa41e4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,37 @@ All notable changes to `holidays` will be documented in this file. +## 1.5.0 - 2024-02-01 + +### What's Changed + +* Fix Danish Easter dates offset by @danielboendergaard in https://github.com/spatie/holidays/pull/197 +* Albanian National Holidays by @MirilTerolli in https://github.com/spatie/holidays/pull/157 +* Add holidays for Jamaica by @oraneedwards in https://github.com/spatie/holidays/pull/185 +* Add public holidays for Ghana by @petersowah in https://github.com/spatie/holidays/pull/175 +* Support for Slovenian language second PR after rebase problem by @juref in https://github.com/spatie/holidays/pull/139 +* Add Moldavian Holidays by @vkosachev in https://github.com/spatie/holidays/pull/95 +* Add `Egypt` Holidays by @michaelnabil230 in https://github.com/spatie/holidays/pull/35 +* add myanmar holidays by @yethusoe91 in https://github.com/spatie/holidays/pull/29 +* Added support for holidays in Nigeria by @cybernerdie in https://github.com/spatie/holidays/pull/10 +* Add support for Swedish holidays by @adevade in https://github.com/spatie/holidays/pull/199 +* Add National and Revolutionary Iran Holidays by @alisalehi1380 in https://github.com/spatie/holidays/pull/146 + +### New Contributors + +* @danielboendergaard made their first contribution in https://github.com/spatie/holidays/pull/197 +* @MirilTerolli made their first contribution in https://github.com/spatie/holidays/pull/157 +* @oraneedwards made their first contribution in https://github.com/spatie/holidays/pull/185 +* @petersowah made their first contribution in https://github.com/spatie/holidays/pull/175 +* @juref made their first contribution in https://github.com/spatie/holidays/pull/139 +* @vkosachev made their first contribution in https://github.com/spatie/holidays/pull/95 +* @michaelnabil230 made their first contribution in https://github.com/spatie/holidays/pull/35 +* @yethusoe91 made their first contribution in https://github.com/spatie/holidays/pull/29 +* @adevade made their first contribution in https://github.com/spatie/holidays/pull/199 +* @alisalehi1380 made their first contribution in https://github.com/spatie/holidays/pull/146 + +**Full Changelog**: https://github.com/spatie/holidays/compare/1.4.0...1.5.0 + ## 1.4.0 - 2024-01-30 ### What's Changed From 0b370fe07c8932f06957e8ad73811275fa2e666a Mon Sep 17 00:00:00 2001 From: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> Date: Thu, 1 Feb 2024 11:00:41 +0100 Subject: [PATCH 051/175] move albanian translations to correct dir --- {src/lang => lang}/albania/de/holidays.json | 0 {src/lang => lang}/albania/en/holidays.json | 0 {src/lang => lang}/albania/es/holidays.json | 0 {src/lang => lang}/albania/fr/holidays.json | 0 {src/lang => lang}/albania/gr/holidays.json | 0 {src/lang => lang}/albania/it/holidays.json | 0 {src/lang => lang}/albania/pt/holidays.json | 0 {src/lang => lang}/albania/ru/holidays.json | 0 {src/lang => lang}/albania/tr/holidays.json | 0 tests/Countries/AlbaniaTest.php | 9 +++++++++ tests/Countries/BelgiumTest.php | 9 +++++++++ 11 files changed, 18 insertions(+) rename {src/lang => lang}/albania/de/holidays.json (100%) rename {src/lang => lang}/albania/en/holidays.json (100%) rename {src/lang => lang}/albania/es/holidays.json (100%) rename {src/lang => lang}/albania/fr/holidays.json (100%) rename {src/lang => lang}/albania/gr/holidays.json (100%) rename {src/lang => lang}/albania/it/holidays.json (100%) rename {src/lang => lang}/albania/pt/holidays.json (100%) rename {src/lang => lang}/albania/ru/holidays.json (100%) rename {src/lang => lang}/albania/tr/holidays.json (100%) diff --git a/src/lang/albania/de/holidays.json b/lang/albania/de/holidays.json similarity index 100% rename from src/lang/albania/de/holidays.json rename to lang/albania/de/holidays.json diff --git a/src/lang/albania/en/holidays.json b/lang/albania/en/holidays.json similarity index 100% rename from src/lang/albania/en/holidays.json rename to lang/albania/en/holidays.json diff --git a/src/lang/albania/es/holidays.json b/lang/albania/es/holidays.json similarity index 100% rename from src/lang/albania/es/holidays.json rename to lang/albania/es/holidays.json diff --git a/src/lang/albania/fr/holidays.json b/lang/albania/fr/holidays.json similarity index 100% rename from src/lang/albania/fr/holidays.json rename to lang/albania/fr/holidays.json diff --git a/src/lang/albania/gr/holidays.json b/lang/albania/gr/holidays.json similarity index 100% rename from src/lang/albania/gr/holidays.json rename to lang/albania/gr/holidays.json diff --git a/src/lang/albania/it/holidays.json b/lang/albania/it/holidays.json similarity index 100% rename from src/lang/albania/it/holidays.json rename to lang/albania/it/holidays.json diff --git a/src/lang/albania/pt/holidays.json b/lang/albania/pt/holidays.json similarity index 100% rename from src/lang/albania/pt/holidays.json rename to lang/albania/pt/holidays.json diff --git a/src/lang/albania/ru/holidays.json b/lang/albania/ru/holidays.json similarity index 100% rename from src/lang/albania/ru/holidays.json rename to lang/albania/ru/holidays.json diff --git a/src/lang/albania/tr/holidays.json b/lang/albania/tr/holidays.json similarity index 100% rename from src/lang/albania/tr/holidays.json rename to lang/albania/tr/holidays.json diff --git a/tests/Countries/AlbaniaTest.php b/tests/Countries/AlbaniaTest.php index 0cc1bf411..1bfb5ba1b 100644 --- a/tests/Countries/AlbaniaTest.php +++ b/tests/Countries/AlbaniaTest.php @@ -16,6 +16,15 @@ expect(formatDates($holidays))->toMatchSnapshot(); }); +it('can get holidays in another locale', function () { + CarbonImmutable::setTestNow('2024-01-01'); + + $holidays = Holidays::for(country: 'al', locale: 'en')->get(); + + expect($holidays[0]['name']) + ->toBe("New Year's Day"); +}); + it('does not return a holiday falsely', function () { $dateInstance = CarbonImmutable::createFromDate('2024-01-03'); $holiday = Holidays::for(country: 'al'); diff --git a/tests/Countries/BelgiumTest.php b/tests/Countries/BelgiumTest.php index 173922950..e118bdf9b 100644 --- a/tests/Countries/BelgiumTest.php +++ b/tests/Countries/BelgiumTest.php @@ -16,3 +16,12 @@ expect(formatDates($holidays))->toMatchSnapshot(); }); + +it('can get holidays in another locale', function () { + CarbonImmutable::setTestNow('2024-01-01'); + + $holidays = Holidays::for(country: 'be', locale: 'fr')->get(); + + expect($holidays[0]['name']) + ->toBe("Jour de l'An"); +}); From 56128ab01e34df9ddebc62bcb78f9ddccec1b5fa Mon Sep 17 00:00:00 2001 From: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> Date: Thu, 1 Feb 2024 11:02:31 +0100 Subject: [PATCH 052/175] lowercase directory for iran --- lang/{Iran => iran}/en/holidays.json | 0 lang/{Iran => iran}/fa/holidays.json | 0 tests/Countries/IranTest.php | 2 +- 3 files changed, 1 insertion(+), 1 deletion(-) rename lang/{Iran => iran}/en/holidays.json (100%) rename lang/{Iran => iran}/fa/holidays.json (100%) diff --git a/lang/Iran/en/holidays.json b/lang/iran/en/holidays.json similarity index 100% rename from lang/Iran/en/holidays.json rename to lang/iran/en/holidays.json diff --git a/lang/Iran/fa/holidays.json b/lang/iran/fa/holidays.json similarity index 100% rename from lang/Iran/fa/holidays.json rename to lang/iran/fa/holidays.json diff --git a/tests/Countries/IranTest.php b/tests/Countries/IranTest.php index 0c5c23f04..f356bba8f 100644 --- a/tests/Countries/IranTest.php +++ b/tests/Countries/IranTest.php @@ -19,7 +19,7 @@ it('can calculate iran holidays in local', function (string $locale, string $newYearsDayName) { CarbonImmutable::setTestNow('2024-01-01'); - $result = Holidays::for(country: 'ir', year: null, locale: $locale)->get(); + $result = Holidays::for(country: 'ir', locale: $locale)->get(); expect($result)->toBeArray(); expect($result[7]['name'])->toBe($newYearsDayName); From 83ed0c195f1f7799afd41efac58d8385e6126c64 Mon Sep 17 00:00:00 2001 From: Nielsvanpach Date: Thu, 1 Feb 2024 10:04:21 +0000 Subject: [PATCH 053/175] Update CHANGELOG --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 54aaa41e4..c9f22404d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,12 @@ All notable changes to `holidays` will be documented in this file. +## 1.5.1 - 2024-02-01 + +Fix translations for Albania & Iran + +**Full Changelog**: https://github.com/spatie/holidays/compare/1.5.0...1.5.1 + ## 1.5.0 - 2024-02-01 ### What's Changed From ddc4fd7782e88d015ac1f9be9f303119721cd942 Mon Sep 17 00:00:00 2001 From: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> Date: Thu, 1 Feb 2024 15:54:52 +0100 Subject: [PATCH 054/175] set Myanmar test on a fixed date --- tests/Countries/MyanmarTest.php | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/tests/Countries/MyanmarTest.php b/tests/Countries/MyanmarTest.php index cee3463f1..bfb4db09a 100644 --- a/tests/Countries/MyanmarTest.php +++ b/tests/Countries/MyanmarTest.php @@ -6,16 +6,13 @@ use Spatie\Holidays\Holidays; it('can calculate myanmar holidays', function () { + CarbonImmutable::setTestNow('2024-01-01'); $holidays = Holidays::for(country: 'mm')->get(); - $result = Holidays::for('mm')->getName(CarbonImmutable::parse('2024-12-25')); - - expect($result)->toBe('ခရစ်စမတ်နေ့'); - - $result = Holidays::for('mm')->getName(CarbonImmutable::parse('2024-01-02')); - expect($result)->toBeNull(); + expect($holidays) + ->toBeArray() + ->not()->toBeEmpty(); expect(formatDates($holidays))->toMatchSnapshot(); - }); From 6b35af7e977c28fec4eaecd88fa17de86cb6ece2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dami=C3=A1n=20Can=C3=B3nica?= Date: Sat, 3 Feb 2024 09:32:16 -0300 Subject: [PATCH 055/175] Add holidays for Argentine (#200) --- src/Countries/Argentine.php | 40 ++++++++++++++++ ...t_can_calculate_argentinians_holidays.snap | 46 +++++++++++++++++++ tests/Countries/ArgentineTest.php | 17 +++++++ 3 files changed, 103 insertions(+) create mode 100644 src/Countries/Argentine.php create mode 100644 tests/.pest/snapshots/Countries/ArgentineTest/it_can_calculate_argentinians_holidays.snap create mode 100644 tests/Countries/ArgentineTest.php diff --git a/src/Countries/Argentine.php b/src/Countries/Argentine.php new file mode 100644 index 000000000..c5ea425d9 --- /dev/null +++ b/src/Countries/Argentine.php @@ -0,0 +1,40 @@ + '01-01', + 'Carnaval' => '12-02', + 'Carnaval' => '13-02', + 'Día Nacional de la Memoria por la Verdad y la Justicia' => '24-04', + 'Día del Veterano y de los Caídos en la Guerra de Malvinas' => '02-04', + 'Día del Trabajador' => '05-01', + 'Revolución de Mayo' => '25-05', + 'Paso a la Inmortalidad del General Manuel Belgrano' => '20-06', + 'Día de la Independencia' => '09-07', + 'Día de la Inmaculada Concepción de María' => '08-12', + 'Navidad' => '12-25', + ], $this->variableHolidays($year)); + } + + /** @return array */ + protected function variableHolidays(int $year): array + { + $easter = $this->easter($year); + + return [ + 'Viernes Santo' => $easter->subDays(2), + ]; + } +} diff --git a/tests/.pest/snapshots/Countries/ArgentineTest/it_can_calculate_argentinians_holidays.snap b/tests/.pest/snapshots/Countries/ArgentineTest/it_can_calculate_argentinians_holidays.snap new file mode 100644 index 000000000..ed25e78a8 --- /dev/null +++ b/tests/.pest/snapshots/Countries/ArgentineTest/it_can_calculate_argentinians_holidays.snap @@ -0,0 +1,46 @@ +[ + { + "name": "D\u00eda de A\u00f1o Nuevo", + "date": "2024-01-01" + }, + { + "name": "D\u00eda del Veterano y de los Ca\u00eddos en la Guerra de Malvinas", + "date": "2024-02-04" + }, + { + "name": "Viernes Santo", + "date": "2024-03-29" + }, + { + "name": "D\u00eda del Trabajador", + "date": "2024-05-01" + }, + { + "name": "D\u00eda de la Inmaculada Concepci\u00f3n de Mar\u00eda", + "date": "2024-08-12" + }, + { + "name": "D\u00eda de la Independencia", + "date": "2024-09-07" + }, + { + "name": "Navidad", + "date": "2024-12-25" + }, + { + "name": "Carnaval", + "date": "2025-01-02" + }, + { + "name": "Paso a la Inmortalidad del General Manuel Belgrano", + "date": "2025-08-06" + }, + { + "name": "D\u00eda Nacional de la Memoria por la Verdad y la Justicia", + "date": "2025-12-04" + }, + { + "name": "Revoluci\u00f3n de Mayo", + "date": "2026-01-05" + } +] \ No newline at end of file diff --git a/tests/Countries/ArgentineTest.php b/tests/Countries/ArgentineTest.php new file mode 100644 index 000000000..492237852 --- /dev/null +++ b/tests/Countries/ArgentineTest.php @@ -0,0 +1,17 @@ +get(); + + expect($holidays) + ->toBeArray() + ->not()->toBeEmpty() + ->and(formatDates($holidays))->toMatchSnapshot(); +}); From 8ef9b967c9e56a5f143a258ab4facb3a1af160ac Mon Sep 17 00:00:00 2001 From: Javier Altez Date: Wed, 7 Feb 2024 10:14:38 +0100 Subject: [PATCH 056/175] Add Spanish Holidays (#34) * Add Spanish Holidays * Holidays added by region for the current year. * Regional holidays: 2023, 2022 * Variable naming as holidays. * Added exceptions and null region check. * Change to custom exceptions. --- src/Countries/Spain.php | 394 ++++++++++++++++++ .../it_can_calculate_spanish_holidays.snap | 42 ++ ...n_calculate_spanish_regional_holidays.snap | 54 +++ tests/Countries/SpainTest.php | 31 ++ 4 files changed, 521 insertions(+) create mode 100644 src/Countries/Spain.php create mode 100644 tests/.pest/snapshots/Countries/SpainTest/it_can_calculate_spanish_holidays.snap create mode 100644 tests/.pest/snapshots/Countries/SpainTest/it_can_calculate_spanish_regional_holidays.snap create mode 100644 tests/Countries/SpainTest.php diff --git a/src/Countries/Spain.php b/src/Countries/Spain.php new file mode 100644 index 000000000..1a005e638 --- /dev/null +++ b/src/Countries/Spain.php @@ -0,0 +1,394 @@ + '01-01', + 'Epifanía del Señor' => '01-06', + 'Día del Trabajador' => '05-01', + 'Asunción de la Virgen' => '08-15', + 'Fiesta Nacional de España' => '10-12', + 'Todos los Santos' => '11-01', + 'Día de la Constitución Española' => '12-06', + 'Inmaculada Concepción' => '12-08', // 2024? + 'Navidad' => '12-25' + ], + $this->variableHolidays($year), + $this->regionHolidays($year), + ); + } + + /** @return array */ + protected function variableHolidays(int $year): array + { + $easter = $this->easter($year); + + return [ + 'Viernes Santo' => $easter->subDays(2), + ]; + } + + /** @return array */ + protected function regionHolidays(int $year): array + { + if ($this->region === null) { + return []; + } + + $method = "regionHolidays{$year}"; + if (method_exists($this, $method)) { + return $this->$method(); + } else { + throw InvalidYear::range($this->countryCode() . " ({$this->region})", 2022, 2024); + } + } + + /** @return array */ + protected function regionHolidays2022(): array + { + $juevesSanto = ['Jueves Santo' => '04-14']; + $lunesPascua = ['Lunes de Pascua' => '04-18']; + $fiestaTrabajo = ['Lunes siguiente a la Fiesta del Trabajo' => '05-02']; + $sanJuan = ['San Juan' => '06-24']; + $santiagoApostol = ['Santiago Apóstol' => '07-25']; + $navidad = ['Lunes siguiente a Navidad' => '12-26']; + + return match ($this->region) { + // Andalucía + 'es-an' => [ + 'Día de Andalucía' => '02-28', + ] + $juevesSanto + $fiestaTrabajo + $navidad, + + // Aragón + 'es-ar' => [ + 'Lunes siguiente a San Jorge, Día de Aragón' => '04-23', + ] + $juevesSanto + $fiestaTrabajo + $navidad, + + // Principado de Asturias + 'es-as' => [ + 'Día de Asturias' => '09-08', + ] + $juevesSanto + $fiestaTrabajo + $navidad, + + // Cantabria + 'es-cb' => [ + 'Día de las Instituciones de Cantabria' => '07-28', + 'La Bien Aparecida' => '09-15', + ] + $juevesSanto + $navidad, + + // Ciudad Autónoma de Ceuta + 'es-ce' => [ + 'Fiesta del Sacrificio Eid al-Adha' => '07-09', + 'Nuestra Señora de África' => '08-05', + 'Día de Ceuta' => '09-02', + ] + $juevesSanto, + + // Castilla y León + 'es-cl' => [ + 'Día de Castilla y León' => '04-23', + ] + $juevesSanto + $fiestaTrabajo + $navidad, + + // Castilla-La Mancha + 'es-cm' => [ + 'Día de Castilla-La Mancha' => '05-31', + 'Corpus Christi' => '06-16', + ] + $juevesSanto + $navidad, + + // Canarias + 'es-cn' => [ + 'Día de Canarias' => '05-30', + ] + $juevesSanto + $navidad, + + // Cataluña / Catalunya + 'es-ct' => [ + 'Pascua Granada' => '06-06', + ] + $lunesPascua + $sanJuan + $navidad, + + // Extremadura + 'es-ex' => [ + 'Día de Extremadura' => '09-08', + ] + $juevesSanto + $fiestaTrabajo + $navidad, + + // Galicia + 'es-ga' => [ + 'Día de las Letras Gallegas' => '05-17', + 'Santiago Apóstol / Día de Galicia' => '07-25', + ] + $juevesSanto + $sanJuan, + + // Islas Baleares / Illes Balears + 'es-ib' => [ + 'Día de les Illes Balears' => '03-01', + ] + $juevesSanto + $lunesPascua + $navidad, + + // Región de Murcia + 'es-mc' => [ + 'Día de la Región de Murcia' => '06-09', + ] + $juevesSanto + $fiestaTrabajo + $navidad, + + // Comunidad de Madrid + 'es-md' => [ + 'Fiesta de la Comunidad de Madrid' => '05-02', + ] + $juevesSanto + $santiagoApostol + $navidad, + + // Ciudad Autónoma de Melilla + 'es-ml' => [ + 'Fiesta del Eid al-Fitr' => '05-03', + 'Fiesta del Sacrificio Eid al-Adha' => '07-11' + ] + $juevesSanto + $navidad, + + // Comunidad Foral de Navarra / Nafarroako Foru Komunitatea + 'es-nc' => $juevesSanto + $lunesPascua + $santiagoApostol + $navidad, + + // País Vasco / Euskal Herria + 'es-pv' => [ + 'V Centenario de la Primera Vuelta al Mundo' => '09-06', + ] + $juevesSanto + $lunesPascua + $santiagoApostol, + + // La Rioja + 'es-ri' => [ + 'Día de La Rioja' => '06-09', + ] + $juevesSanto + $lunesPascua + $navidad, + + // Comunidad Valenciana / Comunitat Valenciana + 'es-vc' => [ + 'Día de la Comunidad Valenciana' => '10-09', + 'San José' => '03-19', + ] + $juevesSanto + $lunesPascua + $sanJuan, + + default => throw InvalidRegion::notFound($this->region), + }; + } + + /** @return array */ + protected function regionHolidays2023(): array + { + $anoNuevo = ['Lunes siguiente a la Fiesta de Año Nuevo' => '01-02']; + $jueveSanto = ['Jueves Santo' => '04-06']; + $lunesPascua = ['Lunes de Pascua' => '04-10']; + $sanJuan = ['San Juan' => '06-24']; + $fiestaSacrificio = ['Fiesta del Sacrificio Eid al-Adha' => '06-29']; + $santiagoApostol = ['Santiago Apóstol' => '07-25']; + + return match ($this->region) { + // Andalucía + 'es-an' => [ + 'Día de Andalucía' => '02-28', + ] + $anoNuevo + $jueveSanto, + + // Aragón + 'es-ar' => [ + 'Lunes siguiente a San Jorge, Día de Aragón' => '04-24', + ] + $anoNuevo + $jueveSanto, + + // Principado de Asturias + 'es-as' => [ + 'Día de Asturias' => '09-08', + ] + $anoNuevo + $jueveSanto, + + // Cantabria + 'es-cb' => [ + 'Día de las Instituciones de Cantabria' => '07-28', + 'La Bien Aparecida' => '09-15', + ] + $jueveSanto, + + // Ciudad Autónoma de Ceuta + 'es-ce' => [ + 'Nuestra Señora de África' => '08-05', + 'Día de Ceuta' => '09-02', + ] + $jueveSanto + $fiestaSacrificio, + + // Castilla y León + 'es-cl' => $anoNuevo + $jueveSanto + $santiagoApostol, + + // Castilla-La Mancha + 'es-cm' => [ + 'Día de Castilla-La Mancha' => '05-31', + 'Corpus Christi' => '06-08', + ] + $jueveSanto, + + // Canarias + 'es-cn' => [ + 'Día de Canarias' => '05-30', + ] + $jueveSanto, + + // Cataluña / Catalunya + 'es-ct' => [ + 'Fiesta Nacional de Cataluña' => '09-11', + 'San Esteban' => '12-26', + ] + $lunesPascua + $sanJuan, + + // Extremadura + 'es-ex' => [ + 'Carnaval' => '02-13', + 'Día de Extremadura' => '09-08', + ] + $jueveSanto, + + // Galicia + 'es-ga' => [ + 'Día de las Letras Gallegas' => '05-17', + 'Santiago Apóstol / Día de Galicia' => '07-25', + ] + $jueveSanto, + + // Islas Baleares / Illes Balears + 'es-ib' => [ + 'Día de les Illes Balears' => '03-01', + ] + $lunesPascua, + + // Región de Murcia + 'es-mc' => [ + 'Día de la Región de Murcia' => '06-09', + ] + $anoNuevo + $jueveSanto, + + // Comunidad de Madrid + 'es-md' => [ + 'Lunes siguiente A San José' => '03-20', + 'Fiesta de la Comunidad de Madrid' => '05-02', + ] + $jueveSanto, + + // Ciudad Autónoma de Melilla + 'es-ml' => [ + 'Fiesta del Eid al-Fitr' => '04-21', + ] + $jueveSanto + $fiestaSacrificio, + + // Comunidad Foral de Navarra / Nafarroako Foru Komunitatea + 'es-nc' => $jueveSanto + $lunesPascua + $santiagoApostol, + + // País Vasco / Euskal Herria + 'es-pv' => $jueveSanto + $lunesPascua + $santiagoApostol, + + // La Rioja + 'es-ri' => [ + 'Día de La Rioja' => '06-09', + ] + $jueveSanto + $lunesPascua, + + // Comunidad Valenciana / Comunitat Valenciana + 'es-vc' => [ + 'Día de la Comunidad Valenciana' => '10-09', + ] + $lunesPascua + $sanJuan, + + default => throw InvalidRegion::notFound($this->region), + }; + } + + /** @return array */ + protected function regionHolidays2024(): array + { + $sanJose = ['San José' => '03-19']; + $juevesSanto = ['Jueves Santo' => '03-28']; + $lunesPascua = ['Lunes de Pascua' => '04-01']; + $fiestaSacrificio = ['Fiesta del Sacrificio Eid al-Adha' => '06-17']; + $sanJuan = ['San Juan' => '06-24']; + $santiagoApostol = ['Santiago Apóstol' => '07-25']; + $inmaculadaConcepcion = ['Lunes siguiente a la Inmaculada Concepción' => '12-09']; + + return match ($this->region) { + // Andalucía + 'es-an' => [ + 'Día de Andalucía' => '02-28', + ] + $juevesSanto + $inmaculadaConcepcion, + + // Aragón + 'es-ar' => [ + 'San Jorge / Día de Aragón' => '04-23', + ] + $juevesSanto + $inmaculadaConcepcion, + + // Principado de Asturias + 'es-as' => [ + 'Lunes siguiente al Día de Asturias' => '09-09', + ] + $juevesSanto + $inmaculadaConcepcion, + + // Cantabria + 'es-cb' => $juevesSanto + $lunesPascua + $santiagoApostol, + + // Ciudad Autónoma de Ceuta + 'es-ce' => [ + 'Nuestra Señora de África' => '08-05', + ] + $juevesSanto + $fiestaSacrificio, + + // Castilla y León + 'es-cl' => [ + 'Fiesta de Castilla y León' => '04-23', + ] + $juevesSanto + $inmaculadaConcepcion, + + // Castilla-La Mancha + 'es-cm' => [ + 'Corpus Christi' => '05-30', + 'Día de Castilla-La Mancha' => '05-31', + ] + $juevesSanto, + + // Canarias + 'es-cn' => [ + 'Día de Canarias' => '05-30', + ] + $juevesSanto, + + // Cataluña / Catalunya + 'es-ct' => [ + 'Fiesta Nacional de Cataluña' => '09-11', + 'San Esteban' => '12-26', + ] + $lunesPascua + $sanJuan, + + // Extremadura + 'es-ex' => [ + 'Carnaval' => '02-13', + ] + $juevesSanto + $inmaculadaConcepcion, + + // Galicia + 'es-ga' => [ + 'Día de las Letras Gallegas' => '05-17', + 'Santiago Apóstol / Día de Galicia' => '07-25', + ] + $juevesSanto, + + // Islas Baleares / Illes Balears + 'es-ib' => [ + 'Día de les Illes Balears' => '03-01', + ] + $juevesSanto + $lunesPascua, + + // Región de Murcia + 'es-mc' => $sanJose + $juevesSanto + $inmaculadaConcepcion, + + // Comunidad de Madrid + 'es-md' => [ + 'Fiesta de la Comunidad de Madrid' => '05-02', + ] + $juevesSanto + $santiagoApostol, + + // Ciudad Autónoma de Melilla + 'es-ml' => $juevesSanto + $fiestaSacrificio + $inmaculadaConcepcion, + + // Comunidad Foral de Navarra / Nafarroako Foru Komunitatea + 'es-nc' => $juevesSanto + $lunesPascua + $santiagoApostol, + + // País Vasco / Euskal Herria + 'es-pv' => $juevesSanto + $lunesPascua + $santiagoApostol, + + // La Rioja + 'es-ri' => [ + 'Lunes siguiente al Día de La Rioja' => '06-10', + ] + $juevesSanto + $lunesPascua, + + // Comunidad Valenciana / Comunitat Valenciana + 'es-vc' => [ + 'Día de la Comunidad Valenciana' => '10-09', + ] + $sanJose + $lunesPascua + $sanJuan, + + default => throw InvalidRegion::notFound($this->region), + }; + } +} diff --git a/tests/.pest/snapshots/Countries/SpainTest/it_can_calculate_spanish_holidays.snap b/tests/.pest/snapshots/Countries/SpainTest/it_can_calculate_spanish_holidays.snap new file mode 100644 index 000000000..b9a396fe9 --- /dev/null +++ b/tests/.pest/snapshots/Countries/SpainTest/it_can_calculate_spanish_holidays.snap @@ -0,0 +1,42 @@ +[ + { + "name": "A\u00f1o Nuevo", + "date": "2024-01-01" + }, + { + "name": "Epifan\u00eda del Se\u00f1or", + "date": "2024-01-06" + }, + { + "name": "Viernes Santo", + "date": "2024-03-29" + }, + { + "name": "D\u00eda del Trabajador", + "date": "2024-05-01" + }, + { + "name": "Asunci\u00f3n de la Virgen", + "date": "2024-08-15" + }, + { + "name": "Fiesta Nacional de Espa\u00f1a", + "date": "2024-10-12" + }, + { + "name": "Todos los Santos", + "date": "2024-11-01" + }, + { + "name": "D\u00eda de la Constituci\u00f3n Espa\u00f1ola", + "date": "2024-12-06" + }, + { + "name": "Inmaculada Concepci\u00f3n", + "date": "2024-12-08" + }, + { + "name": "Navidad", + "date": "2024-12-25" + } +] \ No newline at end of file diff --git a/tests/.pest/snapshots/Countries/SpainTest/it_can_calculate_spanish_regional_holidays.snap b/tests/.pest/snapshots/Countries/SpainTest/it_can_calculate_spanish_regional_holidays.snap new file mode 100644 index 000000000..5684d7595 --- /dev/null +++ b/tests/.pest/snapshots/Countries/SpainTest/it_can_calculate_spanish_regional_holidays.snap @@ -0,0 +1,54 @@ +[ + { + "name": "A\u00f1o Nuevo", + "date": "2024-01-01" + }, + { + "name": "Epifan\u00eda del Se\u00f1or", + "date": "2024-01-06" + }, + { + "name": "Jueves Santo", + "date": "2024-03-28" + }, + { + "name": "Viernes Santo", + "date": "2024-03-29" + }, + { + "name": "San Jorge \/ D\u00eda de Arag\u00f3n", + "date": "2024-04-23" + }, + { + "name": "D\u00eda del Trabajador", + "date": "2024-05-01" + }, + { + "name": "Asunci\u00f3n de la Virgen", + "date": "2024-08-15" + }, + { + "name": "Fiesta Nacional de Espa\u00f1a", + "date": "2024-10-12" + }, + { + "name": "Todos los Santos", + "date": "2024-11-01" + }, + { + "name": "D\u00eda de la Constituci\u00f3n Espa\u00f1ola", + "date": "2024-12-06" + }, + { + "name": "Inmaculada Concepci\u00f3n", + "date": "2024-12-08" + }, + { + "name": "Lunes siguiente a la Inmaculada Concepci\u00f3n", + "date": "2024-12-09" + }, + { + "name": "Navidad", + "date": "2024-12-25" + } +] \ No newline at end of file diff --git a/tests/Countries/SpainTest.php b/tests/Countries/SpainTest.php new file mode 100644 index 000000000..3c39a62e2 --- /dev/null +++ b/tests/Countries/SpainTest.php @@ -0,0 +1,31 @@ +get(); + + expect($holidays) + ->toBeArray() + ->not()->toBeEmpty(); + + expect(formatDates($holidays))->toMatchSnapshot(); +}); + +it('can calculate spanish regional holidays', function () { + CarbonImmutable::setTestNow('2024-01-01'); + + $holidays = Holidays::for(Spain::make('es-ar'))->get(); + + expect($holidays) + ->toBeArray() + ->not()->toBeEmpty(); + + expect(formatDates($holidays))->toMatchSnapshot(); +}); From 7fbed6101dc3ef180217d7063af3d78e4f847f29 Mon Sep 17 00:00:00 2001 From: Nielsvanpach Date: Wed, 7 Feb 2024 09:14:57 +0000 Subject: [PATCH 057/175] Fix styling --- src/Countries/Spain.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Countries/Spain.php b/src/Countries/Spain.php index 1a005e638..9a0afc6d4 100644 --- a/src/Countries/Spain.php +++ b/src/Countries/Spain.php @@ -30,7 +30,7 @@ protected function allHolidays(int $year): array 'Todos los Santos' => '11-01', 'Día de la Constitución Española' => '12-06', 'Inmaculada Concepción' => '12-08', // 2024? - 'Navidad' => '12-25' + 'Navidad' => '12-25', ], $this->variableHolidays($year), $this->regionHolidays($year), @@ -58,7 +58,7 @@ protected function regionHolidays(int $year): array if (method_exists($this, $method)) { return $this->$method(); } else { - throw InvalidYear::range($this->countryCode() . " ({$this->region})", 2022, 2024); + throw InvalidYear::range($this->countryCode()." ({$this->region})", 2022, 2024); } } @@ -151,7 +151,7 @@ protected function regionHolidays2022(): array // Ciudad Autónoma de Melilla 'es-ml' => [ 'Fiesta del Eid al-Fitr' => '05-03', - 'Fiesta del Sacrificio Eid al-Adha' => '07-11' + 'Fiesta del Sacrificio Eid al-Adha' => '07-11', ] + $juevesSanto + $navidad, // Comunidad Foral de Navarra / Nafarroako Foru Komunitatea From 3c5fccb0b44ac5762ad2e2984132c2ca59e37112 Mon Sep 17 00:00:00 2001 From: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> Date: Wed, 7 Feb 2024 10:30:36 +0100 Subject: [PATCH 058/175] rename second Carnival day for Argentine --- src/Countries/Argentine.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Countries/Argentine.php b/src/Countries/Argentine.php index c5ea425d9..50364797d 100644 --- a/src/Countries/Argentine.php +++ b/src/Countries/Argentine.php @@ -16,7 +16,7 @@ protected function allHolidays(int $year): array return array_merge([ 'Día de Año Nuevo' => '01-01', 'Carnaval' => '12-02', - 'Carnaval' => '13-02', + 'Carnaval Día 2' => '13-02', 'Día Nacional de la Memoria por la Verdad y la Justicia' => '24-04', 'Día del Veterano y de los Caídos en la Guerra de Malvinas' => '02-04', 'Día del Trabajador' => '05-01', From f3858d64d23cea9d00f9f87e47dae8ecc3583fc4 Mon Sep 17 00:00:00 2001 From: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> Date: Wed, 7 Feb 2024 10:32:07 +0100 Subject: [PATCH 059/175] fix phpstan issues with Spain --- src/Countries/Spain.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/Countries/Spain.php b/src/Countries/Spain.php index 9a0afc6d4..27a7f166f 100644 --- a/src/Countries/Spain.php +++ b/src/Countries/Spain.php @@ -173,6 +173,7 @@ protected function regionHolidays2022(): array 'San José' => '03-19', ] + $juevesSanto + $lunesPascua + $sanJuan, + null => [], default => throw InvalidRegion::notFound($this->region), }; } @@ -284,6 +285,7 @@ protected function regionHolidays2023(): array 'Día de la Comunidad Valenciana' => '10-09', ] + $lunesPascua + $sanJuan, + null => [], default => throw InvalidRegion::notFound($this->region), }; } @@ -388,6 +390,7 @@ protected function regionHolidays2024(): array 'Día de la Comunidad Valenciana' => '10-09', ] + $sanJose + $lunesPascua + $sanJuan, + null => [], default => throw InvalidRegion::notFound($this->region), }; } From fc6c650fef61b2e133324324b196bd1c933d0b64 Mon Sep 17 00:00:00 2001 From: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> Date: Wed, 7 Feb 2024 10:32:31 +0100 Subject: [PATCH 060/175] update argentina snapshot --- .../it_can_calculate_argentinians_holidays.snap | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tests/.pest/snapshots/Countries/ArgentineTest/it_can_calculate_argentinians_holidays.snap b/tests/.pest/snapshots/Countries/ArgentineTest/it_can_calculate_argentinians_holidays.snap index ed25e78a8..aaa0aa671 100644 --- a/tests/.pest/snapshots/Countries/ArgentineTest/it_can_calculate_argentinians_holidays.snap +++ b/tests/.pest/snapshots/Countries/ArgentineTest/it_can_calculate_argentinians_holidays.snap @@ -23,12 +23,16 @@ "name": "D\u00eda de la Independencia", "date": "2024-09-07" }, + { + "name": "Carnaval", + "date": "2024-12-02" + }, { "name": "Navidad", "date": "2024-12-25" }, { - "name": "Carnaval", + "name": "Carnaval D\u00eda 2", "date": "2025-01-02" }, { From 05873e7d602ab9977b743e108805073ea83355ab Mon Sep 17 00:00:00 2001 From: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> Date: Wed, 7 Feb 2024 10:42:51 +0100 Subject: [PATCH 061/175] run test suite with carbon v2 and v3 --- .github/workflows/run-tests.yml | 5 ++++- composer.json | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index 780a74427..84f9eb311 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -12,6 +12,7 @@ jobs: os: [ubuntu-latest] php: [8.3, 8.2, 8.1] stability: [prefer-lowest, prefer-stable] + carbon: [2.72, 3.0] name: P${{ matrix.php }} - ${{ matrix.stability }} - ${{ matrix.os }} @@ -32,7 +33,9 @@ jobs: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json" - name: Install dependencies - run: composer update --${{ matrix.stability }} --prefer-dist --no-interaction + run: | + composer update --${{ matrix.stability }} --prefer-dist --no-interaction + composer require nesbot/carbon:^${{ matrix.carbon }} --${{ matrix.stability }} --prefer-dist --no-interaction - name: List Installed Dependencies run: composer show -D diff --git a/composer.json b/composer.json index d51ff2f1e..46ef42ee3 100644 --- a/composer.json +++ b/composer.json @@ -22,7 +22,7 @@ "require": { "php": "^8.1", "ext-intl": "*", - "nesbot/carbon": "^2.72.1" + "nesbot/carbon": "^2.72.1|^3.0" }, "require-dev": { "laravel/pint": "^1.0", From 78111895c3a7f736961c215665f1e7906e97e699 Mon Sep 17 00:00:00 2001 From: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> Date: Wed, 7 Feb 2024 11:00:56 +0100 Subject: [PATCH 062/175] upgrade all carbon dependencies too in the tests --- .github/workflows/run-tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index 84f9eb311..80a2047bf 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -35,7 +35,7 @@ jobs: - name: Install dependencies run: | composer update --${{ matrix.stability }} --prefer-dist --no-interaction - composer require nesbot/carbon:^${{ matrix.carbon }} --${{ matrix.stability }} --prefer-dist --no-interaction + composer require nesbot/carbon:^${{ matrix.carbon }} --${{ matrix.stability }} -W --prefer-dist --no-interaction - name: List Installed Dependencies run: composer show -D From 4ceb5750fab046ca8c57b41c2615f7ba7dbd4dcf Mon Sep 17 00:00:00 2001 From: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> Date: Wed, 7 Feb 2024 11:15:02 +0100 Subject: [PATCH 063/175] phpstan fixes after migrating to carbon v3 --- src/Countries/Australia.php | 2 +- src/Countries/Colombia.php | 10 ++++++---- src/Countries/Finland.php | 3 ++- src/Countries/Jamaica.php | 3 ++- src/Countries/NorthernIreland.php | 7 ++++--- src/Countries/Scotland.php | 9 +++++---- src/Countries/Sweden.php | 2 +- src/Countries/Wales.php | 11 ++++++----- 8 files changed, 27 insertions(+), 20 deletions(-) diff --git a/src/Countries/Australia.php b/src/Countries/Australia.php index 3de478baa..b17c853fa 100644 --- a/src/Countries/Australia.php +++ b/src/Countries/Australia.php @@ -41,7 +41,7 @@ protected function variableHolidays(int $year): array 'Canberra Day' => CarbonImmutable::parse("second monday of march {$year}"), 'Easter Saturday' => $easter->subDay(), 'Easter Sunday' => $easter, - 'Reconciliation Day' => CarbonImmutable::create($year, 5, 27)->modify('monday'), + 'Reconciliation Day' => CarbonImmutable::create($year, 5, 27)?->modify('monday'), $this->sovereignBirthdayKey($year) => CarbonImmutable::parse("second monday of june {$year}"), 'Labour Day' => CarbonImmutable::parse("first monday of october {$year}"), ], diff --git a/src/Countries/Colombia.php b/src/Countries/Colombia.php index f3176f794..999264e9d 100644 --- a/src/Countries/Colombia.php +++ b/src/Countries/Colombia.php @@ -3,6 +3,7 @@ namespace Spatie\Holidays\Countries; use Carbon\CarbonImmutable; +use Carbon\CarbonInterface; class Colombia extends Country { @@ -23,7 +24,7 @@ protected function allHolidays(int $year): array ], $this->variableHolidays($year)); } - /** @return array */ + /** @return array */ protected function variableHolidays(int $year): array { $easter = $this->easter($year); @@ -45,13 +46,14 @@ protected function variableHolidays(int $year): array ]; } - private function emilianiHoliday(int $year, int $month, int $day): CarbonImmutable + private function emilianiHoliday(int $year, int $month, int $day): CarbonInterface { $dateObj = CarbonImmutable::createFromDate($year, $month, $day, 'America/Bogota')->startOfDay(); + if ($dateObj->is('Monday')) { return $dateObj; - } else { - return $dateObj->next('Monday'); } + + return $dateObj->next('Monday'); } } diff --git a/src/Countries/Finland.php b/src/Countries/Finland.php index 69fa1fd39..32e75c649 100644 --- a/src/Countries/Finland.php +++ b/src/Countries/Finland.php @@ -3,6 +3,7 @@ namespace Spatie\Holidays\Countries; use Carbon\CarbonImmutable; +use Carbon\CarbonInterface; class Finland extends Country { @@ -29,7 +30,7 @@ protected function fixedHolidays(int $year): array ]; } - /** @return array */ + /** @return array */ protected function variableHolidays(int $year): array { $easter = $this->easter($year); diff --git a/src/Countries/Jamaica.php b/src/Countries/Jamaica.php index e9b3af3d4..751fb994b 100644 --- a/src/Countries/Jamaica.php +++ b/src/Countries/Jamaica.php @@ -3,6 +3,7 @@ namespace Spatie\Holidays\Countries; use Carbon\CarbonImmutable; +use Carbon\CarbonInterface; class Jamaica extends Country { @@ -52,7 +53,7 @@ protected function variableHolidays(int $year): array ]; } - /** @return array */ + /** @return array */ protected function observedHolidays(int $year): array { diff --git a/src/Countries/NorthernIreland.php b/src/Countries/NorthernIreland.php index 889fa513e..cb424980f 100644 --- a/src/Countries/NorthernIreland.php +++ b/src/Countries/NorthernIreland.php @@ -3,6 +3,7 @@ namespace Spatie\Holidays\Countries; use Carbon\CarbonImmutable; +use Carbon\CarbonInterface; class NorthernIreland extends Wales { @@ -11,7 +12,7 @@ public function countryCode(): string return 'gb-nir'; } - /** @return array */ + /** @return array */ private function stPatricksDay(int $year): array { $stPatricksDay = new CarbonImmutable($year.'-03-17', 'Europe/London'); @@ -25,7 +26,7 @@ private function stPatricksDay(int $year): array return [$key => $stPatricksDay]; } - /** @return array */ + /** @return array */ private function battleOfTheBoyne(int $year): array { $battleOfTheBoyne = new CarbonImmutable($year.'-07-12', 'Europe/London'); @@ -51,7 +52,7 @@ protected function oneOffHolidays(int $year): array }; } - /** @return array */ + /** @return array */ protected function allHolidays(int $year): array { $regularHolidays = array_merge( diff --git a/src/Countries/Scotland.php b/src/Countries/Scotland.php index 09e2ea097..f70145325 100644 --- a/src/Countries/Scotland.php +++ b/src/Countries/Scotland.php @@ -3,6 +3,7 @@ namespace Spatie\Holidays\Countries; use Carbon\CarbonImmutable; +use Carbon\CarbonInterface; class Scotland extends Wales { @@ -11,7 +12,7 @@ public function countryCode(): string return 'gb-sct'; } - /** @return array */ + /** @return array */ protected function secondOfJanuary(int $year): array { $newYearsDay = new CarbonImmutable($year.'-01-01', 'Europe/London'); @@ -31,7 +32,7 @@ protected function secondOfJanuary(int $year): array return [$key => $secondOfJanuary]; } - /** @return array */ + /** @return array */ private function stAndrewsDay(int $year): array { $stAndrewsDay = new CarbonImmutable($year.'-11-30', 'Europe/London'); @@ -45,7 +46,7 @@ private function stAndrewsDay(int $year): array return [$key => $stAndrewsDay]; } - /** @return array */ + /** @return array */ protected function oneOffHolidays(int $year): array { return match ($year) { @@ -57,7 +58,7 @@ protected function oneOffHolidays(int $year): array }; } - /** @return array */ + /** @return array */ protected function allHolidays(int $year): array { $regularHolidays = array_merge( diff --git a/src/Countries/Sweden.php b/src/Countries/Sweden.php index e16eae6eb..fce4f7135 100644 --- a/src/Countries/Sweden.php +++ b/src/Countries/Sweden.php @@ -24,7 +24,7 @@ protected function allHolidays(int $year): array ], $this->variableHolidays($year)); } - /** @return array */ + /** @return array */ protected function variableHolidays(int $year): array { $easter = $this->easter($year); diff --git a/src/Countries/Wales.php b/src/Countries/Wales.php index 7468ba889..33e1ca3b8 100644 --- a/src/Countries/Wales.php +++ b/src/Countries/Wales.php @@ -3,6 +3,7 @@ namespace Spatie\Holidays\Countries; use Carbon\CarbonImmutable; +use Carbon\CarbonInterface; class Wales extends Country { @@ -11,7 +12,7 @@ public function countryCode(): string return 'gb-cym'; } - /** @return array */ + /** @return array */ protected function christmasDay(int $year): array { $christmasDay = new CarbonImmutable($year.'-12-25', 'Europe/London'); @@ -30,7 +31,7 @@ protected function christmasDay(int $year): array return [$key => $christmasDay]; } - /** @return array */ + /** @return array */ protected function boxingDay(int $year): array { $christmasDay = new CarbonImmutable($year.'-12-25', 'Europe/London'); @@ -50,7 +51,7 @@ protected function boxingDay(int $year): array return [$key => $boxingDay]; } - /** @return array */ + /** @return array */ protected function newYearsDay(int $year): array { $newYearsDay = new CarbonImmutable($year.'-01-01', 'Europe/London'); @@ -64,7 +65,7 @@ protected function newYearsDay(int $year): array return [$key => $newYearsDay]; } - /** @return array */ + /** @return array */ protected function earlyMayBankHoliday(int $year): array { if ($year === 2020) { @@ -96,7 +97,7 @@ protected function oneOffHolidays(int $year): array }; } - /** @return array */ + /** @return array */ protected function allHolidays(int $year): array { $regularHolidays = array_merge( From 34d6ccd061ca1cc97fa52295990563640ada0f0c Mon Sep 17 00:00:00 2001 From: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> Date: Wed, 7 Feb 2024 11:15:13 +0100 Subject: [PATCH 064/175] update baseline --- phpstan-baseline.neon | 26 +++----------------------- 1 file changed, 3 insertions(+), 23 deletions(-) diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index b253bace3..dffb82781 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -1,34 +1,14 @@ parameters: ignoreErrors: - - - message: "#^Cannot call method modify\\(\\) on Carbon\\\\CarbonImmutable\\|false\\.$#" - count: 1 - path: src/Countries/Australia.php - - message: "#^Argument of an invalid type array\\\\|false supplied for foreach, only iterables are supported\\.$#" count: 1 path: src/Countries/Country.php - - message: "#^Cannot call method startOfDay\\(\\) on Carbon\\\\CarbonImmutable\\|false\\.$#" - count: 2 - path: src/Countries/Country.php - - - - message: "#^Method Spatie\\\\Holidays\\\\Countries\\\\Country\\:\\:get\\(\\) should return array\\ but returns array\\\\.$#" - count: 1 - path: src/Countries/Country.php - - - - message: "#^Parameter \\#2 \\$callback of function uasort expects callable\\(bool\\|Carbon\\\\CarbonImmutable, bool\\|Carbon\\\\CarbonImmutable\\)\\: int, Closure\\(Carbon\\\\CarbonImmutable, Carbon\\\\CarbonImmutable\\)\\: int\\<\\-1, 1\\> given\\.$#" - count: 1 - path: src/Countries/Country.php - - - - message: "#^Cannot call method startOfDay\\(\\) on Carbon\\\\CarbonImmutable\\|false\\.$#" - count: 2 - path: src/Countries/Sweden.php + message: "#^Ternary operator condition is always true\\.$#" + count: 3 + path: src/Countries/Turkey.php - message: "#^Cannot call method setTimeStamp\\(\\) on DateTime\\|false\\.$#" From 4e859b0e18ce39de0cfad13703b4ce60aaa5574f Mon Sep 17 00:00:00 2001 From: Nielsvanpach Date: Wed, 7 Feb 2024 10:20:29 +0000 Subject: [PATCH 065/175] Update CHANGELOG --- CHANGELOG.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index c9f22404d..3490335e6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,21 @@ All notable changes to `holidays` will be documented in this file. +## 1.6.0 - 2024-02-07 + +### What's Changed + +* Add holidays for Argentine by @damian-developer in https://github.com/spatie/holidays/pull/200 +* Add Spanish Holidays by @jaltez in https://github.com/spatie/holidays/pull/34 +* Add support for Carbon v3 by @Nielsvanpach in https://github.com/spatie/holidays/pull/204 + +### New Contributors + +* @damian-developer made their first contribution in https://github.com/spatie/holidays/pull/200 +* @jaltez made their first contribution in https://github.com/spatie/holidays/pull/34 + +**Full Changelog**: https://github.com/spatie/holidays/compare/1.5.1...1.6.0 + ## 1.5.1 - 2024-02-01 Fix translations for Albania & Iran From 9df73f865671e3f7ca7bb1d9c50ad5e44205b35b Mon Sep 17 00:00:00 2001 From: Wessam Ahmed Date: Wed, 7 Feb 2024 12:39:54 +0200 Subject: [PATCH 066/175] Add Egyptian holidays (#155) * Add Egyptian holidays * For consistency * Minor enhancements * Rename holiday * Minor * Minor * Pint * Rename test * Rename method * Early return * Docblock * Docblock * Add New Year's * Minor * Add holidays statically/Turkey solution * Fix translations * Minor * Remove snapshot * This can be misunderstood * Add more translations --------- Co-authored-by: Wessam Ahmed --- lang/egypt/ar/holidays.json | 46 ++- lang/egypt/en/holidays.json | 33 ++ src/Countries/Egypt.php | 365 ++++++++++++++++-- .../it_can_calculate_egypt_holidays.snap | 86 ----- .../it_can_calculate_egyptian_holidays.snap | 130 +++++++ tests/Countries/EgyptTest.php | 9 +- 6 files changed, 536 insertions(+), 133 deletions(-) create mode 100644 lang/egypt/en/holidays.json delete mode 100644 tests/.pest/snapshots/Countries/EgyptTest/it_can_calculate_egypt_holidays.snap create mode 100644 tests/.pest/snapshots/Countries/EgyptTest/it_can_calculate_egyptian_holidays.snap diff --git a/lang/egypt/ar/holidays.json b/lang/egypt/ar/holidays.json index 2ca7af8d3..efdf7779f 100644 --- a/lang/egypt/ar/holidays.json +++ b/lang/egypt/ar/holidays.json @@ -1,23 +1,33 @@ { - "New Year\n's Day": "يوم رأس السنة", - "Coptic Christmas": "عيد الميلاد القبطي", - "Revolution Day January 25": "عيد ثورة 25 يناير", + "New Year\\'s Day": "رأس السنة الميلادية", + "Coptic Christmas Day": "عيد الميلاد المجيد", + "Revolution Day 2011": "ثورة ٢٥ يناير وعيد الشرطة", "March Equinox": "اعتدال مارس", - "Sinai Liberation": "تحرير سيناء", - "Labor": "العمل", - "Coptic Good": "الصالح القبطي", - "Coptic Holy": "المقدس القبطي", - "Coptic Easter": "عيد الفصح القبطي", - "Spring Festival": "مهرجان الربيع", - "June Solstice": "انقلاب يونيو", - "June 30 Revolution": "ثورة 30 يونيو", - "Day off for June 30 Revolution": "يوم عطلة بمناسبة ثورة 30 يونيو", - "Revolution Day July 23": "عيد ثورة 23 يوليو", - "Day off for Revolution Day July 23": "يوم عطلة بمناسبة عيد ثورة 23 يوليو", + "Sinai Liberation Day": "عيد تحرير سيناء (٢٥ أبريل ١٩٨٢)", + "Labour Day": "عيد العمال", + "Coptic Good Friday": "الصالح القبطي", + "Coptic Holy Saturday": "المقدس القبطي", + "Coptic Easter Sunday": "عيد الفصح القبطي", + "Spring Festival": "عيد شم النسيم", + "June Solstice": "الانقلاب الشمسي في يونيو", + "June 30 Revolution Day": "عيد ثورة 30 يونيو", + "Day off for June 30 Revolution Day": "بمناسبة عيد ثورة 30 يونيو", + "Revolution Day": "عيد ثورة 23 يوليو", + "Day off for Revolution Day": "بمناسبة عيد ثورة 23 يوليو", "Flooding of the Nile": "فيضان النيل", "Nayrouz": "النيروز", "September Equinox": "الاعتدال في سبتمبر", - "Armed Forces": "القوات المسلحة", - "Day off for Armed Forces": "يوم عطلة للقوات المسلحة", - "December Solstice": "الانقلاب الشمسي في ديسمبر" -} \ No newline at end of file + "Armed Forces Day": "عيد القوات المسلحة (٦ أكتوبر ١٩٧٣)", + "Day off for Armed Forces Day": "يوم عطلة للقوات المسلحة", + "December Solstice": "الانقلاب الشمسي في ديسمبر", + "Eid al-Fitr": "عيد الفطر المبارك", + "Eid al-Fitr Day 2": "عيد الفطر المبارك", + "Eid al-Fitr Day 3": "عيد الفطر المبارك", + "Eid al-Adha": "عيد الأضحى المبارك", + "Eid al-Adha Day 2": "عيد الأضحى المبارك", + "Eid al-Adha Day 3": "عيد الأضحى المبارك", + "Eid al-Adha Day 4": "عيد الأضحى المبارك", + "Islamic New Year": "رأس السنة الهجرية", + "Birthday of the Prophet Muhammad": "المولد النبوي الشريف", + "Arafat Day": "يوم عرفة (وقفة عيد الأضحى)" +} diff --git a/lang/egypt/en/holidays.json b/lang/egypt/en/holidays.json new file mode 100644 index 000000000..a503639ee --- /dev/null +++ b/lang/egypt/en/holidays.json @@ -0,0 +1,33 @@ +{ + "New Year\\'s Day": "New Year\\'s Day", + "Coptic Christmas Day": "Coptic Christmas Day", + "Revolution Day 2011": "Revolution Day 2011", + "March Equinox": "March Equinox", + "Sinai Liberation Day": "Sinai Liberation Day", + "Labour Day": "Labour Day", + "Coptic Good Friday": "Coptic Good Friday", + "Coptic Holy Saturday": "Coptic Holy Saturday", + "Coptic Easter Sunday": "Coptic Easter Sunday", + "Spring Festival": "Spring Festival", + "June Solstice": "June Solstice", + "June 30 Revolution Day": "June 30 Revolution Day", + "Day off for June 30 Revolution Day": "Day off for June 30 Revolution Day", + "Revolution Day": "Revolution Day", + "Day off for Revolution Day": "Day off for Revolution Day", + "Flooding of the Nile": "Flooding of the Nile", + "Nayrouz": "Nayrouz", + "September Equinox": "September Equinox", + "Armed Forces Day": "Armed Forces Day", + "Day off for Armed Forces Day": "Day off for Armed Forces", + "December Solstice": "December Solstice", + "Eid al-Fitr": "Eid al-Fitr", + "Eid al-Fitr Day 2": "Eid al-Fitr", + "Eid al-Fitr Day 3": "Eid al-Fitr", + "Eid al-Adha": "Eid al-Adha", + "Eid al-Adha Day 2": "Eid al-Adha", + "Eid al-Adha Day 3": "Eid al-Adha", + "Eid al-Adha Day 4": "Eid al-Adha", + "Islamic New Year": "Islamic New Year (Muharram)", + "Birthday of the Prophet Muhammad": "Birthday of the Prophet Muhammad", + "Arafat Day": "Arafat Day", +} diff --git a/src/Countries/Egypt.php b/src/Countries/Egypt.php index 4154b53f4..52ec78672 100644 --- a/src/Countries/Egypt.php +++ b/src/Countries/Egypt.php @@ -3,45 +3,360 @@ namespace Spatie\Holidays\Countries; use Carbon\CarbonImmutable; +use Carbon\CarbonInterface; +use RuntimeException; class Egypt extends Country { + protected const EID_AL_FITR_HOLIDAYS = [ + 2005 => '11-04', + 2006 => '10-24', + 2007 => '10-13', + 2008 => '10-02', + 2009 => '09-21', + 2010 => '09-10', + 2011 => '08-30', + 2012 => '08-19', + 2013 => '08-08', + 2014 => '07-28', + 2015 => '07-17', + 2016 => '07-07', + 2017 => '06-26', + 2018 => '06-15', + 2019 => '06-05', + 2020 => '05-24', + 2021 => '05-13', + 2022 => '05-02', + 2023 => '04-20', + 2024 => '04-10', + 2025 => '03-31', + 2026 => '03-21', + 2027 => '03-10', + 2028 => '02-27', + 2029 => '02-15', + 2030 => '02-04', + 2031 => '01-25', + 2032 => '01-15', + 2033 => '01-03', + 2034 => '12-13', + 2035 => '12-02', + 2036 => '11-20', + 2037 => '11-09', + ]; + + protected const ARAFAT_DAY_HOLIDAYS = [ + 2005 => '01-21', + 2006 => '01-10', + 2007 => '01-01', + 2008 => '12-09', + 2009 => '11-26', + 2010 => '11-15', + 2011 => '11-05', + 2012 => '10-25', + 2013 => '10-15', + 2014 => '10-04', + 2015 => '09-23', + 2016 => '09-11', + 2017 => '08-31', + 2018 => '08-20', + 2019 => '08-10', + 2020 => '07-30', + 2021 => '07-19', + 2022 => '07-09', + 2023 => '06-27', + 2024 => '06-16', + 2025 => '06-06', + 2026 => '05-26', + 2027 => '05-16', + 2028 => '05-05', + 2029 => '04-24', + 2030 => '04-13', + 2031 => '04-02', + 2032 => '03-21', + 2033 => '03-11', + 2034 => '03-01', + 2035 => '02-18', + 2036 => '02-07', + 2037 => '01-26', + ]; + + protected const EID_AL_ADHA_HOLIDAYS = [ + 2005 => '01-22', + 2006 => '01-11', + 2007 => '01-02', + 2008 => '12-10', + 2009 => '11-27', + 2010 => '11-16', + 2011 => '11-06', + 2012 => '10-26', + 2013 => '10-16', + 2014 => '10-05', + 2015 => '09-24', + 2016 => '09-12', + 2017 => '08-31', + 2018 => '08-21', + 2019 => '08-11', + 2020 => '07-31', + 2021 => '07-20', + 2022 => '07-09', + 2023 => '06-28', + 2024 => '06-17', + 2025 => '06-07', + 2026 => '05-27', + 2027 => '05-17', + 2028 => '05-06', + 2029 => '04-25', + 2030 => '04-14', + 2031 => '04-03', + 2032 => '03-22', + 2033 => '03-12', + 2034 => '03-02', + 2035 => '02-19', + 2036 => '02-08', + 2037 => '01-27', + ]; + + protected const ISLAMIC_NEW_YEAR_HOLIDAYS = [ + 2005 => '02-10', + 2006 => '01-31', + 2007 => '01-20', + 2008 => '01-10', + 2009 => '12-18', + 2010 => '12-07', + 2011 => '11-27', + 2012 => '11-15', + 2013 => '11-05', + 2014 => '10-25', + 2015 => '10-14', + 2016 => '10-03', + 2017 => '09-22', + 2018 => '09-11', + 2019 => '08-31', + 2020 => '08-20', + 2021 => '08-09', + 2022 => '07-30', + 2023 => '07-19', + 2024 => '07-08', + 2025 => '06-06', + 2026 => '06-17', + 2027 => '06-07', + 2028 => '05-26', + 2029 => '05-15', + 2030 => '05-05', + 2031 => '04-24', + 2032 => '04-12', + 2033 => '04-01', + 2034 => '03-22', + 2035 => '03-12', + 2036 => '02-29', + 2037 => '02-17', + ]; + + protected const ASHURA_HOLIDAYS = [ + 2005 => '02-19', + 2006 => '02-09', + 2007 => '01-29', + 2008 => '01-19', + 2009 => '12-27', + 2010 => '12-16', + 2011 => '12-06', + 2012 => '11-25', + 2013 => '11-15', + 2014 => '11-04', + 2015 => '10-24', + 2016 => '10-13', + 2017 => '10-02', + 2018 => '09-21', + 2019 => '09-10', + 2020 => '08-30', + 2021 => '08-19', + 2022 => '08-08', + 2023 => '07-28', + 2024 => '07-17', + 2025 => '07-07', + 2026 => '06-26', + 2027 => '06-15', + 2028 => '06-04', + 2029 => '05-24', + 2030 => '05-13', + 2031 => '05-02', + 2032 => '04-20', + 2033 => '04-10', + 2034 => '03-30', + 2035 => '03-19', + 2036 => '03-08', + 2037 => '02-25', + ]; + + protected const PROPHET_MUHAMMAD_BIRTHDAY_HOLIDAYS = [ + 2005 => '04-21', + 2006 => '04-11', + 2007 => '03-31', + 2008 => '03-20', + 2009 => '03-09', + 2010 => '02-26', + 2011 => '02-16', + 2012 => '02-05', + 2013 => '01-24', + 2014 => '01-13', + 2015 => '12-23', + 2016 => '12-12', + 2017 => '12-01', + 2018 => '11-20', + 2019 => '11-09', + 2020 => '10-29', + 2021 => '10-21', + 2022 => '10-08', + 2023 => '09-28', + 2024 => '09-16', + 2025 => '09-06', + 2026 => '08-26', + 2027 => '08-15', + 2028 => '08-04', + 2029 => '07-25', + 2030 => '07-14', + 2031 => '07-03', + 2032 => '06-21', + 2033 => '06-10', + 2034 => '05-31', + 2035 => '05-21', + 2036 => '05-09', + 2037 => '04-29', + ]; + public function countryCode(): string { return 'eg'; } + /** + * @return array + */ protected function allHolidays(int $year): array { + $fixedHolidays = $this->fixedHolidays($year); + $variableHolidays = $this->variableHolidays($year); + return array_merge([ - 'New Year\'s Day' => '01-01', - 'Coptic Christmas' => '01-07', - 'Revolution Day January 25' => '01-25', - 'March Equinox' => '03-20', - 'Sinai Liberation' => '04-25', - 'Labor' => '05-01', - 'Coptic Good' => '05-03', - 'Coptic Holy' => '05-04', - 'Coptic Easter' => '05-05', - 'Spring Festival' => '05-06', - 'June Solstice' => '06-20', - 'June 30 Revolution' => '06-30', - 'Day off for June 30 Revolution' => '07-04', - 'Revolution Day July 23' => '07-23', - 'Day off for Revolution Day July 23' => '07-25', - 'Flooding of the Nile' => '08-15', - 'Nayrouz' => '09-11', - 'September Equinox' => '09-22', - 'Armed Forces' => '10-06', - 'Day off for Armed Forces' => '10-10', - 'December Solstice' => '12-21', - ], $this->variableHolidays($year)); + // These are fixed, but seasonal holidays that aren't observed in Egypt + 'New Year\'s Day' => CarbonImmutable::create($year, 1, 1), + 'Flooding of the Nile' => CarbonImmutable::create($year, 8, 15), + 'March Equinox' => CarbonImmutable::create($year, 3, 20), + 'June Solstice' => CarbonImmutable::create($year, 6, 21), + 'September Equinox' => CarbonImmutable::create($year, 9, 22), + 'Nayrouz' => CarbonImmutable::create($year, 9, 11), + 'December Solstice' => CarbonImmutable::create($year, 12, 21), + ], $fixedHolidays, $variableHolidays); } - /** @return array */ + /** + * @return array + */ protected function variableHolidays(int $year): array { - // The variable holidays all follow the lunar calendar, so their dates are not confirmed. - return []; + $orthodoxEaster = $this->orthodoxEaster($year); + + $eidAlFitrDates = $this->getIslamicHolidayDatesForYear(self::EID_AL_FITR_HOLIDAYS, $year, 'Eid al-Fitr', 3); + $eidAlAdhaDates = $this->getIslamicHolidayDatesForYear(self::EID_AL_ADHA_HOLIDAYS, $year, 'Eid al-Adha', 4); + $arafatDayDates = $this->getIslamicHolidayDatesForYear(self::ARAFAT_DAY_HOLIDAYS, $year, 'Arafat Day'); + $islamicNewYearDates = $this->getIslamicHolidayDatesForYear(self::ISLAMIC_NEW_YEAR_HOLIDAYS, $year, 'Islamic New Year'); + $ashuraDates = $this->getIslamicHolidayDatesForYear(self::ASHURA_HOLIDAYS, $year, 'Ashura'); + $prophetMuhammadBirthdayDates = $this->getIslamicHolidayDatesForYear(self::PROPHET_MUHAMMAD_BIRTHDAY_HOLIDAYS, $year, 'Birthday of the Prophet Muhammad'); + + return array_merge([ + 'Coptic Good Friday' => $orthodoxEaster->subDays(2)->toImmutable(), + 'Coptic Holy Saturday' => $orthodoxEaster->subDays()->toImmutable(), + 'Coptic Easter Sunday' => $orthodoxEaster->toImmutable(), + ], $eidAlFitrDates, $eidAlAdhaDates, $arafatDayDates, $islamicNewYearDates, $ashuraDates, $prophetMuhammadBirthdayDates); + } + + /** + * Prepare holiday dates for the given year. + * + * @param array $holidayDates Array mapping years to dates. + * @param int $year The year for which to prepare holiday dates. + * @param string $holidayName The name of the holiday. + * @param int $duration The duration of the holiday in days. + * @return array An array of holiday dates. + */ + private function getIslamicHolidayDatesForYear(array $holidayDates, int $year, string $holidayName, int $duration = 1): array + { + $dates = []; + + /** + * No reliable sources exist for Islamic holidays observed in Egypt prior to 2005. + * So we'll only calculate holidays from 2005 onwards. + * + * @see https://www.timeanddate.com/holidays/egypt + */ + if (isset($holidayDates[$year])) { + $startDay = CarbonImmutable::createFromFormat('Y-m-d', sprintf('%s-%s', $year, $holidayDates[$year])); + + if (! $startDay instanceof CarbonImmutable) { + throw new RuntimeException('Date could not be created.'); + } + + if ($duration === 1) { + // For single-day holidays, use the holiday name without "Day" + $dates[$holidayName] = $startDay; + } else { + // For multi-day holidays, append "Day N" for the second day onwards + for ($i = 0; $i < $duration; $i++) { + $dayLabel = $i === 0 ? $holidayName : sprintf('%s Day %d', $holidayName, $i + 1); + $dates[$dayLabel] = $startDay->addDays($i); + } + } + } + + return $dates; + } + + /** + * @return array + */ + private function fixedHolidays(int $year): array + { + $holidays = [ + 'Coptic Christmas Day' => CarbonImmutable::create($year, 1, 7), + 'Revolution Day 2011' => CarbonImmutable::create($year, 1, 25), + 'Sinai Liberation Day' => CarbonImmutable::create($year, 4, 25), + 'Labour Day' => CarbonImmutable::create($year, 5, 1), + 'June 30 Revolution Day' => CarbonImmutable::create($year, 6, 30), + 'Revolution Day' => CarbonImmutable::create($year, 7, 23), + 'Armed Forces Day' => CarbonImmutable::create($year, 10, 6), + 'Spring Festival' => $this->orthodoxEaster($year)->addDay()->toImmutable(), + ]; + + foreach ($holidays as $name => $date) { + $holidays = array_merge($holidays, $this->adjustForWeekend($name, $date)); + } + + return $holidays; + } + + /** + * @return array + */ + private function adjustForWeekend(string $name, CarbonImmutable|false $date): array + { + $adjustedHolidays = []; + + if (! $date instanceof CarbonImmutable) { + return []; + } + + // Explicitly define this logic to avoid timezone confusion on the CarbonInterface::next() method + if ($date->isFriday() || $date->isSaturday()) { + // If the holiday falls on a weekend (Friday or Saturday), it is observed on the following Sunday + $adjustedHolidays['Day off for '.$name] = $date->next(CarbonInterface::SUNDAY); + } elseif ($date->isSunday() || $date->isThursday()) { + // If the holiday falls on a Sunday or Thursday, it is observed on the same day + $adjustedHolidays[$name] = $date; + } else { + // If the holiday falls on a weekday (Monday, Tuesday, Wednesday), it is observed on the following Thursday + $adjustedHolidays['Day off for '.$name] = $date->next(CarbonInterface::THURSDAY); + } + + return $adjustedHolidays; } } diff --git a/tests/.pest/snapshots/Countries/EgyptTest/it_can_calculate_egypt_holidays.snap b/tests/.pest/snapshots/Countries/EgyptTest/it_can_calculate_egypt_holidays.snap deleted file mode 100644 index 97a3a8144..000000000 --- a/tests/.pest/snapshots/Countries/EgyptTest/it_can_calculate_egypt_holidays.snap +++ /dev/null @@ -1,86 +0,0 @@ -[ - { - "name": "New Year's Day", - "date": "2024-01-01" - }, - { - "name": "Coptic Christmas", - "date": "2024-01-07" - }, - { - "name": "Revolution Day January 25", - "date": "2024-01-25" - }, - { - "name": "March Equinox", - "date": "2024-03-20" - }, - { - "name": "Sinai Liberation", - "date": "2024-04-25" - }, - { - "name": "Labor", - "date": "2024-05-01" - }, - { - "name": "Coptic Good", - "date": "2024-05-03" - }, - { - "name": "Coptic Holy", - "date": "2024-05-04" - }, - { - "name": "Coptic Easter", - "date": "2024-05-05" - }, - { - "name": "Spring Festival", - "date": "2024-05-06" - }, - { - "name": "June Solstice", - "date": "2024-06-20" - }, - { - "name": "June 30 Revolution", - "date": "2024-06-30" - }, - { - "name": "Day off for June 30 Revolution", - "date": "2024-07-04" - }, - { - "name": "Revolution Day July 23", - "date": "2024-07-23" - }, - { - "name": "Day off for Revolution Day July 23", - "date": "2024-07-25" - }, - { - "name": "Flooding of the Nile", - "date": "2024-08-15" - }, - { - "name": "Nayrouz", - "date": "2024-09-11" - }, - { - "name": "September Equinox", - "date": "2024-09-22" - }, - { - "name": "Armed Forces", - "date": "2024-10-06" - }, - { - "name": "Day off for Armed Forces", - "date": "2024-10-10" - }, - { - "name": "December Solstice", - "date": "2024-12-21" - } -] \ No newline at end of file diff --git a/tests/.pest/snapshots/Countries/EgyptTest/it_can_calculate_egyptian_holidays.snap b/tests/.pest/snapshots/Countries/EgyptTest/it_can_calculate_egyptian_holidays.snap new file mode 100644 index 000000000..2bd487894 --- /dev/null +++ b/tests/.pest/snapshots/Countries/EgyptTest/it_can_calculate_egyptian_holidays.snap @@ -0,0 +1,130 @@ +[ + { + "name": "New Year's Day", + "date": "2024-01-01" + }, + { + "name": "Coptic Christmas Day", + "date": "2024-01-07" + }, + { + "name": "Revolution Day 2011", + "date": "2024-01-25" + }, + { + "name": "March Equinox", + "date": "2024-03-20" + }, + { + "name": "Eid al-Fitr", + "date": "2024-04-10" + }, + { + "name": "Eid al-Fitr Day 2", + "date": "2024-04-11" + }, + { + "name": "Eid al-Fitr Day 3", + "date": "2024-04-12" + }, + { + "name": "Sinai Liberation Day", + "date": "2024-04-25" + }, + { + "name": "Labour Day", + "date": "2024-05-01" + }, + { + "name": "Day off for Labour Day", + "date": "2024-05-02" + }, + { + "name": "Coptic Good Friday", + "date": "2024-05-03" + }, + { + "name": "Coptic Holy Saturday", + "date": "2024-05-04" + }, + { + "name": "Coptic Easter Sunday", + "date": "2024-05-05" + }, + { + "name": "Spring Festival", + "date": "2024-05-06" + }, + { + "name": "Day off for Spring Festival", + "date": "2024-05-09" + }, + { + "name": "Arafat Day", + "date": "2024-06-16" + }, + { + "name": "Eid al-Adha", + "date": "2024-06-17" + }, + { + "name": "Eid al-Adha Day 2", + "date": "2024-06-18" + }, + { + "name": "Eid al-Adha Day 3", + "date": "2024-06-19" + }, + { + "name": "Eid al-Adha Day 4", + "date": "2024-06-20" + }, + { + "name": "June Solstice", + "date": "2024-06-21" + }, + { + "name": "June 30 Revolution Day", + "date": "2024-06-30" + }, + { + "name": "Islamic New Year", + "date": "2024-07-08" + }, + { + "name": "Ashura", + "date": "2024-07-17" + }, + { + "name": "Revolution Day", + "date": "2024-07-23" + }, + { + "name": "Day off for Revolution Day", + "date": "2024-07-25" + }, + { + "name": "Flooding of the Nile", + "date": "2024-08-15" + }, + { + "name": "Nayrouz", + "date": "2024-09-11" + }, + { + "name": "Birthday of the Prophet Muhammad", + "date": "2024-09-16" + }, + { + "name": "September Equinox", + "date": "2024-09-22" + }, + { + "name": "Armed Forces Day", + "date": "2024-10-06" + }, + { + "name": "December Solstice", + "date": "2024-12-21" + } +] \ No newline at end of file diff --git a/tests/Countries/EgyptTest.php b/tests/Countries/EgyptTest.php index 24f5d9ea5..842b8b4ef 100644 --- a/tests/Countries/EgyptTest.php +++ b/tests/Countries/EgyptTest.php @@ -5,13 +5,14 @@ use Carbon\CarbonImmutable; use Spatie\Holidays\Holidays; -it('can calculate egypt holidays', function () { - CarbonImmutable::setTestNowAndTimezone('2024-01-01'); +it('can calculate egyptian holidays', function () { + CarbonImmutable::setTestNowAndTimezone('2024-01-01', 'Africa/Cairo'); $holidays = Holidays::for(country: 'eg')->get(); expect($holidays) ->toBeArray() - ->not()->toBeEmpty() - ->and(formatDates($holidays))->toMatchSnapshot(); + ->not()->toBeEmpty(); + + expect(formatDates($holidays))->toMatchSnapshot(); }); From 3e9ccced56772666ec93cc460a4285f73a0d5b02 Mon Sep 17 00:00:00 2001 From: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> Date: Wed, 7 Feb 2024 11:59:53 +0100 Subject: [PATCH 067/175] fixes for Egypt --- src/Countries/Country.php | 4 +- src/Countries/Egypt.php | 78 ++++++++++++------------- src/Exceptions/InvalidYear.php | 8 +-- tests/Countries/AlbaniaTest.php | 2 +- tests/Countries/AngolaTest.php | 2 +- tests/Countries/ChileTest.php | 2 +- tests/Countries/EgyptTest.php | 9 ++- tests/Countries/EnglandTest.php | 12 ++-- tests/Countries/GhanaTest.php | 6 +- tests/Countries/JamaicaTest.php | 2 +- tests/Countries/KenyaTest.php | 2 +- tests/Countries/MoldovaTest.php | 2 +- tests/Countries/MontenegroTest.php | 2 +- tests/Countries/NigeriaTest.php | 2 +- tests/Countries/NorthernIrelandTest.php | 14 ++--- tests/Countries/ScotlandTest.php | 14 ++--- tests/Countries/SloveniaTest.php | 2 +- tests/Countries/SwitzerlandTest.php | 4 +- tests/Countries/TaiwanTest.php | 2 +- tests/Countries/TanzaniaTest.php | 2 +- tests/Countries/WalesTest.php | 12 ++-- 21 files changed, 93 insertions(+), 90 deletions(-) diff --git a/src/Countries/Country.php b/src/Countries/Country.php index 538b89675..fa0352908 100644 --- a/src/Countries/Country.php +++ b/src/Countries/Country.php @@ -109,11 +109,11 @@ protected function ensureYearCanBeCalculated(int $year): void * https://www.php.net/manual/en/function.easter-date.php */ if ($year < 1970) { - throw InvalidYear::yearTooLow(); + throw InvalidYear::yearTooLow(1970); } if ($year > 2037) { - throw InvalidYear::yearTooHigh(); + throw InvalidYear::yearTooHigh(2038); } } } diff --git a/src/Countries/Egypt.php b/src/Countries/Egypt.php index 52ec78672..b220aca86 100644 --- a/src/Countries/Egypt.php +++ b/src/Countries/Egypt.php @@ -5,6 +5,7 @@ use Carbon\CarbonImmutable; use Carbon\CarbonInterface; use RuntimeException; +use Spatie\Holidays\Exceptions\InvalidYear; class Egypt extends Country { @@ -229,28 +230,24 @@ public function countryCode(): string return 'eg'; } - /** - * @return array - */ protected function allHolidays(int $year): array { $fixedHolidays = $this->fixedHolidays($year); $variableHolidays = $this->variableHolidays($year); return array_merge([ - // These are fixed, but seasonal holidays that aren't observed in Egypt - 'New Year\'s Day' => CarbonImmutable::create($year, 1, 1), - 'Flooding of the Nile' => CarbonImmutable::create($year, 8, 15), - 'March Equinox' => CarbonImmutable::create($year, 3, 20), - 'June Solstice' => CarbonImmutable::create($year, 6, 21), - 'September Equinox' => CarbonImmutable::create($year, 9, 22), - 'Nayrouz' => CarbonImmutable::create($year, 9, 11), - 'December Solstice' => CarbonImmutable::create($year, 12, 21), + 'New Year\'s Day' => '1-1', + 'Flooding of the Nile' => '8-15', + 'March Equinox' => '3-20', + 'June Solstice' => '6-21', + 'Nayrouz' => '9-11', + 'September Equinox' => '9-22', + 'December Solstice' => '12-21', ], $fixedHolidays, $variableHolidays); } /** - * @return array + * @return array */ protected function variableHolidays(int $year): array { @@ -277,7 +274,7 @@ protected function variableHolidays(int $year): array * @param int $year The year for which to prepare holiday dates. * @param string $holidayName The name of the holiday. * @param int $duration The duration of the holiday in days. - * @return array An array of holiday dates. + * @return array An array of holiday dates. */ private function getIslamicHolidayDatesForYear(array $holidayDates, int $year, string $holidayName, int $duration = 1): array { @@ -289,22 +286,25 @@ private function getIslamicHolidayDatesForYear(array $holidayDates, int $year, s * * @see https://www.timeanddate.com/holidays/egypt */ - if (isset($holidayDates[$year])) { - $startDay = CarbonImmutable::createFromFormat('Y-m-d', sprintf('%s-%s', $year, $holidayDates[$year])); - if (! $startDay instanceof CarbonImmutable) { - throw new RuntimeException('Date could not be created.'); - } + if ($year < 2005) { + throw InvalidYear::yearTooLow(2005); + } + + if (! isset($holidayDates[$year])) { + return $dates; + } + + $startDay = CarbonImmutable::createFromFormat('Y-m-d', sprintf('%s-%s', $year, $holidayDates[$year])); - if ($duration === 1) { - // For single-day holidays, use the holiday name without "Day" - $dates[$holidayName] = $startDay; - } else { - // For multi-day holidays, append "Day N" for the second day onwards - for ($i = 0; $i < $duration; $i++) { - $dayLabel = $i === 0 ? $holidayName : sprintf('%s Day %d', $holidayName, $i + 1); - $dates[$dayLabel] = $startDay->addDays($i); - } + if ($duration === 1) { + // For single-day holidays, use the holiday name without "Day" + $dates[$holidayName] = $startDay; + } else { + // For multi-day holidays, append "Day N" for the second day onwards + for ($i = 0; $i < $duration; $i++) { + $dayLabel = $i === 0 ? $holidayName : sprintf('%s Day %d', $holidayName, $i + 1); + $dates[$dayLabel] = $startDay->addDays($i); } } @@ -312,18 +312,18 @@ private function getIslamicHolidayDatesForYear(array $holidayDates, int $year, s } /** - * @return array + * @return array */ private function fixedHolidays(int $year): array { $holidays = [ - 'Coptic Christmas Day' => CarbonImmutable::create($year, 1, 7), - 'Revolution Day 2011' => CarbonImmutable::create($year, 1, 25), - 'Sinai Liberation Day' => CarbonImmutable::create($year, 4, 25), - 'Labour Day' => CarbonImmutable::create($year, 5, 1), - 'June 30 Revolution Day' => CarbonImmutable::create($year, 6, 30), - 'Revolution Day' => CarbonImmutable::create($year, 7, 23), - 'Armed Forces Day' => CarbonImmutable::create($year, 10, 6), + 'Coptic Christmas Day' => CarbonImmutable::createFromDate($year, 1, 7), + 'Revolution Day 2011' => CarbonImmutable::createFromDate($year, 1, 25), + 'Sinai Liberation Day' => CarbonImmutable::createFromDate($year, 4, 25), + 'Labour Day' => CarbonImmutable::createFromDate($year, 5, 1), + 'June 30 Revolution Day' => CarbonImmutable::createFromDate($year, 6, 30), + 'Revolution Day' => CarbonImmutable::createFromDate($year, 7, 23), + 'Armed Forces Day' => CarbonImmutable::createFromDate($year, 10, 6), 'Spring Festival' => $this->orthodoxEaster($year)->addDay()->toImmutable(), ]; @@ -335,16 +335,12 @@ private function fixedHolidays(int $year): array } /** - * @return array + * @return array */ - private function adjustForWeekend(string $name, CarbonImmutable|false $date): array + private function adjustForWeekend(string $name, CarbonImmutable $date): array { $adjustedHolidays = []; - if (! $date instanceof CarbonImmutable) { - return []; - } - // Explicitly define this logic to avoid timezone confusion on the CarbonInterface::next() method if ($date->isFriday() || $date->isSaturday()) { // If the holiday falls on a weekend (Friday or Saturday), it is observed on the following Sunday diff --git a/src/Exceptions/InvalidYear.php b/src/Exceptions/InvalidYear.php index 0eac2b9e1..13fd335ad 100644 --- a/src/Exceptions/InvalidYear.php +++ b/src/Exceptions/InvalidYear.php @@ -6,14 +6,14 @@ class InvalidYear extends RuntimeException { - public static function yearTooLow(): self + public static function yearTooLow(int $year): self { - return new self('Holidays can only be calculated for years after 1970.'); + return new self("Holidays can only be calculated for years after {$year}."); } - public static function yearTooHigh(): self + public static function yearTooHigh(int $year): self { - return new self('Holidays can only be calculated for years before 2038.'); + return new self("Holidays can only be calculated for years before {$year}."); } public static function range(string $country, int $start, int $end): self diff --git a/tests/Countries/AlbaniaTest.php b/tests/Countries/AlbaniaTest.php index 1bfb5ba1b..6099e1a77 100644 --- a/tests/Countries/AlbaniaTest.php +++ b/tests/Countries/AlbaniaTest.php @@ -6,7 +6,7 @@ use Spatie\Holidays\Holidays; it('can calculate albanian holidays', function () { - CarbonImmutable::setTestNowAndTimezone('2024-01-01'); + CarbonImmutable::setTestNow('2024-01-01'); $holidays = Holidays::for(country: 'al')->get(); expect($holidays) diff --git a/tests/Countries/AngolaTest.php b/tests/Countries/AngolaTest.php index ae0e07518..6021f721d 100644 --- a/tests/Countries/AngolaTest.php +++ b/tests/Countries/AngolaTest.php @@ -6,7 +6,7 @@ use Spatie\Holidays\Holidays; it('can calculate angola holidays', function () { - CarbonImmutable::setTestNowAndTimezone('2024-01-01'); + CarbonImmutable::setTestNow('2024-01-01'); $holidays = Holidays::for(country: 'ao')->get(); diff --git a/tests/Countries/ChileTest.php b/tests/Countries/ChileTest.php index aed6f880f..daf50b0e9 100644 --- a/tests/Countries/ChileTest.php +++ b/tests/Countries/ChileTest.php @@ -6,7 +6,7 @@ use Spatie\Holidays\Holidays; it('can calculate chile holidays', function () { - CarbonImmutable::setTestNowAndTimezone('2024-01-01'); + CarbonImmutable::setTestNow('2024-01-01'); $holidays = Holidays::for(country: 'cl')->get(); diff --git a/tests/Countries/EgyptTest.php b/tests/Countries/EgyptTest.php index 842b8b4ef..6579f79c5 100644 --- a/tests/Countries/EgyptTest.php +++ b/tests/Countries/EgyptTest.php @@ -3,10 +3,11 @@ namespace Spatie\Holidays\Tests\Countries; use Carbon\CarbonImmutable; +use Spatie\Holidays\Exceptions\InvalidYear; use Spatie\Holidays\Holidays; it('can calculate egyptian holidays', function () { - CarbonImmutable::setTestNowAndTimezone('2024-01-01', 'Africa/Cairo'); + CarbonImmutable::setTestNow('2024-01-01'); $holidays = Holidays::for(country: 'eg')->get(); @@ -16,3 +17,9 @@ expect(formatDates($holidays))->toMatchSnapshot(); }); + +it('cannot calculate egyptian holidays before 2005', function () { + CarbonImmutable::setTestNow('2024-01-01'); + + Holidays::for(country: 'eg', year: 2004)->get(); +})->throws(InvalidYear::class); diff --git a/tests/Countries/EnglandTest.php b/tests/Countries/EnglandTest.php index ee3d22e80..0746c50a3 100644 --- a/tests/Countries/EnglandTest.php +++ b/tests/Countries/EnglandTest.php @@ -40,7 +40,7 @@ ]); it('can calculate welsh holidays', function () { - CarbonImmutable::setTestNowAndTimezone('2024-01-01'); + CarbonImmutable::setTestNow('2024-01-01'); $holidays = Holidays::for(country: 'gb-eng')->get(); @@ -50,7 +50,7 @@ }); it('returns a substitute day if new years day falls on a weekend', function () { - CarbonImmutable::setTestNowAndTimezone('2033-01-01'); + CarbonImmutable::setTestNow('2033-01-01'); $holidays = Holidays::for(country: 'gb-eng')->get(); @@ -59,7 +59,7 @@ }); it('can calculate welsh holidays if christmas is on a friday', function () { - CarbonImmutable::setTestNowAndTimezone('2020-01-01'); + CarbonImmutable::setTestNow('2020-01-01'); $holidays = Holidays::for(country: 'gb-eng')->get(); @@ -68,7 +68,7 @@ }); it('can calculate welsh holidays if christmas is on a saturday', function () { - CarbonImmutable::setTestNowAndTimezone('2021-01-01'); + CarbonImmutable::setTestNow('2021-01-01'); $holidays = Holidays::for(country: 'gb-eng')->get(); @@ -77,7 +77,7 @@ }); it('can calculate welsh holidays if christmas is on a sunday', function () { - CarbonImmutable::setTestNowAndTimezone('2022-01-01'); + CarbonImmutable::setTestNow('2022-01-01'); $holidays = Holidays::for(country: 'gb-eng')->get(); @@ -86,7 +86,7 @@ }); it('can calculate holidays for 2020', function () { - CarbonImmutable::setTestNowAndTimezone('2020-01-01'); + CarbonImmutable::setTestNow('2020-01-01'); $holidays = Holidays::for(country: 'gb-eng')->get(); diff --git a/tests/Countries/GhanaTest.php b/tests/Countries/GhanaTest.php index 3a02ed9d3..f8186e756 100644 --- a/tests/Countries/GhanaTest.php +++ b/tests/Countries/GhanaTest.php @@ -6,7 +6,7 @@ use Spatie\Holidays\Holidays; it('can calculate Ghana holidays', function () { - CarbonImmutable::setTestNowAndTimezone('2024-01-01'); + CarbonImmutable::setTestNow('2024-01-01'); $holidays = Holidays::for(country: 'gh')->get(); @@ -18,7 +18,7 @@ }); it('can calculate Ghana easter based region holidays', function () { - CarbonImmutable::setTestNowAndTimezone('2024-01-01'); + CarbonImmutable::setTestNow('2024-01-01'); $holidays = Holidays::for(country: 'gh')->get(); @@ -30,7 +30,7 @@ }); it('can calculate Ghana date based regional holidays', function () { - CarbonImmutable::setTestNowAndTimezone('2024-01-01'); + CarbonImmutable::setTestNow('2024-01-01'); $holidays = Holidays::for(country: 'gh')->get(); diff --git a/tests/Countries/JamaicaTest.php b/tests/Countries/JamaicaTest.php index 1ea7b0237..5b06881f5 100644 --- a/tests/Countries/JamaicaTest.php +++ b/tests/Countries/JamaicaTest.php @@ -6,7 +6,7 @@ use Spatie\Holidays\Holidays; it('can calculate jamaican holidays', function () { - CarbonImmutable::setTestNowAndTimezone('2024-01-01'); + CarbonImmutable::setTestNow('2024-01-01'); $holidays = Holidays::for(country: 'jm')->get(); diff --git a/tests/Countries/KenyaTest.php b/tests/Countries/KenyaTest.php index 96d17cdf3..c5aef294d 100644 --- a/tests/Countries/KenyaTest.php +++ b/tests/Countries/KenyaTest.php @@ -6,7 +6,7 @@ use Spatie\Holidays\Holidays; it('can calculate kenyan holidays', function () { - CarbonImmutable::setTestNowAndTimezone('2024-01-01'); + CarbonImmutable::setTestNow('2024-01-01'); $holidays = Holidays::for(country: 'ke')->get(); diff --git a/tests/Countries/MoldovaTest.php b/tests/Countries/MoldovaTest.php index 02ac0db64..86fafa45e 100644 --- a/tests/Countries/MoldovaTest.php +++ b/tests/Countries/MoldovaTest.php @@ -6,7 +6,7 @@ use Spatie\Holidays\Holidays; it('can calculate moldavian holidays', function () { - CarbonImmutable::setTestNowAndTimezone('2024-01-01'); + CarbonImmutable::setTestNow('2024-01-01'); $holidays = Holidays::for(country: 'md')->get(); diff --git a/tests/Countries/MontenegroTest.php b/tests/Countries/MontenegroTest.php index 9f5078b93..e5450ba3f 100644 --- a/tests/Countries/MontenegroTest.php +++ b/tests/Countries/MontenegroTest.php @@ -6,7 +6,7 @@ use Spatie\Holidays\Holidays; it('can calculate montenegro holidays', function () { - CarbonImmutable::setTestNowAndTimezone('2024-01-01'); + CarbonImmutable::setTestNow('2024-01-01'); $holidays = Holidays::for(country: 'me')->get(); diff --git a/tests/Countries/NigeriaTest.php b/tests/Countries/NigeriaTest.php index 8fdb2a32a..d0559a305 100644 --- a/tests/Countries/NigeriaTest.php +++ b/tests/Countries/NigeriaTest.php @@ -6,7 +6,7 @@ use Spatie\Holidays\Holidays; it('can calculate nigerian holidays', function () { - CarbonImmutable::setTestNowAndTimezone('2024-01-01'); + CarbonImmutable::setTestNow('2024-01-01'); $holidays = Holidays::for(country: 'ng')->get(); diff --git a/tests/Countries/NorthernIrelandTest.php b/tests/Countries/NorthernIrelandTest.php index 11266d3af..1f5dc237c 100644 --- a/tests/Countries/NorthernIrelandTest.php +++ b/tests/Countries/NorthernIrelandTest.php @@ -47,7 +47,7 @@ ]); it('can calculate northern irish holidays', function () { - CarbonImmutable::setTestNowAndTimezone('2025-01-01'); + CarbonImmutable::setTestNow('2025-01-01'); $holidays = Holidays::for(country: 'gb-nir')->get(); @@ -57,7 +57,7 @@ }); it('returns a substitute day if new years day falls on a weekend', function () { - CarbonImmutable::setTestNowAndTimezone('2033-01-01'); + CarbonImmutable::setTestNow('2033-01-01'); $holidays = Holidays::for(country: 'gb-nir')->get(); @@ -66,7 +66,7 @@ }); it('returns a substitute day for second of january if new years day falls on a friday', function () { - CarbonImmutable::setTestNowAndTimezone('2021-01-01'); + CarbonImmutable::setTestNow('2021-01-01'); $holidays = Holidays::for(country: 'gb-nir')->get(); @@ -75,7 +75,7 @@ }); it('can calculate northern irish holidays if christmas is on a friday', function () { - CarbonImmutable::setTestNowAndTimezone('2020-01-01'); + CarbonImmutable::setTestNow('2020-01-01'); $holidays = Holidays::for(country: 'gb-nir')->get(); @@ -84,7 +84,7 @@ }); it('can calculate northern irish holidays if christmas is on a saturday', function () { - CarbonImmutable::setTestNowAndTimezone('2021-01-01'); + CarbonImmutable::setTestNow('2021-01-01'); $holidays = Holidays::for(country: 'gb-nir')->get(); @@ -93,7 +93,7 @@ }); it('can calculate northern irish holidays if christmas is on a sunday', function () { - CarbonImmutable::setTestNowAndTimezone('2022-01-01'); + CarbonImmutable::setTestNow('2022-01-01'); $holidays = Holidays::for(country: 'gb-nir')->get(); @@ -102,7 +102,7 @@ }); it('can calculate northern irish for 2020', function () { - CarbonImmutable::setTestNowAndTimezone('2020-01-01'); + CarbonImmutable::setTestNow('2020-01-01'); $holidays = Holidays::for(country: 'gb-eng')->get(); diff --git a/tests/Countries/ScotlandTest.php b/tests/Countries/ScotlandTest.php index f8aa5d926..dc2d9aaad 100644 --- a/tests/Countries/ScotlandTest.php +++ b/tests/Countries/ScotlandTest.php @@ -43,7 +43,7 @@ ]); it('can calculate scottish holidays', function () { - CarbonImmutable::setTestNowAndTimezone('2025-01-01'); + CarbonImmutable::setTestNow('2025-01-01'); $holidays = Holidays::for(country: 'gb-sct')->get(); @@ -53,7 +53,7 @@ }); it('returns a substitute day if new years day falls on a weekend', function () { - CarbonImmutable::setTestNowAndTimezone('2033-01-01'); + CarbonImmutable::setTestNow('2033-01-01'); $holidays = Holidays::for(country: 'gb-sct')->get(); @@ -62,7 +62,7 @@ }); it('returns a substitute day for second of january if new years day falls on a friday', function () { - CarbonImmutable::setTestNowAndTimezone('2021-01-01'); + CarbonImmutable::setTestNow('2021-01-01'); $holidays = Holidays::for(country: 'gb-sct')->get(); @@ -71,7 +71,7 @@ }); it('can calculate scottish holidays if christmas is on a friday', function () { - CarbonImmutable::setTestNowAndTimezone('2020-01-01'); + CarbonImmutable::setTestNow('2020-01-01'); $holidays = Holidays::for(country: 'gb-sct')->get(); @@ -80,7 +80,7 @@ }); it('can calculate scottish holidays if christmas is on a saturday', function () { - CarbonImmutable::setTestNowAndTimezone('2021-01-01'); + CarbonImmutable::setTestNow('2021-01-01'); $holidays = Holidays::for(country: 'gb-sct')->get(); @@ -89,7 +89,7 @@ }); it('can calculate scottish holidays if christmas is on a sunday', function () { - CarbonImmutable::setTestNowAndTimezone('2022-01-01'); + CarbonImmutable::setTestNow('2022-01-01'); $holidays = Holidays::for(country: 'gb-sct')->get(); @@ -98,7 +98,7 @@ }); it('can calculate holidays for 2020', function () { - CarbonImmutable::setTestNowAndTimezone('2020-01-01'); + CarbonImmutable::setTestNow('2020-01-01'); $holidays = Holidays::for(country: 'gb-eng')->get(); diff --git a/tests/Countries/SloveniaTest.php b/tests/Countries/SloveniaTest.php index 0dc846a6e..da8a6e011 100644 --- a/tests/Countries/SloveniaTest.php +++ b/tests/Countries/SloveniaTest.php @@ -6,7 +6,7 @@ use Spatie\Holidays\Holidays; it('can calculate slovenian holidays', function () { - CarbonImmutable::setTestNowAndTimezone('2024-01-01'); + CarbonImmutable::setTestNow('2024-01-01'); $holidays = Holidays::for(country: 'si')->get(); diff --git a/tests/Countries/SwitzerlandTest.php b/tests/Countries/SwitzerlandTest.php index 0e4a97f41..386019210 100644 --- a/tests/Countries/SwitzerlandTest.php +++ b/tests/Countries/SwitzerlandTest.php @@ -8,7 +8,7 @@ use Spatie\Holidays\Holidays; it('can calculate swiss holidays', function () { - CarbonImmutable::setTestNowAndTimezone('2024-01-01'); + CarbonImmutable::setTestNow('2024-01-01'); $holidays = Holidays::for(country: 'ch')->get(); @@ -20,7 +20,7 @@ }); it('can get swiss holidays for a specified region (zh)', function () { - CarbonImmutable::setTestNowAndTimezone('2024-01-01'); + CarbonImmutable::setTestNow('2024-01-01'); $switzerland = new Switzerland(region: 'ch-zh'); diff --git a/tests/Countries/TaiwanTest.php b/tests/Countries/TaiwanTest.php index 75c7b6906..9aa6578bc 100644 --- a/tests/Countries/TaiwanTest.php +++ b/tests/Countries/TaiwanTest.php @@ -6,7 +6,7 @@ use Spatie\Holidays\Holidays; it('can calculate taiwan holidays', function () { - CarbonImmutable::setTestNowAndTimezone('2024-01-01'); + CarbonImmutable::setTestNow('2024-01-01'); $holidays = Holidays::for(country: 'tw')->get(); diff --git a/tests/Countries/TanzaniaTest.php b/tests/Countries/TanzaniaTest.php index 69777866b..38f15ec39 100644 --- a/tests/Countries/TanzaniaTest.php +++ b/tests/Countries/TanzaniaTest.php @@ -6,7 +6,7 @@ use Spatie\Holidays\Holidays; it('can calculate tanzania holidays', function () { - CarbonImmutable::setTestNowAndTimezone('2024-01-01'); + CarbonImmutable::setTestNow('2024-01-01'); $holidays = Holidays::for(country: 'tz')->get(); diff --git a/tests/Countries/WalesTest.php b/tests/Countries/WalesTest.php index 2e840357b..01d65370e 100644 --- a/tests/Countries/WalesTest.php +++ b/tests/Countries/WalesTest.php @@ -58,7 +58,7 @@ ]); it('can calculate welsh holidays', function () { - CarbonImmutable::setTestNowAndTimezone('2024-01-01'); + CarbonImmutable::setTestNow('2024-01-01'); $holidays = Holidays::for(country: 'gb-cym')->get(); @@ -68,7 +68,7 @@ }); it('returns a substitute day if new years day falls on a weekend', function () { - CarbonImmutable::setTestNowAndTimezone('2033-01-01'); + CarbonImmutable::setTestNow('2033-01-01'); $holidays = Holidays::for(country: 'gb-cym')->get(); @@ -77,7 +77,7 @@ }); it('can calculate welsh holidays if christmas is on a friday', function () { - CarbonImmutable::setTestNowAndTimezone('2020-01-01'); + CarbonImmutable::setTestNow('2020-01-01'); $holidays = Holidays::for(country: 'gb-cym')->get(); @@ -86,7 +86,7 @@ }); it('can calculate welsh holidays if christmas is on a saturday', function () { - CarbonImmutable::setTestNowAndTimezone('2021-01-01'); + CarbonImmutable::setTestNow('2021-01-01'); $holidays = Holidays::for(country: 'gb-cym')->get(); @@ -95,7 +95,7 @@ }); it('can calculate welsh holidays if christmas is on a sunday', function () { - CarbonImmutable::setTestNowAndTimezone('2022-01-01'); + CarbonImmutable::setTestNow('2022-01-01'); $holidays = Holidays::for(country: 'gb-cym')->get(); @@ -104,7 +104,7 @@ }); it('can calculate holidays for 2020', function () { - CarbonImmutable::setTestNowAndTimezone('2020-01-01'); + CarbonImmutable::setTestNow('2020-01-01'); $holidays = Holidays::for(country: 'gb-cym')->get(); From 3be86627ac9f9772a1decc3568a56dbd1899f0e6 Mon Sep 17 00:00:00 2001 From: Nielsvanpach Date: Wed, 7 Feb 2024 11:00:24 +0000 Subject: [PATCH 068/175] Fix styling --- src/Countries/Egypt.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/Countries/Egypt.php b/src/Countries/Egypt.php index b220aca86..464759c26 100644 --- a/src/Countries/Egypt.php +++ b/src/Countries/Egypt.php @@ -4,7 +4,6 @@ use Carbon\CarbonImmutable; use Carbon\CarbonInterface; -use RuntimeException; use Spatie\Holidays\Exceptions\InvalidYear; class Egypt extends Country @@ -286,7 +285,6 @@ private function getIslamicHolidayDatesForYear(array $holidayDates, int $year, s * * @see https://www.timeanddate.com/holidays/egypt */ - if ($year < 2005) { throw InvalidYear::yearTooLow(2005); } From 7a335da7507ed0abb0996b9457fdb71dd7756ef3 Mon Sep 17 00:00:00 2001 From: Nielsvanpach Date: Wed, 7 Feb 2024 11:01:32 +0000 Subject: [PATCH 069/175] Update CHANGELOG --- CHANGELOG.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3490335e6..fc14bbaa3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,18 @@ All notable changes to `holidays` will be documented in this file. +## 1.6.1 - 2024-02-07 + +### What's Changed + +* Fixes for Egyptian holidays by @wessama in https://github.com/spatie/holidays/pull/155 + +### New Contributors + +* @wessama made their first contribution in https://github.com/spatie/holidays/pull/155 + +**Full Changelog**: https://github.com/spatie/holidays/compare/1.6.0...1.6.1 + ## 1.6.0 - 2024-02-07 ### What's Changed From 5223465c49ee7339cbd97b16c6a33169938cff41 Mon Sep 17 00:00:00 2001 From: Shokhrukh Shomakhmudov Date: Thu, 8 Feb 2024 14:38:18 +0500 Subject: [PATCH 070/175] Add Uzbekistan Holidays (#81) * Add Uzbekistan Holidays * phpstan error fix * feat: add locale & update islamic holidays * tests updated and verified * tests updated and verified --- lang/uzbekistan/en/holidays.json | 13 ++ lang/uzbekistan/ru/holidays.json | 13 ++ src/Countries/Uzbekistan.php | 165 ++++++++++++++++++ ...olidays_with_data_set___2000____2000_.snap | 42 +++++ ...olidays_with_data_set___2006____2006_.snap | 42 +++++ ...olidays_with_data_set___2022____2022_.snap | 38 ++++ ...olidays_with_data_set___2023____2023_.snap | 38 ++++ tests/Countries/UzbekistanTest.php | 18 ++ 8 files changed, 369 insertions(+) create mode 100644 lang/uzbekistan/en/holidays.json create mode 100644 lang/uzbekistan/ru/holidays.json create mode 100644 src/Countries/Uzbekistan.php create mode 100644 tests/.pest/snapshots/Countries/UzbekistanTest/it_can_calculate_uzbekistan_holidays_with_data_set___2000____2000_.snap create mode 100644 tests/.pest/snapshots/Countries/UzbekistanTest/it_can_calculate_uzbekistan_holidays_with_data_set___2006____2006_.snap create mode 100644 tests/.pest/snapshots/Countries/UzbekistanTest/it_can_calculate_uzbekistan_holidays_with_data_set___2022____2022_.snap create mode 100644 tests/.pest/snapshots/Countries/UzbekistanTest/it_can_calculate_uzbekistan_holidays_with_data_set___2023____2023_.snap create mode 100644 tests/Countries/UzbekistanTest.php diff --git a/lang/uzbekistan/en/holidays.json b/lang/uzbekistan/en/holidays.json new file mode 100644 index 000000000..63db8bac2 --- /dev/null +++ b/lang/uzbekistan/en/holidays.json @@ -0,0 +1,13 @@ +{ + "Yangi yil": "New year", + "Xalqaro xotin-qizlar kuni": "International Women's Day", + "Navro'z": "Nowruz", + "Xotira va qadrlash kuni": "Remembrance Day", + "Mustaqillik kuni": "Independence Day", + "Ustoz va murabbiylar kuni": "Teachers Day", + "Konstitutsiya kuni": "Constitution Day", + "Ramazon Hayiti": "Eid al-Fitr", + "Qurbon Hayiti": "Eid al-Adha", + "Ramazon Hayiti 2": "Eid al-Fitr", + "Qurbon Hayiti 2": "Eid al-Adha" +} \ No newline at end of file diff --git a/lang/uzbekistan/ru/holidays.json b/lang/uzbekistan/ru/holidays.json new file mode 100644 index 000000000..8dea77311 --- /dev/null +++ b/lang/uzbekistan/ru/holidays.json @@ -0,0 +1,13 @@ +{ + "Yangi yil": "Новый год", + "Xalqaro xotin-qizlar kuni": "Международный женский день", + "Navro'z": "Навруз", + "Xotira va qadrlash kuni": "День памяти и почестей", + "Mustaqillik kuni": "День Независимости", + "Ustoz va murabbiylar kuni": "День учителя", + "Konstitutsiya kuni": "День Конституции", + "Ramazon Hayiti": "Рамазан Хаит", + "Qurbon Hayiti": "Курбан Хаит", + "Ramazon Hayiti 2": "Рамазан Хаит", + "Qurbon Hayiti 2": "Курбан Хаит" +} \ No newline at end of file diff --git a/src/Countries/Uzbekistan.php b/src/Countries/Uzbekistan.php new file mode 100644 index 000000000..ffb371916 --- /dev/null +++ b/src/Countries/Uzbekistan.php @@ -0,0 +1,165 @@ + '04-16', + 1992 => '04-04', + 1993 => '03-25', + 1994 => '03-14', + 1995 => '03-03', + 1996 => '02-21', + 1997 => '02-09', + 1998 => '01-30', + 1999 => '01-19', + 2000 => [ + '01-08', + '12-28', + ], + 2001 => '12-17', + 2002 => '12-06', + 2003 => '11-26', + 2004 => '11-14', + 2005 => '11-04', + 2006 => '10-24', + 2007 => '10-13', + 2008 => '10-02', + 2009 => '09-21', + 2010 => '09-10', + 2011 => '08-31', + 2012 => '08-19', + 2013 => '08-08', + 2014 => '07-29', + 2015 => '07-18', + 2016 => '07-07', + 2017 => '06-26', + 2018 => '06-15', + 2019 => '06-04', + 2020 => '05-24', + 2021 => '05-13', + 2022 => '05-02', + 2023 => '04-21', + 2024 => '04-10', + 2025 => '03-31', + 2026 => '03-20', + 2027 => '03-10', + 2028 => '02-27', + 2029 => '02-15', + 2030 => '02-05', + 2031 => '01-25', + 2032 => '01-14', + 2033 => [ + '01-03', + '12-23', + ], + 2034 => '12-12', + 2035 => '12-02', + 2036 => '11-20', + 2037 => '11-10', + ]; + + public const sacrificeHolidays = [ + 1991 => '06-23', + 1992 => '06-11', + 1993 => '06-01', + 1994 => '05-21', + 1995 => '05-10', + 1996 => '04-29', + 1997 => '04-18', + 1998 => '04-08', + 1999 => '03-28', + 2000 => '03-16', + 2001 => '03-06', + 2002 => '02-23', + 2003 => '02-12', + 2004 => '02-02', + 2005 => '01-21', + 2006 => [ + '01-10', + '12-31', + ], + 2007 => '12-20', + 2008 => '12-09', + 2009 => '11-28', + 2010 => '11-17', + 2011 => '11-07', + 2012 => '10-26', + 2013 => '10-15', + 2014 => '10-05', + 2015 => '09-24', + 2016 => '09-13', + 2017 => '09-02', + 2018 => '08-22', + 2019 => '08-11', + 2020 => '07-31', + 2021 => '07-20', + 2022 => '07-09', + 2023 => '06-28', + 2024 => '06-17', + 2025 => '06-07', + 2026 => '05-27', + 2027 => '05-17', + 2028 => '05-05', + 2029 => '04-24', + 2030 => '04-14', + 2031 => '04-03', + 2032 => '03-22', + 2033 => '03-12', + 2034 => '03-01', + 2035 => '02-18', + 2036 => '02-08', + 2037 => '01-27', + ]; + + public function countryCode(): string + { + return 'uz'; + } + + /** @return array */ + protected function allHolidays(int $year): array + { + //After gaining independence on September 1, 1991, Uzbekistan introduced a new set of public holidays. + if ($year < 1991) { + return []; + } + + return array_merge([ + 'Yangi yil' => '01-01', + 'Xalqaro xotin-qizlar kuni' => '03-08', + 'Navro\'z' => '03-21', + 'Xotira va qadrlash kuni' => '05-09', + 'Mustaqillik kuni' => '09-01', + 'Ustoz va murabbiylar kuni' => '10-01', + 'Konstitutsiya kuni' => '12-08', + ], $this->variableHolidays($year)); + } + + /** @return array */ + protected function variableHolidays(int $year): array + { + $holidays = []; + + if (isset(self::ramadanHolidays[$year])) { + foreach ((array) self::ramadanHolidays[$year] as $key => $holiday) { + $prefix = $key == 0 ? '' : ' '.($key + 1); + $holidays['Ramazon Hayiti'.$prefix] = $holiday; + } + } + if (isset(self::sacrificeHolidays[$year])) { + foreach ((array) self::sacrificeHolidays[$year] as $key => $holiday) { + $prefix = $key == 0 ? '' : ' '.($key + 1); + $holidays['Qurbon Hayiti'.$prefix] = $holiday; + } + } + + return $holidays; + } +} diff --git a/tests/.pest/snapshots/Countries/UzbekistanTest/it_can_calculate_uzbekistan_holidays_with_data_set___2000____2000_.snap b/tests/.pest/snapshots/Countries/UzbekistanTest/it_can_calculate_uzbekistan_holidays_with_data_set___2000____2000_.snap new file mode 100644 index 000000000..46826c3aa --- /dev/null +++ b/tests/.pest/snapshots/Countries/UzbekistanTest/it_can_calculate_uzbekistan_holidays_with_data_set___2000____2000_.snap @@ -0,0 +1,42 @@ +[ + { + "name": "Yangi yil", + "date": "2000-01-01" + }, + { + "name": "Ramazon Hayiti", + "date": "2000-01-08" + }, + { + "name": "Xalqaro xotin-qizlar kuni", + "date": "2000-03-08" + }, + { + "name": "Qurbon Hayiti", + "date": "2000-03-16" + }, + { + "name": "Navro'z", + "date": "2000-03-21" + }, + { + "name": "Xotira va qadrlash kuni", + "date": "2000-05-09" + }, + { + "name": "Mustaqillik kuni", + "date": "2000-09-01" + }, + { + "name": "Ustoz va murabbiylar kuni", + "date": "2000-10-01" + }, + { + "name": "Konstitutsiya kuni", + "date": "2000-12-08" + }, + { + "name": "Ramazon Hayiti 2", + "date": "2000-12-28" + } +] \ No newline at end of file diff --git a/tests/.pest/snapshots/Countries/UzbekistanTest/it_can_calculate_uzbekistan_holidays_with_data_set___2006____2006_.snap b/tests/.pest/snapshots/Countries/UzbekistanTest/it_can_calculate_uzbekistan_holidays_with_data_set___2006____2006_.snap new file mode 100644 index 000000000..4717ce431 --- /dev/null +++ b/tests/.pest/snapshots/Countries/UzbekistanTest/it_can_calculate_uzbekistan_holidays_with_data_set___2006____2006_.snap @@ -0,0 +1,42 @@ +[ + { + "name": "Yangi yil", + "date": "2006-01-01" + }, + { + "name": "Qurbon Hayiti", + "date": "2006-01-10" + }, + { + "name": "Xalqaro xotin-qizlar kuni", + "date": "2006-03-08" + }, + { + "name": "Navro'z", + "date": "2006-03-21" + }, + { + "name": "Xotira va qadrlash kuni", + "date": "2006-05-09" + }, + { + "name": "Mustaqillik kuni", + "date": "2006-09-01" + }, + { + "name": "Ustoz va murabbiylar kuni", + "date": "2006-10-01" + }, + { + "name": "Ramazon Hayiti", + "date": "2006-10-24" + }, + { + "name": "Konstitutsiya kuni", + "date": "2006-12-08" + }, + { + "name": "Qurbon Hayiti 2", + "date": "2006-12-31" + } +] \ No newline at end of file diff --git a/tests/.pest/snapshots/Countries/UzbekistanTest/it_can_calculate_uzbekistan_holidays_with_data_set___2022____2022_.snap b/tests/.pest/snapshots/Countries/UzbekistanTest/it_can_calculate_uzbekistan_holidays_with_data_set___2022____2022_.snap new file mode 100644 index 000000000..34a96f797 --- /dev/null +++ b/tests/.pest/snapshots/Countries/UzbekistanTest/it_can_calculate_uzbekistan_holidays_with_data_set___2022____2022_.snap @@ -0,0 +1,38 @@ +[ + { + "name": "Yangi yil", + "date": "2022-01-01" + }, + { + "name": "Xalqaro xotin-qizlar kuni", + "date": "2022-03-08" + }, + { + "name": "Navro'z", + "date": "2022-03-21" + }, + { + "name": "Ramazon Hayiti", + "date": "2022-05-02" + }, + { + "name": "Xotira va qadrlash kuni", + "date": "2022-05-09" + }, + { + "name": "Qurbon Hayiti", + "date": "2022-07-09" + }, + { + "name": "Mustaqillik kuni", + "date": "2022-09-01" + }, + { + "name": "Ustoz va murabbiylar kuni", + "date": "2022-10-01" + }, + { + "name": "Konstitutsiya kuni", + "date": "2022-12-08" + } +] \ No newline at end of file diff --git a/tests/.pest/snapshots/Countries/UzbekistanTest/it_can_calculate_uzbekistan_holidays_with_data_set___2023____2023_.snap b/tests/.pest/snapshots/Countries/UzbekistanTest/it_can_calculate_uzbekistan_holidays_with_data_set___2023____2023_.snap new file mode 100644 index 000000000..516cc91b4 --- /dev/null +++ b/tests/.pest/snapshots/Countries/UzbekistanTest/it_can_calculate_uzbekistan_holidays_with_data_set___2023____2023_.snap @@ -0,0 +1,38 @@ +[ + { + "name": "Yangi yil", + "date": "2023-01-01" + }, + { + "name": "Xalqaro xotin-qizlar kuni", + "date": "2023-03-08" + }, + { + "name": "Navro'z", + "date": "2023-03-21" + }, + { + "name": "Ramazon Hayiti", + "date": "2023-04-21" + }, + { + "name": "Xotira va qadrlash kuni", + "date": "2023-05-09" + }, + { + "name": "Qurbon Hayiti", + "date": "2023-06-28" + }, + { + "name": "Mustaqillik kuni", + "date": "2023-09-01" + }, + { + "name": "Ustoz va murabbiylar kuni", + "date": "2023-10-01" + }, + { + "name": "Konstitutsiya kuni", + "date": "2023-12-08" + } +] \ No newline at end of file diff --git a/tests/Countries/UzbekistanTest.php b/tests/Countries/UzbekistanTest.php new file mode 100644 index 000000000..d59e5a1b9 --- /dev/null +++ b/tests/Countries/UzbekistanTest.php @@ -0,0 +1,18 @@ +get(); + + expect($holidays) + ->toBeArray() + ->not()->toBeEmpty(); + + expect(formatDates($holidays))->toMatchSnapshot(); +})->with([2000, 2006, 2022, 2023]); From 0e9712513e624aed6203bb71959f29e8c63dc49f Mon Sep 17 00:00:00 2001 From: Kenan Aghayev <36705821+kenanaga@users.noreply.github.com> Date: Thu, 8 Feb 2024 13:39:08 +0400 Subject: [PATCH 071/175] Add Azerbaijan holidays (#166) * Add Azerbaijan holidays * Added Azerbaijani holidays in English * update setTestNowAndTimezone to setTestNow --- lang/azerbaijan/en/holidays.json | 13 ++++++ src/Countries/Azerbaijan.php | 37 +++++++++++++++ ...it_can_calculate_azerbaijani_holidays.snap | 46 +++++++++++++++++++ ...ulate_azerbaijani_holidays_in_english.snap | 46 +++++++++++++++++++ tests/Countries/AzerbaijanTest.php | 30 ++++++++++++ 5 files changed, 172 insertions(+) create mode 100644 lang/azerbaijan/en/holidays.json create mode 100644 src/Countries/Azerbaijan.php create mode 100644 tests/.pest/snapshots/Countries/AzerbaijanTest/it_can_calculate_azerbaijani_holidays.snap create mode 100644 tests/.pest/snapshots/Countries/AzerbaijanTest/it_can_calculate_azerbaijani_holidays_in_english.snap create mode 100644 tests/Countries/AzerbaijanTest.php diff --git a/lang/azerbaijan/en/holidays.json b/lang/azerbaijan/en/holidays.json new file mode 100644 index 000000000..2fc0b49c3 --- /dev/null +++ b/lang/azerbaijan/en/holidays.json @@ -0,0 +1,13 @@ +{ + "Yeni il": "New year", + "Beynəlxalq Qadınlar günü": "International Women's Day", + "Novruz bayramı": "Novruz holiday", + "Faşizm üzərində qələbə günü": "Day of Victory over fascism", + "Müstəqillik Günü": "Independence Day", + "Azərbaycan xalqının milli qurtuluş günü": "National Salvation Day of the Azerbaijani people", + "Azərbaycan Respublikasının Silahlı Qüvvələri günü": "Day of Armed Forces of the Republic of Azerbaijan", + "Müstəqilliyin bərpası günü": "Day of Restoration of Independence", + "Zəfər Günü": "Victory Day", + "Azərbaycan Respublikasının Dövlət bayrağı günü": "National Flag Day of the Republic of Azerbaijan", + "Dünya azərbaycanlılarının həmrəyliyi günü": "World Azerbaijanis Solidarity Day" +} diff --git a/src/Countries/Azerbaijan.php b/src/Countries/Azerbaijan.php new file mode 100644 index 000000000..b92cd3b12 --- /dev/null +++ b/src/Countries/Azerbaijan.php @@ -0,0 +1,37 @@ + '01-01', + 'Beynəlxalq Qadınlar günü' => '03-08', + 'Novruz bayramı' => '03-20', + 'Faşizm üzərində qələbə günü' => '05-09', + 'Müstəqillik Günü' => '05-28', + 'Azərbaycan xalqının milli qurtuluş günü' => '06-15', + 'Azərbaycan Respublikasının Silahlı Qüvvələri günü' => '06-26', + 'Müstəqilliyin bərpası günü' => '10-18', + 'Zəfər Günü' => '11-08', + 'Azərbaycan Respublikasının Dövlət bayrağı günü' => '11-09', + 'Dünya azərbaycanlılarının həmrəyliyi günü' => '12-31', + ], $this->variableHolidays($year)); + } + + /** @return array */ + protected function variableHolidays(int $year): array + { + // does not change according to the standard + return []; + } +} diff --git a/tests/.pest/snapshots/Countries/AzerbaijanTest/it_can_calculate_azerbaijani_holidays.snap b/tests/.pest/snapshots/Countries/AzerbaijanTest/it_can_calculate_azerbaijani_holidays.snap new file mode 100644 index 000000000..cb0489f97 --- /dev/null +++ b/tests/.pest/snapshots/Countries/AzerbaijanTest/it_can_calculate_azerbaijani_holidays.snap @@ -0,0 +1,46 @@ +[ + { + "name": "Yeni il", + "date": "2024-01-01" + }, + { + "name": "Beyn\u0259lxalq Qad\u0131nlar g\u00fcn\u00fc", + "date": "2024-03-08" + }, + { + "name": "Novruz bayram\u0131", + "date": "2024-03-20" + }, + { + "name": "Fa\u015fizm \u00fcz\u0259rind\u0259 q\u0259l\u0259b\u0259 g\u00fcn\u00fc", + "date": "2024-05-09" + }, + { + "name": "M\u00fcst\u0259qillik G\u00fcn\u00fc", + "date": "2024-05-28" + }, + { + "name": "Az\u0259rbaycan xalq\u0131n\u0131n milli qurtulu\u015f g\u00fcn\u00fc", + "date": "2024-06-15" + }, + { + "name": "Az\u0259rbaycan Respublikas\u0131n\u0131n Silahl\u0131 Q\u00fcvv\u0259l\u0259ri g\u00fcn\u00fc", + "date": "2024-06-26" + }, + { + "name": "M\u00fcst\u0259qilliyin b\u0259rpas\u0131 g\u00fcn\u00fc", + "date": "2024-10-18" + }, + { + "name": "Z\u0259f\u0259r G\u00fcn\u00fc", + "date": "2024-11-08" + }, + { + "name": "Az\u0259rbaycan Respublikas\u0131n\u0131n D\u00f6vl\u0259t bayra\u011f\u0131 g\u00fcn\u00fc", + "date": "2024-11-09" + }, + { + "name": "D\u00fcnya az\u0259rbaycanl\u0131lar\u0131n\u0131n h\u0259mr\u0259yliyi g\u00fcn\u00fc", + "date": "2024-12-31" + } +] \ No newline at end of file diff --git a/tests/.pest/snapshots/Countries/AzerbaijanTest/it_can_calculate_azerbaijani_holidays_in_english.snap b/tests/.pest/snapshots/Countries/AzerbaijanTest/it_can_calculate_azerbaijani_holidays_in_english.snap new file mode 100644 index 000000000..e1ef8359c --- /dev/null +++ b/tests/.pest/snapshots/Countries/AzerbaijanTest/it_can_calculate_azerbaijani_holidays_in_english.snap @@ -0,0 +1,46 @@ +[ + { + "name": "New year", + "date": "2024-01-01" + }, + { + "name": "International Women's Day", + "date": "2024-03-08" + }, + { + "name": "Novruz holiday", + "date": "2024-03-20" + }, + { + "name": "Day of Victory over fascism", + "date": "2024-05-09" + }, + { + "name": "Independence Day", + "date": "2024-05-28" + }, + { + "name": "National Salvation Day of the Azerbaijani people", + "date": "2024-06-15" + }, + { + "name": "Day of Armed Forces of the Republic of Azerbaijan", + "date": "2024-06-26" + }, + { + "name": "Day of Restoration of Independence", + "date": "2024-10-18" + }, + { + "name": "Victory Day", + "date": "2024-11-08" + }, + { + "name": "National Flag Day of the Republic of Azerbaijan", + "date": "2024-11-09" + }, + { + "name": "World Azerbaijanis Solidarity Day", + "date": "2024-12-31" + } +] \ No newline at end of file diff --git a/tests/Countries/AzerbaijanTest.php b/tests/Countries/AzerbaijanTest.php new file mode 100644 index 000000000..4de5efa5a --- /dev/null +++ b/tests/Countries/AzerbaijanTest.php @@ -0,0 +1,30 @@ +get(); + + expect($holidays) + ->toBeArray() + ->not()->toBeEmpty(); + + expect(formatDates($holidays))->toMatchSnapshot(); +}); + +it('can calculate azerbaijani holidays in english', function () { + CarbonImmutable::setTestNow('2024-01-01'); + + $holidays = Holidays::for(country: 'az',locale: 'en')->get(); + + expect($holidays) + ->toBeArray() + ->not()->toBeEmpty(); + + expect(formatDates($holidays))->toMatchSnapshot(); +}); From fb625e2321ac72c1af869c962a9a802a1c4e5295 Mon Sep 17 00:00:00 2001 From: Nielsvanpach Date: Thu, 8 Feb 2024 09:39:31 +0000 Subject: [PATCH 072/175] Fix styling --- tests/Countries/AzerbaijanTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Countries/AzerbaijanTest.php b/tests/Countries/AzerbaijanTest.php index 4de5efa5a..9aa9180a5 100644 --- a/tests/Countries/AzerbaijanTest.php +++ b/tests/Countries/AzerbaijanTest.php @@ -20,7 +20,7 @@ it('can calculate azerbaijani holidays in english', function () { CarbonImmutable::setTestNow('2024-01-01'); - $holidays = Holidays::for(country: 'az',locale: 'en')->get(); + $holidays = Holidays::for(country: 'az', locale: 'en')->get(); expect($holidays) ->toBeArray() From 0ab3409bbf7648de1d9719ff02bf59417c8529f2 Mon Sep 17 00:00:00 2001 From: Victor Ikpeba Date: Thu, 8 Feb 2024 09:56:10 +0000 Subject: [PATCH 073/175] Enhanced holiday dates in Ghana (#80) * Added holidays for `Ghana` * fix timezone when creating farmers day * Updated holidays that falls within weekend to be observed on the next monday * Fix return types * pr suggestions implemented * removed unwanted timezone in params * removed timezone * Updated test * removed test files * Add back test files * Added return types to methods --- src/Countries/Ghana.php | 91 +++++++++++++++++-- ...te_Ghana_date_based_regional_holidays.snap | 10 +- ...te_Ghana_easter_based_region_holidays.snap | 10 +- .../it_can_calculate_Ghana_holidays.snap | 10 +- 4 files changed, 102 insertions(+), 19 deletions(-) diff --git a/src/Countries/Ghana.php b/src/Countries/Ghana.php index 03342516c..505677c36 100644 --- a/src/Countries/Ghana.php +++ b/src/Countries/Ghana.php @@ -11,18 +11,81 @@ public function countryCode(): string return 'gh'; } + /** + * Return carbon date for christmas + * + * @return CarbonImmutable + */ + protected function getChristmasDay(int $year) + { + return new CarbonImmutable($year . '-12-25'); + } + + /** @return CarbonImmutable */ + protected function christmasDay(int $year): CarbonImmutable + { + $christmasDay = $this->getChristmasDay($year); + + if ($christmasDay->isSaturday()) { + + $christmasDay = $christmasDay->next('monday'); + } + + if ($christmasDay->isSunday()) { + $christmasDay = $christmasDay->next('tuesday'); + } + + return $christmasDay; + } + + /** @return CarbonImmutable */ + protected function boxingDay(int $year): CarbonImmutable + { + $christmasDay = $this->getChristmasDay($year); + $boxingDay = new CarbonImmutable($year . '-12-26'); + + if ($christmasDay->isFriday()) { + $boxingDay = $boxingDay->next('monday'); + } + if ($christmasDay->isSaturday()) { + $boxingDay = $boxingDay->next('tuesday'); + } + + return $boxingDay; + } + + /** + * Get holiday + * + * For example: If a holiday falls on a weekend, the new day to be observed is the next monday + * @return CarbonImmutable + */ + protected function getHoliday(int $year, string $monthAndDay): CarbonImmutable + { + $newYearsDay = new CarbonImmutable($year . '-' . $monthAndDay); + + if ($newYearsDay->isWeekend()) { + $newYearsDay = $newYearsDay->next('monday'); + } + + return $newYearsDay; + } + protected function allHolidays(int $year): array { - return array_merge([ - 'New Year\'s Day' => '01-01', - 'Constitution Day' => '01-07', - 'Independence Day' => '03-06', - 'May Day' => '05-01', - 'Founder\'s Day' => '08-04', - 'Kwame Nkrumah Memorial Day' => '09-21', - 'Christmas Day' => '12-25', - 'Boxing Day' => '12-26', - ], $this->variableHolidays($year)); + return array_merge( + [ + 'New Year\'s Day' => $this->getHoliday($year, '01-01'), + 'Constitution Day' => $this->getHoliday($year, '01-07'), + 'Independence Day' => $this->getHoliday($year, '03-06'), + 'May Day' => $this->getHoliday($year, '05-01'), + 'Founder\'s Day' => $this->getHoliday($year, '08-04'), + 'Kwame Nkrumah Memorial Day' => $this->getHoliday($year, '09-21'), + 'Christmas Day' => $this->christmasDay($year), + 'Boxing Day' => $this->boxingDay($year), + ], + $this->variableHolidays($year) + ); } /** @return array */ @@ -30,9 +93,17 @@ protected function variableHolidays(int $year): array { $easter = $this->easter($year); + $farmersDay = new CarbonImmutable('first friday of December ' . $year); + return [ + 'Farmers Day' => $farmersDay, 'Good Friday' => $easter->subDays(2), 'Easter Monday' => $easter->addDay(), + + // NB: *** There are no fixed dates for the Eid-Ul-Fitr and Eid-Ul-Adha because they are movable feasts. + // The dates for their observation are provided by the Office of the Chief Imam in the course of the year. + // 'Eid-Ul-Fitr' => "", + // 'Eid-Ul-Adha' => "", ]; } } diff --git a/tests/.pest/snapshots/Countries/GhanaTest/it_can_calculate_Ghana_date_based_regional_holidays.snap b/tests/.pest/snapshots/Countries/GhanaTest/it_can_calculate_Ghana_date_based_regional_holidays.snap index 3d29c9e8f..b5d9a6c72 100644 --- a/tests/.pest/snapshots/Countries/GhanaTest/it_can_calculate_Ghana_date_based_regional_holidays.snap +++ b/tests/.pest/snapshots/Countries/GhanaTest/it_can_calculate_Ghana_date_based_regional_holidays.snap @@ -5,7 +5,7 @@ }, { "name": "Constitution Day", - "date": "2024-01-07" + "date": "2024-01-08" }, { "name": "Independence Day", @@ -25,11 +25,15 @@ }, { "name": "Founder's Day", - "date": "2024-08-04" + "date": "2024-08-05" }, { "name": "Kwame Nkrumah Memorial Day", - "date": "2024-09-21" + "date": "2024-09-23" + }, + { + "name": "Farmers Day", + "date": "2024-12-06" }, { "name": "Christmas Day", diff --git a/tests/.pest/snapshots/Countries/GhanaTest/it_can_calculate_Ghana_easter_based_region_holidays.snap b/tests/.pest/snapshots/Countries/GhanaTest/it_can_calculate_Ghana_easter_based_region_holidays.snap index 3d29c9e8f..b5d9a6c72 100644 --- a/tests/.pest/snapshots/Countries/GhanaTest/it_can_calculate_Ghana_easter_based_region_holidays.snap +++ b/tests/.pest/snapshots/Countries/GhanaTest/it_can_calculate_Ghana_easter_based_region_holidays.snap @@ -5,7 +5,7 @@ }, { "name": "Constitution Day", - "date": "2024-01-07" + "date": "2024-01-08" }, { "name": "Independence Day", @@ -25,11 +25,15 @@ }, { "name": "Founder's Day", - "date": "2024-08-04" + "date": "2024-08-05" }, { "name": "Kwame Nkrumah Memorial Day", - "date": "2024-09-21" + "date": "2024-09-23" + }, + { + "name": "Farmers Day", + "date": "2024-12-06" }, { "name": "Christmas Day", diff --git a/tests/.pest/snapshots/Countries/GhanaTest/it_can_calculate_Ghana_holidays.snap b/tests/.pest/snapshots/Countries/GhanaTest/it_can_calculate_Ghana_holidays.snap index 3d29c9e8f..b5d9a6c72 100644 --- a/tests/.pest/snapshots/Countries/GhanaTest/it_can_calculate_Ghana_holidays.snap +++ b/tests/.pest/snapshots/Countries/GhanaTest/it_can_calculate_Ghana_holidays.snap @@ -5,7 +5,7 @@ }, { "name": "Constitution Day", - "date": "2024-01-07" + "date": "2024-01-08" }, { "name": "Independence Day", @@ -25,11 +25,15 @@ }, { "name": "Founder's Day", - "date": "2024-08-04" + "date": "2024-08-05" }, { "name": "Kwame Nkrumah Memorial Day", - "date": "2024-09-21" + "date": "2024-09-23" + }, + { + "name": "Farmers Day", + "date": "2024-12-06" }, { "name": "Christmas Day", From a96f91368cc70d72b8f30172ac74de8611c385c2 Mon Sep 17 00:00:00 2001 From: Nielsvanpach Date: Thu, 8 Feb 2024 09:56:31 +0000 Subject: [PATCH 074/175] Fix styling --- src/Countries/Ghana.php | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/Countries/Ghana.php b/src/Countries/Ghana.php index 505677c36..7d922e88d 100644 --- a/src/Countries/Ghana.php +++ b/src/Countries/Ghana.php @@ -18,10 +18,9 @@ public function countryCode(): string */ protected function getChristmasDay(int $year) { - return new CarbonImmutable($year . '-12-25'); + return new CarbonImmutable($year.'-12-25'); } - /** @return CarbonImmutable */ protected function christmasDay(int $year): CarbonImmutable { $christmasDay = $this->getChristmasDay($year); @@ -38,11 +37,10 @@ protected function christmasDay(int $year): CarbonImmutable return $christmasDay; } - /** @return CarbonImmutable */ protected function boxingDay(int $year): CarbonImmutable { $christmasDay = $this->getChristmasDay($year); - $boxingDay = new CarbonImmutable($year . '-12-26'); + $boxingDay = new CarbonImmutable($year.'-12-26'); if ($christmasDay->isFriday()) { $boxingDay = $boxingDay->next('monday'); @@ -58,11 +56,10 @@ protected function boxingDay(int $year): CarbonImmutable * Get holiday * * For example: If a holiday falls on a weekend, the new day to be observed is the next monday - * @return CarbonImmutable */ protected function getHoliday(int $year, string $monthAndDay): CarbonImmutable { - $newYearsDay = new CarbonImmutable($year . '-' . $monthAndDay); + $newYearsDay = new CarbonImmutable($year.'-'.$monthAndDay); if ($newYearsDay->isWeekend()) { $newYearsDay = $newYearsDay->next('monday'); @@ -93,7 +90,7 @@ protected function variableHolidays(int $year): array { $easter = $this->easter($year); - $farmersDay = new CarbonImmutable('first friday of December ' . $year); + $farmersDay = new CarbonImmutable('first friday of December '.$year); return [ 'Farmers Day' => $farmersDay, From 34f8217c4b8e6055f3931bfb867d2e5c24a31b36 Mon Sep 17 00:00:00 2001 From: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> Date: Thu, 8 Feb 2024 10:57:28 +0100 Subject: [PATCH 075/175] use --compact for tests --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 46ef42ee3..5937dbf4a 100644 --- a/composer.json +++ b/composer.json @@ -46,7 +46,7 @@ "scripts": { "analyse": "vendor/bin/phpstan analyse", "baseline": "vendor/bin/phpstan analyse --generate-baseline", - "test": "vendor/bin/pest", + "test": "vendor/bin/pest --compact", "test-coverage": "vendor/bin/pest --coverage", "format": "vendor/bin/pint" }, From 91232cf6bb8961c0316a7a78e40219aceb073c61 Mon Sep 17 00:00:00 2001 From: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> Date: Thu, 8 Feb 2024 11:11:59 +0100 Subject: [PATCH 076/175] code cleanup for Ghana --- src/Countries/Ghana.php | 106 +++++++++++++++++++--------------------- 1 file changed, 50 insertions(+), 56 deletions(-) diff --git a/src/Countries/Ghana.php b/src/Countries/Ghana.php index 7d922e88d..1a6f0cab0 100644 --- a/src/Countries/Ghana.php +++ b/src/Countries/Ghana.php @@ -3,6 +3,7 @@ namespace Spatie\Holidays\Countries; use Carbon\CarbonImmutable; +use Carbon\CarbonInterface; class Ghana extends Country { @@ -11,86 +12,81 @@ public function countryCode(): string return 'gh'; } - /** - * Return carbon date for christmas - * - * @return CarbonImmutable - */ - protected function getChristmasDay(int $year) + protected function allHolidays(int $year): array { - return new CarbonImmutable($year.'-12-25'); + return array_merge( + $this->observedHolidays($year), + $this->variableHolidays($year), + ); } - protected function christmasDay(int $year): CarbonImmutable + /** @return array */ + protected function observedHolidays(int $year): array { - $christmasDay = $this->getChristmasDay($year); - - if ($christmasDay->isSaturday()) { - - $christmasDay = $christmasDay->next('monday'); - } + $holidays = [ + 'New Year\'s Day' => '01-01', + 'Constitution Day' => '01-07', + 'Independence Day' => '03-06', + 'May Day' => '05-01', + 'Founder\'s Day' => '08-04', + 'Kwame Nkrumah Memorial Day' => '09-21', + ]; - if ($christmasDay->isSunday()) { - $christmasDay = $christmasDay->next('tuesday'); - } + $holidays = array_map(function ($holiday) use ($year) { + return $this->observed($holiday, $year); + }, $holidays); - return $christmasDay; + return array_merge($holidays, [ + 'Christmas Day' => $this->observedChristmasDay($year), + 'Boxing Day' => $this->observedBoxingDay($year), + ]); } - protected function boxingDay(int $year): CarbonImmutable + protected function observed(string $date, int $year): CarbonInterface { - $christmasDay = $this->getChristmasDay($year); - $boxingDay = new CarbonImmutable($year.'-12-26'); + $holiday = CarbonImmutable::createFromFormat('Y-m-d', "{$year}-{$date}")->startOfDay(); - if ($christmasDay->isFriday()) { - $boxingDay = $boxingDay->next('monday'); - } - if ($christmasDay->isSaturday()) { - $boxingDay = $boxingDay->next('tuesday'); + if ($holiday->isWeekend()) { + return $holiday->next('monday'); } - return $boxingDay; + return $holiday; } - /** - * Get holiday - * - * For example: If a holiday falls on a weekend, the new day to be observed is the next monday - */ - protected function getHoliday(int $year, string $monthAndDay): CarbonImmutable + protected function christmas(int $year): CarbonInterface { - $newYearsDay = new CarbonImmutable($year.'-'.$monthAndDay); + return (new CarbonImmutable($year.'-12-25'))->startOfDay(); + } - if ($newYearsDay->isWeekend()) { - $newYearsDay = $newYearsDay->next('monday'); - } + protected function observedChristmasDay(int $year): CarbonInterface + { + $christmasDay = $this->christmas($year); - return $newYearsDay; + return match ($christmasDay->dayName) { + 'Saturday' => $christmasDay->next('monday'), + 'Sunday' => $christmasDay->next('tuesday'), + default => $christmasDay, + }; } - protected function allHolidays(int $year): array + protected function observedBoxingDay(int $year): CarbonInterface { - return array_merge( - [ - 'New Year\'s Day' => $this->getHoliday($year, '01-01'), - 'Constitution Day' => $this->getHoliday($year, '01-07'), - 'Independence Day' => $this->getHoliday($year, '03-06'), - 'May Day' => $this->getHoliday($year, '05-01'), - 'Founder\'s Day' => $this->getHoliday($year, '08-04'), - 'Kwame Nkrumah Memorial Day' => $this->getHoliday($year, '09-21'), - 'Christmas Day' => $this->christmasDay($year), - 'Boxing Day' => $this->boxingDay($year), - ], - $this->variableHolidays($year) - ); + $christmasDay = $this->christmas($year); + $boxingDay = new CarbonImmutable($year.'-12-26'); + + return match ($christmasDay->dayName) { + 'Friday' => $boxingDay->next('monday'), + 'Saturday' => $boxingDay->next('tuesday'), + default => $boxingDay, + }; } - /** @return array */ + /** @return array */ protected function variableHolidays(int $year): array { $easter = $this->easter($year); - $farmersDay = new CarbonImmutable('first friday of December '.$year); + $farmersDay = (new CarbonImmutable('first friday of December '.$year))->startOfDay(); return [ 'Farmers Day' => $farmersDay, @@ -99,8 +95,6 @@ protected function variableHolidays(int $year): array // NB: *** There are no fixed dates for the Eid-Ul-Fitr and Eid-Ul-Adha because they are movable feasts. // The dates for their observation are provided by the Office of the Chief Imam in the course of the year. - // 'Eid-Ul-Fitr' => "", - // 'Eid-Ul-Adha' => "", ]; } } From 9a7cf77f740c23fae87a5fcf362054dce0401533 Mon Sep 17 00:00:00 2001 From: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> Date: Thu, 8 Feb 2024 11:25:54 +0100 Subject: [PATCH 077/175] cleanup Canada --- src/Countries/Angola.php | 1 - src/Countries/Canada.php | 45 ++++++++++++++------------------------- src/Countries/Country.php | 6 +++++- 3 files changed, 21 insertions(+), 31 deletions(-) diff --git a/src/Countries/Angola.php b/src/Countries/Angola.php index 0ef3bb72a..982c4f3ed 100644 --- a/src/Countries/Angola.php +++ b/src/Countries/Angola.php @@ -13,7 +13,6 @@ public function countryCode(): string protected function allHolidays(int $year): array { - return array_merge([ 'Dia de Ano Novo' => '01-01', 'Dia do Inicio da Luta Armada de Libertação Nacional' => '02-04', diff --git a/src/Countries/Canada.php b/src/Countries/Canada.php index 52ea0e958..653f6b0c9 100644 --- a/src/Countries/Canada.php +++ b/src/Countries/Canada.php @@ -3,6 +3,7 @@ namespace Spatie\Holidays\Countries; use Carbon\CarbonImmutable; +use Carbon\CarbonInterface; class Canada extends Country { @@ -13,48 +14,34 @@ public function countryCode(): string protected function allHolidays(int $year): array { - return array_merge( - [ - 'New Year\'s Day' => new CarbonImmutable($year.'-01-01', 'America/Toronto'), - 'Canada Day' => new CarbonImmutable($year.'-07-01', 'America/Toronto'), - 'Civic Holiday' => new CarbonImmutable( - 'first monday of August '.$year, 'America/Toronto' - ), - 'Labour Day' => new CarbonImmutable( - 'first monday of September '.$year, 'America/Toronto' - ), - 'National Day for Truth and Reconciliation' => new CarbonImmutable( - $year.'-09-30', - 'America/Toronto' - ), - 'Remembrance Day' => new CarbonImmutable($year.'-11-11', 'America/Toronto'), - 'Christmas Day' => new CarbonImmutable($year.'-12-25', 'America/Toronto'), - 'Boxing Day' => new CarbonImmutable($year.'-12-26', 'America/Toronto'), - ], - $this->variableHolidays($year) - ); + return array_merge([ + 'New Year\'s Day' => '01-01', + 'Canada Day' => '07-01', + 'Civic Holiday' => 'first monday of August', + 'Labour Day' => 'first monday of September', + 'National Day for Truth and Reconciliation' => '09-30', + 'Remembrance Day' => '11-11', + 'Christmas Day' => '12-25', + 'Boxing Day' => '12-26', + ], $this->variableHolidays($year)); } - /** @return array */ + /** @return array */ protected function variableHolidays(int $year): array { $easter = $this->easter($year); - $goodFriday = $easter->subDays(2); - $easterMonday = $easter->addDay(); + $victoriaDay = (new CarbonImmutable("last monday of May $year"))->startOfDay(); - $victoriaDay = new CarbonImmutable("last monday of May $year", 'America/Toronto'); if ($victoriaDay->day < 25) { $victoriaDay = $victoriaDay->addWeek(); } - $thanksgiving = new CarbonImmutable("second monday of October $year", 'America/Toronto'); - return [ 'Victoria Day' => $victoriaDay, - 'Good Friday' => $goodFriday, - 'Easter Monday' => $easterMonday, - 'Thanksgiving' => $thanksgiving, + 'Good Friday' => $easter->subDays(2), + 'Easter Monday' => $easter->addDay(), + 'Thanksgiving' => "second monday of October", ]; } } diff --git a/src/Countries/Country.php b/src/Countries/Country.php index fa0352908..7006191bd 100644 --- a/src/Countries/Country.php +++ b/src/Countries/Country.php @@ -26,7 +26,11 @@ public function get(int $year, ?string $locale = null): array $translatedHolidays = []; foreach ($allHolidays as $name => $date) { if (is_string($date)) { - $date = CarbonImmutable::createFromFormat('Y-m-d', "{$year}-{$date}"); + if (strlen($date) > 5) { + $date = (new CarbonImmutable($date . ' ' . $year))->startOfDay(); + } else { + $date = CarbonImmutable::createFromFormat('Y-m-d', "{$year}-{$date}"); + } } $name = $this->translate(basename(str_replace('\\', '/', static::class)), $name, $locale); From 2656e5b1dbba0c16bd23dec677272734ebda3115 Mon Sep 17 00:00:00 2001 From: Nielsvanpach Date: Thu, 8 Feb 2024 10:26:31 +0000 Subject: [PATCH 078/175] Fix styling --- src/Countries/Canada.php | 2 +- src/Countries/Country.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Countries/Canada.php b/src/Countries/Canada.php index 653f6b0c9..f1350e198 100644 --- a/src/Countries/Canada.php +++ b/src/Countries/Canada.php @@ -41,7 +41,7 @@ protected function variableHolidays(int $year): array 'Victoria Day' => $victoriaDay, 'Good Friday' => $easter->subDays(2), 'Easter Monday' => $easter->addDay(), - 'Thanksgiving' => "second monday of October", + 'Thanksgiving' => 'second monday of October', ]; } } diff --git a/src/Countries/Country.php b/src/Countries/Country.php index 7006191bd..34f0284d2 100644 --- a/src/Countries/Country.php +++ b/src/Countries/Country.php @@ -27,7 +27,7 @@ public function get(int $year, ?string $locale = null): array foreach ($allHolidays as $name => $date) { if (is_string($date)) { if (strlen($date) > 5) { - $date = (new CarbonImmutable($date . ' ' . $year))->startOfDay(); + $date = (new CarbonImmutable($date.' '.$year))->startOfDay(); } else { $date = CarbonImmutable::createFromFormat('Y-m-d', "{$year}-{$date}"); } From c1bf3597de13f370e50cdcb2088ed0b9d4059b3d Mon Sep 17 00:00:00 2001 From: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> Date: Thu, 8 Feb 2024 11:31:14 +0100 Subject: [PATCH 079/175] cleanup Finland --- src/Countries/Finland.php | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/src/Countries/Finland.php b/src/Countries/Finland.php index 32e75c649..84fcf74a6 100644 --- a/src/Countries/Finland.php +++ b/src/Countries/Finland.php @@ -14,19 +14,22 @@ public function countryCode(): string protected function allHolidays(int $year): array { - return array_merge($this->fixedHolidays($year), $this->variableHolidays($year)); + return array_merge( + $this->fixedHolidays(), + $this->variableHolidays($year) + ); } - /** @return array */ - protected function fixedHolidays(int $year): array + /** @return array */ + protected function fixedHolidays(): array { return [ - 'Uudenvuodenpäivä' => CarbonImmutable::createFromDate($year, 1, 1), - 'Loppiainen' => CarbonImmutable::createFromDate($year, 1, 6), - 'Vappu' => CarbonImmutable::createFromDate($year, 5, 1), - 'Itsenäisyyspäivä' => CarbonImmutable::createFromDate($year, 12, 6), - 'Joulupäivä' => CarbonImmutable::createFromDate($year, 12, 25), - 'Tapaninpäivä' => CarbonImmutable::createFromDate($year, 12, 26), + 'Uudenvuodenpäivä' => '01-01', + 'Loppiainen' => '01-06', + 'Vappu' => '05-01', + 'Itsenäisyyspäivä' => '12-06', + 'Joulupäivä' => '12-25', + 'Tapaninpäivä' => '12-26' ]; } @@ -36,7 +39,7 @@ protected function variableHolidays(int $year): array $easter = $this->easter($year); $midsummerDay = CarbonImmutable::createFromDate($year, 6, 20) - ->next(CarbonImmutable::SATURDAY); + ->next(CarbonInterface::SATURDAY); return [ 'Pitkäperjantai' => $easter->subDays(2), @@ -48,7 +51,7 @@ protected function variableHolidays(int $year): array ? $midsummerDay->subWeek() : $midsummerDay, 'Pyhäinpäivä' => CarbonImmutable::createFromDate($year, 10, 31) - ->next(CarbonImmutable::SATURDAY), + ->next(CarbonInterface::SATURDAY), ]; } } From 1068902d7c16c4dc4adeb579a0a4e4b266eeb233 Mon Sep 17 00:00:00 2001 From: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> Date: Thu, 8 Feb 2024 11:35:16 +0100 Subject: [PATCH 080/175] cleanup Germany --- src/Countries/Germany.php | 78 +++++++++++++++++++-------------------- 1 file changed, 39 insertions(+), 39 deletions(-) diff --git a/src/Countries/Germany.php b/src/Countries/Germany.php index e0b61f282..fda0dc46e 100644 --- a/src/Countries/Germany.php +++ b/src/Countries/Germany.php @@ -16,25 +16,48 @@ public function countryCode(): string return 'de'; } - private function getRepentanceAndPrayerDay(int $year): string + protected function allHolidays(int $year): array + { + return array_merge([ + 'Neujahr' => '01-01', + 'Tag der Arbeit' => '05-01', + '1. Weihnachtstag' => '12-25', + '2. Weihnachtstag' => '12-26', + ], + $this->variableHolidays($year), + $this->historicalHolidays($year), + $this->regionHolidays($year) + ); + } + + /** @return array */ + protected function variableHolidays(int $year): array { - $repentanceAndPrayerDay = new CarbonImmutable('next wednesday '.$year.'-11-15', 'Europe/Berlin'); + $easter = $this->easter($year); - return $repentanceAndPrayerDay->format('m-d'); + return [ + 'Karfreitag' => $easter->subDays(2), + 'Ostermontag' => $easter->addDay(), + 'Himmelfahrt' => $easter->addDays(39), + 'Pfingstmontag' => $easter->addDays(50), + ]; } /** @return array */ protected function historicalHolidays(int $year): array { $historicalHolidays = []; + if ($year >= 1954 && $year <= 1990) { $historicalHolidays['Tag der deutschen Einheit'] = '06-17'; } else { $historicalHolidays['Tag der deutschen Einheit'] = '10-03'; } + if ($year >= 1990 && $year <= 1994) { $historicalHolidays['Buß- und Bettag'] = $this->getRepentanceAndPrayerDay($year); } + if ($year === 2017) { $historicalHolidays['Reformationstag'] = '10-31'; } @@ -42,32 +65,6 @@ protected function historicalHolidays(int $year): array return $historicalHolidays; } - /** @return array */ - protected function allHolidays(int $year): array - { - - return array_merge([ - 'Neujahr' => '01-01', - 'Tag der Arbeit' => '05-01', - '1. Weihnachtstag' => '12-25', - '2. Weihnachtstag' => '12-26', - ], $this->variableHolidays($year), $this->historicalHolidays($year), $this->regionHolidays($year)); - } - - /** @return array */ - protected function variableHolidays(int $year): array - { - - $easter = $this->easter($year); - - return [ - 'Karfreitag' => $easter->subDays(2), - 'Ostermontag' => $easter->addDay(), - 'Himmelfahrt' => $easter->addDays(39), - 'Pfingstmontag' => $easter->addDays(50), - ]; - } - /** @return array */ protected function regionHolidays(int $year): array { @@ -111,12 +108,12 @@ protected function regionHolidays(int $year): array 'Reformationstag' => '10-31', 'Pfingstsonntag' => $easter->addDays(49), ]; - } else { - return [ - 'Ostersonntag' => $easter, - 'Pfingstsonntag' => $easter->addDays(49), - ]; } + + return [ + 'Ostersonntag' => $easter, + 'Pfingstsonntag' => $easter->addDays(49), + ]; case 'DE-HB': case 'DE-HH': case 'DE-NI': @@ -125,12 +122,10 @@ protected function regionHolidays(int $year): array return [ 'Reformationstag' => '10-31', ]; - } else { - return [ - - ]; } + return []; + case 'DE-HE': return [ 'Ostersonntag' => $easter, @@ -142,6 +137,7 @@ protected function regionHolidays(int $year): array if ($year >= 1990) { $mvHolidays['Reformationstag'] = '10-31'; } + if ($year >= 2023) { $mvHolidays['Internationaler Frauentag'] = '03-08'; } @@ -191,9 +187,13 @@ protected function regionHolidays(int $year): array } return $thHolidays; - } return []; } + + protected function getRepentanceAndPrayerDay(int $year): CarbonImmutable + { + return (new CarbonImmutable('next wednesday '.$year.'-11-15'))->startOfDay(); + } } From b86e83177524ba7b076b2178c49b49c3aa87d0e0 Mon Sep 17 00:00:00 2001 From: Nielsvanpach Date: Thu, 8 Feb 2024 10:35:54 +0000 Subject: [PATCH 081/175] Fix styling --- src/Countries/Finland.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Countries/Finland.php b/src/Countries/Finland.php index 84fcf74a6..bcb2e72cd 100644 --- a/src/Countries/Finland.php +++ b/src/Countries/Finland.php @@ -29,7 +29,7 @@ protected function fixedHolidays(): array 'Vappu' => '05-01', 'Itsenäisyyspäivä' => '12-06', 'Joulupäivä' => '12-25', - 'Tapaninpäivä' => '12-26' + 'Tapaninpäivä' => '12-26', ]; } From 5076e376ae127e009838a2dbc3483259d36e80cc Mon Sep 17 00:00:00 2001 From: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> Date: Thu, 8 Feb 2024 11:37:36 +0100 Subject: [PATCH 082/175] cleanup Greece --- src/Countries/Greece.php | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/Countries/Greece.php b/src/Countries/Greece.php index 5a0b0a450..095405980 100644 --- a/src/Countries/Greece.php +++ b/src/Countries/Greece.php @@ -29,32 +29,30 @@ protected function allHolidays(int $year): array /** @return array */ protected function variableHolidays(int $year): array { - // OrthodoxEaster needs to setTimezone $orthodoxEaster = $this->orthodoxEaster($year); - $cleanMonday = $orthodoxEaster->copy()->subDays(48); + $megaliParaskevi = $orthodoxEaster->copy()->subDays(2); - $megaloSavvato = $orthodoxEaster->copy()->subDays(1); + $megaloSavvato = $orthodoxEaster->copy()->subDay(); $deuteraPasha = $orthodoxEaster->copy()->addDay(); - $agiouPneumatos = $orthodoxEaster->copy()->addDays(50); - /** @var CarbonImmutable $protomagia */ $protomagia = CarbonImmutable::createFromFormat('Y-m-d', "{$year}-05-01"); $moveProtomagia = [$megaliParaskevi, $megaloSavvato, $orthodoxEaster, $deuteraPasha]; - if (in_array($protomagia, $moveProtomagia)) { + if (in_array($protomagia, $moveProtomagia, true)) { $protomagia = $orthodoxEaster->copy()->addDays(2); } + if ($protomagia->isSunday()) { $protomagia = $protomagia->copy()->addDay(); } return [ - 'Καθαρά Δευτέρα' => $cleanMonday, //always Monday + 'Καθαρά Δευτέρα' => $orthodoxEaster->copy()->subDays(48), //always Monday 'Πρωτομαγιά' => $protomagia, 'Μεγάλη Παρασκευή' => $megaliParaskevi, 'Κυριακή του Πάσχα' => $orthodoxEaster, 'Δευτέρα του Πάσχα' => $deuteraPasha, - 'Αγίου Πνεύματος' => $agiouPneumatos, //always Monday + 'Αγίου Πνεύματος' => $orthodoxEaster->copy()->addDays(50), //always Monday ]; } } From 1de06fde013cb89c6268c8b2ec4df162de23e141 Mon Sep 17 00:00:00 2001 From: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> Date: Thu, 8 Feb 2024 11:43:12 +0100 Subject: [PATCH 083/175] cleanup Ireland --- src/Countries/Ireland.php | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/src/Countries/Ireland.php b/src/Countries/Ireland.php index 527cd487e..5c24fe3fe 100644 --- a/src/Countries/Ireland.php +++ b/src/Countries/Ireland.php @@ -16,6 +16,10 @@ protected function allHolidays(int $year): array return array_merge([ 'New Year\'s Day' => '01-01', 'Saint Patrick\'s Day' => '03-17', + 'May Public Holiday' => 'first monday of May', + 'June Public Holiday' => 'first monday of June', + 'August Public Holiday' => 'first monday of August', + 'October Public Holiday' => 'last monday of October', 'Christmas Day' => '12-25', 'Saint Stephen\'s Day' => '12-26', ], $this->variableHolidays($year)); @@ -26,26 +30,17 @@ protected function variableHolidays(int $year): array { $easter = $this->easter($year); - $mayHoliday = new CarbonImmutable("first monday of May $year", 'Europe/Dublin'); - $juneHoliday = new CarbonImmutable("first monday of June $year", 'Europe/Dublin'); - $augHoliday = new CarbonImmutable("first monday of August $year", 'Europe/Dublin'); - $octHoliday = new CarbonImmutable("last monday of October $year", 'Europe/Dublin'); - $variableHolidays = [ - 'Easter Monday' => $easter->addDays(1), - 'May Public Holiday' => $mayHoliday, - 'June Public Holiday' => $juneHoliday, - 'August Public Holiday' => $augHoliday, - 'October Public Holiday' => $octHoliday, + 'Easter Monday' => $this->easter($year)->addDay(), ]; - // In 2023, Ireland added a new public holiday for St Brigid's day. - // It is the First Monday in February, or 1 February if the date falls on a Friday if ($year >= 2023) { - $stBrigidsDay = new CarbonImmutable("$year-02-01", 'Europe/Dublin'); + $stBrigidsDay = (new CarbonImmutable("$year-02-01"))->startOfDay(); + if (! $stBrigidsDay->isFriday()) { - $stBrigidsDay = new CarbonImmutable("first monday of February $year", 'Europe/Dublin'); + $stBrigidsDay = 'first monday of February'; } + $variableHolidays['St Brigid\'s Day'] = $stBrigidsDay; } From 3b399729c889f4cb27d136870c6c852b8de3c164 Mon Sep 17 00:00:00 2001 From: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> Date: Thu, 8 Feb 2024 12:17:37 +0100 Subject: [PATCH 084/175] cleanup Jamaica --- src/Countries/Ireland.php | 2 +- src/Countries/Jamaica.php | 57 +++++++++++++++------------------ tests/Countries/JamaicaTest.php | 1 - 3 files changed, 26 insertions(+), 34 deletions(-) diff --git a/src/Countries/Ireland.php b/src/Countries/Ireland.php index 5c24fe3fe..9478a026a 100644 --- a/src/Countries/Ireland.php +++ b/src/Countries/Ireland.php @@ -25,7 +25,7 @@ protected function allHolidays(int $year): array ], $this->variableHolidays($year)); } - /** @return array */ + /** @return array */ protected function variableHolidays(int $year): array { $easter = $this->easter($year); diff --git a/src/Countries/Jamaica.php b/src/Countries/Jamaica.php index 751fb994b..9867a50de 100644 --- a/src/Countries/Jamaica.php +++ b/src/Countries/Jamaica.php @@ -14,18 +14,14 @@ public function countryCode(): string protected function allHolidays(int $year): array { - - $holidays = array_merge( - $this->fixedHolidays(), + return array_merge( + $this->fixedHolidays($year), $this->variableHolidays($year), - $this->observedHolidays($year) ); - - return $holidays; } - /** @return array */ - protected function fixedHolidays(): array + /** @return array */ + protected function fixedHolidays(int $year): array { $holidays = [ 'New Year\'s Day' => '01-01', @@ -36,49 +32,46 @@ protected function fixedHolidays(): array 'Boxing Day' => '12-26', ]; + foreach ($holidays as $name => $date) { + $observedDay = $this->observed($name, $date, $year); + + if ($observedDay) { + $holidays[$name . ' Observed'] = $observedDay; + } + } + return $holidays; } - /** @return array */ + /** @return array */ protected function variableHolidays(int $year): array { $easter = $this->easter($year); - $heroesDay = new CarbonImmutable("third monday of October $year"); return [ 'Ash Wednesday' => $easter->subDays(46), 'Good Friday' => $easter->subDays(2), 'Easter Monday' => $easter->addDay(), - 'National Heroes Day' => $heroesDay, + 'National Heroes Day' => 'third monday of October', ]; } - /** @return array */ - protected function observedHolidays(int $year): array + protected function observed(string $name, string $date, int $year): ?CarbonInterface { + $holiday = CarbonImmutable::createFromFormat('Y-m-d', "{$year}-{$date}")->startOfDay(); - $observedHolidays = []; - - foreach ($this->fixedHolidays() as $name => $date) { - $date = CarbonImmutable::parse("$year-$date"); - - // If any holiday falls on a Sunday, then it is observed on Monday - if ($date->dayOfWeek === 0) { - $observedHolidays["{$name} Observed"] = $date->next(CarbonImmutable::MONDAY); - } + if ($holiday->isSunday()) { + return $holiday->next('monday'); + } - // If Labour Day falls on a Saturday, then it is observed on Monday - if ($name == 'Labour Day' && $date->dayOfWeek === 6) { - $observedHolidays["{$name} Observed"] = $date->next(CarbonImmutable::MONDAY); - } + if ($name === 'Labour Day' && $holiday->isSaturday()) { + return $holiday->next('monday'); + } - // If Boxing Day falls on a Monday, then it is observed on Tuesday (Christmas Day is observed on Monday) - // https://jis.gov.jm/observance-public-holidays-christmas-day-monday-december-26th-boxing-day-tuesday-december-27th/ - if ($name == 'Boxing Day' && $date->dayOfWeek === 1) { - $observedHolidays["{$name} Observed"] = $date->next(CarbonImmutable::TUESDAY); - } + if ($name === 'Boxing Day' && $holiday->isMonday()) { + return $holiday->next('tuesday'); } - return $observedHolidays; + return null; } } diff --git a/tests/Countries/JamaicaTest.php b/tests/Countries/JamaicaTest.php index 5b06881f5..2f1a06efd 100644 --- a/tests/Countries/JamaicaTest.php +++ b/tests/Countries/JamaicaTest.php @@ -30,5 +30,4 @@ // Check that there is no Observerd New Year's Day $holidays = Holidays::for(country: 'jm', year: 2024)->get(); expect(array_search('Labour Day Observed', array_column($holidays, 'name')))->toBeFalse(); - }); From 05dfd85ecb8c39a2a8eaa7c7fd6e2b5becf22595 Mon Sep 17 00:00:00 2001 From: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> Date: Thu, 8 Feb 2024 12:19:23 +0100 Subject: [PATCH 085/175] cleanup Japan --- src/Countries/Japan.php | 30 +++++------------------------- 1 file changed, 5 insertions(+), 25 deletions(-) diff --git a/src/Countries/Japan.php b/src/Countries/Japan.php index a15d890c5..455c9c7b8 100644 --- a/src/Countries/Japan.php +++ b/src/Countries/Japan.php @@ -2,8 +2,6 @@ namespace Spatie\Holidays\Countries; -use Carbon\CarbonImmutable; - class Japan extends Country { public function countryCode(): string @@ -13,8 +11,9 @@ public function countryCode(): string protected function allHolidays(int $year): array { - return array_merge([ + return [ '元日' => '01-01', // New Year's Day + '成人の日' => 'second monday of january', '建国記念の日' => '02-11', // Foundation Day '天皇誕生日' => '02-23', // Emperor's Birthday '春分の日' => '03-20', // Vernal Equinox Day *Decided each year; rarely on 03-21 @@ -22,33 +21,14 @@ protected function allHolidays(int $year): array '憲法記念日' => '05-03', // Constitution Day 'みどりの日' => '05-04', // Greenery Day 'こどもの日' => '05-05', // Children's Day + '海の日' => 'third monday of july', '山の日' => '08-11', // Mountain Day + '敬老の日' => 'third monday of september', '秋分の日' => '09-23', // Autumnal Equinox Day *Decided each year; rarely on 09-22 + 'スポーツの日' => 'second monday of october', '文化の日' => '11-03', // Culture Day '勤労感謝の日' => '11-23', // Labor Thanksgiving Day - ], $this->variableHolidays($year)); - } - - /** @return array */ - protected function variableHolidays(int $year): array - { - $comingOfAgeDay = (new CarbonImmutable("second monday of january $year"))->startOfDay(); - - $oceansDay = (new CarbonImmutable("third monday of july $year"))->startOfDay(); - - $respectForTheAgedDay = (new CarbonImmutable("third monday of september $year"))->startOfDay(); - - $sportsDay = (new CarbonImmutable("second monday of october $year"))->startOfDay(); - - $holidays = [ - '成人の日' => $comingOfAgeDay, - '海の日' => $oceansDay, - '敬老の日' => $respectForTheAgedDay, - 'スポーツの日' => $sportsDay, ]; - - return $holidays; - } } From bdcaa57b87134e89d3d64fc8133c4fe1c8ab63f3 Mon Sep 17 00:00:00 2001 From: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> Date: Thu, 8 Feb 2024 12:24:39 +0100 Subject: [PATCH 086/175] cleanup --- src/Countries/Latvia.php | 7 ++-- src/Countries/Montenegro.php | 7 ++-- src/Countries/Netherlands.php | 1 - src/Countries/NorthernIreland.php | 58 +++++++++++-------------------- 4 files changed, 28 insertions(+), 45 deletions(-) diff --git a/src/Countries/Latvia.php b/src/Countries/Latvia.php index b5c088605..fb26ede73 100644 --- a/src/Countries/Latvia.php +++ b/src/Countries/Latvia.php @@ -24,7 +24,10 @@ protected function allHolidays(int $year): array 'Pirmie Ziemassvētki' => '12-25', 'Otrie Ziemassvētki' => '12-26', 'Vecgada vakars' => '12-31', - ], $this->variableHolidays($year), $this->postponedHolidays($year)); + ], + $this->variableHolidays($year), + $this->observedHolidays($year) + ); } /** @return array */ @@ -40,7 +43,7 @@ protected function variableHolidays(int $year): array } /** @return array */ - protected function postponedHolidays(int $year): array + protected function observedHolidays(int $year): array { // If the holidays - May 4 and November 18 - fall on a Saturday or Sunday, // the next working day is designated as a holiday. diff --git a/src/Countries/Montenegro.php b/src/Countries/Montenegro.php index b653d4a4f..9ff1de06e 100644 --- a/src/Countries/Montenegro.php +++ b/src/Countries/Montenegro.php @@ -35,15 +35,12 @@ public function allHolidays(int $year): array /** @return array */ public function variableHolidays(int $year): array { - // Orthodox Easter calculation needs to be in the same timezone as the country $orthodoxEaster = $this->orthodoxEaster($year); - $goodFriday = $orthodoxEaster->copy()->subDays(2); - $orthodoxEasterMonday = $orthodoxEaster->copy()->addDay(); return [ 'Vaskrs' => $orthodoxEaster, - 'Vaskršnji ponedjeljak' => $orthodoxEasterMonday, - 'Veliki petak' => $goodFriday, + 'Vaskršnji ponedjeljak' => $orthodoxEaster->copy()->addDay(), + 'Veliki petak' => $orthodoxEaster->copy()->subDays(2), ]; } } diff --git a/src/Countries/Netherlands.php b/src/Countries/Netherlands.php index 44ae6ae7c..34f3b37fc 100644 --- a/src/Countries/Netherlands.php +++ b/src/Countries/Netherlands.php @@ -24,7 +24,6 @@ protected function allHolidays(int $year): array /** @return array */ protected function variableHolidays(int $year): array { - /** @var CarbonImmutable $koningsDag */ $koningsDag = CarbonImmutable::createFromFormat('Y-m-d', "{$year}-04-27"); if ($koningsDag->isSunday()) { diff --git a/src/Countries/NorthernIreland.php b/src/Countries/NorthernIreland.php index cb424980f..4bdbf2c1f 100644 --- a/src/Countries/NorthernIreland.php +++ b/src/Countries/NorthernIreland.php @@ -12,6 +12,27 @@ public function countryCode(): string return 'gb-nir'; } + protected function allHolidays(int $year): array + { + $regularHolidays = array_merge( + $this->newYearsDay($year), + $this->stPatricksDay($year), + $this->earlyMayBankHoliday($year), + $this->battleOfTheBoyne($year), + [ + 'Spring bank holiday' => new CarbonImmutable("last monday of may {$year}", 'Europe/London'), + 'Summer bank holiday' => new CarbonImmutable("last monday of august {$year}", 'Europe/London'), + ], + $this->christmasDay($year), + $this->boxingDay($year), + $this->variableHolidays($year) + ); + + $oneOffHolidays = $this->oneOffHolidays($year); + + return array_merge($regularHolidays, $oneOffHolidays); + } + /** @return array */ private function stPatricksDay(int $year): array { @@ -51,41 +72,4 @@ protected function oneOffHolidays(int $year): array default => [], }; } - - /** @return array */ - protected function allHolidays(int $year): array - { - $regularHolidays = array_merge( - $this->newYearsDay($year), - $this->stPatricksDay($year), - $this->earlyMayBankHoliday($year), - $this->battleOfTheBoyne($year), - [ - 'Spring bank holiday' => new CarbonImmutable("last monday of may {$year}", 'Europe/London'), - 'Summer bank holiday' => new CarbonImmutable("last monday of august {$year}", 'Europe/London'), - ], - $this->christmasDay($year), - $this->boxingDay($year), - $this->variableHolidays($year) - ); - - $oneOffHolidays = $this->oneOffHolidays($year); - - return array_merge($regularHolidays, $oneOffHolidays); - - } - - /** @return array */ - protected function variableHolidays(int $year): array - { - $easterSunday = $this->easter($year); - - $goodFriday = $easterSunday->subDays(2); - $easterMonday = $easterSunday->addDay(); - - return [ - 'Good Friday' => $goodFriday, - 'Easter Monday' => $easterMonday, - ]; - } } From bf1c6a52902746b6576bdb5e9e703bad3daa348e Mon Sep 17 00:00:00 2001 From: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> Date: Thu, 8 Feb 2024 12:29:14 +0100 Subject: [PATCH 087/175] cleanup SouthAfrica --- src/Countries/SouthAfrica.php | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/src/Countries/SouthAfrica.php b/src/Countries/SouthAfrica.php index 64d404127..1d9cb1379 100644 --- a/src/Countries/SouthAfrica.php +++ b/src/Countries/SouthAfrica.php @@ -4,6 +4,7 @@ use Carbon\CarbonImmutable; +use Carbon\CarbonInterface; use function in_array; class SouthAfrica extends Country @@ -31,16 +32,10 @@ protected function allHolidays(int $year): array ]; foreach ($holidays as $name => $date) { - $holidayDate = CarbonImmutable::createFromFormat('Y-m-d', "{$year}-{$date}"); - assert($holidayDate instanceof CarbonImmutable); - - // The Public Holidays Act (Act No 36 of 1994) states that whenever a public holiday falls on a Sunday, the Monday following it will be a public holiday. - // https://www.gov.za/documents/public-holidays-act - if ( - $holidayDate->isSunday() && - ! in_array($holidayDate->addDay()->format('m-d'), $holidays, true) // Check that the Monday is not already a holiday - ) { - $holidays[$name.' Observed'] = $holidayDate->addDay(); + $observedDay = $this->observed($date, $year); + + if ($observedDay) { + $holidays[$name . ' Observed'] = $observedDay; } } @@ -57,4 +52,16 @@ protected function variableHolidays(int $year): array 'Family Day' => $easter->addDay(), ]; } + + protected function observed(string $date, int $year): ?CarbonInterface + { + $holiday = CarbonImmutable::createFromFormat('Y-m-d', "{$year}-{$date}")->startOfDay(); + + // https://www.gov.za/documents/public-holidays-act + if ($holiday->isSunday()) { + return $holiday->next('monday'); + } + + return null; + } } From 9d5fcdfc736d1982d9d890f08d0c2417652e380d Mon Sep 17 00:00:00 2001 From: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> Date: Thu, 8 Feb 2024 12:32:34 +0100 Subject: [PATCH 088/175] cleanup --- src/Countries/Spain.php | 4 ++-- src/Countries/UnitedStates.php | 27 +++++++++------------------ 2 files changed, 11 insertions(+), 20 deletions(-) diff --git a/src/Countries/Spain.php b/src/Countries/Spain.php index 27a7f166f..46a46e805 100644 --- a/src/Countries/Spain.php +++ b/src/Countries/Spain.php @@ -57,9 +57,9 @@ protected function regionHolidays(int $year): array $method = "regionHolidays{$year}"; if (method_exists($this, $method)) { return $this->$method(); - } else { - throw InvalidYear::range($this->countryCode()." ({$this->region})", 2022, 2024); } + + throw InvalidYear::range($this->countryCode()." ({$this->region})", 2022, 2024); } /** @return array */ diff --git a/src/Countries/UnitedStates.php b/src/Countries/UnitedStates.php index 695103dca..9cccfad73 100644 --- a/src/Countries/UnitedStates.php +++ b/src/Countries/UnitedStates.php @@ -2,8 +2,6 @@ namespace Spatie\Holidays\Countries; -use Carbon\CarbonImmutable; - class UnitedStates extends Country { public function countryCode(): string @@ -18,7 +16,7 @@ protected function allHolidays(int $year): array 'Independence Day' => '07-04', 'Veterans Day' => '11-11', 'Christmas' => '12-25', - ], $this->variableHolidays($year)); + ], $this->variableHolidays()); if ($year >= 2021) { $holidays['Juneteenth National Independence Day'] = '06-19'; @@ -27,23 +25,16 @@ protected function allHolidays(int $year): array return $holidays; } - /** @return array */ - protected function variableHolidays(int $year): array + /** @return array */ + protected function variableHolidays(): array { - $martinLutherKingDay = new CarbonImmutable("third monday of January $year", 'America/Los_Angeles'); - $presidentsDay = new CarbonImmutable("third monday of February $year", 'America/Los_Angeles'); - $memorialDay = new CarbonImmutable("last monday of May $year", 'America/Los_Angeles'); - $laborDay = new CarbonImmutable("first monday of September $year", 'America/Los_Angeles'); - $columbusDay = new CarbonImmutable("second monday of October $year", 'America/Los_Angeles'); - $thanksgiving = new CarbonImmutable("fourth thursday of November $year", 'America/Los_Angeles'); - return [ - 'Martin Luther King Day' => $martinLutherKingDay, - 'Presidents\' Day' => $presidentsDay, - 'Memorial Day' => $memorialDay, - 'Labor Day' => $laborDay, - 'Columbus Day' => $columbusDay, - 'Thanksgiving' => $thanksgiving, + 'Martin Luther King Day' => 'third monday of January', + 'Presidents\' Day' => 'third monday of February', + 'Memorial Day' => 'last monday of May', + 'Labor Day' => 'first monday of September', + 'Columbus Day' => 'second monday of October', + 'Thanksgiving' => 'fourth thursday of November', ]; } } From 4b1740c3234bf47a2f7f4621f99e5adeb72fcc89 Mon Sep 17 00:00:00 2001 From: Nielsvanpach Date: Thu, 8 Feb 2024 11:33:08 +0000 Subject: [PATCH 089/175] Fix styling --- src/Countries/Jamaica.php | 2 +- src/Countries/SouthAfrica.php | 4 +--- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/src/Countries/Jamaica.php b/src/Countries/Jamaica.php index 9867a50de..801217120 100644 --- a/src/Countries/Jamaica.php +++ b/src/Countries/Jamaica.php @@ -36,7 +36,7 @@ protected function fixedHolidays(int $year): array $observedDay = $this->observed($name, $date, $year); if ($observedDay) { - $holidays[$name . ' Observed'] = $observedDay; + $holidays[$name.' Observed'] = $observedDay; } } diff --git a/src/Countries/SouthAfrica.php b/src/Countries/SouthAfrica.php index 1d9cb1379..f85b14255 100644 --- a/src/Countries/SouthAfrica.php +++ b/src/Countries/SouthAfrica.php @@ -3,9 +3,7 @@ namespace Spatie\Holidays\Countries; use Carbon\CarbonImmutable; - use Carbon\CarbonInterface; -use function in_array; class SouthAfrica extends Country { @@ -35,7 +33,7 @@ protected function allHolidays(int $year): array $observedDay = $this->observed($date, $year); if ($observedDay) { - $holidays[$name . ' Observed'] = $observedDay; + $holidays[$name.' Observed'] = $observedDay; } } From 09d3f02f6e0d2bbade09328aad505cc8d911f82f Mon Sep 17 00:00:00 2001 From: abdulrhman aboukalam <108075143+abdulrhmanak213@users.noreply.github.com> Date: Thu, 8 Feb 2024 14:37:45 +0300 Subject: [PATCH 090/175] Adding holidays for syria (#201) * Adding holidays for syria * fix language error * Update src/Countries/Syria.php --------- Co-authored-by: abdalrhman ak Co-authored-by: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> --- lang/syria/ar/holidays.json | 16 +++++ src/Countries/Syria.php | 40 +++++++++++++ .../it_can_calculate_syria_holidays.snap | 58 +++++++++++++++++++ ..._translate_syria_holidays_into_arabic.snap | 58 +++++++++++++++++++ tests/Countries/SyriaTest.php | 25 ++++++++ 5 files changed, 197 insertions(+) create mode 100644 lang/syria/ar/holidays.json create mode 100644 src/Countries/Syria.php create mode 100644 tests/.pest/snapshots/Countries/SyriaTest/it_can_calculate_syria_holidays.snap create mode 100644 tests/.pest/snapshots/Countries/SyriaTest/it_can_translate_syria_holidays_into_arabic.snap create mode 100644 tests/Countries/SyriaTest.php diff --git a/lang/syria/ar/holidays.json b/lang/syria/ar/holidays.json new file mode 100644 index 000000000..0d8232130 --- /dev/null +++ b/lang/syria/ar/holidays.json @@ -0,0 +1,16 @@ +{ + "New Year\n's Day": "يوم رأس السنة", + "Mother\n's Day": "عيد الأم", + "Teacher\n's Day": "عيد المعلم", + "Western Easter": "عيد الفصح الغربي", + "Eid al-Fitr": "عيد الفطر السعيد", + "Syrian Independence Day": "عيد الجلاء واستقلال سورية", + "Labor Day": "عيد العمال", + "Eastern Easter": "عيد الفصح الشرقي", + "Martyrs\n' Day": "عيد الشهداء", + "Eid al-Adha": "عيد الأضحى المبارك", + "Islamic New Year": "عيد رأس السنة الهجرية", + "The commemoration of the birth of the Prophet Muhammad": "عيد مولد الرسول الأعظم", + "The October Liberation War": "ذكرى حرب تشرين التحريرية", + "Merry Christmas": "عيد الميلاد المجيد" +} diff --git a/src/Countries/Syria.php b/src/Countries/Syria.php new file mode 100644 index 000000000..b71845d0b --- /dev/null +++ b/src/Countries/Syria.php @@ -0,0 +1,40 @@ + '01-01', + "Mother\n's Day" => '03-21', + "Teacher\n's Day" => '03-21', + "Western Easter" => '03-31', + "Eid al-Fitr" => '04-10', + "Syrian Independence Day" => '04-17', + "Labor Day" => '05-01', + "Eastern Easter" => '05-05', + "Martyr\n's Day" => '05-06', + "Eid al-Adha" => '06-16', + "Islamic New Year" => '07-07', + "The commemoration of the birth of the Prophet Muhammad" => '09-15', + "The October Liberation War" => '10-06', + "Christmas" => '12-25', + ], $this->variableHolidays($year)); + } + + /** @return array */ + protected function variableHolidays(int $year): array + { + // The variable holidays all follow the lunar calendar, so their dates are not confirmed. + return []; + } +} diff --git a/tests/.pest/snapshots/Countries/SyriaTest/it_can_calculate_syria_holidays.snap b/tests/.pest/snapshots/Countries/SyriaTest/it_can_calculate_syria_holidays.snap new file mode 100644 index 000000000..ac2f037d4 --- /dev/null +++ b/tests/.pest/snapshots/Countries/SyriaTest/it_can_calculate_syria_holidays.snap @@ -0,0 +1,58 @@ +[ + { + "name": "New Year\n's Day", + "date": "2024-01-01" + }, + { + "name": "Mother\n's Day", + "date": "2024-03-21" + }, + { + "name": "Teacher\n's Day", + "date": "2024-03-21" + }, + { + "name": "Western Easter", + "date": "2024-03-31" + }, + { + "name": "Eid al-Fitr", + "date": "2024-04-10" + }, + { + "name": "Syrian Independence Day", + "date": "2024-04-17" + }, + { + "name": "Labor Day", + "date": "2024-05-01" + }, + { + "name": "Eastern Easter", + "date": "2024-05-05" + }, + { + "name": "Martyr\n's Day", + "date": "2024-05-06" + }, + { + "name": "Eid al-Adha", + "date": "2024-06-16" + }, + { + "name": "Islamic New Year", + "date": "2024-07-07" + }, + { + "name": "The commemoration of the birth of the Prophet Muhammad", + "date": "2024-09-15" + }, + { + "name": "The October Liberation War", + "date": "2024-10-06" + }, + { + "name": "Merry Christmas", + "date": "2024-12-25" + } +] \ No newline at end of file diff --git a/tests/.pest/snapshots/Countries/SyriaTest/it_can_translate_syria_holidays_into_arabic.snap b/tests/.pest/snapshots/Countries/SyriaTest/it_can_translate_syria_holidays_into_arabic.snap new file mode 100644 index 000000000..f61ec2e69 --- /dev/null +++ b/tests/.pest/snapshots/Countries/SyriaTest/it_can_translate_syria_holidays_into_arabic.snap @@ -0,0 +1,58 @@ +[ + { + "name": "\u064a\u0648\u0645 \u0631\u0623\u0633 \u0627\u0644\u0633\u0646\u0629", + "date": "2024-01-01" + }, + { + "name": "\u0639\u064a\u062f \u0627\u0644\u0623\u0645", + "date": "2024-03-21" + }, + { + "name": "\u0639\u064a\u062f \u0627\u0644\u0645\u0639\u0644\u0645", + "date": "2024-03-21" + }, + { + "name": "\u0639\u064a\u062f \u0627\u0644\u0641\u0635\u062d \u0627\u0644\u063a\u0631\u0628\u064a", + "date": "2024-03-31" + }, + { + "name": "\u0639\u064a\u062f \u0627\u0644\u0641\u0637\u0631 \u0627\u0644\u0633\u0639\u064a\u062f", + "date": "2024-04-10" + }, + { + "name": "\u0639\u064a\u062f \u0627\u0644\u062c\u0644\u0627\u0621 \u0648\u0627\u0633\u062a\u0642\u0644\u0627\u0644 \u0633\u0648\u0631\u064a\u0629", + "date": "2024-04-17" + }, + { + "name": "\u0639\u064a\u062f \u0627\u0644\u0639\u0645\u0627\u0644", + "date": "2024-05-01" + }, + { + "name": "\u0639\u064a\u062f \u0627\u0644\u0641\u0635\u062d \u0627\u0644\u0634\u0631\u0642\u064a", + "date": "2024-05-05" + }, + { + "name": "Martyr\n's Day", + "date": "2024-05-06" + }, + { + "name": "\u0639\u064a\u062f \u0627\u0644\u0623\u0636\u062d\u0649 \u0627\u0644\u0645\u0628\u0627\u0631\u0643", + "date": "2024-06-16" + }, + { + "name": "\u0639\u064a\u062f \u0631\u0623\u0633 \u0627\u0644\u0633\u0646\u0629 \u0627\u0644\u0647\u062c\u0631\u064a\u0629", + "date": "2024-07-07" + }, + { + "name": "\u0639\u064a\u062f \u0645\u0648\u0644\u062f \u0627\u0644\u0631\u0633\u0648\u0644 \u0627\u0644\u0623\u0639\u0638\u0645", + "date": "2024-09-15" + }, + { + "name": "\u0630\u0643\u0631\u0649 \u062d\u0631\u0628 \u062a\u0634\u0631\u064a\u0646 \u0627\u0644\u062a\u062d\u0631\u064a\u0631\u064a\u0629", + "date": "2024-10-06" + }, + { + "name": "\u0639\u064a\u062f \u0627\u0644\u0645\u064a\u0644\u0627\u062f \u0627\u0644\u0645\u062c\u064a\u062f", + "date": "2024-12-25" + } +] \ No newline at end of file diff --git a/tests/Countries/SyriaTest.php b/tests/Countries/SyriaTest.php new file mode 100644 index 000000000..6bf5ed7df --- /dev/null +++ b/tests/Countries/SyriaTest.php @@ -0,0 +1,25 @@ +get(); + + expect($holidays) + ->toBeArray() + ->not()->toBeEmpty() + ->and(formatDates($holidays))->toMatchSnapshot(); +}); +it('can translate syria holidays into arabic', function () { + $holidays = Holidays::for(country: 'sy', year: 2024, locale: 'ar')->get(); + expect($holidays) + ->toBeArray() + ->not()->toBeEmpty(); + + expect(formatDates($holidays))->toMatchSnapshot(); +}); From 6d47df35843efd83063a9f9eb80fb0e482b5e8f9 Mon Sep 17 00:00:00 2001 From: Nielsvanpach Date: Thu, 8 Feb 2024 11:38:04 +0000 Subject: [PATCH 091/175] Fix styling --- src/Countries/Syria.php | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/Countries/Syria.php b/src/Countries/Syria.php index b71845d0b..86ecd5d38 100644 --- a/src/Countries/Syria.php +++ b/src/Countries/Syria.php @@ -17,17 +17,17 @@ protected function allHolidays(int $year): array "New Year\n's Day" => '01-01', "Mother\n's Day" => '03-21', "Teacher\n's Day" => '03-21', - "Western Easter" => '03-31', - "Eid al-Fitr" => '04-10', - "Syrian Independence Day" => '04-17', - "Labor Day" => '05-01', - "Eastern Easter" => '05-05', + 'Western Easter' => '03-31', + 'Eid al-Fitr' => '04-10', + 'Syrian Independence Day' => '04-17', + 'Labor Day' => '05-01', + 'Eastern Easter' => '05-05', "Martyr\n's Day" => '05-06', - "Eid al-Adha" => '06-16', - "Islamic New Year" => '07-07', - "The commemoration of the birth of the Prophet Muhammad" => '09-15', - "The October Liberation War" => '10-06', - "Christmas" => '12-25', + 'Eid al-Adha' => '06-16', + 'Islamic New Year' => '07-07', + 'The commemoration of the birth of the Prophet Muhammad' => '09-15', + 'The October Liberation War' => '10-06', + 'Christmas' => '12-25', ], $this->variableHolidays($year)); } From b62b7e09b67d2ab0aeb5b133ed49cc2f848b3827 Mon Sep 17 00:00:00 2001 From: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> Date: Thu, 8 Feb 2024 12:39:12 +0100 Subject: [PATCH 092/175] update name --- .../Countries/SyriaTest/it_can_calculate_syria_holidays.snap | 2 +- .../SyriaTest/it_can_translate_syria_holidays_into_arabic.snap | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/.pest/snapshots/Countries/SyriaTest/it_can_calculate_syria_holidays.snap b/tests/.pest/snapshots/Countries/SyriaTest/it_can_calculate_syria_holidays.snap index ac2f037d4..4216d3aef 100644 --- a/tests/.pest/snapshots/Countries/SyriaTest/it_can_calculate_syria_holidays.snap +++ b/tests/.pest/snapshots/Countries/SyriaTest/it_can_calculate_syria_holidays.snap @@ -52,7 +52,7 @@ "date": "2024-10-06" }, { - "name": "Merry Christmas", + "name": "Christmas", "date": "2024-12-25" } ] \ No newline at end of file diff --git a/tests/.pest/snapshots/Countries/SyriaTest/it_can_translate_syria_holidays_into_arabic.snap b/tests/.pest/snapshots/Countries/SyriaTest/it_can_translate_syria_holidays_into_arabic.snap index f61ec2e69..297cf12ab 100644 --- a/tests/.pest/snapshots/Countries/SyriaTest/it_can_translate_syria_holidays_into_arabic.snap +++ b/tests/.pest/snapshots/Countries/SyriaTest/it_can_translate_syria_holidays_into_arabic.snap @@ -52,7 +52,7 @@ "date": "2024-10-06" }, { - "name": "\u0639\u064a\u062f \u0627\u0644\u0645\u064a\u0644\u0627\u062f \u0627\u0644\u0645\u062c\u064a\u062f", + "name": "Christmas", "date": "2024-12-25" } ] \ No newline at end of file From 4dfcad3caa624ce4c13ce764005cbc38096589dc Mon Sep 17 00:00:00 2001 From: Nielsvanpach Date: Thu, 8 Feb 2024 11:40:42 +0000 Subject: [PATCH 093/175] Update CHANGELOG --- CHANGELOG.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index fc14bbaa3..4e34faae1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,24 @@ All notable changes to `holidays` will be documented in this file. +## 1.7.0 - 2024-02-08 + +### What's Changed + +* Add Uzbekistan Holidays by @shoxrux1996 in https://github.com/spatie/holidays/pull/81 +* Add Azerbaijan holidays by @kenanaga in https://github.com/spatie/holidays/pull/166 +* Enhanced holiday dates in Ghana by @Ikpeba4ll in https://github.com/spatie/holidays/pull/80 +* Adding holidays for syria by @abdulrhmanak213 in https://github.com/spatie/holidays/pull/201 + +### New Contributors + +* @shoxrux1996 made their first contribution in https://github.com/spatie/holidays/pull/81 +* @kenanaga made their first contribution in https://github.com/spatie/holidays/pull/166 +* @Ikpeba4ll made their first contribution in https://github.com/spatie/holidays/pull/80 +* @abdulrhmanak213 made their first contribution in https://github.com/spatie/holidays/pull/201 + +**Full Changelog**: https://github.com/spatie/holidays/compare/1.6.1...1.7.0 + ## 1.6.1 - 2024-02-07 ### What's Changed From aefc29be4479e691a0e026b2e17a83a63513e509 Mon Sep 17 00:00:00 2001 From: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> Date: Thu, 8 Feb 2024 12:47:01 +0100 Subject: [PATCH 094/175] fix typehint --- phpstan-baseline.neon | 4 ---- src/Countries/Country.php | 2 +- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index dffb82781..7363751c6 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -25,7 +25,3 @@ parameters: count: 1 path: src/Holidays.php - - - message: "#^Property Spatie\\\\Holidays\\\\Holidays\\:\\:\\$holidays \\(array\\\\) does not accept array\\\\.$#" - count: 1 - path: src/Holidays.php diff --git a/src/Countries/Country.php b/src/Countries/Country.php index 34f0284d2..8c0322e21 100644 --- a/src/Countries/Country.php +++ b/src/Countries/Country.php @@ -16,7 +16,7 @@ abstract public function countryCode(): string; /** @return array */ abstract protected function allHolidays(int $year): array; - /** @return array */ + /** @return array */ public function get(int $year, ?string $locale = null): array { $this->ensureYearCanBeCalculated($year); From 0e9c3b5e1eca78d778a9bbf2f842c82615856b80 Mon Sep 17 00:00:00 2001 From: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> Date: Thu, 8 Feb 2024 12:48:34 +0100 Subject: [PATCH 095/175] Update README.md --- README.md | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/README.md b/README.md index 69240bf97..ff0482a2b 100644 --- a/README.md +++ b/README.md @@ -109,12 +109,9 @@ Holidays::has('be'); // true Holidays::has('unknown'); // false ``` -### Package limitations -1. Islamic holidays are not supported (yet) - ## Contributing -This is a community driven package. If you find any errors, please create an issue or a pull request. +This is a community driven package. If you find any errors, please create a pull request with the fix, or at least an issue. ## Adding a new country From cfb44ecaf47e849331858a8a430b8bd7e9442158 Mon Sep 17 00:00:00 2001 From: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> Date: Thu, 8 Feb 2024 12:49:01 +0100 Subject: [PATCH 096/175] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index ff0482a2b..a695c87d5 100644 --- a/README.md +++ b/README.md @@ -111,7 +111,7 @@ Holidays::has('unknown'); // false ## Contributing -This is a community driven package. If you find any errors, please create a pull request with the fix, or at least an issue. +This is a community driven package. If you find any errors, please create a pull request with the fix, or at least open an issue. ## Adding a new country From 26a8a5996fdb2d3ac05696820482ebe7b53c57ae Mon Sep 17 00:00:00 2001 From: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> Date: Thu, 8 Feb 2024 13:00:06 +0100 Subject: [PATCH 097/175] change for Ghana --- src/Countries/Ghana.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/Countries/Ghana.php b/src/Countries/Ghana.php index 1a6f0cab0..1046fa768 100644 --- a/src/Countries/Ghana.php +++ b/src/Countries/Ghana.php @@ -86,10 +86,8 @@ protected function variableHolidays(int $year): array { $easter = $this->easter($year); - $farmersDay = (new CarbonImmutable('first friday of December '.$year))->startOfDay(); - return [ - 'Farmers Day' => $farmersDay, + 'Farmers Day' => 'first friday of December', 'Good Friday' => $easter->subDays(2), 'Easter Monday' => $easter->addDay(), From 2f9a616fa558f526b1173efcad5ad35362b5d3cb Mon Sep 17 00:00:00 2001 From: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> Date: Thu, 8 Feb 2024 13:45:04 +0100 Subject: [PATCH 098/175] phpstan fix --- src/Countries/Ghana.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Countries/Ghana.php b/src/Countries/Ghana.php index 1046fa768..08951f1a5 100644 --- a/src/Countries/Ghana.php +++ b/src/Countries/Ghana.php @@ -81,7 +81,7 @@ protected function observedBoxingDay(int $year): CarbonInterface }; } - /** @return array */ + /** @return array */ protected function variableHolidays(int $year): array { $easter = $this->easter($year); From a5640531fb1563cdb10854a4a68ce94fa9e37b09 Mon Sep 17 00:00:00 2001 From: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> Date: Fri, 9 Feb 2024 11:31:03 +0100 Subject: [PATCH 099/175] move Observed holiday logic to separate trait --- src/Concerns/Observable.php | 54 +++++++++++++ src/Countries/Ghana.php | 54 +++++-------- src/Countries/Ireland.php | 10 +-- src/Countries/Japan.php | 19 +++-- src/Countries/NorthernIreland.php | 4 +- src/Countries/Wales.php | 130 +++++++++++------------------- 6 files changed, 140 insertions(+), 131 deletions(-) create mode 100644 src/Concerns/Observable.php diff --git a/src/Concerns/Observable.php b/src/Concerns/Observable.php new file mode 100644 index 000000000..52342c6fe --- /dev/null +++ b/src/Concerns/Observable.php @@ -0,0 +1,54 @@ +startOfDay(); + + return match ($christmasDay->dayName) { + 'Saturday' => $christmasDay->next('monday'), + 'Sunday' => $christmasDay->next('tuesday'), + default => null, + }; + } + + protected function observedBoxingDay(int $year): ?CarbonInterface + { + $christmasDay = (new CarbonImmutable($year.'-12-25'))->startOfDay(); + $boxingDay = $christmasDay->addDay(); + + return match ($christmasDay->dayName) { + 'Friday' => $boxingDay->next('monday'), + 'Saturday' => $boxingDay->next('tuesday'), + default => null, + }; + } + + protected function weekendToNextMonday(string|CarbonInterface $date, int $year): ?CarbonInterface + { + if (is_string($date)) { + $date = CarbonImmutable::createFromFormat('Y-m-d', "{$year}-{$date}")->startOfDay(); + } + + if ($date->isWeekend()) { + return $date->next('monday'); + } + + return null; + } + + protected function sundayToNextMonday(CarbonInterface $date): ?CarbonInterface + { + if ($date->isSunday()) { + return $date->next('monday'); + } + + return null; + } +} diff --git a/src/Countries/Ghana.php b/src/Countries/Ghana.php index 08951f1a5..2e9ed2d2d 100644 --- a/src/Countries/Ghana.php +++ b/src/Countries/Ghana.php @@ -4,9 +4,12 @@ use Carbon\CarbonImmutable; use Carbon\CarbonInterface; +use Spatie\Holidays\Concerns\Observable; class Ghana extends Country { + use Observable; + public function countryCode(): string { return 'gh'; @@ -20,7 +23,7 @@ protected function allHolidays(int $year): array ); } - /** @return array */ + /** @return array */ protected function observedHolidays(int $year): array { $holidays = [ @@ -30,16 +33,23 @@ protected function observedHolidays(int $year): array 'May Day' => '05-01', 'Founder\'s Day' => '08-04', 'Kwame Nkrumah Memorial Day' => '09-21', + 'Christmas Day' => '12-25', + 'Boxing Day' => '12-26', ]; - $holidays = array_map(function ($holiday) use ($year) { - return $this->observed($holiday, $year); - }, $holidays); + foreach ($holidays as $name => $date) { + $observedDay = match ($name) { + 'Christmas Day' => $this->observedChristmasDay($year), + 'Boxing Day' => $this->observedBoxingDay($year), + default => $this->weekendToNextMonday($date, $year), + }; + + if ($observedDay) { + $holidays[$name] = $observedDay; + } + } - return array_merge($holidays, [ - 'Christmas Day' => $this->observedChristmasDay($year), - 'Boxing Day' => $this->observedBoxingDay($year), - ]); + return $holidays; } protected function observed(string $date, int $year): CarbonInterface @@ -53,34 +63,6 @@ protected function observed(string $date, int $year): CarbonInterface return $holiday; } - protected function christmas(int $year): CarbonInterface - { - return (new CarbonImmutable($year.'-12-25'))->startOfDay(); - } - - protected function observedChristmasDay(int $year): CarbonInterface - { - $christmasDay = $this->christmas($year); - - return match ($christmasDay->dayName) { - 'Saturday' => $christmasDay->next('monday'), - 'Sunday' => $christmasDay->next('tuesday'), - default => $christmasDay, - }; - } - - protected function observedBoxingDay(int $year): CarbonInterface - { - $christmasDay = $this->christmas($year); - $boxingDay = new CarbonImmutable($year.'-12-26'); - - return match ($christmasDay->dayName) { - 'Friday' => $boxingDay->next('monday'), - 'Saturday' => $boxingDay->next('tuesday'), - default => $boxingDay, - }; - } - /** @return array */ protected function variableHolidays(int $year): array { diff --git a/src/Countries/Ireland.php b/src/Countries/Ireland.php index 9478a026a..092bfdbdc 100644 --- a/src/Countries/Ireland.php +++ b/src/Countries/Ireland.php @@ -16,10 +16,6 @@ protected function allHolidays(int $year): array return array_merge([ 'New Year\'s Day' => '01-01', 'Saint Patrick\'s Day' => '03-17', - 'May Public Holiday' => 'first monday of May', - 'June Public Holiday' => 'first monday of June', - 'August Public Holiday' => 'first monday of August', - 'October Public Holiday' => 'last monday of October', 'Christmas Day' => '12-25', 'Saint Stephen\'s Day' => '12-26', ], $this->variableHolidays($year)); @@ -28,10 +24,12 @@ protected function allHolidays(int $year): array /** @return array */ protected function variableHolidays(int $year): array { - $easter = $this->easter($year); - $variableHolidays = [ 'Easter Monday' => $this->easter($year)->addDay(), + 'May Public Holiday' => 'first monday of May', + 'June Public Holiday' => 'first monday of June', + 'August Public Holiday' => 'first monday of August', + 'October Public Holiday' => 'last monday of October', ]; if ($year >= 2023) { diff --git a/src/Countries/Japan.php b/src/Countries/Japan.php index 455c9c7b8..3f00fdf29 100644 --- a/src/Countries/Japan.php +++ b/src/Countries/Japan.php @@ -2,6 +2,8 @@ namespace Spatie\Holidays\Countries; +use Carbon\CarbonImmutable; + class Japan extends Country { public function countryCode(): string @@ -11,9 +13,8 @@ public function countryCode(): string protected function allHolidays(int $year): array { - return [ + return array_merge([ '元日' => '01-01', // New Year's Day - '成人の日' => 'second monday of january', '建国記念の日' => '02-11', // Foundation Day '天皇誕生日' => '02-23', // Emperor's Birthday '春分の日' => '03-20', // Vernal Equinox Day *Decided each year; rarely on 03-21 @@ -21,14 +22,22 @@ protected function allHolidays(int $year): array '憲法記念日' => '05-03', // Constitution Day 'みどりの日' => '05-04', // Greenery Day 'こどもの日' => '05-05', // Children's Day - '海の日' => 'third monday of july', '山の日' => '08-11', // Mountain Day - '敬老の日' => 'third monday of september', '秋分の日' => '09-23', // Autumnal Equinox Day *Decided each year; rarely on 09-22 - 'スポーツの日' => 'second monday of october', '文化の日' => '11-03', // Culture Day '勤労感謝の日' => '11-23', // Labor Thanksgiving Day + ], $this->variableHolidays()); + } + + /** @return array */ + protected function variableHolidays(): array + { + return [ + '成人の日' => 'second monday of january', + '海の日' => 'third monday of july', + '敬老の日' => 'third monday of september', + 'スポーツの日' => 'second monday of october', ]; } } diff --git a/src/Countries/NorthernIreland.php b/src/Countries/NorthernIreland.php index 4bdbf2c1f..c5c30a2c3 100644 --- a/src/Countries/NorthernIreland.php +++ b/src/Countries/NorthernIreland.php @@ -20,8 +20,8 @@ protected function allHolidays(int $year): array $this->earlyMayBankHoliday($year), $this->battleOfTheBoyne($year), [ - 'Spring bank holiday' => new CarbonImmutable("last monday of may {$year}", 'Europe/London'), - 'Summer bank holiday' => new CarbonImmutable("last monday of august {$year}", 'Europe/London'), + 'Spring bank holiday' => 'last monday of may', + 'Summer bank holiday' => 'last monday of august', ], $this->christmasDay($year), $this->boxingDay($year), diff --git a/src/Countries/Wales.php b/src/Countries/Wales.php index 33e1ca3b8..f2ebc8612 100644 --- a/src/Countries/Wales.php +++ b/src/Countries/Wales.php @@ -4,130 +4,96 @@ use Carbon\CarbonImmutable; use Carbon\CarbonInterface; +use Spatie\Holidays\Concerns\Observable; class Wales extends Country { + use Observable; + public function countryCode(): string { return 'gb-cym'; } - /** @return array */ - protected function christmasDay(int $year): array + /** @return array */ + protected function allHolidays(int $year): array { - $christmasDay = new CarbonImmutable($year.'-12-25', 'Europe/London'); - $key = 'Christmas Day'; - - if ($christmasDay->isSaturday()) { - $key .= ' (substitute day)'; - $christmasDay = $christmasDay->next('monday'); - } - - if ($christmasDay->isSunday()) { - $key .= ' (substitute day)'; - $christmasDay = $christmasDay->next('tuesday'); - } - - return [$key => $christmasDay]; + return array_merge( + $this->observedHolidays($year), + $this->earlyMayBankHoliday($year), + $this->variableHolidays($year), + $this->oneOffHolidays($year), + ); } - /** @return array */ - protected function boxingDay(int $year): array + /** @return array */ + protected function observedHolidays(int $year): array { - $christmasDay = new CarbonImmutable($year.'-12-25', 'Europe/London'); - $boxingDay = new CarbonImmutable($year.'-12-26', 'Europe/London'); - $key = 'Boxing Day'; - - if ($christmasDay->isFriday()) { - $key .= ' (substitute day)'; - $boxingDay = $boxingDay->next('monday'); - } + $holidays = [ + 'New Year\'s Day' => '01-01', + 'Christmas Day' => '12-25', + 'Boxing Day' => '12-26', + ]; - if ($christmasDay->isSaturday()) { - $key .= ' (substitute day)'; - $boxingDay = $boxingDay->next('tuesday'); + foreach ($holidays as $name => $date) { + $observedDay = match ($name) { + 'Christmas Day' => $this->observedChristmasDay($year), + 'Boxing Day' => $this->observedBoxingDay($year), + default => $this->weekendToNextMonday($date, $year), + }; + + if ($observedDay) { + $holidays[$name.' (substitute day)'] = $observedDay; + unset($holidays[$name]); + } } - return [$key => $boxingDay]; + return $holidays; } - /** @return array */ - protected function newYearsDay(int $year): array + /** @return array */ + protected function variableHolidays(int $year): array { - $newYearsDay = new CarbonImmutable($year.'-01-01', 'Europe/London'); - $key = 'New Year\'s Day'; + $easterSunday = $this->easter($year); - if ($newYearsDay->isWeekend()) { - $key .= ' (substitute day)'; - $newYearsDay = $newYearsDay->next('monday'); - } + $goodFriday = $easterSunday->subDays(2); + $easterMonday = $easterSunday->addDay(); - return [$key => $newYearsDay]; + return [ + 'Good Friday' => $goodFriday, + 'Easter Monday' => $easterMonday, + 'Spring bank holiday' => 'last monday of may', + 'Summer bank holiday' => 'last monday of august', + ]; } - /** @return array */ + /** @return array */ protected function earlyMayBankHoliday(int $year): array { if ($year === 2020) { return [ - 'Early May bank holiday (VE day)' => new CarbonImmutable('2020-05-08', 'Europe/London'), + 'Early May bank holiday (VE day)' => (new CarbonImmutable('2020-05-08'))->startOfDay(), ]; } if ($year === 2023) { return [ - 'Bank holiday for the coronation of King Charles III' => new CarbonImmutable('2020-05-08', 'Europe/London'), + 'Bank holiday for the coronation of King Charles III' => (new CarbonImmutable('2020-05-08'))->startOfDay(), ]; } - return ['Early May bank holiday' => new CarbonImmutable("first monday of may {$year}", 'Europe/London')]; + return ['Early May bank holiday' => 'first monday of may']; } - /** - * @return array|CarbonImmutable[] - */ + /** @return array */ protected function oneOffHolidays(int $year): array { return match ($year) { 2022 => [ - 'Platinum Jubilee bank holiday' => new CarbonImmutable('2022-06-03', 'Europe/London'), - 'Bank Holiday for the State Funeral of Queen Elizabeth II' => new CarbonImmutable('2022-09-19', 'Europe/London'), + 'Platinum Jubilee bank holiday' => (new CarbonImmutable('2022-06-03'))->startOfDay(), + 'Bank Holiday for the State Funeral of Queen Elizabeth II' => (new CarbonImmutable('2022-09-19'))->startOfDay(), ], default => [], }; } - - /** @return array */ - protected function allHolidays(int $year): array - { - $regularHolidays = array_merge( - $this->newYearsDay($year), - $this->earlyMayBankHoliday($year), - [ - 'Spring bank holiday' => new CarbonImmutable("last monday of may {$year}", 'Europe/London'), - 'Summer bank holiday' => new CarbonImmutable("last monday of august {$year}", 'Europe/London'), - ], - $this->christmasDay($year), - $this->boxingDay($year), - $this->variableHolidays($year) - ); - - $oneOffHolidays = $this->oneOffHolidays($year); - - return array_merge($regularHolidays, $oneOffHolidays); - } - - /** @return array */ - protected function variableHolidays(int $year): array - { - $easterSunday = $this->easter($year); - - $goodFriday = $easterSunday->subDays(2); - $easterMonday = $easterSunday->addDay(); - - return [ - 'Good Friday' => $goodFriday, - 'Easter Monday' => $easterMonday, - ]; - } } From 8e8a4a15e30ab0e14119b2010dc457294f52796a Mon Sep 17 00:00:00 2001 From: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> Date: Fri, 9 Feb 2024 11:55:53 +0100 Subject: [PATCH 100/175] cleanup Wales related countries --- src/Countries/NorthernIreland.php | 76 +++++++-------------- src/Countries/Scotland.php | 109 ++++++++++++------------------ 2 files changed, 71 insertions(+), 114 deletions(-) diff --git a/src/Countries/NorthernIreland.php b/src/Countries/NorthernIreland.php index c5c30a2c3..1d3779dfb 100644 --- a/src/Countries/NorthernIreland.php +++ b/src/Countries/NorthernIreland.php @@ -14,62 +14,38 @@ public function countryCode(): string protected function allHolidays(int $year): array { - $regularHolidays = array_merge( - $this->newYearsDay($year), - $this->stPatricksDay($year), + return array_merge( + $this->observedHolidays($year), $this->earlyMayBankHoliday($year), - $this->battleOfTheBoyne($year), - [ - 'Spring bank holiday' => 'last monday of may', - 'Summer bank holiday' => 'last monday of august', - ], - $this->christmasDay($year), - $this->boxingDay($year), - $this->variableHolidays($year) + $this->variableHolidays($year), + $this->oneOffHolidays($year), ); - - $oneOffHolidays = $this->oneOffHolidays($year); - - return array_merge($regularHolidays, $oneOffHolidays); - } - - /** @return array */ - private function stPatricksDay(int $year): array - { - $stPatricksDay = new CarbonImmutable($year.'-03-17', 'Europe/London'); - $key = 'St Patrick\'s Day'; - - if ($stPatricksDay->isWeekend()) { - $key .= ' (substitute day)'; - $stPatricksDay = $stPatricksDay->next('monday'); - } - - return [$key => $stPatricksDay]; } - /** @return array */ - private function battleOfTheBoyne(int $year): array + /** @return array */ + protected function observedHolidays(int $year): array { - $battleOfTheBoyne = new CarbonImmutable($year.'-07-12', 'Europe/London'); - $key = 'Battle of the Boyne (Orangemen\'s Day)'; - - if ($battleOfTheBoyne->isWeekend()) { - $key .= ' (substitute day)'; - $battleOfTheBoyne = $battleOfTheBoyne->next('monday'); + $holidays = [ + 'New Year\'s Day' => '01-01', + 'St Patrick\'s Day' => '03-17', + 'Battle of the Boyne (Orangemen\'s Day)' => '07-12', + 'Christmas Day' => '12-25', + 'Boxing Day' => '12-26', + ]; + + foreach ($holidays as $name => $date) { + $observedDay = match ($name) { + 'Christmas Day' => $this->observedChristmasDay($year), + 'Boxing Day' => $this->observedBoxingDay($year), + default => $this->weekendToNextMonday($date, $year), + }; + + if ($observedDay) { + $holidays[$name.' (substitute day)'] = $observedDay; + unset($holidays[$name]); + } } - return [$key => $battleOfTheBoyne]; - } - - /** @return array */ - protected function oneOffHolidays(int $year): array - { - return match ($year) { - 2022 => [ - 'Platinum Jubilee bank holiday' => new CarbonImmutable('2022-06-03', 'Europe/London'), - 'Bank Holiday for the State Funeral of Queen Elizabeth II' => new CarbonImmutable('2022-09-19', 'Europe/London'), - ], - default => [], - }; + return $holidays; } } diff --git a/src/Countries/Scotland.php b/src/Countries/Scotland.php index f70145325..662c0ea06 100644 --- a/src/Countries/Scotland.php +++ b/src/Countries/Scotland.php @@ -12,84 +12,65 @@ public function countryCode(): string return 'gb-sct'; } - /** @return array */ - protected function secondOfJanuary(int $year): array + protected function allHolidays(int $year): array { - $newYearsDay = new CarbonImmutable($year.'-01-01', 'Europe/London'); - $secondOfJanuary = new CarbonImmutable($year.'-01-02', 'Europe/London'); - $key = '2nd January'; - - if ($newYearsDay->isFriday()) { - $key .= ' (substitute day)'; - $secondOfJanuary = $secondOfJanuary->next('monday'); - } - - if ($newYearsDay->isWeekend()) { - $key .= ' (substitute day)'; - $secondOfJanuary = $secondOfJanuary->next('tuesday'); - } - - return [$key => $secondOfJanuary]; + return array_merge( + $this->observedHolidays($year), + $this->earlyMayBankHoliday($year), + $this->variableHolidays($year), + $this->oneOffHolidays($year), + ); } - /** @return array */ - private function stAndrewsDay(int $year): array + /** @return array */ + protected function observedHolidays(int $year): array { - $stAndrewsDay = new CarbonImmutable($year.'-11-30', 'Europe/London'); - $key = 'St Andrew\'s Day'; + $holidays = [ + 'New Year\'s Day' => '01-01', + '2nd January' => '01-02', + 'St Andrew\'s Day' => '11-30', + 'Christmas Day' => '12-25', + 'Boxing Day' => '12-26', + ]; - if ($stAndrewsDay->isWeekend()) { - $key .= ' (substitute day)'; - $stAndrewsDay = $stAndrewsDay->next('monday'); + foreach ($holidays as $name => $date) { + $observedDay = match ($name) { + '2nd January' => $this->secondOfJanuary($year), + 'Christmas Day' => $this->observedChristmasDay($year), + 'Boxing Day' => $this->observedBoxingDay($year), + default => $this->weekendToNextMonday($date, $year), + }; + + if ($observedDay) { + $holidays[$name.' (substitute day)'] = $observedDay; + unset($holidays[$name]); + } } - return [$key => $stAndrewsDay]; - } - - /** @return array */ - protected function oneOffHolidays(int $year): array - { - return match ($year) { - 2022 => [ - 'Platinum Jubilee bank holiday' => new CarbonImmutable('2022-06-03', 'Europe/London'), - 'Bank Holiday for the State Funeral of Queen Elizabeth II' => new CarbonImmutable('2022-09-19', 'Europe/London'), - ], - default => [], - }; + return $holidays; } - /** @return array */ - protected function allHolidays(int $year): array + /** @return array */ + protected function variableHolidays(int $year): array { - $regularHolidays = array_merge( - $this->newYearsDay($year), - $this->secondOfJanuary($year), - $this->earlyMayBankHoliday($year), - [ - 'Spring bank holiday' => new CarbonImmutable("last monday of may {$year}", 'Europe/London'), - 'Summer bank holiday' => new CarbonImmutable("first monday of august {$year}", 'Europe/London'), - ], - $this->stAndrewsDay($year), - $this->christmasDay($year), - $this->boxingDay($year), - $this->variableHolidays($year) - ); - - $oneOffHolidays = $this->oneOffHolidays($year); - - return array_merge($regularHolidays, $oneOffHolidays); + $easter = $this->easter($year); + return [ + 'Good Friday' => $easter->subDays(2), + 'Spring bank holiday' => 'last monday of may', + 'Summer bank holiday' => 'first monday of august', + ]; } - /** @return array */ - protected function variableHolidays(int $year): array + protected function secondOfJanuary(int $year): ?CarbonInterface { - $easterSunday = $this->easter($year); - - $goodFriday = $easterSunday->subDays(2); + $newYearsDay = (new CarbonImmutable($year.'-01-01'))->startOfDay(); + $secondOfJanuary = $newYearsDay->addDay(); - return [ - 'Good Friday' => $goodFriday, - ]; + return match ($newYearsDay->dayName) { + 'Friday' => $secondOfJanuary->next('monday'), + 'Saturday', 'Sunday' => $secondOfJanuary->next('tuesday'), + default => null, + }; } } From 073efe7e7da321faabab00585cbce4f4a528b679 Mon Sep 17 00:00:00 2001 From: Nielsvanpach Date: Fri, 9 Feb 2024 10:56:26 +0000 Subject: [PATCH 101/175] Fix styling --- src/Countries/Japan.php | 2 -- src/Countries/NorthernIreland.php | 1 - 2 files changed, 3 deletions(-) diff --git a/src/Countries/Japan.php b/src/Countries/Japan.php index 3f00fdf29..879238b2b 100644 --- a/src/Countries/Japan.php +++ b/src/Countries/Japan.php @@ -2,8 +2,6 @@ namespace Spatie\Holidays\Countries; -use Carbon\CarbonImmutable; - class Japan extends Country { public function countryCode(): string diff --git a/src/Countries/NorthernIreland.php b/src/Countries/NorthernIreland.php index 1d3779dfb..0b6a7575c 100644 --- a/src/Countries/NorthernIreland.php +++ b/src/Countries/NorthernIreland.php @@ -2,7 +2,6 @@ namespace Spatie\Holidays\Countries; -use Carbon\CarbonImmutable; use Carbon\CarbonInterface; class NorthernIreland extends Wales From df9d4d652487b9671a876f0c816a6eb8d1b3ebeb Mon Sep 17 00:00:00 2001 From: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> Date: Fri, 9 Feb 2024 13:11:30 +0100 Subject: [PATCH 102/175] use Observable trait where possible --- src/Concerns/Observable.php | 6 +++++- src/Countries/Jamaica.php | 12 +++++++----- src/Countries/Latvia.php | 28 +++++++++++++++++----------- src/Countries/SouthAfrica.php | 17 ++++------------- 4 files changed, 33 insertions(+), 30 deletions(-) diff --git a/src/Concerns/Observable.php b/src/Concerns/Observable.php index 52342c6fe..686c11b6d 100644 --- a/src/Concerns/Observable.php +++ b/src/Concerns/Observable.php @@ -43,8 +43,12 @@ protected function weekendToNextMonday(string|CarbonInterface $date, int $year): return null; } - protected function sundayToNextMonday(CarbonInterface $date): ?CarbonInterface + protected function sundayToNextMonday(string|CarbonInterface $date, int $year): ?CarbonInterface { + if (is_string($date)) { + $date = CarbonImmutable::createFromFormat('Y-m-d', "{$year}-{$date}")->startOfDay(); + } + if ($date->isSunday()) { return $date->next('monday'); } diff --git a/src/Countries/Jamaica.php b/src/Countries/Jamaica.php index 801217120..96472e60f 100644 --- a/src/Countries/Jamaica.php +++ b/src/Countries/Jamaica.php @@ -4,9 +4,12 @@ use Carbon\CarbonImmutable; use Carbon\CarbonInterface; +use Spatie\Holidays\Concerns\Observable; class Jamaica extends Country { + use Observable; + public function countryCode(): string { return 'jm'; @@ -33,7 +36,10 @@ protected function fixedHolidays(int $year): array ]; foreach ($holidays as $name => $date) { - $observedDay = $this->observed($name, $date, $year); + $observedDay = match ($name) { + 'Labour Day', 'Boxing Day' => $this->observed($name, $date, $year), + default => $this->sundayToNextMonday($date, $year), + }; if ($observedDay) { $holidays[$name.' Observed'] = $observedDay; @@ -60,10 +66,6 @@ protected function observed(string $name, string $date, int $year): ?CarbonInter { $holiday = CarbonImmutable::createFromFormat('Y-m-d', "{$year}-{$date}")->startOfDay(); - if ($holiday->isSunday()) { - return $holiday->next('monday'); - } - if ($name === 'Labour Day' && $holiday->isSaturday()) { return $holiday->next('monday'); } diff --git a/src/Countries/Latvia.php b/src/Countries/Latvia.php index fb26ede73..ff6ac9346 100644 --- a/src/Countries/Latvia.php +++ b/src/Countries/Latvia.php @@ -3,9 +3,12 @@ namespace Spatie\Holidays\Countries; use Carbon\CarbonImmutable; +use Spatie\Holidays\Concerns\Observable; class Latvia extends Country { + use Observable; + public function countryCode(): string { return 'lv'; @@ -45,20 +48,23 @@ protected function variableHolidays(int $year): array /** @return array */ protected function observedHolidays(int $year): array { - // If the holidays - May 4 and November 18 - fall on a Saturday or Sunday, - // the next working day is designated as a holiday. - $holidays = []; + $holidays = [ + 'Latvijas Republikas Neatkarības deklarācijas pasludināšanas diena' => '05-04', + 'Latvijas Republikas proklamēšanas diena' => '11-18', + ]; - $date = new CarbonImmutable(); + foreach ($holidays as $name => $date) { + $observedDay = $this->weekendToNextMonday($date, $year); - $date = $date->setDate($year, 5, 4); - if ($date->isWeekend()) { - $holidays['Pārceltā 4. maija brīvdiena'] = $date->nextWeekday()->format('m-d'); - } + if ($observedDay) { + if ($name === 'Latvijas Republikas Neatkarības deklarācijas pasludināšanas diena') { + $holidays['Pārceltā 4. maija brīvdiena'] = $observedDay; + } - $date = $date->setDate($year, 11, 18); - if ($date->isWeekend()) { - $holidays['Pārceltā 18. novembra brīvdiena'] = $date->nextWeekday()->format('m-d'); + if ($name === 'Latvijas Republikas proklamēšanas diena') { + $holidays['Pārceltā 18. novembra brīvdiena'] = $observedDay; + } + } } return $holidays; diff --git a/src/Countries/SouthAfrica.php b/src/Countries/SouthAfrica.php index f85b14255..8ef21ac51 100644 --- a/src/Countries/SouthAfrica.php +++ b/src/Countries/SouthAfrica.php @@ -4,9 +4,12 @@ use Carbon\CarbonImmutable; use Carbon\CarbonInterface; +use Spatie\Holidays\Concerns\Observable; class SouthAfrica extends Country { + use Observable; + public function countryCode(): string { return 'za'; @@ -30,7 +33,7 @@ protected function allHolidays(int $year): array ]; foreach ($holidays as $name => $date) { - $observedDay = $this->observed($date, $year); + $observedDay = $this->sundayToNextMonday($date, $year); if ($observedDay) { $holidays[$name.' Observed'] = $observedDay; @@ -50,16 +53,4 @@ protected function variableHolidays(int $year): array 'Family Day' => $easter->addDay(), ]; } - - protected function observed(string $date, int $year): ?CarbonInterface - { - $holiday = CarbonImmutable::createFromFormat('Y-m-d', "{$year}-{$date}")->startOfDay(); - - // https://www.gov.za/documents/public-holidays-act - if ($holiday->isSunday()) { - return $holiday->next('monday'); - } - - return null; - } } From 6a2c268abacbd72d881d60edf3b7af0071444b14 Mon Sep 17 00:00:00 2001 From: Nielsvanpach Date: Fri, 9 Feb 2024 12:12:26 +0000 Subject: [PATCH 103/175] Fix styling --- src/Countries/SouthAfrica.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Countries/SouthAfrica.php b/src/Countries/SouthAfrica.php index 8ef21ac51..81cf73979 100644 --- a/src/Countries/SouthAfrica.php +++ b/src/Countries/SouthAfrica.php @@ -3,7 +3,6 @@ namespace Spatie\Holidays\Countries; use Carbon\CarbonImmutable; -use Carbon\CarbonInterface; use Spatie\Holidays\Concerns\Observable; class SouthAfrica extends Country From 289a130ef6c9b1173ba25ce8088261b9be308c53 Mon Sep 17 00:00:00 2001 From: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> Date: Fri, 9 Feb 2024 13:14:03 +0100 Subject: [PATCH 104/175] reorganise --- src/Concerns/Observable.php | 46 ++++++++++++++++++------------------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/src/Concerns/Observable.php b/src/Concerns/Observable.php index 686c11b6d..aa7254ff7 100644 --- a/src/Concerns/Observable.php +++ b/src/Concerns/Observable.php @@ -7,29 +7,6 @@ trait Observable { - protected function observedChristmasDay(int $year): ?CarbonInterface - { - $christmasDay = (new CarbonImmutable($year.'-12-25'))->startOfDay(); - - return match ($christmasDay->dayName) { - 'Saturday' => $christmasDay->next('monday'), - 'Sunday' => $christmasDay->next('tuesday'), - default => null, - }; - } - - protected function observedBoxingDay(int $year): ?CarbonInterface - { - $christmasDay = (new CarbonImmutable($year.'-12-25'))->startOfDay(); - $boxingDay = $christmasDay->addDay(); - - return match ($christmasDay->dayName) { - 'Friday' => $boxingDay->next('monday'), - 'Saturday' => $boxingDay->next('tuesday'), - default => null, - }; - } - protected function weekendToNextMonday(string|CarbonInterface $date, int $year): ?CarbonInterface { if (is_string($date)) { @@ -55,4 +32,27 @@ protected function sundayToNextMonday(string|CarbonInterface $date, int $year): return null; } + + protected function observedChristmasDay(int $year): ?CarbonInterface + { + $christmasDay = (new CarbonImmutable($year.'-12-25'))->startOfDay(); + + return match ($christmasDay->dayName) { + 'Saturday' => $christmasDay->next('monday'), + 'Sunday' => $christmasDay->next('tuesday'), + default => null, + }; + } + + protected function observedBoxingDay(int $year): ?CarbonInterface + { + $christmasDay = (new CarbonImmutable($year.'-12-25'))->startOfDay(); + $boxingDay = $christmasDay->addDay(); + + return match ($christmasDay->dayName) { + 'Friday' => $boxingDay->next('monday'), + 'Saturday' => $boxingDay->next('tuesday'), + default => null, + }; + } } From 8bea6acc3cc50f12617f0c1b612efe6aed486244 Mon Sep 17 00:00:00 2001 From: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> Date: Fri, 9 Feb 2024 13:28:00 +0100 Subject: [PATCH 105/175] use unique name for carbon on ci --- .github/workflows/run-tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index 80a2047bf..e12602421 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -14,7 +14,7 @@ jobs: stability: [prefer-lowest, prefer-stable] carbon: [2.72, 3.0] - name: P${{ matrix.php }} - ${{ matrix.stability }} - ${{ matrix.os }} + name: P${{ matrix.php }} - ${{ matrix.stability }} - ${{ matrix.os }} - Carbon ${{ matrix.carbon }} steps: - name: Checkout code From 9106de5cb44e4a4364bca1cfb9eaf14c63b405e1 Mon Sep 17 00:00:00 2001 From: HAMAD ABDULLA Date: Wed, 21 Feb 2024 12:01:40 +0300 Subject: [PATCH 106/175] Adding holidays for Bahrain (#206) * Adding holidays for Bahrain * Update Bahrain.php * Update tests/Countries/BahrainTest.php Co-authored-by: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> --------- Co-authored-by: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> --- lang/bahrain/ar/holidays.json | 16 ++ lang/bahrain/en/holidays.json | 16 ++ src/Countries/Bahrain.php | 212 ++++++++++++++++++ .../it_can_calculate_bahrain_holidays.snap | 62 +++++ tests/Countries/BahrainTest.php | 18 ++ 5 files changed, 324 insertions(+) create mode 100644 lang/bahrain/ar/holidays.json create mode 100644 lang/bahrain/en/holidays.json create mode 100644 src/Countries/Bahrain.php create mode 100644 tests/.pest/snapshots/Countries/BahrainTest/it_can_calculate_bahrain_holidays.snap create mode 100644 tests/Countries/BahrainTest.php diff --git a/lang/bahrain/ar/holidays.json b/lang/bahrain/ar/holidays.json new file mode 100644 index 000000000..a1fcc4b34 --- /dev/null +++ b/lang/bahrain/ar/holidays.json @@ -0,0 +1,16 @@ +{ + "New Year\\'s Day": "رأس السنة الميلادية", + "Labour Day": "عيد العمال", + "Eid al-Fitr": "عيد الفطر المبارك", + "Eid al-Fitr Day 2": "عيد الفطر المبارك", + "Eid al-Fitr Day 3": "عيد الفطر المبارك", + "Eid al-Adha": "عيد الأضحى المبارك", + "Eid al-Adha Day 2": "عيد الأضحى المبارك", + "Eid al-Adha Day 3": "عيد الأضحى المبارك", + "Islamic New Year": "رأس السنة الهجرية", + "Birthday of the Prophet Muhammad": "المولد النبوي الشريف", + "Arafat Day": "يوم عرفة", + "National Day": "اليوم الوطني", + "National Day 2": "اليوم الوطني", + "Arafat Day 2": "يوم عرفة", +} \ No newline at end of file diff --git a/lang/bahrain/en/holidays.json b/lang/bahrain/en/holidays.json new file mode 100644 index 000000000..a5be25ff9 --- /dev/null +++ b/lang/bahrain/en/holidays.json @@ -0,0 +1,16 @@ +{ + "New Year\\'s Day": "New Year\\'s Day", + "Labour Day": "Labour Day", + "Eid al-Fitr": "Eid al-Fitr", + "Eid al-Fitr Day 2": "Eid al-Fitr", + "Eid al-Fitr Day 3": "Eid al-Fitr", + "Eid al-Adha": "Eid al-Adha", + "Eid al-Adha Day 2": "Eid al-Adha", + "Eid al-Adha Day 3": "Eid al-Adha", + "Islamic New Year": "Islamic New Year", + "Birthday of the Prophet Muhammad": "Birthday of the Prophet Muhammad", + "Arafat Day": "Arafat Day", + "National Day": "National Day", + "National Day 2": "National Day", + "Arafat Day 2": "Arafat Day", +} diff --git a/src/Countries/Bahrain.php b/src/Countries/Bahrain.php new file mode 100644 index 000000000..71e66bbc8 --- /dev/null +++ b/src/Countries/Bahrain.php @@ -0,0 +1,212 @@ + '05-24', + 2021 => '05-13', + 2022 => '05-02', + 2023 => '04-20', + 2024 => '04-10', + 2025 => '03-31', + 2026 => '03-21', + 2027 => '03-10', + 2028 => '02-27', + 2029 => '02-15', + 2030 => '02-04', + 2031 => '01-25', + 2032 => '01-15', + 2033 => '01-03', + 2034 => '12-13', + 2035 => '12-02', + 2036 => '11-20', + 2037 => '11-09', + ]; + + protected const ARAFAT_DAY_HOLIDAYS = [ + 2020 => '07-30', + 2021 => '07-19', + 2022 => '07-09', + 2023 => '06-27', + 2024 => '06-16', + 2025 => '06-06', + 2026 => '05-26', + 2027 => '05-16', + 2028 => '05-05', + 2029 => '04-24', + 2030 => '04-13', + 2031 => '04-02', + 2032 => '03-21', + 2033 => '03-11', + 2034 => '03-01', + 2035 => '02-18', + 2036 => '02-07', + 2037 => '01-26', + ]; + + protected const EID_AL_ADHA_HOLIDAYS = [ + 2020 => '07-31', + 2021 => '07-20', + 2022 => '07-09', + 2023 => '06-28', + 2024 => '06-17', + 2025 => '06-07', + 2026 => '05-27', + 2027 => '05-17', + 2028 => '05-06', + 2029 => '04-25', + 2030 => '04-14', + 2031 => '04-03', + 2032 => '03-22', + 2033 => '03-12', + 2034 => '03-02', + 2035 => '02-19', + 2036 => '02-08', + 2037 => '01-27', + ]; + + protected const ISLAMIC_NEW_YEAR_HOLIDAYS = [ + 2020 => '08-20', + 2021 => '08-09', + 2022 => '07-30', + 2023 => '07-19', + 2024 => '07-08', + 2025 => '06-06', + 2026 => '06-17', + 2027 => '06-07', + 2028 => '05-26', + 2029 => '05-15', + 2030 => '05-05', + 2031 => '04-24', + 2032 => '04-12', + 2033 => '04-01', + 2034 => '03-22', + 2035 => '03-12', + 2036 => '02-29', + 2037 => '02-17', + ]; + + protected const ASHURA_HOLIDAYS = [ + 2020 => '08-30', + 2021 => '08-19', + 2022 => '08-08', + 2023 => '07-28', + 2024 => '07-17', + 2025 => '07-07', + 2026 => '06-26', + 2027 => '06-15', + 2028 => '06-04', + 2029 => '05-24', + 2030 => '05-13', + 2031 => '05-02', + 2032 => '04-20', + 2033 => '04-10', + 2034 => '03-30', + 2035 => '03-19', + 2036 => '03-08', + 2037 => '02-25', + ]; + + protected const PROPHET_MUHAMMAD_BIRTHDAY_HOLIDAYS = [ + 2020 => '10-29', + 2021 => '10-21', + 2022 => '10-08', + 2023 => '09-28', + 2024 => '09-16', + 2025 => '09-06', + 2026 => '08-26', + 2027 => '08-15', + 2028 => '08-04', + 2029 => '07-25', + 2030 => '07-14', + 2031 => '07-03', + 2032 => '06-21', + 2033 => '06-10', + 2034 => '05-31', + 2035 => '05-21', + 2036 => '05-09', + 2037 => '04-29', + ]; + + public function countryCode(): string + { + return 'bh'; + } + + protected function allHolidays(int $year): array + { + $variableHolidays = $this->variableHolidays($year); + + return array_merge([ + 'New Year\'s Day' => '1-1', + 'Labour Day' => '5-1', + 'National Day' => '12-16', + 'National Day 2' => '12-17', + ], $variableHolidays); + } + + /** + * @return array + */ +protected function variableHolidays(int $year): array +{ + $holidays = [ + ['EID_AL_FITR_HOLIDAYS', 'Eid al-Fitr', 3], + ['EID_AL_ADHA_HOLIDAYS', 'Eid al-Adha', 3], + ['ARAFAT_DAY_HOLIDAYS', 'Arafat Day'], + ['ISLAMIC_NEW_YEAR_HOLIDAYS', 'Islamic New Year'], + ['ASHURA_HOLIDAYS', 'Ashura', 2], + ['PROPHET_MUHAMMAD_BIRTHDAY_HOLIDAYS', 'Birthday of the Prophet Muhammad'] + ]; + + $dates = []; + foreach ($holidays as $holiday) { + $dates = array_merge($dates, $this->getIslamicHolidayDatesForYear(constant('self::' . $holiday[0]), $year, $holiday[1], $holiday[2] ?? 1)); + } + + return $dates; +} + + /** + * Prepare holiday dates for the given year. + * + * @param array $holidayDates Array mapping years to dates. + * @param int $year The year for which to prepare holiday dates. + * @param string $holidayName The name of the holiday. + * @param int $duration The duration of the holiday in days. + * @return array An array of holiday dates. + */ + private function getIslamicHolidayDatesForYear(array $holidayDates, int $year, string $holidayName, int $duration = 1): array + { + $dates = []; + + if ($year < 2020) { + throw InvalidYear::yearTooLow(2020); + } + + if (! isset($holidayDates[$year])) { + return $dates; + } + + $startDay = CarbonImmutable::createFromFormat('Y-m-d', sprintf('%s-%s', $year, $holidayDates[$year])); + + if ($duration === 1) { + // For single-day holidays, use the holiday name without "Day" + $dates[$holidayName] = $startDay; + } else { + // For multi-day holidays, append "Day N" for the second day onwards + for ($i = 0; $i < $duration; $i++) { + $dayLabel = $i === 0 ? $holidayName : sprintf('%s Day %d', $holidayName, $i + 1); + $dates[$dayLabel] = $startDay->addDays($i); + } + } + + return $dates; + } +} diff --git a/tests/.pest/snapshots/Countries/BahrainTest/it_can_calculate_bahrain_holidays.snap b/tests/.pest/snapshots/Countries/BahrainTest/it_can_calculate_bahrain_holidays.snap new file mode 100644 index 000000000..457cb19b2 --- /dev/null +++ b/tests/.pest/snapshots/Countries/BahrainTest/it_can_calculate_bahrain_holidays.snap @@ -0,0 +1,62 @@ +[ + { + "name": "New Year's Day", + "date": "2024-01-01" + }, + { + "name": "Eid al-Fitr", + "date": "2024-04-10" + }, + { + "name": "Eid al-Fitr Day 2", + "date": "2024-04-11" + }, + { + "name": "Eid al-Fitr Day 3", + "date": "2024-04-12" + }, + { + "name": "Labour Day", + "date": "2024-05-01" + }, + { + "name": "Arafat Day", + "date": "2024-06-16" + }, + { + "name": "Eid al-Adha", + "date": "2024-06-17" + }, + { + "name": "Eid al-Adha Day 2", + "date": "2024-06-18" + }, + { + "name": "Eid al-Adha Day 3", + "date": "2024-06-19" + }, + { + "name": "Islamic New Year", + "date": "2024-07-08" + }, + { + "name": "Ashura", + "date": "2024-07-17" + }, + { + "name": "Ashura Day 2", + "date": "2024-07-18" + }, + { + "name": "Birthday of the Prophet Muhammad", + "date": "2024-09-16" + }, + { + "name": "National Day", + "date": "2024-12-16" + }, + { + "name": "National Day 2", + "date": "2024-12-17" + } +] \ No newline at end of file diff --git a/tests/Countries/BahrainTest.php b/tests/Countries/BahrainTest.php new file mode 100644 index 000000000..b8a7c458a --- /dev/null +++ b/tests/Countries/BahrainTest.php @@ -0,0 +1,18 @@ +get(); + + expect($holidays) + ->toBeArray() + ->not()->toBeEmpty(); + + expect(formatDates($holidays))->toMatchSnapshot(); +}); From 0e1036109f89b86a34c374148e515ef015a790ec Mon Sep 17 00:00:00 2001 From: Nielsvanpach Date: Wed, 21 Feb 2024 09:02:09 +0000 Subject: [PATCH 107/175] Fix styling --- src/Countries/Bahrain.php | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/src/Countries/Bahrain.php b/src/Countries/Bahrain.php index 71e66bbc8..1c7cee12d 100644 --- a/src/Countries/Bahrain.php +++ b/src/Countries/Bahrain.php @@ -154,24 +154,24 @@ protected function allHolidays(int $year): array /** * @return array */ -protected function variableHolidays(int $year): array -{ - $holidays = [ - ['EID_AL_FITR_HOLIDAYS', 'Eid al-Fitr', 3], - ['EID_AL_ADHA_HOLIDAYS', 'Eid al-Adha', 3], - ['ARAFAT_DAY_HOLIDAYS', 'Arafat Day'], - ['ISLAMIC_NEW_YEAR_HOLIDAYS', 'Islamic New Year'], - ['ASHURA_HOLIDAYS', 'Ashura', 2], - ['PROPHET_MUHAMMAD_BIRTHDAY_HOLIDAYS', 'Birthday of the Prophet Muhammad'] - ]; + protected function variableHolidays(int $year): array + { + $holidays = [ + ['EID_AL_FITR_HOLIDAYS', 'Eid al-Fitr', 3], + ['EID_AL_ADHA_HOLIDAYS', 'Eid al-Adha', 3], + ['ARAFAT_DAY_HOLIDAYS', 'Arafat Day'], + ['ISLAMIC_NEW_YEAR_HOLIDAYS', 'Islamic New Year'], + ['ASHURA_HOLIDAYS', 'Ashura', 2], + ['PROPHET_MUHAMMAD_BIRTHDAY_HOLIDAYS', 'Birthday of the Prophet Muhammad'], + ]; - $dates = []; - foreach ($holidays as $holiday) { - $dates = array_merge($dates, $this->getIslamicHolidayDatesForYear(constant('self::' . $holiday[0]), $year, $holiday[1], $holiday[2] ?? 1)); - } + $dates = []; + foreach ($holidays as $holiday) { + $dates = array_merge($dates, $this->getIslamicHolidayDatesForYear(constant('self::'.$holiday[0]), $year, $holiday[1], $holiday[2] ?? 1)); + } - return $dates; -} + return $dates; + } /** * Prepare holiday dates for the given year. From e750838d28faffd9fdf2cd3fae8bb9c0922a184f Mon Sep 17 00:00:00 2001 From: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> Date: Wed, 21 Feb 2024 12:59:00 +0100 Subject: [PATCH 108/175] move trait from abstract class + introduce new interface --- src/Concerns/Translatable.php | 10 +++++++++- src/Contracts/HasTranslations.php | 10 ++++++++++ src/Countries/Country.php | 7 ++++--- 3 files changed, 23 insertions(+), 4 deletions(-) create mode 100644 src/Contracts/HasTranslations.php diff --git a/src/Concerns/Translatable.php b/src/Concerns/Translatable.php index 237c8905a..11e40f07e 100644 --- a/src/Concerns/Translatable.php +++ b/src/Concerns/Translatable.php @@ -6,9 +6,17 @@ trait Translatable { - protected function translate(string $country, string $name, ?string $locale = null): string + public function translate(string $country, string $name, ?string $locale = null): string { if ($locale === null) { + if ($this->defaultLocale()) { + $locale = $this->defaultLocale(); + } else { + return $name; + } + } + + if ($locale === $this->defaultLocale()) { return $name; } diff --git a/src/Contracts/HasTranslations.php b/src/Contracts/HasTranslations.php new file mode 100644 index 000000000..45939535b --- /dev/null +++ b/src/Contracts/HasTranslations.php @@ -0,0 +1,10 @@ + */ @@ -33,7 +32,9 @@ public function get(int $year, ?string $locale = null): array } } - $name = $this->translate(basename(str_replace('\\', '/', static::class)), $name, $locale); + if ($this instanceof HasTranslations) { + $name = $this->translate(basename(str_replace('\\', '/', static::class)), $name, $locale); + } $translatedHolidays[$name] = $date; } From d674cbdc2421ac14916d08d5017662d85b1dfe11 Mon Sep 17 00:00:00 2001 From: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> Date: Wed, 21 Feb 2024 12:59:20 +0100 Subject: [PATCH 109/175] introduce default locale for countries with translations --- src/Countries/Albania.php | 11 ++++++++++- src/Countries/Azerbaijan.php | 12 ++++++++++-- src/Countries/Bahrain.php | 11 ++++++++++- src/Countries/Bangladesh.php | 11 ++++++++++- src/Countries/Belarus.php | 11 ++++++++++- src/Countries/Belgium.php | 11 ++++++++++- src/Countries/Egypt.php | 11 ++++++++++- src/Countries/Finland.php | 11 ++++++++++- src/Countries/Germany.php | 11 ++++++++++- src/Countries/Iran.php | 12 +++++++++++- src/Countries/Montenegro.php | 11 ++++++++++- src/Countries/Switzerland.php | 11 ++++++++++- src/Countries/Syria.php | 11 ++++++++++- src/Countries/Uzbekistan.php | 11 ++++++++++- src/Countries/Vietnam.php | 10 +++++++++- 15 files changed, 150 insertions(+), 16 deletions(-) diff --git a/src/Countries/Albania.php b/src/Countries/Albania.php index dd0e05d32..65424c769 100644 --- a/src/Countries/Albania.php +++ b/src/Countries/Albania.php @@ -3,15 +3,24 @@ namespace Spatie\Holidays\Countries; use Carbon\CarbonImmutable; +use Spatie\Holidays\Concerns\Translatable; +use Spatie\Holidays\Contracts\HasTranslations; use Spatie\Holidays\Exceptions\InvalidYear; -class Albania extends Country +class Albania extends Country implements HasTranslations { + use Translatable; + public function countryCode(): string { return 'al'; } + public function defaultLocale(): string + { + return 'al'; + } + protected function allHolidays(int $year): array { return array_merge([ diff --git a/src/Countries/Azerbaijan.php b/src/Countries/Azerbaijan.php index b92cd3b12..10b10abfc 100644 --- a/src/Countries/Azerbaijan.php +++ b/src/Countries/Azerbaijan.php @@ -3,14 +3,23 @@ namespace Spatie\Holidays\Countries; use Carbon\CarbonImmutable; +use Spatie\Holidays\Concerns\Translatable; +use Spatie\Holidays\Contracts\HasTranslations; -class Azerbaijan extends Country +class Azerbaijan extends Country implements HasTranslations { + use Translatable; + public function countryCode(): string { return 'az'; } + public function defaultLocale(): string + { + return 'az'; + } + protected function allHolidays(int $year): array { return array_merge([ @@ -31,7 +40,6 @@ protected function allHolidays(int $year): array /** @return array */ protected function variableHolidays(int $year): array { - // does not change according to the standard return []; } } diff --git a/src/Countries/Bahrain.php b/src/Countries/Bahrain.php index 1c7cee12d..9d9b4d6ba 100644 --- a/src/Countries/Bahrain.php +++ b/src/Countries/Bahrain.php @@ -4,10 +4,14 @@ use Carbon\CarbonImmutable; use Carbon\CarbonInterface; +use Spatie\Holidays\Concerns\Translatable; +use Spatie\Holidays\Contracts\HasTranslations; use Spatie\Holidays\Exceptions\InvalidYear; -class Bahrain extends Country +class Bahrain extends Country implements HasTranslations { + use Translatable; + protected const EID_AL_FITR_HOLIDAYS = [ 2020 => '05-24', 2021 => '05-13', @@ -139,6 +143,11 @@ public function countryCode(): string return 'bh'; } + public function defaultLocale(): string + { + return 'en'; + } + protected function allHolidays(int $year): array { $variableHolidays = $this->variableHolidays($year); diff --git a/src/Countries/Bangladesh.php b/src/Countries/Bangladesh.php index b269f53dd..a11c99074 100644 --- a/src/Countries/Bangladesh.php +++ b/src/Countries/Bangladesh.php @@ -3,14 +3,23 @@ namespace Spatie\Holidays\Countries; use Carbon\CarbonImmutable; +use Spatie\Holidays\Concerns\Translatable; +use Spatie\Holidays\Contracts\HasTranslations; -class Bangladesh extends Country +class Bangladesh extends Country implements HasTranslations { + use Translatable; + public function countryCode(): string { return 'bd'; } + public function defaultLocale(): string + { + return 'en'; + } + protected function allHolidays(int $year): array { return array_merge([ diff --git a/src/Countries/Belarus.php b/src/Countries/Belarus.php index f065d714e..18eca92b7 100644 --- a/src/Countries/Belarus.php +++ b/src/Countries/Belarus.php @@ -3,14 +3,23 @@ namespace Spatie\Holidays\Countries; use Carbon\CarbonImmutable; +use Spatie\Holidays\Concerns\Translatable; +use Spatie\Holidays\Contracts\HasTranslations; -class Belarus extends Country +class Belarus extends Country implements HasTranslations { + use Translatable; + public function countryCode(): string { return 'by'; } + public function defaultLocale(): string + { + return 'be'; + } + protected function allHolidays(int $year): array { return array_merge([ diff --git a/src/Countries/Belgium.php b/src/Countries/Belgium.php index 8710daf74..3c9b423b1 100644 --- a/src/Countries/Belgium.php +++ b/src/Countries/Belgium.php @@ -3,14 +3,23 @@ namespace Spatie\Holidays\Countries; use Carbon\CarbonImmutable; +use Spatie\Holidays\Concerns\Translatable; +use Spatie\Holidays\Contracts\HasTranslations; -class Belgium extends Country +class Belgium extends Country implements HasTranslations { + use Translatable; + public function countryCode(): string { return 'be'; } + public function defaultLocale(): string + { + return 'nl'; + } + protected function allHolidays(int $year): array { return array_merge([ diff --git a/src/Countries/Egypt.php b/src/Countries/Egypt.php index 464759c26..d6f8af4ef 100644 --- a/src/Countries/Egypt.php +++ b/src/Countries/Egypt.php @@ -4,10 +4,14 @@ use Carbon\CarbonImmutable; use Carbon\CarbonInterface; +use Spatie\Holidays\Concerns\Translatable; +use Spatie\Holidays\Contracts\HasTranslations; use Spatie\Holidays\Exceptions\InvalidYear; -class Egypt extends Country +class Egypt extends Country implements HasTranslations { + use Translatable; + protected const EID_AL_FITR_HOLIDAYS = [ 2005 => '11-04', 2006 => '10-24', @@ -229,6 +233,11 @@ public function countryCode(): string return 'eg'; } + public function defaultLocale(): string + { + return 'en'; + } + protected function allHolidays(int $year): array { $fixedHolidays = $this->fixedHolidays($year); diff --git a/src/Countries/Finland.php b/src/Countries/Finland.php index bcb2e72cd..c9d6d6014 100644 --- a/src/Countries/Finland.php +++ b/src/Countries/Finland.php @@ -4,14 +4,23 @@ use Carbon\CarbonImmutable; use Carbon\CarbonInterface; +use Spatie\Holidays\Concerns\Translatable; +use Spatie\Holidays\Contracts\HasTranslations; -class Finland extends Country +class Finland extends Country implements HasTranslations { + use Translatable; + public function countryCode(): string { return 'fi'; } + public function defaultLocale(): string + { + return 'fi'; + } + protected function allHolidays(int $year): array { return array_merge( diff --git a/src/Countries/Germany.php b/src/Countries/Germany.php index fda0dc46e..04fdda152 100644 --- a/src/Countries/Germany.php +++ b/src/Countries/Germany.php @@ -3,9 +3,13 @@ namespace Spatie\Holidays\Countries; use Carbon\CarbonImmutable; +use Spatie\Holidays\Concerns\Translatable; +use Spatie\Holidays\Contracts\HasTranslations; -class Germany extends Country +class Germany extends Country implements HasTranslations { + use Translatable; + protected function __construct( protected ?string $region = null, ) { @@ -16,6 +20,11 @@ public function countryCode(): string return 'de'; } + public function defaultLocale(): string + { + return 'de'; + } + protected function allHolidays(int $year): array { return array_merge([ diff --git a/src/Countries/Iran.php b/src/Countries/Iran.php index a70be6c58..d118bf913 100644 --- a/src/Countries/Iran.php +++ b/src/Countries/Iran.php @@ -2,13 +2,23 @@ namespace Spatie\Holidays\Countries; -class Iran extends Country +use Spatie\Holidays\Concerns\Translatable; +use Spatie\Holidays\Contracts\HasTranslations; + +class Iran extends Country implements HasTranslations { + use Translatable; + public function countryCode(): string { return 'ir'; } + public function defaultLocale(): string + { + return 'fa'; + } + protected function allHolidays(int $year): array { return [ diff --git a/src/Countries/Montenegro.php b/src/Countries/Montenegro.php index 9ff1de06e..a8d41397c 100644 --- a/src/Countries/Montenegro.php +++ b/src/Countries/Montenegro.php @@ -3,14 +3,23 @@ namespace Spatie\Holidays\Countries; use Carbon\CarbonImmutable; +use Spatie\Holidays\Concerns\Translatable; +use Spatie\Holidays\Contracts\HasTranslations; -class Montenegro extends Country +class Montenegro extends Country implements HasTranslations { + use Translatable; + public function countryCode(): string { return 'me'; } + public function defaultLocale(): string + { + return 'sr'; + } + public function allHolidays(int $year): array { // Montenegro has two days off for most holidays diff --git a/src/Countries/Switzerland.php b/src/Countries/Switzerland.php index d4d710689..d9305fbf0 100644 --- a/src/Countries/Switzerland.php +++ b/src/Countries/Switzerland.php @@ -3,10 +3,14 @@ namespace Spatie\Holidays\Countries; use Carbon\CarbonImmutable; +use Spatie\Holidays\Concerns\Translatable; +use Spatie\Holidays\Contracts\HasTranslations; use Spatie\Holidays\Exceptions\InvalidRegion; -class Switzerland extends Country +class Switzerland extends Country implements HasTranslations { + use Translatable; + private const REGIONS = [ 'ch-ag', 'ch-ar', @@ -82,6 +86,11 @@ public function countryCode(): string return 'ch'; } + public function defaultLocale(): string + { + return 'de'; + } + /** * @return array */ diff --git a/src/Countries/Syria.php b/src/Countries/Syria.php index 86ecd5d38..51d9e5f68 100644 --- a/src/Countries/Syria.php +++ b/src/Countries/Syria.php @@ -3,14 +3,23 @@ namespace Spatie\Holidays\Countries; use Carbon\CarbonImmutable; +use Spatie\Holidays\Concerns\Translatable; +use Spatie\Holidays\Contracts\HasTranslations; -class Syria extends Country +class Syria extends Country implements HasTranslations { + use Translatable; + public function countryCode(): string { return 'sy'; } + public function defaultLocale(): string + { + return 'en'; + } + protected function allHolidays(int $year): array { return array_merge([ diff --git a/src/Countries/Uzbekistan.php b/src/Countries/Uzbekistan.php index ffb371916..ceb3cade3 100644 --- a/src/Countries/Uzbekistan.php +++ b/src/Countries/Uzbekistan.php @@ -3,9 +3,13 @@ namespace Spatie\Holidays\Countries; use Carbon\CarbonImmutable; +use Spatie\Holidays\Concerns\Translatable; +use Spatie\Holidays\Contracts\HasTranslations; -class Uzbekistan extends Country +class Uzbekistan extends Country implements HasTranslations { + use Translatable; + /** * Islamic holidays (Ramadan & Sacrifice) are obtained constantly from 1991 to 2037 (https://www.timeanddate.com/holidays/uzbekistan/) */ @@ -123,6 +127,11 @@ public function countryCode(): string return 'uz'; } + public function defaultLocale(): string + { + return 'uz'; + } + /** @return array */ protected function allHolidays(int $year): array { diff --git a/src/Countries/Vietnam.php b/src/Countries/Vietnam.php index 7d6504047..51564dba6 100644 --- a/src/Countries/Vietnam.php +++ b/src/Countries/Vietnam.php @@ -5,9 +5,12 @@ use Carbon\CarbonImmutable; use Carbon\CarbonInterface; use Spatie\Holidays\Calendars\ChineseCalendar; +use Spatie\Holidays\Concerns\Translatable; +use Spatie\Holidays\Contracts\HasTranslations; -class Vietnam extends Country +class Vietnam extends Country implements HasTranslations { + use Translatable; use ChineseCalendar; public function countryCode(): string @@ -15,6 +18,11 @@ public function countryCode(): string return 'vn'; } + public function defaultLocale(): string + { + return 'vi'; + } + protected function allHolidays(int $year): array { return array_merge([ From df6dff525c4362d20b8295811ee20f3a65244cb5 Mon Sep 17 00:00:00 2001 From: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> Date: Wed, 21 Feb 2024 13:01:16 +0100 Subject: [PATCH 110/175] remove all translation files if default locale --- lang/bahrain/en/holidays.json | 16 --------------- lang/bangladesh/en/holidays.json | 10 ---------- lang/egypt/en/holidays.json | 33 ------------------------------- lang/iran/fa/holidays.json | 12 ----------- lang/montenegro/sr/holidays.json | 18 ----------------- lang/switzerland/de/holidays.json | 19 ------------------ 6 files changed, 108 deletions(-) delete mode 100644 lang/bahrain/en/holidays.json delete mode 100644 lang/bangladesh/en/holidays.json delete mode 100644 lang/egypt/en/holidays.json delete mode 100644 lang/iran/fa/holidays.json delete mode 100644 lang/montenegro/sr/holidays.json delete mode 100644 lang/switzerland/de/holidays.json diff --git a/lang/bahrain/en/holidays.json b/lang/bahrain/en/holidays.json deleted file mode 100644 index a5be25ff9..000000000 --- a/lang/bahrain/en/holidays.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "New Year\\'s Day": "New Year\\'s Day", - "Labour Day": "Labour Day", - "Eid al-Fitr": "Eid al-Fitr", - "Eid al-Fitr Day 2": "Eid al-Fitr", - "Eid al-Fitr Day 3": "Eid al-Fitr", - "Eid al-Adha": "Eid al-Adha", - "Eid al-Adha Day 2": "Eid al-Adha", - "Eid al-Adha Day 3": "Eid al-Adha", - "Islamic New Year": "Islamic New Year", - "Birthday of the Prophet Muhammad": "Birthday of the Prophet Muhammad", - "Arafat Day": "Arafat Day", - "National Day": "National Day", - "National Day 2": "National Day", - "Arafat Day 2": "Arafat Day", -} diff --git a/lang/bangladesh/en/holidays.json b/lang/bangladesh/en/holidays.json deleted file mode 100644 index 456af3986..000000000 --- a/lang/bangladesh/en/holidays.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "International Mother Language Day": "International Mother Language Day", - "Birthday of Sheikh Mujibur Rahman": "Birthday of Sheikh Mujibur Rahman", - "Independence Day": "Independence Day", - "Bengali New Year": "Bengali New Year", - "May Day": "May Day", - "National Mourning Day": "National Mourning Day", - "Victory Day": "Victory Day", - "Christmas Day": "Christmas Day" -} diff --git a/lang/egypt/en/holidays.json b/lang/egypt/en/holidays.json deleted file mode 100644 index a503639ee..000000000 --- a/lang/egypt/en/holidays.json +++ /dev/null @@ -1,33 +0,0 @@ -{ - "New Year\\'s Day": "New Year\\'s Day", - "Coptic Christmas Day": "Coptic Christmas Day", - "Revolution Day 2011": "Revolution Day 2011", - "March Equinox": "March Equinox", - "Sinai Liberation Day": "Sinai Liberation Day", - "Labour Day": "Labour Day", - "Coptic Good Friday": "Coptic Good Friday", - "Coptic Holy Saturday": "Coptic Holy Saturday", - "Coptic Easter Sunday": "Coptic Easter Sunday", - "Spring Festival": "Spring Festival", - "June Solstice": "June Solstice", - "June 30 Revolution Day": "June 30 Revolution Day", - "Day off for June 30 Revolution Day": "Day off for June 30 Revolution Day", - "Revolution Day": "Revolution Day", - "Day off for Revolution Day": "Day off for Revolution Day", - "Flooding of the Nile": "Flooding of the Nile", - "Nayrouz": "Nayrouz", - "September Equinox": "September Equinox", - "Armed Forces Day": "Armed Forces Day", - "Day off for Armed Forces Day": "Day off for Armed Forces", - "December Solstice": "December Solstice", - "Eid al-Fitr": "Eid al-Fitr", - "Eid al-Fitr Day 2": "Eid al-Fitr", - "Eid al-Fitr Day 3": "Eid al-Fitr", - "Eid al-Adha": "Eid al-Adha", - "Eid al-Adha Day 2": "Eid al-Adha", - "Eid al-Adha Day 3": "Eid al-Adha", - "Eid al-Adha Day 4": "Eid al-Adha", - "Islamic New Year": "Islamic New Year (Muharram)", - "Birthday of the Prophet Muhammad": "Birthday of the Prophet Muhammad", - "Arafat Day": "Arafat Day", -} diff --git a/lang/iran/fa/holidays.json b/lang/iran/fa/holidays.json deleted file mode 100644 index a8f7a256b..000000000 --- a/lang/iran/fa/holidays.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "پیروزی انقلاب اسلامی پنجاه و هفت": "پیروزی انقلاب اسلامی پنجاه و هفت", - "روز ملی شدن صنعت نفت": "روز ملی شدن صنعت نفت", - "نخستین روز نوروز": "نخستین روز نوروز", - "دومین روز نوروز": "دومین روز نوروز", - "سومین روز نوروز": "سومین روز نوروز", - "چهارمین روز نوروز": "چهارمین روز نوروز", - "روز جمهوری اسلامی": "روز جمهوری اسلامی", - "سیزده بدر": "سیزده بدر", - "رحلت روح\u200Cالله خمینی": "رحلت روح\u200Cالله خمینی", - "قیام ۱۵ خرداد": "قیام ۱۵ خرداد" -} \ No newline at end of file diff --git a/lang/montenegro/sr/holidays.json b/lang/montenegro/sr/holidays.json deleted file mode 100644 index e09ad680a..000000000 --- a/lang/montenegro/sr/holidays.json +++ /dev/null @@ -1,18 +0,0 @@ -{ - "Nova godina - prvi dan": "Nova godina - prvi dan", - "Nova godina - drugi dan": "Nova godina - drugi dan", - "Badnji dan": "Badnji dan", - "Božić - prvi dan": "Božić - prvi dan", - "Božić - drugi dan": "Božić - drugi dan", - "Praznik rada - prvi dan": "Praznik rada - prvi dan", - "Praznik rada - drugi dan": "Praznik rada - drugi dan", - "Veliki petak": "Veliki petak", - "Vaskrs": "Vaskrs", - "Vaskršnji ponedjeljak": "Vaskršnji ponedeljak", - "Dan nezavisnosti - prvi dan": "Dan nezavisnosti - prvi dan", - "Dan nezavisnosti - drugi dan": "Dan nezavisnosti - drugi dan", - "Dan državnosti - prvi dan": "Dan državnosti - prvi dan", - "Dan državnosti - drugi dan": "Dan državnosti - drugi dan", - "Njegošev dan - prvi dan": "Njegošev dan - prvi dan", - "Njegošev dan - drugi dan": "Njegošev dan - drugi dan" -} \ No newline at end of file diff --git a/lang/switzerland/de/holidays.json b/lang/switzerland/de/holidays.json deleted file mode 100644 index f59358468..000000000 --- a/lang/switzerland/de/holidays.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - "Neujahr": "Neujahr", - "Berchtoldstag": "Berchtoldstag", - "Heilige Drei Könige": "Heilige Drei Könige", - "Josefstag": "Josefstag", - "Karfreitag": "Karfreitag", - "Ostermontag": "Ostermontag", - "Tag der Arbeit": "Tag der Arbeit", - "Auffahrt": "Auffahrt", - "Pfingstmontag": "Pfingstmontag", - "Fronleichnam": "Fronleichnam", - "Bundesfeier": "Bundesfeier", - "Maria Himmelfahrt": "Maria Himmelfahrt", - "Buss- und Bettag" : "Buss- und Bettag", - "Allerheiligen": "Allerheiligen", - "Maria Empfängnis": "Maria Empfängnis", - "Weihnachtstag": "Weihnachtstag", - "Stephanstag": "Stephanstag" -} From 98fa89a9e152b20c9b1ca1d54cd2c14bab3e9b5f Mon Sep 17 00:00:00 2001 From: Nielsvanpach Date: Wed, 21 Feb 2024 12:01:41 +0000 Subject: [PATCH 111/175] Fix styling --- src/Countries/Country.php | 1 - src/Countries/Vietnam.php | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Countries/Country.php b/src/Countries/Country.php index c39755688..c0a668606 100644 --- a/src/Countries/Country.php +++ b/src/Countries/Country.php @@ -3,7 +3,6 @@ namespace Spatie\Holidays\Countries; use Carbon\CarbonImmutable; -use Spatie\Holidays\Concerns\Translatable; use Spatie\Holidays\Contracts\HasTranslations; use Spatie\Holidays\Exceptions\InvalidCountry; use Spatie\Holidays\Exceptions\InvalidYear; diff --git a/src/Countries/Vietnam.php b/src/Countries/Vietnam.php index 51564dba6..a57ae68a7 100644 --- a/src/Countries/Vietnam.php +++ b/src/Countries/Vietnam.php @@ -10,8 +10,8 @@ class Vietnam extends Country implements HasTranslations { - use Translatable; use ChineseCalendar; + use Translatable; public function countryCode(): string { From 6ed98737e622b43701e3c8684a837b289613775c Mon Sep 17 00:00:00 2001 From: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> Date: Wed, 21 Feb 2024 13:08:07 +0100 Subject: [PATCH 112/175] make more readable --- src/Concerns/Translatable.php | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/Concerns/Translatable.php b/src/Concerns/Translatable.php index 11e40f07e..4b33cbb64 100644 --- a/src/Concerns/Translatable.php +++ b/src/Concerns/Translatable.php @@ -9,11 +9,8 @@ trait Translatable public function translate(string $country, string $name, ?string $locale = null): string { if ($locale === null) { - if ($this->defaultLocale()) { - $locale = $this->defaultLocale(); - } else { - return $name; - } + return $name; + } if ($locale === $this->defaultLocale()) { From 7010c1f0059fe993e3ad809131598b2e9567ad17 Mon Sep 17 00:00:00 2001 From: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> Date: Wed, 21 Feb 2024 13:30:48 +0100 Subject: [PATCH 113/175] cleanup --- src/Concerns/Observable.php | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/Concerns/Observable.php b/src/Concerns/Observable.php index aa7254ff7..9dd550061 100644 --- a/src/Concerns/Observable.php +++ b/src/Concerns/Observable.php @@ -46,12 +46,11 @@ protected function observedChristmasDay(int $year): ?CarbonInterface protected function observedBoxingDay(int $year): ?CarbonInterface { - $christmasDay = (new CarbonImmutable($year.'-12-25'))->startOfDay(); - $boxingDay = $christmasDay->addDay(); + $boxingDay = (new CarbonImmutable($year.'-12-26'))->startOfDay(); - return match ($christmasDay->dayName) { - 'Friday' => $boxingDay->next('monday'), - 'Saturday' => $boxingDay->next('tuesday'), + return match ($boxingDay->dayName) { + 'Saturday' => $boxingDay->next('monday'), + 'Sunday' => $boxingDay->next('tuesday'), default => null, }; } From c818d8484f3cacf7614b4425337dd37437f920ae Mon Sep 17 00:00:00 2001 From: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> Date: Wed, 21 Feb 2024 09:21:23 +0100 Subject: [PATCH 114/175] add Islamic trait & contract --- src/Calendars/IslamicCalendar.php | 27 +++++++++++++++++++++++++++ src/Contracts/Islamic.php | 12 ++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 src/Calendars/IslamicCalendar.php create mode 100644 src/Contracts/Islamic.php diff --git a/src/Calendars/IslamicCalendar.php b/src/Calendars/IslamicCalendar.php new file mode 100644 index 000000000..e95aca89b --- /dev/null +++ b/src/Calendars/IslamicCalendar.php @@ -0,0 +1,27 @@ +countryCode(), 1970, 2037); + } + + $start = CarbonImmutable::createFromFormat('Y-m-d', "{$year}-{$date}"); + $end = $start->addDays(3); + + return CarbonPeriod::create($start, '1 day', $end); + } +} diff --git a/src/Contracts/Islamic.php b/src/Contracts/Islamic.php new file mode 100644 index 000000000..637467b72 --- /dev/null +++ b/src/Contracts/Islamic.php @@ -0,0 +1,12 @@ + Date: Wed, 21 Feb 2024 09:21:37 +0100 Subject: [PATCH 115/175] bump php version --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 5937dbf4a..ea5498234 100644 --- a/composer.json +++ b/composer.json @@ -20,7 +20,7 @@ } ], "require": { - "php": "^8.1", + "php": "^8.2", "ext-intl": "*", "nesbot/carbon": "^2.72.1|^3.0" }, From dca2942aae01765c2c0ab52dd9dac4f860474560 Mon Sep 17 00:00:00 2001 From: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> Date: Wed, 21 Feb 2024 09:21:48 +0100 Subject: [PATCH 116/175] wip: turkey refactor --- src/Countries/Turkey.php | 35 ++++++++++++++++++++++++++++++---- tests/Countries/TurkeyTest.php | 15 ++++++++++++++- 2 files changed, 45 insertions(+), 5 deletions(-) diff --git a/src/Countries/Turkey.php b/src/Countries/Turkey.php index 5957d6fd3..7d57a87e2 100644 --- a/src/Countries/Turkey.php +++ b/src/Countries/Turkey.php @@ -3,10 +3,17 @@ namespace Spatie\Holidays\Countries; use Carbon\CarbonImmutable; +use Carbon\CarbonInterface; +use Carbon\CarbonInterval; +use Carbon\CarbonPeriod; use RuntimeException; +use Spatie\Holidays\Calendars\IslamicCalendar; +use Spatie\Holidays\Contracts\Islamic; +use Spatie\Holidays\Exceptions\InvalidYear; -class Turkey extends Country +class Turkey extends Country implements Islamic { + use IslamicCalendar; /** * No library or built-in php intl functions convert dates properly for all years or all country including * “geniusts/hijri-dates”. It is most logical to prepare the dates between 1970 and 2037 as a constant property @@ -16,7 +23,7 @@ class Turkey extends Country * Ramadan and Sacrifice holidays vary for Turkey and other countries. * A converter algorithm that will cover all years does not seem possible. */ - public const ramadanHolidays = [ + public const eidAlFitr = [ 1970 => '12-01', 1971 => '11-20', 1972 => '11-08', @@ -201,10 +208,9 @@ protected function allHolidays(int $year): array protected function variableHolidays(int $year): array { return array_merge([ - ], $this->getIslamicHolidays( year: $year, - holidays: self::ramadanHolidays, + holidays: self::eidAlFitr, label: 'Ramazan Bayramı', day: 3 ), $this->getIslamicHolidays( @@ -215,6 +221,27 @@ protected function variableHolidays(int $year): array )); } + public function islamicHolidays(int $year): array + { + $holidays = [ + 'Eid al-Fitr' => $this->eidAlFitr($year), + ]; + + $result = []; + + foreach ($holidays as $name => $holiday) { + if ($holiday instanceof CarbonPeriod) { + foreach ($holiday as $index => $day) { + $holidayName = "{$name} Day " . $index+1; + + $result[$holidayName] = $day->toImmutable(); + } + } + } + + return $result; + } + /** * @param array> $holidays * @return array diff --git a/tests/Countries/TurkeyTest.php b/tests/Countries/TurkeyTest.php index 129d4c4b6..21404119e 100644 --- a/tests/Countries/TurkeyTest.php +++ b/tests/Countries/TurkeyTest.php @@ -5,7 +5,7 @@ use Carbon\CarbonImmutable; use Spatie\Holidays\Holidays; -it('can calculate turkey holidays', function ($year) { +/**it('can calculate turkey holidays', function ($year) { CarbonImmutable::setTestNow($year.'-01-01'); $holidays = Holidays::for(country: 'tr')->get(); @@ -16,3 +16,16 @@ expect(formatDates($holidays))->toMatchSnapshot(); })->with([1970, 1973, 1974, 1975, 1999, 2000, 2001, 2005, 2006, 2007, 2008, 2009, 2016, 2017, 2021, 2022, 2023, 2024, 2025, 2032, 2033, 2034, 2037]); +*/ + +it('can calculate turkey holidays', function ($year) { + CarbonImmutable::setTestNow($year.'-01-01'); + + $holidays = Holidays::for(country: 'tr')->get(); + + expect($holidays) + ->toBeArray() + ->not()->toBeEmpty(); + + expect(formatDates($holidays))->toMatchSnapshot(); +})->with([2024]); From d8d86aad9395aad44f8598a9ca8b43705b36803d Mon Sep 17 00:00:00 2001 From: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> Date: Wed, 21 Feb 2024 11:01:53 +0100 Subject: [PATCH 117/175] refactor Bahrain --- src/Calendars/IslamicCalendar.php | 25 +++++++++-- src/Countries/Bahrain.php | 74 +++++++++++++------------------ src/Countries/Turkey.php | 14 +----- 3 files changed, 55 insertions(+), 58 deletions(-) diff --git a/src/Calendars/IslamicCalendar.php b/src/Calendars/IslamicCalendar.php index e95aca89b..72e642762 100644 --- a/src/Calendars/IslamicCalendar.php +++ b/src/Calendars/IslamicCalendar.php @@ -11,7 +11,7 @@ /** @mixin Country */ trait IslamicCalendar { - public function eidAlFitr(int $year): CarbonPeriod + public function eidAlFitr(int $year, int $totalDays = 3): CarbonPeriod { try { $date = self::eidAlFitr[$year]; @@ -19,9 +19,28 @@ public function eidAlFitr(int $year): CarbonPeriod throw InvalidYear::range($this->countryCode(), 1970, 2037); } - $start = CarbonImmutable::createFromFormat('Y-m-d', "{$year}-{$date}"); - $end = $start->addDays(3); + $start = CarbonImmutable::createFromFormat('Y-m-d', "{$year}-{$date}")->startOfDay(); + $end = $start->addDays($totalDays-1)->startOfDay(); return CarbonPeriod::create($start, '1 day', $end); } + + protected function convertPeriods(array $holidays, string $suffix = 'Day'): array + { + $result = []; + + foreach ($holidays as $name => $holiday) { + if ($holiday instanceof CarbonPeriod) { + foreach ($holiday as $index => $day) { + $holidayName = "{$name} {$suffix} " . $index+1; + + $result[$holidayName] = $day->toImmutable(); + } + } else { + $result[$name] = $holiday; + } + } + + return $result; + } } diff --git a/src/Countries/Bahrain.php b/src/Countries/Bahrain.php index 9d9b4d6ba..7db92c078 100644 --- a/src/Countries/Bahrain.php +++ b/src/Countries/Bahrain.php @@ -6,13 +6,17 @@ use Carbon\CarbonInterface; use Spatie\Holidays\Concerns\Translatable; use Spatie\Holidays\Contracts\HasTranslations; +use Carbon\CarbonPeriod; +use RuntimeException; +use Spatie\Holidays\Calendars\IslamicCalendar; use Spatie\Holidays\Exceptions\InvalidYear; class Bahrain extends Country implements HasTranslations { use Translatable; + use IslamicCalendar; - protected const EID_AL_FITR_HOLIDAYS = [ + protected const eidAlFitr = [ 2020 => '05-24', 2021 => '05-13', 2022 => '05-02', @@ -166,56 +170,42 @@ protected function allHolidays(int $year): array protected function variableHolidays(int $year): array { $holidays = [ - ['EID_AL_FITR_HOLIDAYS', 'Eid al-Fitr', 3], - ['EID_AL_ADHA_HOLIDAYS', 'Eid al-Adha', 3], - ['ARAFAT_DAY_HOLIDAYS', 'Arafat Day'], - ['ISLAMIC_NEW_YEAR_HOLIDAYS', 'Islamic New Year'], - ['ASHURA_HOLIDAYS', 'Ashura', 2], - ['PROPHET_MUHAMMAD_BIRTHDAY_HOLIDAYS', 'Birthday of the Prophet Muhammad'], + 'Eid al-Fitr' => $this->eidAlFitr($year), + 'Eid al-Adha' => $this->eidAlAdha($year), + 'Arafat Day' => self::ARAFAT_DAY_HOLIDAYS[$year], + 'Islamic New Year' => self::ISLAMIC_NEW_YEAR_HOLIDAYS[$year], + 'Ashura' => $this->ashura($year), + 'Birthday of the Prophet Muhammad' => self::PROPHET_MUHAMMAD_BIRTHDAY_HOLIDAYS[$year], ]; - $dates = []; - foreach ($holidays as $holiday) { - $dates = array_merge($dates, $this->getIslamicHolidayDatesForYear(constant('self::'.$holiday[0]), $year, $holiday[1], $holiday[2] ?? 1)); - } - - return $dates; + return $this->convertPeriods($holidays); } - /** - * Prepare holiday dates for the given year. - * - * @param array $holidayDates Array mapping years to dates. - * @param int $year The year for which to prepare holiday dates. - * @param string $holidayName The name of the holiday. - * @param int $duration The duration of the holiday in days. - * @return array An array of holiday dates. - */ - private function getIslamicHolidayDatesForYear(array $holidayDates, int $year, string $holidayName, int $duration = 1): array + protected function eidAlAdha(int $year): CarbonPeriod { - $dates = []; - - if ($year < 2020) { - throw InvalidYear::yearTooLow(2020); + try { + $date = self::EID_AL_ADHA_HOLIDAYS[$year]; + } catch (RuntimeException) { + throw InvalidYear::range($this->countryCode(), 1970, 2037); } - if (! isset($holidayDates[$year])) { - return $dates; - } + $start = CarbonImmutable::createFromFormat('Y-m-d', "{$year}-{$date}"); + $end = $start->addDays(2); + + return CarbonPeriod::create($start, '1 day', $end); + } - $startDay = CarbonImmutable::createFromFormat('Y-m-d', sprintf('%s-%s', $year, $holidayDates[$year])); - - if ($duration === 1) { - // For single-day holidays, use the holiday name without "Day" - $dates[$holidayName] = $startDay; - } else { - // For multi-day holidays, append "Day N" for the second day onwards - for ($i = 0; $i < $duration; $i++) { - $dayLabel = $i === 0 ? $holidayName : sprintf('%s Day %d', $holidayName, $i + 1); - $dates[$dayLabel] = $startDay->addDays($i); - } + protected function ashura(int $year): CarbonPeriod + { + try { + $date = self::ASHURA_HOLIDAYS[$year]; + } catch (RuntimeException) { + throw InvalidYear::range($this->countryCode(), 1970, 2037); } - return $dates; + $start = CarbonImmutable::createFromFormat('Y-m-d', "{$year}-{$date}"); + $end = $start->addDay(); + + return CarbonPeriod::create($start, '1 day', $end); } } diff --git a/src/Countries/Turkey.php b/src/Countries/Turkey.php index 7d57a87e2..25ef2ef87 100644 --- a/src/Countries/Turkey.php +++ b/src/Countries/Turkey.php @@ -227,19 +227,7 @@ public function islamicHolidays(int $year): array 'Eid al-Fitr' => $this->eidAlFitr($year), ]; - $result = []; - - foreach ($holidays as $name => $holiday) { - if ($holiday instanceof CarbonPeriod) { - foreach ($holiday as $index => $day) { - $holidayName = "{$name} Day " . $index+1; - - $result[$holidayName] = $day->toImmutable(); - } - } - } - - return $result; + return $this->convertPeriods($holidays); } /** From 7450fb64b21a563dc83f9b0dd5be76238a8a19e4 Mon Sep 17 00:00:00 2001 From: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> Date: Wed, 21 Feb 2024 11:36:42 +0100 Subject: [PATCH 118/175] wip: turkey refactor --- src/Calendars/IslamicCalendar.php | 9 ++++++--- src/Countries/Bahrain.php | 20 ++++++++++---------- src/Countries/Turkey.php | 21 ++++++++++++++++++--- 3 files changed, 34 insertions(+), 16 deletions(-) diff --git a/src/Calendars/IslamicCalendar.php b/src/Calendars/IslamicCalendar.php index 72e642762..e49e1f2b3 100644 --- a/src/Calendars/IslamicCalendar.php +++ b/src/Calendars/IslamicCalendar.php @@ -25,14 +25,17 @@ public function eidAlFitr(int $year, int $totalDays = 3): CarbonPeriod return CarbonPeriod::create($start, '1 day', $end); } - protected function convertPeriods(array $holidays, string $suffix = 'Day'): array - { + protected function convertPeriods( + array $holidays, + string $suffix = 'Day', + string $prefix = '' + ): array { $result = []; foreach ($holidays as $name => $holiday) { if ($holiday instanceof CarbonPeriod) { foreach ($holiday as $index => $day) { - $holidayName = "{$name} {$suffix} " . $index+1; + $holidayName = "{$prefix}{$name} {$suffix} " . $index+1; $result[$holidayName] = $day->toImmutable(); } diff --git a/src/Countries/Bahrain.php b/src/Countries/Bahrain.php index 7db92c078..e8eb5fe95 100644 --- a/src/Countries/Bahrain.php +++ b/src/Countries/Bahrain.php @@ -37,7 +37,7 @@ class Bahrain extends Country implements HasTranslations 2037 => '11-09', ]; - protected const ARAFAT_DAY_HOLIDAYS = [ + protected const arafatDay = [ 2020 => '07-30', 2021 => '07-19', 2022 => '07-09', @@ -58,7 +58,7 @@ class Bahrain extends Country implements HasTranslations 2037 => '01-26', ]; - protected const EID_AL_ADHA_HOLIDAYS = [ + protected const eidAlAdha = [ 2020 => '07-31', 2021 => '07-20', 2022 => '07-09', @@ -79,7 +79,7 @@ class Bahrain extends Country implements HasTranslations 2037 => '01-27', ]; - protected const ISLAMIC_NEW_YEAR_HOLIDAYS = [ + protected const islamicNewYear = [ 2020 => '08-20', 2021 => '08-09', 2022 => '07-30', @@ -100,7 +100,7 @@ class Bahrain extends Country implements HasTranslations 2037 => '02-17', ]; - protected const ASHURA_HOLIDAYS = [ + protected const ashura = [ 2020 => '08-30', 2021 => '08-19', 2022 => '08-08', @@ -121,7 +121,7 @@ class Bahrain extends Country implements HasTranslations 2037 => '02-25', ]; - protected const PROPHET_MUHAMMAD_BIRTHDAY_HOLIDAYS = [ + protected const prophetMuhammadBirthday = [ 2020 => '10-29', 2021 => '10-21', 2022 => '10-08', @@ -172,10 +172,10 @@ protected function variableHolidays(int $year): array $holidays = [ 'Eid al-Fitr' => $this->eidAlFitr($year), 'Eid al-Adha' => $this->eidAlAdha($year), - 'Arafat Day' => self::ARAFAT_DAY_HOLIDAYS[$year], - 'Islamic New Year' => self::ISLAMIC_NEW_YEAR_HOLIDAYS[$year], + 'Arafat Day' => self::arafatDay[$year], + 'Islamic New Year' => self::islamicNewYear[$year], 'Ashura' => $this->ashura($year), - 'Birthday of the Prophet Muhammad' => self::PROPHET_MUHAMMAD_BIRTHDAY_HOLIDAYS[$year], + 'Birthday of the Prophet Muhammad' => self::prophetMuhammadBirthday[$year], ]; return $this->convertPeriods($holidays); @@ -184,7 +184,7 @@ protected function variableHolidays(int $year): array protected function eidAlAdha(int $year): CarbonPeriod { try { - $date = self::EID_AL_ADHA_HOLIDAYS[$year]; + $date = self::eidAlAdha[$year]; } catch (RuntimeException) { throw InvalidYear::range($this->countryCode(), 1970, 2037); } @@ -198,7 +198,7 @@ protected function eidAlAdha(int $year): CarbonPeriod protected function ashura(int $year): CarbonPeriod { try { - $date = self::ASHURA_HOLIDAYS[$year]; + $date = self::ashura[$year]; } catch (RuntimeException) { throw InvalidYear::range($this->countryCode(), 1970, 2037); } diff --git a/src/Countries/Turkey.php b/src/Countries/Turkey.php index 25ef2ef87..80ba4c7fb 100644 --- a/src/Countries/Turkey.php +++ b/src/Countries/Turkey.php @@ -201,7 +201,7 @@ protected function allHolidays(int $year): array 'Zafer Bayramı' => '08-30', 'Cumhuriyet Bayramı Arifesi' => '10-28', 'Cumhuriyet Bayramı' => '10-29', - ], $newHolidays, $this->variableHolidays($year)); + ], $newHolidays, $this->islamicHolidays($year)); } /** @return array */ @@ -224,10 +224,25 @@ protected function variableHolidays(int $year): array public function islamicHolidays(int $year): array { $holidays = [ - 'Eid al-Fitr' => $this->eidAlFitr($year), + 'Ramazan Bayramı' => $this->eidAlFitr($year), + 'Kurban Bayramı' => $this->sacrifice($year), ]; - return $this->convertPeriods($holidays); + return $this->convertPeriods($holidays, 'Gün'); + } + + public function sacrifice(int $year): CarbonPeriod + { + try { + $date = self::sacrificeHolidays[$year]; + } catch (RuntimeException) { + throw InvalidYear::range($this->countryCode(), 1970, 2037); + } + + $start = CarbonImmutable::createFromFormat('Y-m-d', "{$year}-{$date}")->startOfDay(); + $end = $start->addDays(3)->startOfDay(); + + return CarbonPeriod::create($start, '1 day', $end); } /** From db02e8593bbc251358f3dca6995b5495f8da2bae Mon Sep 17 00:00:00 2001 From: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> Date: Wed, 21 Feb 2024 14:14:40 +0100 Subject: [PATCH 119/175] get Turkey in same format as other country classes --- lang/turkey/tr/holidays.json | 19 ++++ src/Calendars/IslamicCalendar.php | 28 ++---- src/Concerns/Translatable.php | 15 +-- src/Countries/Country.php | 29 ++++++ src/Countries/Turkey.php | 150 +++++------------------------- tests/HolidaysTest.php | 14 ++- 6 files changed, 95 insertions(+), 160 deletions(-) create mode 100644 lang/turkey/tr/holidays.json diff --git a/lang/turkey/tr/holidays.json b/lang/turkey/tr/holidays.json new file mode 100644 index 000000000..500bda7c2 --- /dev/null +++ b/lang/turkey/tr/holidays.json @@ -0,0 +1,19 @@ +{ + "New Year's Day": "Yılbaşı", + "Eid al-Fitr": "Ramazan Bayramı Arifesi", + "Eid al-Fitr Day 1": "Ramazan Bayramı 1. Gün", + "Eid al-Fitr Day 2": "Ramazan Bayramı 2. Gün", + "Eid al-Fitr Day 3": "Ramazan Bayramı 3. Gün", + "National Sovereignty and Children's Day": "Ulusal Egemenlik ve Çocuk Bayramı", + "Labor and Solidarity Day": "Emek ve Dayanışma Günü", + "Commemoration of Atatürk, Youth and Sports Day": "Atatürk'ü Anma, Gençlik ve Spor Bayramı", + "Eid al-Adha": "Kurban Bayramı Arifesi", + "Eid al-Adha Day 1": "Kurban Bayramı 1. Gün", + "Eid al-Adha Day 2": "Kurban Bayramı 2. Gün", + "Eid al-Adha Day 3": "Kurban Bayramı 3. Gün", + "Eid al-Adha Day 4": "Kurban Bayramı 4. Gün", + "Democracy and National Unity Day": "Demokrasi ve Millî Birlik Günü", + "Victory Day": "Zafer Bayramı", + "Republic Day Eve": "Cumhuriyet Bayramı Arifesi", + "Republic Day": "Cumhuriyet Bayramı" +} diff --git a/src/Calendars/IslamicCalendar.php b/src/Calendars/IslamicCalendar.php index e49e1f2b3..926a6f17a 100644 --- a/src/Calendars/IslamicCalendar.php +++ b/src/Calendars/IslamicCalendar.php @@ -25,25 +25,17 @@ public function eidAlFitr(int $year, int $totalDays = 3): CarbonPeriod return CarbonPeriod::create($start, '1 day', $end); } - protected function convertPeriods( - array $holidays, - string $suffix = 'Day', - string $prefix = '' - ): array { - $result = []; - - foreach ($holidays as $name => $holiday) { - if ($holiday instanceof CarbonPeriod) { - foreach ($holiday as $index => $day) { - $holidayName = "{$prefix}{$name} {$suffix} " . $index+1; - - $result[$holidayName] = $day->toImmutable(); - } - } else { - $result[$name] = $holiday; - } + public function eidAlAdha(int $year, int $totalDays = 4): CarbonPeriod + { + try { + $date = self::eidAlAdha[$year]; + } catch (RuntimeException) { + throw InvalidYear::range($this->countryCode(), 1970, 2037); } - return $result; + $start = CarbonImmutable::createFromFormat('Y-m-d', "{$year}-{$date}")->startOfDay(); + $end = $start->addDays($totalDays-1)->startOfDay(); + + return CarbonPeriod::create($start, '1 day', $end); } } diff --git a/src/Concerns/Translatable.php b/src/Concerns/Translatable.php index 4b33cbb64..afd9f2084 100644 --- a/src/Concerns/Translatable.php +++ b/src/Concerns/Translatable.php @@ -8,22 +8,19 @@ trait Translatable { public function translate(string $country, string $name, ?string $locale = null): string { - if ($locale === null) { - return $name; - - } - if ($locale === $this->defaultLocale()) { return $name; } + $locale = $locale ?? $this->defaultLocale(); + $countryName = strtolower($country); $filePath = __DIR__."/../../lang/{$countryName}/{$locale}/holidays.json"; if (file_exists($filePath)) { $content = file_get_contents($filePath); } else { - throw InvalidLocale::notFound($country, $locale); + return $name; } if ($content === false) { @@ -33,10 +30,6 @@ public function translate(string $country, string $name, ?string $locale = null) /** @var array $data */ $data = json_decode($content, true); - if (! isset($data[$name])) { - return $name; - } - - return $data[$name]; + return $data[$name] ?? $name; } } diff --git a/src/Countries/Country.php b/src/Countries/Country.php index c0a668606..2e6ca4801 100644 --- a/src/Countries/Country.php +++ b/src/Countries/Country.php @@ -3,6 +3,7 @@ namespace Spatie\Holidays\Countries; use Carbon\CarbonImmutable; +use Carbon\CarbonPeriod; use Spatie\Holidays\Contracts\HasTranslations; use Spatie\Holidays\Exceptions\InvalidCountry; use Spatie\Holidays\Exceptions\InvalidYear; @@ -120,4 +121,32 @@ protected function ensureYearCanBeCalculated(int $year): void throw InvalidYear::yearTooHigh(2038); } } + + protected function convertPeriods( + array $holidays, + string $suffix = 'Day', + string $prefix = '' + ): array { + $result = []; + + foreach ($holidays as $name => $holiday) { + if ($holiday instanceof CarbonPeriod) { + foreach ($holiday as $index => $day) { + if ($index === 0) { + $formattedSuffix = ''; + } else { + $formattedSuffix = " {$suffix} " . $index+1; + } + + $holidayName = "{$prefix}{$name}{$formattedSuffix}"; + + $result[$holidayName] = $day->toImmutable(); + } + } else { + $result[$name] = $holiday; + } + } + + return $result; + } } diff --git a/src/Countries/Turkey.php b/src/Countries/Turkey.php index 80ba4c7fb..7ad4fbcb4 100644 --- a/src/Countries/Turkey.php +++ b/src/Countries/Turkey.php @@ -8,12 +8,16 @@ use Carbon\CarbonPeriod; use RuntimeException; use Spatie\Holidays\Calendars\IslamicCalendar; +use Spatie\Holidays\Concerns\Translatable; +use Spatie\Holidays\Contracts\HasTranslations; use Spatie\Holidays\Contracts\Islamic; use Spatie\Holidays\Exceptions\InvalidYear; -class Turkey extends Country implements Islamic +class Turkey extends Country implements Islamic, HasTranslations { use IslamicCalendar; + use Translatable; + /** * No library or built-in php intl functions convert dates properly for all years or all country including * “geniusts/hijri-dates”. It is most logical to prepare the dates between 1970 and 2037 as a constant property @@ -100,7 +104,7 @@ class Turkey extends Country implements Islamic 2037 => '11-09', ]; - public const sacrificeHolidays = [ + public const eidAlAdha = [ 1970 => '02-17', 1971 => '02-16', 1972 => '01-27', @@ -182,150 +186,40 @@ public function countryCode(): string return 'tr'; } + public function defaultLocale(): string + { + return 'tr'; + } + protected function allHolidays(int $year): array { $newHolidays = []; if ($year >= 2009) { - $newHolidays['Emek ve Dayanışma Günü'] = '05-01'; + $newHolidays['Labor and Solidarity Day'] = '05-01'; } if ($year >= 2017) { - $newHolidays['Demokrasi ve Millî Birlik Günü'] = '07-15'; + $newHolidays['Democracy and National Unity Day'] = '07-15'; } return array_merge([ - 'Yılbaşı' => '01-01', - 'Ulusal Egemenlik ve Çocuk Bayramı' => '04-23', - 'Atatürk\'ü Anma, Gençlik ve Spor Bayramı' => '05-19', - 'Zafer Bayramı' => '08-30', - 'Cumhuriyet Bayramı Arifesi' => '10-28', - 'Cumhuriyet Bayramı' => '10-29', + "New Year's Day" => "01-01", + "National Sovereignty and Children's Day" => "04-23", + "Commemoration of Atatürk, Youth and Sports Day" => "05-19", + "Victory Day" => "08-30", + "Republic Day Eve" => "10-28", + "Republic Day" => "10-29", ], $newHolidays, $this->islamicHolidays($year)); } - /** @return array */ - protected function variableHolidays(int $year): array - { - return array_merge([ - ], $this->getIslamicHolidays( - year: $year, - holidays: self::eidAlFitr, - label: 'Ramazan Bayramı', - day: 3 - ), $this->getIslamicHolidays( - year: $year, - holidays: self::sacrificeHolidays, - label: 'Kurban Bayramı', - day: 4 - )); - } - public function islamicHolidays(int $year): array { $holidays = [ - 'Ramazan Bayramı' => $this->eidAlFitr($year), - 'Kurban Bayramı' => $this->sacrifice($year), + 'Eid al-Fitr' => $this->eidAlFitr($year), + 'Eid al-Adha' => $this->eidAlAdha($year), ]; - return $this->convertPeriods($holidays, 'Gün'); - } - - public function sacrifice(int $year): CarbonPeriod - { - try { - $date = self::sacrificeHolidays[$year]; - } catch (RuntimeException) { - throw InvalidYear::range($this->countryCode(), 1970, 2037); - } - - $start = CarbonImmutable::createFromFormat('Y-m-d', "{$year}-{$date}")->startOfDay(); - $end = $start->addDays(3)->startOfDay(); - - return CarbonPeriod::create($start, '1 day', $end); - } - - /** - * @param array> $holidays - * @return array - */ - protected function getIslamicHolidays( - int $year, - array $holidays, - string $label, - int $day, - ): array { - $islamicHolidays = []; - $counter = 0; - - if ($year != 1970) { - $previousHoliday = is_array($holidays[$year - 1]) ? $holidays[$year - 1][1] : $holidays[$year - 1]; - - $previousHoliday = CarbonImmutable::createFromFormat('Y-m-d', ($year - 1).'-'.$previousHoliday) - ?: throw new RuntimeException('Date could not be created.'); - - if ($previousHoliday->addDays($day - 1)->year == $year) { - $islamicHolidays = $this->prepareHolidays( - holiday: $previousHoliday, - day: $day, - label: $label, - filterYear: $year - ); - $counter++; - } - } - - $currentYearHolidays = is_array($holidays[$year]) ? $holidays[$year] : [$holidays[$year]]; - - foreach ($currentYearHolidays as $currentYearHoliday) { - $currentYearHoliday = CarbonImmutable::createFromFormat('Y-m-d', "{$year}-{$currentYearHoliday}") - ?: throw new RuntimeException('Date could not be created.'); - - $islamicHolidays = array_merge($islamicHolidays, $this->prepareHolidays( - holiday: $currentYearHoliday, - day: $day, - label: $label, - filterYear: $year, - prefix: $counter ? ($counter + 1).'. ' : '' - )); - $counter++; - } - - if ($year != 2037) { - $nextHoliday = is_array($holidays[$year + 1]) ? $holidays[$year + 1][1] : $holidays[$year + 1]; - - $nextHoliday = CarbonImmutable::createFromFormat('Y-m-d', ($year + 1).'-'.$nextHoliday) - ?: throw new RuntimeException('Date could not be created.'); - - if ($nextHoliday->addDays(-1)->year == $year) { - $islamicHolidays = array_merge($islamicHolidays, $this->prepareHolidays( - holiday: $nextHoliday, - day: $day, - label: $label, - filterYear: $year, - prefix: $counter ? ($counter + 1).'. ' : '' - )); - } - } - - return $islamicHolidays; - } - - /** @return array */ - protected function prepareHolidays( - CarbonImmutable $holiday, - int $day, - string $label, - int $filterYear, - string $prefix = '' - ): array { - $holidays = []; - - $holidays[$prefix.$label.' Arifesi'] = $holiday->addDays(-1); - foreach (range(1, $day) as $range) { - $holidays[$prefix.$label.' '.$range.'. Gün'] = $holiday->addDays($range - 1); - } - - return array_filter($holidays, fn ($holiday) => $holiday->year == $filterYear); + return $this->convertPeriods($holidays); } } diff --git a/tests/HolidaysTest.php b/tests/HolidaysTest.php index 99f8a792a..b18a5c720 100644 --- a/tests/HolidaysTest.php +++ b/tests/HolidaysTest.php @@ -100,6 +100,14 @@ expect($result[0]['name'])->toBe('Jour de l\'An'); }); -it('cannot get translated holiday names for unsupported locales', function () { - Holidays::for(country: 'be', year: 2020, locale: 'en')->get(); -})->throws(InvalidLocale::class, 'Locale `en` is not supported for country `Belgium`.'); +it('default when the locale file is missing', function () { + // so we don't need to have a translation file for the language in the Country class + $holidays = Holidays::for(country: 'be', locale: 'en')->get(); + + expect($holidays) + ->toBeArray() + ->not()->toBeEmpty(); + + expect($holidays[0]['name'])->toBe('Nieuwjaar'); + expect($holidays[0]['date']->format('Y-m-d'))->toBe('2024-01-01'); +}); From 7a0a8ef0c91927bb8e330a5d81bf97944188c499 Mon Sep 17 00:00:00 2001 From: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> Date: Wed, 21 Feb 2024 14:27:03 +0100 Subject: [PATCH 120/175] add Eve dates for Turkey --- lang/turkey/tr/holidays.json | 8 ++++---- src/Countries/Turkey.php | 5 +++++ tests/Countries/TurkeyTest.php | 15 +-------------- 3 files changed, 10 insertions(+), 18 deletions(-) diff --git a/lang/turkey/tr/holidays.json b/lang/turkey/tr/holidays.json index 500bda7c2..086f42789 100644 --- a/lang/turkey/tr/holidays.json +++ b/lang/turkey/tr/holidays.json @@ -1,14 +1,14 @@ { "New Year's Day": "Yılbaşı", - "Eid al-Fitr": "Ramazan Bayramı Arifesi", - "Eid al-Fitr Day 1": "Ramazan Bayramı 1. Gün", + "Eid al-Fitr Eve": "Ramazan Bayramı Arifesi", + "Eid al-Fitr": "Ramazan Bayramı 1. Gün", "Eid al-Fitr Day 2": "Ramazan Bayramı 2. Gün", "Eid al-Fitr Day 3": "Ramazan Bayramı 3. Gün", "National Sovereignty and Children's Day": "Ulusal Egemenlik ve Çocuk Bayramı", "Labor and Solidarity Day": "Emek ve Dayanışma Günü", "Commemoration of Atatürk, Youth and Sports Day": "Atatürk'ü Anma, Gençlik ve Spor Bayramı", - "Eid al-Adha": "Kurban Bayramı Arifesi", - "Eid al-Adha Day 1": "Kurban Bayramı 1. Gün", + "Eid al-Adha Eve": "Kurban Bayramı Arifesi", + "Eid al-Adha": "Kurban Bayramı 1. Gün", "Eid al-Adha Day 2": "Kurban Bayramı 2. Gün", "Eid al-Adha Day 3": "Kurban Bayramı 3. Gün", "Eid al-Adha Day 4": "Kurban Bayramı 4. Gün", diff --git a/src/Countries/Turkey.php b/src/Countries/Turkey.php index 7ad4fbcb4..c71ff0407 100644 --- a/src/Countries/Turkey.php +++ b/src/Countries/Turkey.php @@ -215,8 +215,13 @@ protected function allHolidays(int $year): array public function islamicHolidays(int $year): array { + $eidAlFitr = $this->eidAlFitr($year); + $eidAlAdha = $this->eidAlAdha($year); + $holidays = [ + 'Eid al-Fitr Eve' => $eidAlFitr->first()?->subDay()->toImmutable(), 'Eid al-Fitr' => $this->eidAlFitr($year), + 'Eid al-Adha Eve' => $eidAlAdha->first()?->subDay()->toImmutable(), 'Eid al-Adha' => $this->eidAlAdha($year), ]; diff --git a/tests/Countries/TurkeyTest.php b/tests/Countries/TurkeyTest.php index 21404119e..129d4c4b6 100644 --- a/tests/Countries/TurkeyTest.php +++ b/tests/Countries/TurkeyTest.php @@ -5,19 +5,6 @@ use Carbon\CarbonImmutable; use Spatie\Holidays\Holidays; -/**it('can calculate turkey holidays', function ($year) { - CarbonImmutable::setTestNow($year.'-01-01'); - - $holidays = Holidays::for(country: 'tr')->get(); - - expect($holidays) - ->toBeArray() - ->not()->toBeEmpty(); - - expect(formatDates($holidays))->toMatchSnapshot(); -})->with([1970, 1973, 1974, 1975, 1999, 2000, 2001, 2005, 2006, 2007, 2008, 2009, 2016, 2017, 2021, 2022, 2023, 2024, 2025, 2032, 2033, 2034, 2037]); -*/ - it('can calculate turkey holidays', function ($year) { CarbonImmutable::setTestNow($year.'-01-01'); @@ -28,4 +15,4 @@ ->not()->toBeEmpty(); expect(formatDates($holidays))->toMatchSnapshot(); -})->with([2024]); +})->with([1970, 1973, 1974, 1975, 1999, 2000, 2001, 2005, 2006, 2007, 2008, 2009, 2016, 2017, 2021, 2022, 2023, 2024, 2025, 2032, 2033, 2034, 2037]); From df81e4934064c90882bc67148edbcde5670ca148 Mon Sep 17 00:00:00 2001 From: Nielsvanpach Date: Wed, 21 Feb 2024 13:37:33 +0000 Subject: [PATCH 121/175] Fix styling --- src/Calendars/IslamicCalendar.php | 4 ++-- src/Countries/Bahrain.php | 6 +++--- src/Countries/Country.php | 2 +- src/Countries/Turkey.php | 20 +++++++------------- tests/HolidaysTest.php | 1 - 5 files changed, 13 insertions(+), 20 deletions(-) diff --git a/src/Calendars/IslamicCalendar.php b/src/Calendars/IslamicCalendar.php index 926a6f17a..d3af071cb 100644 --- a/src/Calendars/IslamicCalendar.php +++ b/src/Calendars/IslamicCalendar.php @@ -20,7 +20,7 @@ public function eidAlFitr(int $year, int $totalDays = 3): CarbonPeriod } $start = CarbonImmutable::createFromFormat('Y-m-d', "{$year}-{$date}")->startOfDay(); - $end = $start->addDays($totalDays-1)->startOfDay(); + $end = $start->addDays($totalDays - 1)->startOfDay(); return CarbonPeriod::create($start, '1 day', $end); } @@ -34,7 +34,7 @@ public function eidAlAdha(int $year, int $totalDays = 4): CarbonPeriod } $start = CarbonImmutable::createFromFormat('Y-m-d', "{$year}-{$date}")->startOfDay(); - $end = $start->addDays($totalDays-1)->startOfDay(); + $end = $start->addDays($totalDays - 1)->startOfDay(); return CarbonPeriod::create($start, '1 day', $end); } diff --git a/src/Countries/Bahrain.php b/src/Countries/Bahrain.php index e8eb5fe95..66e2942fd 100644 --- a/src/Countries/Bahrain.php +++ b/src/Countries/Bahrain.php @@ -4,17 +4,17 @@ use Carbon\CarbonImmutable; use Carbon\CarbonInterface; -use Spatie\Holidays\Concerns\Translatable; -use Spatie\Holidays\Contracts\HasTranslations; use Carbon\CarbonPeriod; use RuntimeException; use Spatie\Holidays\Calendars\IslamicCalendar; +use Spatie\Holidays\Concerns\Translatable; +use Spatie\Holidays\Contracts\HasTranslations; use Spatie\Holidays\Exceptions\InvalidYear; class Bahrain extends Country implements HasTranslations { - use Translatable; use IslamicCalendar; + use Translatable; protected const eidAlFitr = [ 2020 => '05-24', diff --git a/src/Countries/Country.php b/src/Countries/Country.php index 2e6ca4801..ebcec46fb 100644 --- a/src/Countries/Country.php +++ b/src/Countries/Country.php @@ -135,7 +135,7 @@ protected function convertPeriods( if ($index === 0) { $formattedSuffix = ''; } else { - $formattedSuffix = " {$suffix} " . $index+1; + $formattedSuffix = " {$suffix} ".$index + 1; } $holidayName = "{$prefix}{$name}{$formattedSuffix}"; diff --git a/src/Countries/Turkey.php b/src/Countries/Turkey.php index c71ff0407..a50d14b67 100644 --- a/src/Countries/Turkey.php +++ b/src/Countries/Turkey.php @@ -2,18 +2,12 @@ namespace Spatie\Holidays\Countries; -use Carbon\CarbonImmutable; -use Carbon\CarbonInterface; -use Carbon\CarbonInterval; -use Carbon\CarbonPeriod; -use RuntimeException; use Spatie\Holidays\Calendars\IslamicCalendar; use Spatie\Holidays\Concerns\Translatable; use Spatie\Holidays\Contracts\HasTranslations; use Spatie\Holidays\Contracts\Islamic; -use Spatie\Holidays\Exceptions\InvalidYear; -class Turkey extends Country implements Islamic, HasTranslations +class Turkey extends Country implements HasTranslations, Islamic { use IslamicCalendar; use Translatable; @@ -204,12 +198,12 @@ protected function allHolidays(int $year): array } return array_merge([ - "New Year's Day" => "01-01", - "National Sovereignty and Children's Day" => "04-23", - "Commemoration of Atatürk, Youth and Sports Day" => "05-19", - "Victory Day" => "08-30", - "Republic Day Eve" => "10-28", - "Republic Day" => "10-29", + "New Year's Day" => '01-01', + "National Sovereignty and Children's Day" => '04-23', + 'Commemoration of Atatürk, Youth and Sports Day' => '05-19', + 'Victory Day' => '08-30', + 'Republic Day Eve' => '10-28', + 'Republic Day' => '10-29', ], $newHolidays, $this->islamicHolidays($year)); } diff --git a/tests/HolidaysTest.php b/tests/HolidaysTest.php index b18a5c720..3d2c6b0ff 100644 --- a/tests/HolidaysTest.php +++ b/tests/HolidaysTest.php @@ -4,7 +4,6 @@ use Spatie\Holidays\Countries\Belgium; use Spatie\Holidays\Countries\Netherlands; use Spatie\Holidays\Exceptions\InvalidCountry; -use Spatie\Holidays\Exceptions\InvalidLocale; use Spatie\Holidays\Exceptions\InvalidYear; use Spatie\Holidays\Holidays; From 9d9d4d2dcdd18c0d241ce6cda85b380416cd7acd Mon Sep 17 00:00:00 2001 From: Warren White Date: Thu, 7 Mar 2024 08:53:32 -0800 Subject: [PATCH 122/175] Fixed: incorrect date for Victoria Day in 2024 is May 20th, not May 27th --- .../CanadaTest/it_can_calculate_canadian_holidays.snap | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/.pest/snapshots/Countries/CanadaTest/it_can_calculate_canadian_holidays.snap b/tests/.pest/snapshots/Countries/CanadaTest/it_can_calculate_canadian_holidays.snap index 3168b8ea2..19caffc6d 100644 --- a/tests/.pest/snapshots/Countries/CanadaTest/it_can_calculate_canadian_holidays.snap +++ b/tests/.pest/snapshots/Countries/CanadaTest/it_can_calculate_canadian_holidays.snap @@ -13,7 +13,7 @@ }, { "name": "Victoria Day", - "date": "2024-05-27" + "date": "2024-05-20" }, { "name": "Canada Day", From 619930adba23de3e11cb2413b2a4a149919aca1f Mon Sep 17 00:00:00 2001 From: Warren White Date: Thu, 7 Mar 2024 09:00:20 -0800 Subject: [PATCH 123/175] Fixed: Victoria day is the first Monday preceding May 25th Changed from the last Monday of May which is incorrect. --- src/Countries/Canada.php | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/Countries/Canada.php b/src/Countries/Canada.php index f1350e198..414a8369d 100644 --- a/src/Countries/Canada.php +++ b/src/Countries/Canada.php @@ -31,11 +31,9 @@ protected function variableHolidays(int $year): array { $easter = $this->easter($year); - $victoriaDay = (new CarbonImmutable("last monday of May $year"))->startOfDay(); - - if ($victoriaDay->day < 25) { - $victoriaDay = $victoriaDay->addWeek(); - } + // the Monday preceding May 25 + $victoriaDay = CarbonImmutable::createFromFormat( 'Y-m-d', "{$year}-05-25" ) + ->previous('Monday'); return [ 'Victoria Day' => $victoriaDay, From 75edf147994625c6d6bd67ac812687c130ae0c84 Mon Sep 17 00:00:00 2001 From: Nielsvanpach Date: Fri, 8 Mar 2024 09:22:01 +0000 Subject: [PATCH 124/175] Fix styling --- src/Countries/Canada.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Countries/Canada.php b/src/Countries/Canada.php index 414a8369d..021738ac9 100644 --- a/src/Countries/Canada.php +++ b/src/Countries/Canada.php @@ -32,7 +32,7 @@ protected function variableHolidays(int $year): array $easter = $this->easter($year); // the Monday preceding May 25 - $victoriaDay = CarbonImmutable::createFromFormat( 'Y-m-d', "{$year}-05-25" ) + $victoriaDay = CarbonImmutable::createFromFormat('Y-m-d', "{$year}-05-25") ->previous('Monday'); return [ From ee306aeca1f6851a0e59b16f7c44de3009e7c175 Mon Sep 17 00:00:00 2001 From: Nielsvanpach Date: Fri, 8 Mar 2024 09:23:13 +0000 Subject: [PATCH 125/175] Update CHANGELOG --- CHANGELOG.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4e34faae1..c80882d25 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,21 @@ All notable changes to `holidays` will be documented in this file. +## 1.8.0 - 2024-03-08 + +### What's Changed + +* Adding holidays for Bahrain by @bo3bdo in https://github.com/spatie/holidays/pull/206 +* Add default locale by @Nielsvanpach in https://github.com/spatie/holidays/pull/208 +* Fix: Canada Victoria Day correction in test and calculation by @mercury64 in https://github.com/spatie/holidays/pull/211 + +### New Contributors + +* @bo3bdo made their first contribution in https://github.com/spatie/holidays/pull/206 +* @mercury64 made their first contribution in https://github.com/spatie/holidays/pull/211 + +**Full Changelog**: https://github.com/spatie/holidays/compare/1.7.0...1.8.0 + ## 1.7.0 - 2024-02-08 ### What's Changed From e003bf4abaf2a2a8ba3df69a34e6cf6d0251140e Mon Sep 17 00:00:00 2001 From: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> Date: Mon, 11 Mar 2024 13:22:24 +0100 Subject: [PATCH 126/175] handle lunar holidays that can happen twice a year --- lang/turkey/tr/holidays.json | 11 ++++++- src/Calendars/IslamicCalendar.php | 50 ++++++++++++++++++++++++------- src/Contracts/Islamic.php | 2 +- src/Countries/Turkey.php | 39 ++++++++++++++++++++---- tests/HolidaysTest.php | 2 ++ 5 files changed, 86 insertions(+), 18 deletions(-) diff --git a/lang/turkey/tr/holidays.json b/lang/turkey/tr/holidays.json index 086f42789..964fc9e90 100644 --- a/lang/turkey/tr/holidays.json +++ b/lang/turkey/tr/holidays.json @@ -15,5 +15,14 @@ "Democracy and National Unity Day": "Demokrasi ve Millî Birlik Günü", "Victory Day": "Zafer Bayramı", "Republic Day Eve": "Cumhuriyet Bayramı Arifesi", - "Republic Day": "Cumhuriyet Bayramı" + "Republic Day": "Cumhuriyet Bayramı", + "2. Eid al-Fitr Eve": "2. Ramazan Bayramı Arifesi", + "2. Eid al-Fitr": "2. Ramazan Bayramı 1. Gün", + "2. Eid al-Fitr Day 2": "2. Ramazan Bayramı 2. Gün", + "2. Eid al-Fitr Day 3": "2. Ramazan Bayramı 3. Gün", + "2. Eid al-Adha Eve": "2. Kurban Bayramı Arifesi", + "2. Eid al-Adha": "2. Kurban Bayramı 1. Gün", + "2. Eid al-Adha Day 2": "2. Kurban Bayramı 2. Gün", + "2. Eid al-Adha Day 3": "2. Kurban Bayramı 3. Gün", + "2. Eid al-Adha Day 4": "2. Kurban Bayramı 4. Gün" } diff --git a/src/Calendars/IslamicCalendar.php b/src/Calendars/IslamicCalendar.php index d3af071cb..c010028e8 100644 --- a/src/Calendars/IslamicCalendar.php +++ b/src/Calendars/IslamicCalendar.php @@ -11,31 +11,61 @@ /** @mixin Country */ trait IslamicCalendar { - public function eidAlFitr(int $year, int $totalDays = 3): CarbonPeriod + /** @return CarbonPeriod|array */ + public function eidAlFitr(int $year, int $totalDays = 3): CarbonPeriod|array { try { $date = self::eidAlFitr[$year]; - } catch (RuntimeException) { + } catch (\Exception) { throw InvalidYear::range($this->countryCode(), 1970, 2037); } - $start = CarbonImmutable::createFromFormat('Y-m-d', "{$year}-{$date}")->startOfDay(); - $end = $start->addDays($totalDays - 1)->startOfDay(); + if (! is_array($date)) { + $start = CarbonImmutable::createFromFormat('Y-m-d', "{$year}-{$date}")->startOfDay(); + $end = $start->addDays($totalDays - 1)->startOfDay(); - return CarbonPeriod::create($start, '1 day', $end); + return CarbonPeriod::create($start, '1 day', $end); + } + + // Twice a year + $periods = []; + $dates = $date; + + foreach ($dates as $date) { + $start = CarbonImmutable::createFromFormat('Y-m-d', "{$year}-{$date}")->startOfDay(); + $end = $start->addDays($totalDays-1)->startOfDay(); + $periods[] = CarbonPeriod::create($start, '1 day', $end); + } + + return $periods; } - public function eidAlAdha(int $year, int $totalDays = 4): CarbonPeriod + /** @return CarbonPeriod|array */ + public function eidAlAdha(int $year, int $totalDays = 4): CarbonPeriod|array { try { $date = self::eidAlAdha[$year]; - } catch (RuntimeException) { + } catch (\Exception) { throw InvalidYear::range($this->countryCode(), 1970, 2037); } - $start = CarbonImmutable::createFromFormat('Y-m-d', "{$year}-{$date}")->startOfDay(); - $end = $start->addDays($totalDays - 1)->startOfDay(); + if (! is_array($date)) { + $start = CarbonImmutable::createFromFormat('Y-m-d', "{$year}-{$date}")->startOfDay(); + $end = $start->addDays($totalDays - 1)->startOfDay(); + + return CarbonPeriod::create($start, '1 day', $end); + } + + // Twice a year + $periods = []; + $dates = $date; + + foreach ($dates as $date) { + $start = CarbonImmutable::createFromFormat('Y-m-d', "{$year}-{$date}")->startOfDay(); + $end = $start->addDays($totalDays-1)->startOfDay(); + $periods[] = CarbonPeriod::create($start, '1 day', $end); + } - return CarbonPeriod::create($start, '1 day', $end); + return $periods; } } diff --git a/src/Contracts/Islamic.php b/src/Contracts/Islamic.php index 637467b72..582f49413 100644 --- a/src/Contracts/Islamic.php +++ b/src/Contracts/Islamic.php @@ -8,5 +8,5 @@ interface Islamic { public function islamicHolidays(int $year): array; - public function eidAlFitr(int $year): CarbonPeriod; + public function eidAlFitr(int $year): CarbonPeriod|array; } diff --git a/src/Countries/Turkey.php b/src/Countries/Turkey.php index a50d14b67..a4395d120 100644 --- a/src/Countries/Turkey.php +++ b/src/Countries/Turkey.php @@ -212,12 +212,39 @@ public function islamicHolidays(int $year): array $eidAlFitr = $this->eidAlFitr($year); $eidAlAdha = $this->eidAlAdha($year); - $holidays = [ - 'Eid al-Fitr Eve' => $eidAlFitr->first()?->subDay()->toImmutable(), - 'Eid al-Fitr' => $this->eidAlFitr($year), - 'Eid al-Adha Eve' => $eidAlAdha->first()?->subDay()->toImmutable(), - 'Eid al-Adha' => $this->eidAlAdha($year), - ]; + if (is_array($eidAlAdha)) { + $holidays = [ + 'Eid al-Adha Eve' => $eidAlAdha[0]->first()?->subDay()->toImmutable(), + 'Eid al-Adha' => $eidAlAdha[0], + ]; + + $holidays = array_merge($holidays, [ + '2. Eid al-Adha Eve' => $eidAlAdha[1]->first()?->subDay()->toImmutable(), + '2. Eid al-Adha' => $eidAlAdha[1], + ]); + } else { + $holidays = [ + 'Eid al-Adha Eve' => $eidAlAdha->first()?->subDay()->toImmutable(), + 'Eid al-Adha' => $eidAlAdha, + ]; + } + + if (is_array($eidAlFitr)) { + $holidays = array_merge($holidays, [ + 'Eid al-Fitr Eve' => $eidAlFitr[0]->first()?->subDay()->toImmutable(), + 'Eid al-Fitr' => $eidAlFitr[0], + ]); + + $holidays = array_merge($holidays, [ + 'Eid al-Fitr Eve' => $eidAlFitr[1]->first()?->subDay()->toImmutable(), + 'Eid al-Fitr' => $eidAlFitr[1], + ]); + } else { + $holidays = array_merge($holidays, [ + 'Eid al-Fitr Eve' => $eidAlFitr->first()?->subDay()->toImmutable(), + 'Eid al-Fitr' => $eidAlFitr, + ]); + } return $this->convertPeriods($holidays); } diff --git a/tests/HolidaysTest.php b/tests/HolidaysTest.php index 3d2c6b0ff..6c83275b9 100644 --- a/tests/HolidaysTest.php +++ b/tests/HolidaysTest.php @@ -100,6 +100,8 @@ }); it('default when the locale file is missing', function () { + CarbonImmutable::setTestNow('2024-01-01'); + // so we don't need to have a translation file for the language in the Country class $holidays = Holidays::for(country: 'be', locale: 'en')->get(); From 683e3990f7dda5786872c5df271a742d2803a696 Mon Sep 17 00:00:00 2001 From: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> Date: Mon, 11 Mar 2024 15:52:37 +0100 Subject: [PATCH 127/175] handle more edge cases --- src/Calendars/IslamicCalendar.php | 44 +++++++++++++++++++------------ src/Countries/Bahrain.php | 2 +- src/Countries/Country.php | 7 +++++ src/Countries/Turkey.php | 6 ++--- 4 files changed, 38 insertions(+), 21 deletions(-) diff --git a/src/Calendars/IslamicCalendar.php b/src/Calendars/IslamicCalendar.php index c010028e8..937eb33af 100644 --- a/src/Calendars/IslamicCalendar.php +++ b/src/Calendars/IslamicCalendar.php @@ -13,13 +13,30 @@ trait IslamicCalendar { /** @return CarbonPeriod|array */ public function eidAlFitr(int $year, int $totalDays = 3): CarbonPeriod|array + { + return $this->getHoliday(self::eidAlFitr, $year, $totalDays); + } + + /** @return CarbonPeriod|array */ + public function eidAlAdha(int $year, int $totalDays = 4): CarbonPeriod|array + { + return $this->getHoliday(self::eidAlAdha, $year, $totalDays); + } + + protected function getHoliday(array $collection, int $year, int $totalDays): CarbonPeriod|array { try { - $date = self::eidAlFitr[$year]; + $date = $collection[$year]; } catch (\Exception) { throw InvalidYear::range($this->countryCode(), 1970, 2037); } + $overlap = $this->getOverlapping(self::eidAlFitr, $year, $totalDays); + + if ($overlap) { + $date = [$date, $overlap]; + } + if (! is_array($date)) { $start = CarbonImmutable::createFromFormat('Y-m-d', "{$year}-{$date}")->startOfDay(); $end = $start->addDays($totalDays - 1)->startOfDay(); @@ -40,32 +57,25 @@ public function eidAlFitr(int $year, int $totalDays = 3): CarbonPeriod|array return $periods; } - /** @return CarbonPeriod|array */ - public function eidAlAdha(int $year, int $totalDays = 4): CarbonPeriod|array + protected function getOverlapping(array $collection, int $year, $totalDays): ?string { try { - $date = self::eidAlAdha[$year]; + $date = $collection[$year-1]; } catch (\Exception) { throw InvalidYear::range($this->countryCode(), 1970, 2037); } - if (! is_array($date)) { - $start = CarbonImmutable::createFromFormat('Y-m-d', "{$year}-{$date}")->startOfDay(); - $end = $start->addDays($totalDays - 1)->startOfDay(); - - return CarbonPeriod::create($start, '1 day', $end); + if (is_array($date)) { + $date = end($date); } - // Twice a year - $periods = []; - $dates = $date; + $start = CarbonImmutable::createFromFormat('Y-m-d', "{$year}-{$date}")->startOfDay(); + $end = $start->addDays($totalDays-1)->startOfDay(); - foreach ($dates as $date) { - $start = CarbonImmutable::createFromFormat('Y-m-d', "{$year}-{$date}")->startOfDay(); - $end = $start->addDays($totalDays-1)->startOfDay(); - $periods[] = CarbonPeriod::create($start, '1 day', $end); + if ($end->year !== $year) { + return $date; } - return $periods; + return null; } } diff --git a/src/Countries/Bahrain.php b/src/Countries/Bahrain.php index 66e2942fd..b7fe08804 100644 --- a/src/Countries/Bahrain.php +++ b/src/Countries/Bahrain.php @@ -178,7 +178,7 @@ protected function variableHolidays(int $year): array 'Birthday of the Prophet Muhammad' => self::prophetMuhammadBirthday[$year], ]; - return $this->convertPeriods($holidays); + return $this->convertPeriods($holidays, $year); } protected function eidAlAdha(int $year): CarbonPeriod diff --git a/src/Countries/Country.php b/src/Countries/Country.php index ebcec46fb..0c749e875 100644 --- a/src/Countries/Country.php +++ b/src/Countries/Country.php @@ -3,6 +3,7 @@ namespace Spatie\Holidays\Countries; use Carbon\CarbonImmutable; +use Carbon\CarbonInterface; use Carbon\CarbonPeriod; use Spatie\Holidays\Contracts\HasTranslations; use Spatie\Holidays\Exceptions\InvalidCountry; @@ -124,6 +125,7 @@ protected function ensureYearCanBeCalculated(int $year): void protected function convertPeriods( array $holidays, + int $year, string $suffix = 'Day', string $prefix = '' ): array { @@ -131,7 +133,12 @@ protected function convertPeriods( foreach ($holidays as $name => $holiday) { if ($holiday instanceof CarbonPeriod) { + /** @var CarbonInterface $day */ foreach ($holiday as $index => $day) { + if ($day->year !== $year) { + continue; + } + if ($index === 0) { $formattedSuffix = ''; } else { diff --git a/src/Countries/Turkey.php b/src/Countries/Turkey.php index a4395d120..5202901eb 100644 --- a/src/Countries/Turkey.php +++ b/src/Countries/Turkey.php @@ -236,8 +236,8 @@ public function islamicHolidays(int $year): array ]); $holidays = array_merge($holidays, [ - 'Eid al-Fitr Eve' => $eidAlFitr[1]->first()?->subDay()->toImmutable(), - 'Eid al-Fitr' => $eidAlFitr[1], + '2. Eid al-Fitr Eve' => $eidAlFitr[1]->first()?->subDay()->toImmutable(), + '2. Eid al-Fitr' => $eidAlFitr[1], ]); } else { $holidays = array_merge($holidays, [ @@ -246,6 +246,6 @@ public function islamicHolidays(int $year): array ]); } - return $this->convertPeriods($holidays); + return $this->convertPeriods($holidays, $year); } } From e1df42fc37ebdf36d864fbf46d55ca07b5bcb36f Mon Sep 17 00:00:00 2001 From: Nielsvanpach Date: Mon, 11 Mar 2024 14:54:30 +0000 Subject: [PATCH 128/175] Fix styling --- src/Calendars/IslamicCalendar.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/Calendars/IslamicCalendar.php b/src/Calendars/IslamicCalendar.php index 937eb33af..223c377d1 100644 --- a/src/Calendars/IslamicCalendar.php +++ b/src/Calendars/IslamicCalendar.php @@ -4,7 +4,6 @@ use Carbon\CarbonImmutable; use Carbon\CarbonPeriod; -use RuntimeException; use Spatie\Holidays\Countries\Country; use Spatie\Holidays\Exceptions\InvalidYear; @@ -50,7 +49,7 @@ protected function getHoliday(array $collection, int $year, int $totalDays): Car foreach ($dates as $date) { $start = CarbonImmutable::createFromFormat('Y-m-d', "{$year}-{$date}")->startOfDay(); - $end = $start->addDays($totalDays-1)->startOfDay(); + $end = $start->addDays($totalDays - 1)->startOfDay(); $periods[] = CarbonPeriod::create($start, '1 day', $end); } @@ -60,7 +59,7 @@ protected function getHoliday(array $collection, int $year, int $totalDays): Car protected function getOverlapping(array $collection, int $year, $totalDays): ?string { try { - $date = $collection[$year-1]; + $date = $collection[$year - 1]; } catch (\Exception) { throw InvalidYear::range($this->countryCode(), 1970, 2037); } @@ -70,7 +69,7 @@ protected function getOverlapping(array $collection, int $year, $totalDays): ?st } $start = CarbonImmutable::createFromFormat('Y-m-d', "{$year}-{$date}")->startOfDay(); - $end = $start->addDays($totalDays-1)->startOfDay(); + $end = $start->addDays($totalDays - 1)->startOfDay(); if ($end->year !== $year) { return $date; From 98a6fc57b938599f458477bc055b6ae119cec488 Mon Sep 17 00:00:00 2001 From: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> Date: Mon, 11 Mar 2024 15:56:35 +0100 Subject: [PATCH 129/175] remove 8.1 --- .github/workflows/run-tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index e12602421..84bbb7a1b 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -10,7 +10,7 @@ jobs: fail-fast: true matrix: os: [ubuntu-latest] - php: [8.3, 8.2, 8.1] + php: [8.3, 8.2] stability: [prefer-lowest, prefer-stable] carbon: [2.72, 3.0] From 13cf38116783f2d99d74c80bd4f56a00ccf40cf0 Mon Sep 17 00:00:00 2001 From: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> Date: Thu, 21 Mar 2024 21:23:49 +0100 Subject: [PATCH 130/175] fix Turkey --- src/Calendars/IslamicCalendar.php | 32 ++++++++++++++++++++++--------- src/Countries/Country.php | 6 ++++++ 2 files changed, 29 insertions(+), 9 deletions(-) diff --git a/src/Calendars/IslamicCalendar.php b/src/Calendars/IslamicCalendar.php index 223c377d1..03f62ecd3 100644 --- a/src/Calendars/IslamicCalendar.php +++ b/src/Calendars/IslamicCalendar.php @@ -30,17 +30,16 @@ protected function getHoliday(array $collection, int $year, int $totalDays): Car throw InvalidYear::range($this->countryCode(), 1970, 2037); } - $overlap = $this->getOverlapping(self::eidAlFitr, $year, $totalDays); + $overlap = $this->getOverlapping($collection, $year, $totalDays); if ($overlap) { - $date = [$date, $overlap]; + $period = $this->createPeriod($overlap, $year -1, $totalDays); + + $date = [$period, $date]; } if (! is_array($date)) { - $start = CarbonImmutable::createFromFormat('Y-m-d', "{$year}-{$date}")->startOfDay(); - $end = $start->addDays($totalDays - 1)->startOfDay(); - - return CarbonPeriod::create($start, '1 day', $end); + return $this->createPeriod($date, $year, $totalDays); } // Twice a year @@ -48,16 +47,31 @@ protected function getHoliday(array $collection, int $year, int $totalDays): Car $dates = $date; foreach ($dates as $date) { - $start = CarbonImmutable::createFromFormat('Y-m-d', "{$year}-{$date}")->startOfDay(); - $end = $start->addDays($totalDays - 1)->startOfDay(); - $periods[] = CarbonPeriod::create($start, '1 day', $end); + if ($date instanceof CarbonPeriod) { + $periods[] = $date; + continue; + } + + $periods[] = $this->createPeriod($date, $year, $totalDays); } return $periods; } + protected function createPeriod(string $date, int $year, int $totalDays): CarbonPeriod + { + $start = CarbonImmutable::createFromFormat('Y-m-d', "{$year}-{$date}")->startOfDay(); + $end = $start->addDays($totalDays -1)->startOfDay(); + + return CarbonPeriod::create($start, '1 day', $end); + } + protected function getOverlapping(array $collection, int $year, $totalDays): ?string { + if ($year === 1970) { + return null; + } + try { $date = $collection[$year - 1]; } catch (\Exception) { diff --git a/src/Countries/Country.php b/src/Countries/Country.php index 0c749e875..74e01ab2a 100644 --- a/src/Countries/Country.php +++ b/src/Countries/Country.php @@ -150,6 +150,12 @@ protected function convertPeriods( $result[$holidayName] = $day->toImmutable(); } } else { + if ($holiday instanceof CarbonInterface) { + if ($holiday->year !== $year) { + continue; + } + } + $result[$name] = $holiday; } } From bbfdf94368e6f0a6643403bd40500cbf9c063871 Mon Sep 17 00:00:00 2001 From: Nielsvanpach Date: Thu, 21 Mar 2024 20:24:21 +0000 Subject: [PATCH 131/175] Fix styling --- src/Calendars/IslamicCalendar.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Calendars/IslamicCalendar.php b/src/Calendars/IslamicCalendar.php index 03f62ecd3..47010862e 100644 --- a/src/Calendars/IslamicCalendar.php +++ b/src/Calendars/IslamicCalendar.php @@ -33,7 +33,7 @@ protected function getHoliday(array $collection, int $year, int $totalDays): Car $overlap = $this->getOverlapping($collection, $year, $totalDays); if ($overlap) { - $period = $this->createPeriod($overlap, $year -1, $totalDays); + $period = $this->createPeriod($overlap, $year - 1, $totalDays); $date = [$period, $date]; } @@ -49,6 +49,7 @@ protected function getHoliday(array $collection, int $year, int $totalDays): Car foreach ($dates as $date) { if ($date instanceof CarbonPeriod) { $periods[] = $date; + continue; } @@ -61,7 +62,7 @@ protected function getHoliday(array $collection, int $year, int $totalDays): Car protected function createPeriod(string $date, int $year, int $totalDays): CarbonPeriod { $start = CarbonImmutable::createFromFormat('Y-m-d', "{$year}-{$date}")->startOfDay(); - $end = $start->addDays($totalDays -1)->startOfDay(); + $end = $start->addDays($totalDays - 1)->startOfDay(); return CarbonPeriod::create($start, '1 day', $end); } From 07613d7f06c3147cd8c51349f994cd07abfa13d4 Mon Sep 17 00:00:00 2001 From: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> Date: Thu, 21 Mar 2024 22:21:39 +0100 Subject: [PATCH 132/175] phpstan changes --- src/Calendars/IslamicCalendar.php | 28 ++++++++++++++++++++-------- src/Contracts/Islamic.php | 2 ++ src/Countries/Bahrain.php | 30 +----------------------------- src/Countries/Country.php | 20 +++++++++++++------- src/Countries/Turkey.php | 1 + 5 files changed, 37 insertions(+), 44 deletions(-) diff --git a/src/Calendars/IslamicCalendar.php b/src/Calendars/IslamicCalendar.php index 47010862e..3d085431d 100644 --- a/src/Calendars/IslamicCalendar.php +++ b/src/Calendars/IslamicCalendar.php @@ -22,11 +22,21 @@ public function eidAlAdha(int $year, int $totalDays = 4): CarbonPeriod|array return $this->getHoliday(self::eidAlAdha, $year, $totalDays); } + /** @return CarbonPeriod|array */ + protected function ashura(int $year, int $totalDays = 2): CarbonPeriod|array + { + return $this->getHoliday(self::ashura, $year, $totalDays); + } + + /** + * @param array> $collection + * @return CarbonPeriod|array + */ protected function getHoliday(array $collection, int $year, int $totalDays): CarbonPeriod|array { - try { - $date = $collection[$year]; - } catch (\Exception) { + $date = $collection[$year] ?? null; + + if ($date === null) { throw InvalidYear::range($this->countryCode(), 1970, 2037); } @@ -46,6 +56,7 @@ protected function getHoliday(array $collection, int $year, int $totalDays): Car $periods = []; $dates = $date; + /** @var CarbonPeriod|string $date */ foreach ($dates as $date) { if ($date instanceof CarbonPeriod) { $periods[] = $date; @@ -67,15 +78,16 @@ protected function createPeriod(string $date, int $year, int $totalDays): Carbon return CarbonPeriod::create($start, '1 day', $end); } - protected function getOverlapping(array $collection, int $year, $totalDays): ?string + /** @param array> $collection */ + protected function getOverlapping(array $collection, int $year, int $totalDays): ?string { if ($year === 1970) { return null; } - try { - $date = $collection[$year - 1]; - } catch (\Exception) { + $date = $collection[$year - 1] ?? null; + + if ($date === null) { throw InvalidYear::range($this->countryCode(), 1970, 2037); } @@ -87,7 +99,7 @@ protected function getOverlapping(array $collection, int $year, $totalDays): ?st $end = $start->addDays($totalDays - 1)->startOfDay(); if ($end->year !== $year) { - return $date; + return (string) $date; } return null; diff --git a/src/Contracts/Islamic.php b/src/Contracts/Islamic.php index 582f49413..f666ff627 100644 --- a/src/Contracts/Islamic.php +++ b/src/Contracts/Islamic.php @@ -6,7 +6,9 @@ interface Islamic { + /** @return array */ public function islamicHolidays(int $year): array; + /** @return CarbonPeriod|array */ public function eidAlFitr(int $year): CarbonPeriod|array; } diff --git a/src/Countries/Bahrain.php b/src/Countries/Bahrain.php index b7fe08804..f7617d98a 100644 --- a/src/Countries/Bahrain.php +++ b/src/Countries/Bahrain.php @@ -171,7 +171,7 @@ protected function variableHolidays(int $year): array { $holidays = [ 'Eid al-Fitr' => $this->eidAlFitr($year), - 'Eid al-Adha' => $this->eidAlAdha($year), + 'Eid al-Adha' => $this->eidAlAdha($year, 3), 'Arafat Day' => self::arafatDay[$year], 'Islamic New Year' => self::islamicNewYear[$year], 'Ashura' => $this->ashura($year), @@ -180,32 +180,4 @@ protected function variableHolidays(int $year): array return $this->convertPeriods($holidays, $year); } - - protected function eidAlAdha(int $year): CarbonPeriod - { - try { - $date = self::eidAlAdha[$year]; - } catch (RuntimeException) { - throw InvalidYear::range($this->countryCode(), 1970, 2037); - } - - $start = CarbonImmutable::createFromFormat('Y-m-d', "{$year}-{$date}"); - $end = $start->addDays(2); - - return CarbonPeriod::create($start, '1 day', $end); - } - - protected function ashura(int $year): CarbonPeriod - { - try { - $date = self::ashura[$year]; - } catch (RuntimeException) { - throw InvalidYear::range($this->countryCode(), 1970, 2037); - } - - $start = CarbonImmutable::createFromFormat('Y-m-d', "{$year}-{$date}"); - $end = $start->addDay(); - - return CarbonPeriod::create($start, '1 day', $end); - } } diff --git a/src/Countries/Country.php b/src/Countries/Country.php index 74e01ab2a..3f506edd7 100644 --- a/src/Countries/Country.php +++ b/src/Countries/Country.php @@ -123,6 +123,10 @@ protected function ensureYearCanBeCalculated(int $year): void } } + /** + * @param array> $holidays + * @return array + */ protected function convertPeriods( array $holidays, int $year, @@ -149,15 +153,17 @@ protected function convertPeriods( $result[$holidayName] = $day->toImmutable(); } - } else { - if ($holiday instanceof CarbonInterface) { - if ($holiday->year !== $year) { - continue; - } - } - $result[$name] = $holiday; + continue; + } + + if ($holiday instanceof CarbonImmutable) { + if ($holiday->year !== $year) { + continue; + } } + + $result[$name] = $holiday; } return $result; diff --git a/src/Countries/Turkey.php b/src/Countries/Turkey.php index 5202901eb..fed761df5 100644 --- a/src/Countries/Turkey.php +++ b/src/Countries/Turkey.php @@ -207,6 +207,7 @@ protected function allHolidays(int $year): array ], $newHolidays, $this->islamicHolidays($year)); } + /** @return array */ public function islamicHolidays(int $year): array { $eidAlFitr = $this->eidAlFitr($year); From cc24837894f0092ed60235e372c598f00abcb4f6 Mon Sep 17 00:00:00 2001 From: Nielsvanpach Date: Thu, 21 Mar 2024 21:22:08 +0000 Subject: [PATCH 133/175] Fix styling --- src/Calendars/IslamicCalendar.php | 2 +- src/Countries/Bahrain.php | 4 ---- src/Countries/Country.php | 2 +- 3 files changed, 2 insertions(+), 6 deletions(-) diff --git a/src/Calendars/IslamicCalendar.php b/src/Calendars/IslamicCalendar.php index 3d085431d..ba3971fdb 100644 --- a/src/Calendars/IslamicCalendar.php +++ b/src/Calendars/IslamicCalendar.php @@ -29,7 +29,7 @@ protected function ashura(int $year, int $totalDays = 2): CarbonPeriod|array } /** - * @param array> $collection + * @param array> $collection * @return CarbonPeriod|array */ protected function getHoliday(array $collection, int $year, int $totalDays): CarbonPeriod|array diff --git a/src/Countries/Bahrain.php b/src/Countries/Bahrain.php index f7617d98a..63dcb48ca 100644 --- a/src/Countries/Bahrain.php +++ b/src/Countries/Bahrain.php @@ -2,14 +2,10 @@ namespace Spatie\Holidays\Countries; -use Carbon\CarbonImmutable; use Carbon\CarbonInterface; -use Carbon\CarbonPeriod; -use RuntimeException; use Spatie\Holidays\Calendars\IslamicCalendar; use Spatie\Holidays\Concerns\Translatable; use Spatie\Holidays\Contracts\HasTranslations; -use Spatie\Holidays\Exceptions\InvalidYear; class Bahrain extends Country implements HasTranslations { diff --git a/src/Countries/Country.php b/src/Countries/Country.php index 3f506edd7..fc636960b 100644 --- a/src/Countries/Country.php +++ b/src/Countries/Country.php @@ -124,7 +124,7 @@ protected function ensureYearCanBeCalculated(int $year): void } /** - * @param array> $holidays + * @param array> $holidays * @return array */ protected function convertPeriods( From 3be5393ad1fa0644c7b0381ca1a40531f9156699 Mon Sep 17 00:00:00 2001 From: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> Date: Fri, 22 Mar 2024 11:28:38 +0100 Subject: [PATCH 134/175] refactor code for readability --- phpstan-baseline.neon | 14 ++++- src/Calendars/IslamicCalendar.php | 22 ++++---- src/Contracts/Islamic.php | 6 +- src/Countries/Bahrain.php | 3 +- src/Countries/Country.php | 93 +++++++++++++++++++++++-------- src/Countries/Turkey.php | 48 ++++++---------- 6 files changed, 114 insertions(+), 72 deletions(-) diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 7363751c6..fd61bf430 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -1,13 +1,23 @@ parameters: ignoreErrors: + - + message: "#^Argument of an invalid type Carbon\\\\CarbonPeriod supplied for foreach, only iterables are supported\\.$#" + count: 1 + path: src/Countries/Country.php + - message: "#^Argument of an invalid type array\\\\|false supplied for foreach, only iterables are supported\\.$#" count: 1 path: src/Countries/Country.php - - message: "#^Ternary operator condition is always true\\.$#" - count: 3 + message: "#^Binary operation \"\\+\" between non\\-falsy\\-string and 1 results in an error\\.$#" + count: 1 + path: src/Countries/Country.php + + - + message: "#^Access to undefined constant Spatie\\\\Holidays\\\\Countries\\\\Turkey\\:\\:ashura\\.$#" + count: 1 path: src/Countries/Turkey.php - diff --git a/src/Calendars/IslamicCalendar.php b/src/Calendars/IslamicCalendar.php index ba3971fdb..bb6b513bb 100644 --- a/src/Calendars/IslamicCalendar.php +++ b/src/Calendars/IslamicCalendar.php @@ -10,29 +10,29 @@ /** @mixin Country */ trait IslamicCalendar { - /** @return CarbonPeriod|array */ - public function eidAlFitr(int $year, int $totalDays = 3): CarbonPeriod|array + /** @return array */ + public function eidAlFitr(int $year, int $totalDays = 3): array { return $this->getHoliday(self::eidAlFitr, $year, $totalDays); } - /** @return CarbonPeriod|array */ - public function eidAlAdha(int $year, int $totalDays = 4): CarbonPeriod|array + /** @return array */ + public function eidAlAdha(int $year, int $totalDays = 4): array { return $this->getHoliday(self::eidAlAdha, $year, $totalDays); } - /** @return CarbonPeriod|array */ - protected function ashura(int $year, int $totalDays = 2): CarbonPeriod|array + /** @return array */ + protected function ashura(int $year, int $totalDays = 2): array { return $this->getHoliday(self::ashura, $year, $totalDays); } /** - * @param array> $collection - * @return CarbonPeriod|array + * @param array> $collection + * @return array */ - protected function getHoliday(array $collection, int $year, int $totalDays): CarbonPeriod|array + protected function getHoliday(array $collection, int $year, int $totalDays): array { $date = $collection[$year] ?? null; @@ -49,7 +49,7 @@ protected function getHoliday(array $collection, int $year, int $totalDays): Car } if (! is_array($date)) { - return $this->createPeriod($date, $year, $totalDays); + return [$this->createPeriod($date, $year, $totalDays)]; } // Twice a year @@ -78,7 +78,7 @@ protected function createPeriod(string $date, int $year, int $totalDays): Carbon return CarbonPeriod::create($start, '1 day', $end); } - /** @param array> $collection */ + /** @param array> $collection */ protected function getOverlapping(array $collection, int $year, int $totalDays): ?string { if ($year === 1970) { diff --git a/src/Contracts/Islamic.php b/src/Contracts/Islamic.php index f666ff627..0ce2696c3 100644 --- a/src/Contracts/Islamic.php +++ b/src/Contracts/Islamic.php @@ -2,13 +2,11 @@ namespace Spatie\Holidays\Contracts; +use Carbon\CarbonImmutable; use Carbon\CarbonPeriod; interface Islamic { - /** @return array */ + /** @return array */ public function islamicHolidays(int $year): array; - - /** @return CarbonPeriod|array */ - public function eidAlFitr(int $year): CarbonPeriod|array; } diff --git a/src/Countries/Bahrain.php b/src/Countries/Bahrain.php index 63dcb48ca..9da296dc9 100644 --- a/src/Countries/Bahrain.php +++ b/src/Countries/Bahrain.php @@ -3,6 +3,7 @@ namespace Spatie\Holidays\Countries; use Carbon\CarbonInterface; +use Carbon\CarbonPeriod; use Spatie\Holidays\Calendars\IslamicCalendar; use Spatie\Holidays\Concerns\Translatable; use Spatie\Holidays\Contracts\HasTranslations; @@ -161,7 +162,7 @@ protected function allHolidays(int $year): array } /** - * @return array + * @return array */ protected function variableHolidays(int $year): array { diff --git a/src/Countries/Country.php b/src/Countries/Country.php index fc636960b..e83e0b5c6 100644 --- a/src/Countries/Country.php +++ b/src/Countries/Country.php @@ -124,8 +124,11 @@ protected function ensureYearCanBeCalculated(int $year): void } /** - * @param array> $holidays - * @return array + * Convert holidays that are represented as CarbonPeriods to an array of CarbonImmutable dates. + * This is useful for holidays like Eid-al-Fitr that happen on multiple days. + * + * @param array> $holidays + * @return array */ protected function convertPeriods( array $holidays, @@ -133,39 +136,85 @@ protected function convertPeriods( string $suffix = 'Day', string $prefix = '' ): array { - $result = []; + $allDays = []; foreach ($holidays as $name => $holiday) { - if ($holiday instanceof CarbonPeriod) { - /** @var CarbonInterface $day */ - foreach ($holiday as $index => $day) { - if ($day->year !== $year) { - continue; - } + if (is_string($holiday)) { + $allDays[$name] = $holiday; - if ($index === 0) { - $formattedSuffix = ''; - } else { - $formattedSuffix = " {$suffix} ".$index + 1; - } + continue; + } - $holidayName = "{$prefix}{$name}{$formattedSuffix}"; + if ($holiday instanceof CarbonImmutable) { + $allDays[$name] = $holiday; - $result[$holidayName] = $day->toImmutable(); - } + continue; + } + + if ($holiday instanceof CarbonPeriod) { + $allDays = array_merge( + $allDays, + $this->handleCarbonPeriod($holiday, $year, $name, $suffix, $prefix) + ); continue; } - if ($holiday instanceof CarbonImmutable) { - if ($holiday->year !== $year) { - continue; + foreach ($holiday as $day) { + if ($day instanceof CarbonPeriod) { + $allDays = array_merge( + $allDays, + $this->handleCarbonPeriod($day, $year, $name, $suffix, $prefix) + ); } } + } - $result[$name] = $holiday; + return $allDays; + } + + /** + * Convert holidays that are represented as CarbonPeriods to an array of CarbonImmutable dates. + * This is useful for holidays like `Eid-al-Fitr` that happen on multiple days. + * + * @return array + */ + protected function handleCarbonPeriod( + CarbonPeriod $period, + int $year, + string $name, + string $suffix = 'Day', + string $prefix = '', + bool $includeEve = false, + ): array { + $allDays = []; + + if ($includeEve) { + $eve = $period->first()?->subDay(); + + if ($eve && $eve->year === $year) { + $allDays[$name . ' Eve'] = $eve->toImmutable(); + } } - return $result; + /** @var CarbonInterface $day */ + foreach ($period as $index => $day) { + if ($day->year !== $year) { + continue; // Lunar based holidays can overlap in 2 years + } + + if ($index > 0) { + $formattedSuffix = " {$suffix} ".$index + 1; + } else { + $formattedSuffix = ''; + } + + $holidayName = "{$prefix}{$name}{$formattedSuffix}"; + + $allDays[$holidayName] = $day->toImmutable(); + } + + return $allDays; } + } diff --git a/src/Countries/Turkey.php b/src/Countries/Turkey.php index fed761df5..d3406a77c 100644 --- a/src/Countries/Turkey.php +++ b/src/Countries/Turkey.php @@ -2,6 +2,8 @@ namespace Spatie\Holidays\Countries; +use Carbon\CarbonImmutable; +use Carbon\CarbonPeriod; use Spatie\Holidays\Calendars\IslamicCalendar; use Spatie\Holidays\Concerns\Translatable; use Spatie\Holidays\Contracts\HasTranslations; @@ -207,46 +209,28 @@ protected function allHolidays(int $year): array ], $newHolidays, $this->islamicHolidays($year)); } - /** @return array */ public function islamicHolidays(int $year): array { $eidAlFitr = $this->eidAlFitr($year); $eidAlAdha = $this->eidAlAdha($year); - if (is_array($eidAlAdha)) { - $holidays = [ - 'Eid al-Adha Eve' => $eidAlAdha[0]->first()?->subDay()->toImmutable(), - 'Eid al-Adha' => $eidAlAdha[0], - ]; - - $holidays = array_merge($holidays, [ - '2. Eid al-Adha Eve' => $eidAlAdha[1]->first()?->subDay()->toImmutable(), - '2. Eid al-Adha' => $eidAlAdha[1], - ]); - } else { - $holidays = [ - 'Eid al-Adha Eve' => $eidAlAdha->first()?->subDay()->toImmutable(), - 'Eid al-Adha' => $eidAlAdha, - ]; + $holidays = array_merge( + $this->handleCarbonPeriod($eidAlAdha[0], $year, 'Eid al-Adha', includeEve: true), + $this->handleCarbonPeriod($eidAlFitr[0], $year, 'Eid al-Fitr', includeEve: true), + ); + + if (count($eidAlAdha) > 1) { + $holidays = array_merge($holidays, + $this->handleCarbonPeriod($eidAlAdha[1], $year, '2. Eid al-Adha', includeEve: true), + ); } - if (is_array($eidAlFitr)) { - $holidays = array_merge($holidays, [ - 'Eid al-Fitr Eve' => $eidAlFitr[0]->first()?->subDay()->toImmutable(), - 'Eid al-Fitr' => $eidAlFitr[0], - ]); - - $holidays = array_merge($holidays, [ - '2. Eid al-Fitr Eve' => $eidAlFitr[1]->first()?->subDay()->toImmutable(), - '2. Eid al-Fitr' => $eidAlFitr[1], - ]); - } else { - $holidays = array_merge($holidays, [ - 'Eid al-Fitr Eve' => $eidAlFitr->first()?->subDay()->toImmutable(), - 'Eid al-Fitr' => $eidAlFitr, - ]); + if (count($eidAlFitr) > 1) { + $holidays = array_merge($holidays, + $this->handleCarbonPeriod($eidAlFitr[1], $year, '2. Eid al-Fitr', includeEve: true), + ); } - return $this->convertPeriods($holidays, $year); + return $holidays; } } From af20753b92ce9b704552dc641874a72fb740e6d3 Mon Sep 17 00:00:00 2001 From: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> Date: Fri, 22 Mar 2024 11:46:27 +0100 Subject: [PATCH 135/175] refactor Bahrain too --- src/Countries/Bahrain.php | 27 +++++++++++--------- src/Countries/Country.php | 52 +-------------------------------------- src/Countries/Turkey.php | 8 +++--- 3 files changed, 20 insertions(+), 67 deletions(-) diff --git a/src/Countries/Bahrain.php b/src/Countries/Bahrain.php index 9da296dc9..2d6fde2d0 100644 --- a/src/Countries/Bahrain.php +++ b/src/Countries/Bahrain.php @@ -7,8 +7,9 @@ use Spatie\Holidays\Calendars\IslamicCalendar; use Spatie\Holidays\Concerns\Translatable; use Spatie\Holidays\Contracts\HasTranslations; +use Spatie\Holidays\Contracts\Islamic; -class Bahrain extends Country implements HasTranslations +class Bahrain extends Country implements HasTranslations, Islamic { use IslamicCalendar; use Translatable; @@ -151,30 +152,32 @@ public function defaultLocale(): string protected function allHolidays(int $year): array { - $variableHolidays = $this->variableHolidays($year); - return array_merge([ 'New Year\'s Day' => '1-1', 'Labour Day' => '5-1', 'National Day' => '12-16', 'National Day 2' => '12-17', - ], $variableHolidays); + ], + $this->islamicHolidays($year) + ); } - /** - * @return array - */ - protected function variableHolidays(int $year): array + public function islamicHolidays(int $year): array { + $eidAlFitr = $this->eidAlFitr($year); + $eidAlAdha = $this->eidAlAdha($year, 3); + $ashura = $this->ashura($year); + $holidays = [ - 'Eid al-Fitr' => $this->eidAlFitr($year), - 'Eid al-Adha' => $this->eidAlAdha($year, 3), 'Arafat Day' => self::arafatDay[$year], 'Islamic New Year' => self::islamicNewYear[$year], - 'Ashura' => $this->ashura($year), 'Birthday of the Prophet Muhammad' => self::prophetMuhammadBirthday[$year], ]; - return $this->convertPeriods($holidays, $year); + return array_merge($holidays, + $this->convertPeriods($eidAlAdha[0], $year, 'Eid al-Adha'), + $this->convertPeriods($eidAlFitr[0], $year, 'Eid al-Fitr'), + $this->convertPeriods($ashura[0], $year, 'Ashura'), + ); } } diff --git a/src/Countries/Country.php b/src/Countries/Country.php index e83e0b5c6..fcf8f04b1 100644 --- a/src/Countries/Country.php +++ b/src/Countries/Country.php @@ -123,63 +123,13 @@ protected function ensureYearCanBeCalculated(int $year): void } } - /** - * Convert holidays that are represented as CarbonPeriods to an array of CarbonImmutable dates. - * This is useful for holidays like Eid-al-Fitr that happen on multiple days. - * - * @param array> $holidays - * @return array - */ - protected function convertPeriods( - array $holidays, - int $year, - string $suffix = 'Day', - string $prefix = '' - ): array { - $allDays = []; - - foreach ($holidays as $name => $holiday) { - if (is_string($holiday)) { - $allDays[$name] = $holiday; - - continue; - } - - if ($holiday instanceof CarbonImmutable) { - $allDays[$name] = $holiday; - - continue; - } - - if ($holiday instanceof CarbonPeriod) { - $allDays = array_merge( - $allDays, - $this->handleCarbonPeriod($holiday, $year, $name, $suffix, $prefix) - ); - - continue; - } - - foreach ($holiday as $day) { - if ($day instanceof CarbonPeriod) { - $allDays = array_merge( - $allDays, - $this->handleCarbonPeriod($day, $year, $name, $suffix, $prefix) - ); - } - } - } - - return $allDays; - } - /** * Convert holidays that are represented as CarbonPeriods to an array of CarbonImmutable dates. * This is useful for holidays like `Eid-al-Fitr` that happen on multiple days. * * @return array */ - protected function handleCarbonPeriod( + protected function convertPeriods( CarbonPeriod $period, int $year, string $name, diff --git a/src/Countries/Turkey.php b/src/Countries/Turkey.php index d3406a77c..910259ea2 100644 --- a/src/Countries/Turkey.php +++ b/src/Countries/Turkey.php @@ -215,19 +215,19 @@ public function islamicHolidays(int $year): array $eidAlAdha = $this->eidAlAdha($year); $holidays = array_merge( - $this->handleCarbonPeriod($eidAlAdha[0], $year, 'Eid al-Adha', includeEve: true), - $this->handleCarbonPeriod($eidAlFitr[0], $year, 'Eid al-Fitr', includeEve: true), + $this->convertPeriods($eidAlAdha[0], $year, 'Eid al-Adha', includeEve: true), + $this->convertPeriods($eidAlFitr[0], $year, 'Eid al-Fitr', includeEve: true), ); if (count($eidAlAdha) > 1) { $holidays = array_merge($holidays, - $this->handleCarbonPeriod($eidAlAdha[1], $year, '2. Eid al-Adha', includeEve: true), + $this->convertPeriods($eidAlAdha[1], $year, '2. Eid al-Adha', includeEve: true), ); } if (count($eidAlFitr) > 1) { $holidays = array_merge($holidays, - $this->handleCarbonPeriod($eidAlFitr[1], $year, '2. Eid al-Fitr', includeEve: true), + $this->convertPeriods($eidAlFitr[1], $year, '2. Eid al-Fitr', includeEve: true), ); } From 04e8299c6ff74f7bb4cc4d420aa4143242b4a33e Mon Sep 17 00:00:00 2001 From: Nielsvanpach Date: Fri, 22 Mar 2024 10:46:51 +0000 Subject: [PATCH 136/175] Fix styling --- src/Countries/Bahrain.php | 2 -- src/Countries/Country.php | 3 +-- src/Countries/Turkey.php | 2 -- 3 files changed, 1 insertion(+), 6 deletions(-) diff --git a/src/Countries/Bahrain.php b/src/Countries/Bahrain.php index 2d6fde2d0..d01ed0eef 100644 --- a/src/Countries/Bahrain.php +++ b/src/Countries/Bahrain.php @@ -2,8 +2,6 @@ namespace Spatie\Holidays\Countries; -use Carbon\CarbonInterface; -use Carbon\CarbonPeriod; use Spatie\Holidays\Calendars\IslamicCalendar; use Spatie\Holidays\Concerns\Translatable; use Spatie\Holidays\Contracts\HasTranslations; diff --git a/src/Countries/Country.php b/src/Countries/Country.php index fcf8f04b1..841c5c0d7 100644 --- a/src/Countries/Country.php +++ b/src/Countries/Country.php @@ -143,7 +143,7 @@ protected function convertPeriods( $eve = $period->first()?->subDay(); if ($eve && $eve->year === $year) { - $allDays[$name . ' Eve'] = $eve->toImmutable(); + $allDays[$name.' Eve'] = $eve->toImmutable(); } } @@ -166,5 +166,4 @@ protected function convertPeriods( return $allDays; } - } diff --git a/src/Countries/Turkey.php b/src/Countries/Turkey.php index 910259ea2..5a5b164a0 100644 --- a/src/Countries/Turkey.php +++ b/src/Countries/Turkey.php @@ -2,8 +2,6 @@ namespace Spatie\Holidays\Countries; -use Carbon\CarbonImmutable; -use Carbon\CarbonPeriod; use Spatie\Holidays\Calendars\IslamicCalendar; use Spatie\Holidays\Concerns\Translatable; use Spatie\Holidays\Contracts\HasTranslations; From 0c1c5e5410b28235d70d91038603344fed067e01 Mon Sep 17 00:00:00 2001 From: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> Date: Fri, 22 Mar 2024 11:47:26 +0100 Subject: [PATCH 137/175] run 8.1 again --- .github/workflows/run-tests.yml | 2 +- composer.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index 84bbb7a1b..e12602421 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -10,7 +10,7 @@ jobs: fail-fast: true matrix: os: [ubuntu-latest] - php: [8.3, 8.2] + php: [8.3, 8.2, 8.1] stability: [prefer-lowest, prefer-stable] carbon: [2.72, 3.0] diff --git a/composer.json b/composer.json index ea5498234..5937dbf4a 100644 --- a/composer.json +++ b/composer.json @@ -20,7 +20,7 @@ } ], "require": { - "php": "^8.2", + "php": "^8.1", "ext-intl": "*", "nesbot/carbon": "^2.72.1|^3.0" }, From 97c3c1a5a80349de67cf7df820382d307965ab03 Mon Sep 17 00:00:00 2001 From: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> Date: Fri, 22 Mar 2024 11:58:54 +0100 Subject: [PATCH 138/175] edit phpstan runner --- .github/workflows/phpstan.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/phpstan.yml b/.github/workflows/phpstan.yml index e171b0463..bdfa0fcce 100644 --- a/.github/workflows/phpstan.yml +++ b/.github/workflows/phpstan.yml @@ -12,7 +12,7 @@ jobs: - name: Setup PHP uses: shivammathur/setup-php@v2 with: - php-version: '8.2' + php-version: '8.1' coverage: none - name: Install composer dependencies @@ -21,4 +21,4 @@ jobs: COMPOSER_AUTH: ${{ secrets.COMPOSER_AUTH }} - name: Run PHPStan - run: ./vendor/bin/phpstan --error-format=github + run: ./vendor/bin/phpstan From 3529facbb4262fe28d19a0f50561c45fd4cec0f6 Mon Sep 17 00:00:00 2001 From: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> Date: Fri, 22 Mar 2024 12:20:07 +0100 Subject: [PATCH 139/175] handle new phpstan issues --- phpstan.neon.dist | 2 ++ src/Calendars/IslamicCalendar.php | 4 ++-- src/Countries/Country.php | 5 +++++ src/Countries/Egypt.php | 5 +++++ src/Countries/Greece.php | 2 +- src/Countries/Netherlands.php | 2 +- src/Countries/Panama.php | 14 +++++++++----- 7 files changed, 25 insertions(+), 9 deletions(-) diff --git a/phpstan.neon.dist b/phpstan.neon.dist index 4bfcedd04..cf486a4f4 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -8,3 +8,5 @@ parameters: ignoreErrors: - '#Unsafe usage of new static#' + - '#Cannot call method startOfDay\(\) on Carbon\\CarbonImmutable\|null#' + - '#Cannot call method addDays\(\) on Carbon\\CarbonImmutable\|null#' diff --git a/src/Calendars/IslamicCalendar.php b/src/Calendars/IslamicCalendar.php index bb6b513bb..9ab97a8c6 100644 --- a/src/Calendars/IslamicCalendar.php +++ b/src/Calendars/IslamicCalendar.php @@ -72,7 +72,7 @@ protected function getHoliday(array $collection, int $year, int $totalDays): arr protected function createPeriod(string $date, int $year, int $totalDays): CarbonPeriod { - $start = CarbonImmutable::createFromFormat('Y-m-d', "{$year}-{$date}")->startOfDay(); + $start = CarbonImmutable::createFromFormat('Y-m-d', "{$year}-{$date}")?->startOfDay(); $end = $start->addDays($totalDays - 1)->startOfDay(); return CarbonPeriod::create($start, '1 day', $end); @@ -95,7 +95,7 @@ protected function getOverlapping(array $collection, int $year, int $totalDays): $date = end($date); } - $start = CarbonImmutable::createFromFormat('Y-m-d', "{$year}-{$date}")->startOfDay(); + $start = CarbonImmutable::createFromFormat('Y-m-d', "{$year}-{$date}")?->startOfDay(); $end = $start->addDays($totalDays - 1)->startOfDay(); if ($end->year !== $year) { diff --git a/src/Countries/Country.php b/src/Countries/Country.php index 841c5c0d7..a6ab1d72a 100644 --- a/src/Countries/Country.php +++ b/src/Countries/Country.php @@ -5,6 +5,7 @@ use Carbon\CarbonImmutable; use Carbon\CarbonInterface; use Carbon\CarbonPeriod; +use Carbon\Exceptions\InvalidFormatException; use Spatie\Holidays\Contracts\HasTranslations; use Spatie\Holidays\Exceptions\InvalidCountry; use Spatie\Holidays\Exceptions\InvalidYear; @@ -33,6 +34,10 @@ public function get(int $year, ?string $locale = null): array } } + if ($date === null) { + throw new InvalidFormatException("Invalid date for holiday `{$name}`"); + } + if ($this instanceof HasTranslations) { $name = $this->translate(basename(str_replace('\\', '/', static::class)), $name, $locale); } diff --git a/src/Countries/Egypt.php b/src/Countries/Egypt.php index d6f8af4ef..d9532b697 100644 --- a/src/Countries/Egypt.php +++ b/src/Countries/Egypt.php @@ -4,6 +4,7 @@ use Carbon\CarbonImmutable; use Carbon\CarbonInterface; +use Carbon\Exceptions\InvalidFormatException; use Spatie\Holidays\Concerns\Translatable; use Spatie\Holidays\Contracts\HasTranslations; use Spatie\Holidays\Exceptions\InvalidYear; @@ -304,6 +305,10 @@ private function getIslamicHolidayDatesForYear(array $holidayDates, int $year, s $startDay = CarbonImmutable::createFromFormat('Y-m-d', sprintf('%s-%s', $year, $holidayDates[$year])); + if ($startDay === null) { + throw new InvalidFormatException("Invalid date format for holiday: {$holidayName}"); + } + if ($duration === 1) { // For single-day holidays, use the holiday name without "Day" $dates[$holidayName] = $startDay; diff --git a/src/Countries/Greece.php b/src/Countries/Greece.php index 095405980..290a34f10 100644 --- a/src/Countries/Greece.php +++ b/src/Countries/Greece.php @@ -35,7 +35,7 @@ protected function variableHolidays(int $year): array $megaloSavvato = $orthodoxEaster->copy()->subDay(); $deuteraPasha = $orthodoxEaster->copy()->addDay(); - $protomagia = CarbonImmutable::createFromFormat('Y-m-d', "{$year}-05-01"); + $protomagia = CarbonImmutable::createFromDate($year, 5, 1); $moveProtomagia = [$megaliParaskevi, $megaloSavvato, $orthodoxEaster, $deuteraPasha]; if (in_array($protomagia, $moveProtomagia, true)) { diff --git a/src/Countries/Netherlands.php b/src/Countries/Netherlands.php index 34f3b37fc..0e9fecb54 100644 --- a/src/Countries/Netherlands.php +++ b/src/Countries/Netherlands.php @@ -24,7 +24,7 @@ protected function allHolidays(int $year): array /** @return array */ protected function variableHolidays(int $year): array { - $koningsDag = CarbonImmutable::createFromFormat('Y-m-d', "{$year}-04-27"); + $koningsDag = CarbonImmutable::createFromDate($year, 4, 27); if ($koningsDag->isSunday()) { $koningsDag = $koningsDag->subDay(); diff --git a/src/Countries/Panama.php b/src/Countries/Panama.php index 98e10eb1d..c8229257d 100644 --- a/src/Countries/Panama.php +++ b/src/Countries/Panama.php @@ -3,6 +3,7 @@ namespace Spatie\Holidays\Countries; use Carbon\CarbonImmutable; +use Carbon\Exceptions\InvalidFormatException; class Panama extends Country { @@ -80,11 +81,14 @@ protected function calculateBridgeDays(array $fixedHolidays, int $year): array foreach ($fixedHolidays as $name => $date) { $holiday = CarbonImmutable::createFromFormat('Y-m-d', "{$year}-{$date}"); - if ($holiday !== false) { - $holidays[$name] = $holiday; - if ($holiday->isSunday()) { - $holidays[$name.' (Puente)'] = $holiday->addDay(); - } + if ($holiday === null) { + throw new InvalidFormatException("Invalid date format for holiday: {$name}"); + } + + $holidays[$name] = $holiday; + + if ($holiday->isSunday()) { + $holidays[$name.' (Puente)'] = $holiday->addDay(); } } From a920d3584b3b61c33a0123c6dfda38cd8597e4ae Mon Sep 17 00:00:00 2001 From: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> Date: Fri, 22 Mar 2024 13:13:08 +0100 Subject: [PATCH 140/175] ignore weird phpstan error --- phpstan.neon.dist | 1 + 1 file changed, 1 insertion(+) diff --git a/phpstan.neon.dist b/phpstan.neon.dist index cf486a4f4..79a6c0fc4 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -10,3 +10,4 @@ parameters: - '#Unsafe usage of new static#' - '#Cannot call method startOfDay\(\) on Carbon\\CarbonImmutable\|null#' - '#Cannot call method addDays\(\) on Carbon\\CarbonImmutable\|null#' + - '#Cannot call method previous\(\) on Carbon\\CarbonImmutable\|null#' From ac47d08437d4cff42f4ccd3838f751c2b44960a4 Mon Sep 17 00:00:00 2001 From: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> Date: Fri, 22 Mar 2024 13:26:06 +0100 Subject: [PATCH 141/175] use a fixed version for phpstan --- composer.json | 2 +- phpstan.neon.dist | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/composer.json b/composer.json index 5937dbf4a..1d2d8065e 100644 --- a/composer.json +++ b/composer.json @@ -28,7 +28,7 @@ "laravel/pint": "^1.0", "laravel/prompts": "^0.1.15", "pestphp/pest": "^2.31", - "phpstan/phpstan": "^1.10.56", + "phpstan/phpstan": "1.10.60", "spatie/invade": "^2.0", "spatie/ray": "^1.40.1", "symfony/var-dumper": "^6.4" diff --git a/phpstan.neon.dist b/phpstan.neon.dist index 79a6c0fc4..cf486a4f4 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -10,4 +10,3 @@ parameters: - '#Unsafe usage of new static#' - '#Cannot call method startOfDay\(\) on Carbon\\CarbonImmutable\|null#' - '#Cannot call method addDays\(\) on Carbon\\CarbonImmutable\|null#' - - '#Cannot call method previous\(\) on Carbon\\CarbonImmutable\|null#' From d77fd5ace28648d0cf54a1019067c5c9d7600a7e Mon Sep 17 00:00:00 2001 From: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> Date: Fri, 22 Mar 2024 13:28:38 +0100 Subject: [PATCH 142/175] rename for Egypt --- src/Countries/Egypt.php | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/src/Countries/Egypt.php b/src/Countries/Egypt.php index d9532b697..48d213cd9 100644 --- a/src/Countries/Egypt.php +++ b/src/Countries/Egypt.php @@ -5,15 +5,18 @@ use Carbon\CarbonImmutable; use Carbon\CarbonInterface; use Carbon\Exceptions\InvalidFormatException; +use Spatie\Holidays\Calendars\IslamicCalendar; use Spatie\Holidays\Concerns\Translatable; use Spatie\Holidays\Contracts\HasTranslations; +use Spatie\Holidays\Contracts\Islamic; use Spatie\Holidays\Exceptions\InvalidYear; -class Egypt extends Country implements HasTranslations +class Egypt extends Country implements HasTranslations, Islamic { + use IslamicCalendar; use Translatable; - protected const EID_AL_FITR_HOLIDAYS = [ + protected const eidAlFitr = [ 2005 => '11-04', 2006 => '10-24', 2007 => '10-13', @@ -49,7 +52,7 @@ class Egypt extends Country implements HasTranslations 2037 => '11-09', ]; - protected const ARAFAT_DAY_HOLIDAYS = [ + protected const arafat = [ 2005 => '01-21', 2006 => '01-10', 2007 => '01-01', @@ -85,7 +88,7 @@ class Egypt extends Country implements HasTranslations 2037 => '01-26', ]; - protected const EID_AL_ADHA_HOLIDAYS = [ + protected const eidAlAdha = [ 2005 => '01-22', 2006 => '01-11', 2007 => '01-02', @@ -121,7 +124,7 @@ class Egypt extends Country implements HasTranslations 2037 => '01-27', ]; - protected const ISLAMIC_NEW_YEAR_HOLIDAYS = [ + protected const islamicNewYear = [ 2005 => '02-10', 2006 => '01-31', 2007 => '01-20', @@ -157,7 +160,7 @@ class Egypt extends Country implements HasTranslations 2037 => '02-17', ]; - protected const ASHURA_HOLIDAYS = [ + protected const ashura = [ 2005 => '02-19', 2006 => '02-09', 2007 => '01-29', @@ -193,7 +196,7 @@ class Egypt extends Country implements HasTranslations 2037 => '02-25', ]; - protected const PROPHET_MUHAMMAD_BIRTHDAY_HOLIDAYS = [ + protected const prophetMuhammadBirthday = [ 2005 => '04-21', 2006 => '04-11', 2007 => '03-31', @@ -262,12 +265,12 @@ protected function variableHolidays(int $year): array { $orthodoxEaster = $this->orthodoxEaster($year); - $eidAlFitrDates = $this->getIslamicHolidayDatesForYear(self::EID_AL_FITR_HOLIDAYS, $year, 'Eid al-Fitr', 3); - $eidAlAdhaDates = $this->getIslamicHolidayDatesForYear(self::EID_AL_ADHA_HOLIDAYS, $year, 'Eid al-Adha', 4); - $arafatDayDates = $this->getIslamicHolidayDatesForYear(self::ARAFAT_DAY_HOLIDAYS, $year, 'Arafat Day'); - $islamicNewYearDates = $this->getIslamicHolidayDatesForYear(self::ISLAMIC_NEW_YEAR_HOLIDAYS, $year, 'Islamic New Year'); - $ashuraDates = $this->getIslamicHolidayDatesForYear(self::ASHURA_HOLIDAYS, $year, 'Ashura'); - $prophetMuhammadBirthdayDates = $this->getIslamicHolidayDatesForYear(self::PROPHET_MUHAMMAD_BIRTHDAY_HOLIDAYS, $year, 'Birthday of the Prophet Muhammad'); + $eidAlFitrDates = $this->getIslamicHolidayDatesForYear(self::eidAlFitr, $year, 'Eid al-Fitr', 3); + $eidAlAdhaDates = $this->getIslamicHolidayDatesForYear(self::eidAlAdha, $year, 'Eid al-Adha', 4); + $arafatDayDates = $this->getIslamicHolidayDatesForYear(self::arafat, $year, 'Arafat Day'); + $islamicNewYearDates = $this->getIslamicHolidayDatesForYear(self::islamicNewYear, $year, 'Islamic New Year'); + $ashuraDates = $this->getIslamicHolidayDatesForYear(self::ashura, $year, 'Ashura'); + $prophetMuhammadBirthdayDates = $this->getIslamicHolidayDatesForYear(self::prophetMuhammadBirthday, $year, 'Birthday of the Prophet Muhammad'); return array_merge([ 'Coptic Good Friday' => $orthodoxEaster->subDays(2)->toImmutable(), @@ -367,4 +370,9 @@ private function adjustForWeekend(string $name, CarbonImmutable $date): array return $adjustedHolidays; } + + public function islamicHolidays(int $year): array + { + // TODO: Implement islamicHolidays() method. + } } From f45c8846f7fe111bac35efde76995a60053b1df3 Mon Sep 17 00:00:00 2001 From: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> Date: Fri, 22 Mar 2024 14:21:16 +0100 Subject: [PATCH 143/175] update Egypt --- phpstan-baseline.neon | 15 +++++ src/Calendars/IslamicCalendar.php | 42 ++++++++++-- src/Countries/Bahrain.php | 8 +-- src/Countries/Egypt.php | 107 ++++++++++-------------------- 4 files changed, 93 insertions(+), 79 deletions(-) diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index fd61bf430..b41917f8c 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -15,11 +15,26 @@ parameters: count: 1 path: src/Countries/Country.php + - + message: "#^Access to undefined constant Spatie\\\\Holidays\\\\Countries\\\\Turkey\\:\\:arafat\\.$#" + count: 1 + path: src/Countries/Turkey.php + - message: "#^Access to undefined constant Spatie\\\\Holidays\\\\Countries\\\\Turkey\\:\\:ashura\\.$#" count: 1 path: src/Countries/Turkey.php + - + message: "#^Access to undefined constant Spatie\\\\Holidays\\\\Countries\\\\Turkey\\:\\:islamicNewYear\\.$#" + count: 1 + path: src/Countries/Turkey.php + + - + message: "#^Access to undefined constant Spatie\\\\Holidays\\\\Countries\\\\Turkey\\:\\:prophetMuhammadBirthday\\.$#" + count: 1 + path: src/Countries/Turkey.php + - message: "#^Cannot call method setTimeStamp\\(\\) on DateTime\\|false\\.$#" count: 1 diff --git a/src/Calendars/IslamicCalendar.php b/src/Calendars/IslamicCalendar.php index 9ab97a8c6..9eb1fc0eb 100644 --- a/src/Calendars/IslamicCalendar.php +++ b/src/Calendars/IslamicCalendar.php @@ -4,6 +4,7 @@ use Carbon\CarbonImmutable; use Carbon\CarbonPeriod; +use Carbon\Exceptions\InvalidFormatException; use Spatie\Holidays\Countries\Country; use Spatie\Holidays\Exceptions\InvalidYear; @@ -13,26 +14,59 @@ trait IslamicCalendar /** @return array */ public function eidAlFitr(int $year, int $totalDays = 3): array { - return $this->getHoliday(self::eidAlFitr, $year, $totalDays); + return $this->getMultiDayHoliday(self::eidAlFitr, $year, $totalDays); } /** @return array */ public function eidAlAdha(int $year, int $totalDays = 4): array { - return $this->getHoliday(self::eidAlAdha, $year, $totalDays); + return $this->getMultiDayHoliday(self::eidAlAdha, $year, $totalDays); } /** @return array */ protected function ashura(int $year, int $totalDays = 2): array { - return $this->getHoliday(self::ashura, $year, $totalDays); + return $this->getMultiDayHoliday(self::ashura, $year, $totalDays); + } + + protected function arafat(int $year): CarbonImmutable + { + return $this->getSingleDayHoliday(self::arafat, $year); + } + + protected function islamicNewYear(int $year): CarbonImmutable + { + return $this->getSingleDayHoliday(self::islamicNewYear, $year); + } + + protected function prophetMuhammadBirthday(int $year): CarbonImmutable + { + return $this->getSingleDayHoliday(self::prophetMuhammadBirthday, $year); + } + + /** @param array $collection */ + protected function getSingleDayHoliday(array $collection, int $year): CarbonImmutable + { + $date = $collection[$year] ?? null; + + if ($date === null) { + throw InvalidYear::range($this->countryCode(), 1970, 2037); + } + + $date = CarbonImmutable::createFromFormat('Y-m-d', "{$year}-{$date}")?->startOfDay(); + + if ($date === null) { + throw new InvalidFormatException("Invalid date for holiday"); + } + + return $date; } /** * @param array> $collection * @return array */ - protected function getHoliday(array $collection, int $year, int $totalDays): array + protected function getMultiDayHoliday(array $collection, int $year, int $totalDays): array { $date = $collection[$year] ?? null; diff --git a/src/Countries/Bahrain.php b/src/Countries/Bahrain.php index d01ed0eef..bfbfb26d1 100644 --- a/src/Countries/Bahrain.php +++ b/src/Countries/Bahrain.php @@ -33,7 +33,7 @@ class Bahrain extends Country implements HasTranslations, Islamic 2037 => '11-09', ]; - protected const arafatDay = [ + protected const arafat = [ 2020 => '07-30', 2021 => '07-19', 2022 => '07-09', @@ -167,9 +167,9 @@ public function islamicHolidays(int $year): array $ashura = $this->ashura($year); $holidays = [ - 'Arafat Day' => self::arafatDay[$year], - 'Islamic New Year' => self::islamicNewYear[$year], - 'Birthday of the Prophet Muhammad' => self::prophetMuhammadBirthday[$year], + 'Arafat Day' => $this->arafat($year), + 'Islamic New Year' => $this->islamicNewYear($year), + 'Birthday of the Prophet Muhammad' => $this->prophetMuhammadBirthday($year), ]; return array_merge($holidays, diff --git a/src/Countries/Egypt.php b/src/Countries/Egypt.php index 48d213cd9..f5d1308ba 100644 --- a/src/Countries/Egypt.php +++ b/src/Countries/Egypt.php @@ -244,9 +244,6 @@ public function defaultLocale(): string protected function allHolidays(int $year): array { - $fixedHolidays = $this->fixedHolidays($year); - $variableHolidays = $this->variableHolidays($year); - return array_merge([ 'New Year\'s Day' => '1-1', 'Flooding of the Nile' => '8-15', @@ -255,75 +252,23 @@ protected function allHolidays(int $year): array 'Nayrouz' => '9-11', 'September Equinox' => '9-22', 'December Solstice' => '12-21', - ], $fixedHolidays, $variableHolidays); + ], + $this->fixedHolidays($year), + $this->variableHolidays($year), + $this->islamicHolidays($year), + ); } - /** - * @return array - */ + /** @return array */ protected function variableHolidays(int $year): array { $orthodoxEaster = $this->orthodoxEaster($year); - $eidAlFitrDates = $this->getIslamicHolidayDatesForYear(self::eidAlFitr, $year, 'Eid al-Fitr', 3); - $eidAlAdhaDates = $this->getIslamicHolidayDatesForYear(self::eidAlAdha, $year, 'Eid al-Adha', 4); - $arafatDayDates = $this->getIslamicHolidayDatesForYear(self::arafat, $year, 'Arafat Day'); - $islamicNewYearDates = $this->getIslamicHolidayDatesForYear(self::islamicNewYear, $year, 'Islamic New Year'); - $ashuraDates = $this->getIslamicHolidayDatesForYear(self::ashura, $year, 'Ashura'); - $prophetMuhammadBirthdayDates = $this->getIslamicHolidayDatesForYear(self::prophetMuhammadBirthday, $year, 'Birthday of the Prophet Muhammad'); - - return array_merge([ + return [ 'Coptic Good Friday' => $orthodoxEaster->subDays(2)->toImmutable(), 'Coptic Holy Saturday' => $orthodoxEaster->subDays()->toImmutable(), 'Coptic Easter Sunday' => $orthodoxEaster->toImmutable(), - ], $eidAlFitrDates, $eidAlAdhaDates, $arafatDayDates, $islamicNewYearDates, $ashuraDates, $prophetMuhammadBirthdayDates); - } - - /** - * Prepare holiday dates for the given year. - * - * @param array $holidayDates Array mapping years to dates. - * @param int $year The year for which to prepare holiday dates. - * @param string $holidayName The name of the holiday. - * @param int $duration The duration of the holiday in days. - * @return array An array of holiday dates. - */ - private function getIslamicHolidayDatesForYear(array $holidayDates, int $year, string $holidayName, int $duration = 1): array - { - $dates = []; - - /** - * No reliable sources exist for Islamic holidays observed in Egypt prior to 2005. - * So we'll only calculate holidays from 2005 onwards. - * - * @see https://www.timeanddate.com/holidays/egypt - */ - if ($year < 2005) { - throw InvalidYear::yearTooLow(2005); - } - - if (! isset($holidayDates[$year])) { - return $dates; - } - - $startDay = CarbonImmutable::createFromFormat('Y-m-d', sprintf('%s-%s', $year, $holidayDates[$year])); - - if ($startDay === null) { - throw new InvalidFormatException("Invalid date format for holiday: {$holidayName}"); - } - - if ($duration === 1) { - // For single-day holidays, use the holiday name without "Day" - $dates[$holidayName] = $startDay; - } else { - // For multi-day holidays, append "Day N" for the second day onwards - for ($i = 0; $i < $duration; $i++) { - $dayLabel = $i === 0 ? $holidayName : sprintf('%s Day %d', $holidayName, $i + 1); - $dates[$dayLabel] = $startDay->addDays($i); - } - } - - return $dates; + ]; } /** @@ -349,9 +294,34 @@ private function fixedHolidays(int $year): array return $holidays; } - /** - * @return array - */ + public function islamicHolidays(int $year): array + { + /** + * No reliable sources exist for Islamic holidays observed in Egypt prior to 2005. + * So we'll only calculate holidays from 2005 onwards. + * @see https://www.timeanddate.com/holidays/egypt + */ + if ($year < 2005) { + throw InvalidYear::yearTooLow(2005); + } + + $eidAlFitr = $this->eidAlFitr($year); + $eidAlAdha = $this->eidAlAdha($year); + $ashura = $this->ashura($year, 1); + + return array_merge( + [ + 'Arafat Day' => $this->arafat($year), + 'Islamic New Year' => $this->islamicNewYear($year), + 'Birthday of the Prophet Muhammad' => $this->prophetMuhammadBirthday($year), + ], + $this->convertPeriods($eidAlAdha[0], $year, 'Eid al-Adha'), + $this->convertPeriods($eidAlFitr[0], $year, 'Eid al-Fitr'), + $this->convertPeriods($ashura[0], $year, 'Ashura'), + ); + } + + /** @return array */ private function adjustForWeekend(string $name, CarbonImmutable $date): array { $adjustedHolidays = []; @@ -370,9 +340,4 @@ private function adjustForWeekend(string $name, CarbonImmutable $date): array return $adjustedHolidays; } - - public function islamicHolidays(int $year): array - { - // TODO: Implement islamicHolidays() method. - } } From 4dd9815e40851b05acfc71c251e4f9354a787faa Mon Sep 17 00:00:00 2001 From: Nielsvanpach Date: Fri, 22 Mar 2024 13:21:41 +0000 Subject: [PATCH 144/175] Fix styling --- src/Calendars/IslamicCalendar.php | 2 +- src/Countries/Egypt.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Calendars/IslamicCalendar.php b/src/Calendars/IslamicCalendar.php index 9eb1fc0eb..33b6be64f 100644 --- a/src/Calendars/IslamicCalendar.php +++ b/src/Calendars/IslamicCalendar.php @@ -56,7 +56,7 @@ protected function getSingleDayHoliday(array $collection, int $year): CarbonImmu $date = CarbonImmutable::createFromFormat('Y-m-d', "{$year}-{$date}")?->startOfDay(); if ($date === null) { - throw new InvalidFormatException("Invalid date for holiday"); + throw new InvalidFormatException('Invalid date for holiday'); } return $date; diff --git a/src/Countries/Egypt.php b/src/Countries/Egypt.php index f5d1308ba..d33e89fc1 100644 --- a/src/Countries/Egypt.php +++ b/src/Countries/Egypt.php @@ -4,7 +4,6 @@ use Carbon\CarbonImmutable; use Carbon\CarbonInterface; -use Carbon\Exceptions\InvalidFormatException; use Spatie\Holidays\Calendars\IslamicCalendar; use Spatie\Holidays\Concerns\Translatable; use Spatie\Holidays\Contracts\HasTranslations; @@ -299,6 +298,7 @@ public function islamicHolidays(int $year): array /** * No reliable sources exist for Islamic holidays observed in Egypt prior to 2005. * So we'll only calculate holidays from 2005 onwards. + * * @see https://www.timeanddate.com/holidays/egypt */ if ($year < 2005) { From 20cc6749d4680e8ae1a9aa23e449386a98af07a7 Mon Sep 17 00:00:00 2001 From: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> Date: Fri, 22 Mar 2024 14:23:17 +0100 Subject: [PATCH 145/175] change signature --- src/Countries/Bahrain.php | 6 +++--- src/Countries/Country.php | 4 ++-- src/Countries/Egypt.php | 6 +++--- src/Countries/Turkey.php | 8 ++++---- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/Countries/Bahrain.php b/src/Countries/Bahrain.php index bfbfb26d1..6fcf009d6 100644 --- a/src/Countries/Bahrain.php +++ b/src/Countries/Bahrain.php @@ -173,9 +173,9 @@ public function islamicHolidays(int $year): array ]; return array_merge($holidays, - $this->convertPeriods($eidAlAdha[0], $year, 'Eid al-Adha'), - $this->convertPeriods($eidAlFitr[0], $year, 'Eid al-Fitr'), - $this->convertPeriods($ashura[0], $year, 'Ashura'), + $this->convertPeriods('Eid al-Adha', $year, $eidAlAdha[0]), + $this->convertPeriods('Eid al-Fitr', $year, $eidAlFitr[0]), + $this->convertPeriods('Ashura', $year, $ashura[0]), ); } } diff --git a/src/Countries/Country.php b/src/Countries/Country.php index a6ab1d72a..4fbf79b7c 100644 --- a/src/Countries/Country.php +++ b/src/Countries/Country.php @@ -135,9 +135,9 @@ protected function ensureYearCanBeCalculated(int $year): void * @return array */ protected function convertPeriods( - CarbonPeriod $period, - int $year, string $name, + int $year, + CarbonPeriod $period, string $suffix = 'Day', string $prefix = '', bool $includeEve = false, diff --git a/src/Countries/Egypt.php b/src/Countries/Egypt.php index d33e89fc1..bb3e5c743 100644 --- a/src/Countries/Egypt.php +++ b/src/Countries/Egypt.php @@ -315,9 +315,9 @@ public function islamicHolidays(int $year): array 'Islamic New Year' => $this->islamicNewYear($year), 'Birthday of the Prophet Muhammad' => $this->prophetMuhammadBirthday($year), ], - $this->convertPeriods($eidAlAdha[0], $year, 'Eid al-Adha'), - $this->convertPeriods($eidAlFitr[0], $year, 'Eid al-Fitr'), - $this->convertPeriods($ashura[0], $year, 'Ashura'), + $this->convertPeriods('Eid al-Adha', $year, $eidAlAdha[0]), + $this->convertPeriods('Eid al-Fitr', $year, $eidAlFitr[0]), + $this->convertPeriods('Ashura', $year, $ashura[0]), ); } diff --git a/src/Countries/Turkey.php b/src/Countries/Turkey.php index 5a5b164a0..aafd8184e 100644 --- a/src/Countries/Turkey.php +++ b/src/Countries/Turkey.php @@ -213,19 +213,19 @@ public function islamicHolidays(int $year): array $eidAlAdha = $this->eidAlAdha($year); $holidays = array_merge( - $this->convertPeriods($eidAlAdha[0], $year, 'Eid al-Adha', includeEve: true), - $this->convertPeriods($eidAlFitr[0], $year, 'Eid al-Fitr', includeEve: true), + $this->convertPeriods('Eid al-Adha', $year, $eidAlAdha[0], includeEve: true), + $this->convertPeriods('Eid al-Fitr', $year, $eidAlFitr[0], includeEve: true), ); if (count($eidAlAdha) > 1) { $holidays = array_merge($holidays, - $this->convertPeriods($eidAlAdha[1], $year, '2. Eid al-Adha', includeEve: true), + $this->convertPeriods('2. Eid al-Adha', $year, $eidAlAdha[1], includeEve: true), ); } if (count($eidAlFitr) > 1) { $holidays = array_merge($holidays, - $this->convertPeriods($eidAlFitr[1], $year, '2. Eid al-Fitr', includeEve: true), + $this->convertPeriods('2. Eid al-Fitr', $year, $eidAlFitr[1], includeEve: true), ); } From 048ca870870e241aebc5c6086cf1978db1a35f0d Mon Sep 17 00:00:00 2001 From: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> Date: Fri, 22 Mar 2024 14:23:52 +0100 Subject: [PATCH 146/175] fix phpstan version --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 1d2d8065e..332946a9f 100644 --- a/composer.json +++ b/composer.json @@ -28,7 +28,7 @@ "laravel/pint": "^1.0", "laravel/prompts": "^0.1.15", "pestphp/pest": "^2.31", - "phpstan/phpstan": "1.10.60", + "phpstan/phpstan": "1.10.56", "spatie/invade": "^2.0", "spatie/ray": "^1.40.1", "symfony/var-dumper": "^6.4" From 0bb161fda2ccf8ce8efce70eaf0b4f1d1517b3fc Mon Sep 17 00:00:00 2001 From: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> Date: Fri, 22 Mar 2024 14:36:48 +0100 Subject: [PATCH 147/175] use Islamic contract on Albania --- src/Countries/Albania.php | 85 ++++++++++++++++++++------------------- 1 file changed, 44 insertions(+), 41 deletions(-) diff --git a/src/Countries/Albania.php b/src/Countries/Albania.php index 65424c769..29f0868f0 100644 --- a/src/Countries/Albania.php +++ b/src/Countries/Albania.php @@ -3,14 +3,45 @@ namespace Spatie\Holidays\Countries; use Carbon\CarbonImmutable; +use Spatie\Holidays\Calendars\IslamicCalendar; use Spatie\Holidays\Concerns\Translatable; use Spatie\Holidays\Contracts\HasTranslations; +use Spatie\Holidays\Contracts\Islamic; use Spatie\Holidays\Exceptions\InvalidYear; -class Albania extends Country implements HasTranslations +class Albania extends Country implements HasTranslations, Islamic { + use IslamicCalendar; use Translatable; + public const eidAlFitr = [ + 2024 => '04-10', + 2025 => '03-30', + 2026 => '03-20', + 2027 => '03-09', + 2028 => '02-26', + 2029 => '02-14', + 2030 => '02-04', + 2031 => '01-24', + 2032 => '01-14', + 2033 => '01-02', + 2034 => '12-12', + ]; + + public const eidAlAdha = [ + 2024 => '06-17', + 2025 => '06-07', + 2026 => '05-27', + 2027 => '05-17', + 2028 => '05-05', + 2029 => '04-24', + 2030 => '04-14', + 2031 => '04-03', + 2032 => '03-22', + 2033 => '03-12', + 2034 => '03-01', + ]; + public function countryCode(): string { return 'al'; @@ -33,7 +64,10 @@ protected function allHolidays(int $year): array 'Dita e Çlirimit' => '11-29', 'Dita Kombëtare e Rinisë' => '12-08', 'Krishtlindja' => '12-25', - ], $this->variableHolidays($year)); + ], + $this->variableHolidays($year), + $this->islamicHolidays($year), + ); } /** @return array */ @@ -42,53 +76,22 @@ protected function variableHolidays(int $year): array return array_filter([ 'E diela e Pashkëve Katolike' => $this->easter($year), 'E diela e Pashkëve Ortodokse' => $this->orthodoxEaster($year), - 'Dita e Bajramit të Madh' => $this->getEidAlFitrHoliday($year), - 'Dita e Kurban Bajramit' => $this->getEidAlAdhaHoliday($year), ]); } - private function getEidAlFitrHoliday(int $year): string + public function islamicHolidays(int $year): array { /** * Provided until 2034 by qppstudio.net. * https://www.qppstudio.net/global-holidays-observances/eid-al-fitr-end-of-ramadan.htm */ - return match ($year) { - 2024 => '04-10', - 2025 => '03-30', - 2026 => '03-20', - 2027 => '03-09', - 2028 => '02-26', - 2029 => '02-14', - 2030 => '02-04', - 2031 => '01-24', - 2032 => '01-14', - 2033 => '01-02', - 2034 => '12-12', - default => throw InvalidYear::range('Albania', 2024, 2034), - }; - } + if ($year < 2024 || $year > 2034) { + throw InvalidYear::range('Albania', 2024, 2034); + } - private function getEidAlAdhaHoliday(int $year): string - { - /** - * Tentative dates. - * Provided until 2034 by timeanddate.com. - * https://www.timeanddate.com/holidays/us/eid-al-adha - */ - return match ($year) { - 2024 => '06-17', - 2025 => '06-07', - 2026 => '05-27', - 2027 => '05-17', - 2028 => '05-05', - 2029 => '04-24', - 2030 => '04-14', - 2031 => '04-03', - 2032 => '03-22', - 2033 => '03-12', - 2034 => '03-01', - default => throw InvalidYear::range('Albania', 2024, 2034), - }; + return [ + 'Dita e Bajramit të Madh' => self::eidAlFitr[$year], + 'Dita e Kurban Bajramit' => self::eidAlAdha[$year], + ]; } } From ffa73826d01f86ce60e89670548129875247223d Mon Sep 17 00:00:00 2001 From: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> Date: Fri, 22 Mar 2024 14:52:03 +0100 Subject: [PATCH 148/175] implement Islamic interface on Syria --- composer.json | 2 +- src/Countries/Canada.php | 1 + src/Countries/Syria.php | 17 ++++++++++++++--- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/composer.json b/composer.json index 332946a9f..5937dbf4a 100644 --- a/composer.json +++ b/composer.json @@ -28,7 +28,7 @@ "laravel/pint": "^1.0", "laravel/prompts": "^0.1.15", "pestphp/pest": "^2.31", - "phpstan/phpstan": "1.10.56", + "phpstan/phpstan": "^1.10.56", "spatie/invade": "^2.0", "spatie/ray": "^1.40.1", "symfony/var-dumper": "^6.4" diff --git a/src/Countries/Canada.php b/src/Countries/Canada.php index f1350e198..b12f273dc 100644 --- a/src/Countries/Canada.php +++ b/src/Countries/Canada.php @@ -31,6 +31,7 @@ protected function variableHolidays(int $year): array { $easter = $this->easter($year); + /** @var CarbonImmutable $victoriaDay */ $victoriaDay = (new CarbonImmutable("last monday of May $year"))->startOfDay(); if ($victoriaDay->day < 25) { diff --git a/src/Countries/Syria.php b/src/Countries/Syria.php index 51d9e5f68..ae6b95245 100644 --- a/src/Countries/Syria.php +++ b/src/Countries/Syria.php @@ -3,11 +3,14 @@ namespace Spatie\Holidays\Countries; use Carbon\CarbonImmutable; +use Spatie\Holidays\Calendars\IslamicCalendar; use Spatie\Holidays\Concerns\Translatable; use Spatie\Holidays\Contracts\HasTranslations; +use Spatie\Holidays\Contracts\Islamic; -class Syria extends Country implements HasTranslations +class Syria extends Country implements HasTranslations, Islamic { + use IslamicCalendar; use Translatable; public function countryCode(): string @@ -22,6 +25,7 @@ public function defaultLocale(): string protected function allHolidays(int $year): array { + // @todo the islamic holidays should be calculated return array_merge([ "New Year\n's Day" => '01-01', "Mother\n's Day" => '03-21', @@ -37,13 +41,20 @@ protected function allHolidays(int $year): array 'The commemoration of the birth of the Prophet Muhammad' => '09-15', 'The October Liberation War' => '10-06', 'Christmas' => '12-25', - ], $this->variableHolidays($year)); + ], + $this->variableHolidays($year), + $this->islamicHolidays($year), + ); } /** @return array */ protected function variableHolidays(int $year): array { - // The variable holidays all follow the lunar calendar, so their dates are not confirmed. return []; } + + public function islamicHolidays(int $year): array + { + return []; // @todo + } } From 84538f4cf1df6397b0d3e11109ac18b921685b9f Mon Sep 17 00:00:00 2001 From: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> Date: Fri, 22 Mar 2024 14:54:55 +0100 Subject: [PATCH 149/175] phpstan --- phpstan-baseline.neon | 20 ++++++++++++++++++++ src/Countries/Syria.php | 2 +- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index b41917f8c..a8a609863 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -1,5 +1,25 @@ parameters: ignoreErrors: + - + message: "#^Access to undefined constant Spatie\\\\Holidays\\\\Countries\\\\Albania\\:\\:arafat\\.$#" + count: 1 + path: src/Countries/Albania.php + + - + message: "#^Access to undefined constant Spatie\\\\Holidays\\\\Countries\\\\Albania\\:\\:ashura\\.$#" + count: 1 + path: src/Countries/Albania.php + + - + message: "#^Access to undefined constant Spatie\\\\Holidays\\\\Countries\\\\Albania\\:\\:islamicNewYear\\.$#" + count: 1 + path: src/Countries/Albania.php + + - + message: "#^Access to undefined constant Spatie\\\\Holidays\\\\Countries\\\\Albania\\:\\:prophetMuhammadBirthday\\.$#" + count: 1 + path: src/Countries/Albania.php + - message: "#^Argument of an invalid type Carbon\\\\CarbonPeriod supplied for foreach, only iterables are supported\\.$#" count: 1 diff --git a/src/Countries/Syria.php b/src/Countries/Syria.php index ae6b95245..89d278b99 100644 --- a/src/Countries/Syria.php +++ b/src/Countries/Syria.php @@ -10,7 +10,7 @@ class Syria extends Country implements HasTranslations, Islamic { - use IslamicCalendar; + //use IslamicCalendar; use Translatable; public function countryCode(): string From 69ed981a2997c112e7218c8422a101c8be4724a5 Mon Sep 17 00:00:00 2001 From: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> Date: Fri, 22 Mar 2024 15:03:00 +0100 Subject: [PATCH 150/175] phpstan --- src/Countries/Canada.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Countries/Canada.php b/src/Countries/Canada.php index 021738ac9..dd606a430 100644 --- a/src/Countries/Canada.php +++ b/src/Countries/Canada.php @@ -32,7 +32,7 @@ protected function variableHolidays(int $year): array $easter = $this->easter($year); // the Monday preceding May 25 - $victoriaDay = CarbonImmutable::createFromFormat('Y-m-d', "{$year}-05-25") + $victoriaDay = CarbonImmutable::createFromDate($year, 5, 25) ->previous('Monday'); return [ From 6ce8f027ab95da864360716eac2ad78d2e965667 Mon Sep 17 00:00:00 2001 From: DesaBL Date: Fri, 22 Mar 2024 15:22:45 +0100 Subject: [PATCH 151/175] Add holidays for Bosnia And Herzegovina (#203) * Add holidays for Bosnia And Herzegovina * Add more tests and translation for Bosnia and Herzegovina --- lang/bosniaAndHerzegovina/en/holidays.json | 25 ++++++ src/Countries/BosniaAndHerzegovina.php | 87 +++++++++++++++++++ ...late__bosnia_and_herzegovina_holidays.snap | 34 ++++++++ ...ulate_bosnia_and_herzegovina_holidays.snap | 34 ++++++++ ...t_can_translate_holidays_into_english.snap | 34 ++++++++ tests/Countries/BosniaAndHerzegovinaTest.php | 47 ++++++++++ 6 files changed, 261 insertions(+) create mode 100644 lang/bosniaAndHerzegovina/en/holidays.json create mode 100644 src/Countries/BosniaAndHerzegovina.php create mode 100644 tests/.pest/snapshots/Countries/BosniaAndHerzegovinaTest/it_can_calculate__bosnia_and_herzegovina_holidays.snap create mode 100644 tests/.pest/snapshots/Countries/BosniaAndHerzegovinaTest/it_can_calculate_bosnia_and_herzegovina_holidays.snap create mode 100644 tests/.pest/snapshots/Countries/BosniaAndHerzegovinaTest/it_can_translate_holidays_into_english.snap create mode 100644 tests/Countries/BosniaAndHerzegovinaTest.php 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'); +}); From 147eaf81adfaf4d8d3e2c854c808006d84663c29 Mon Sep 17 00:00:00 2001 From: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> Date: Fri, 22 Mar 2024 15:31:42 +0100 Subject: [PATCH 152/175] fixes for Bosnia --- src/Countries/BosniaAndHerzegovina.php | 13 +++++++++++-- tests/Countries/BosniaAndHerzegovinaTest.php | 2 +- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/Countries/BosniaAndHerzegovina.php b/src/Countries/BosniaAndHerzegovina.php index 0e28ac74a..24021be13 100644 --- a/src/Countries/BosniaAndHerzegovina.php +++ b/src/Countries/BosniaAndHerzegovina.php @@ -3,11 +3,15 @@ namespace Spatie\Holidays\Countries; use Carbon\CarbonImmutable; +use Spatie\Holidays\Concerns\Translatable; +use Spatie\Holidays\Contracts\HasTranslations; use Spatie\Holidays\Exceptions\InvalidRegion; -class BosniaAndHerzegovina extends Country +class BosniaAndHerzegovina extends Country implements HasTranslations { - private const REGIONS = [ + use Translatable; + + protected const REGIONS = [ 'ba-rs', 'ba-fbih', 'ba-bd', @@ -25,6 +29,11 @@ public function countryCode(): string return 'ba'; } + public function defaultLocale(): string + { + return 'hr'; + } + protected function allHolidays(int $year): array { return array_merge([ diff --git a/tests/Countries/BosniaAndHerzegovinaTest.php b/tests/Countries/BosniaAndHerzegovinaTest.php index 9dcc2cf5d..1392ca2e8 100644 --- a/tests/Countries/BosniaAndHerzegovinaTest.php +++ b/tests/Countries/BosniaAndHerzegovinaTest.php @@ -34,7 +34,7 @@ }); it('can translate holidays into english', function () { - $holidays = Holidays::for(country: 'ba', locale: 'en', year: 2024)->get(); + $holidays = Holidays::for(country: 'ba', year: 2024, locale: 'en')->get(); expect($holidays) ->toBeArray() From e5e23caf77fe089117b121e3a17f5f69c4c22b70 Mon Sep 17 00:00:00 2001 From: Nielsvanpach Date: Fri, 22 Mar 2024 14:32:28 +0000 Subject: [PATCH 153/175] Update CHANGELOG --- CHANGELOG.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index c80882d25..cecec3255 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,19 @@ All notable changes to `holidays` will be documented in this file. +## 1.9.0 - 2024-03-22 + +### What's Changed + +* Implement Islamic calendar by @Nielsvanpach in https://github.com/spatie/holidays/pull/214 +* Add holidays for Bosnia And Herzegovina by @DesaBL in https://github.com/spatie/holidays/pull/203 + +### New Contributors + +* @DesaBL made their first contribution in https://github.com/spatie/holidays/pull/203 + +**Full Changelog**: https://github.com/spatie/holidays/compare/1.8.0...1.9.0 + ## 1.8.0 - 2024-03-08 ### What's Changed From 9d68e8ee23e3d0b4cf7b1c666ed6f9f0c6bc54a4 Mon Sep 17 00:00:00 2001 From: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> Date: Fri, 22 Mar 2024 16:27:21 +0100 Subject: [PATCH 154/175] add extension to composer --- composer.json | 1 + 1 file changed, 1 insertion(+) diff --git a/composer.json b/composer.json index 5937dbf4a..58ec631ed 100644 --- a/composer.json +++ b/composer.json @@ -22,6 +22,7 @@ "require": { "php": "^8.1", "ext-intl": "*", + "ext-calendar": "*", "nesbot/carbon": "^2.72.1|^3.0" }, "require-dev": { From 3d7ebb4650a251b16ace936741b23b96d7992132 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 26 Mar 2024 08:51:07 +0100 Subject: [PATCH 155/175] Bump dependabot/fetch-metadata from 1.6.0 to 2.0.0 (#215) Bumps [dependabot/fetch-metadata](https://github.com/dependabot/fetch-metadata) from 1.6.0 to 2.0.0. - [Release notes](https://github.com/dependabot/fetch-metadata/releases) - [Commits](https://github.com/dependabot/fetch-metadata/compare/v1.6.0...v2.0.0) --- updated-dependencies: - dependency-name: dependabot/fetch-metadata dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .github/workflows/dependabot-auto-merge.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/dependabot-auto-merge.yml b/.github/workflows/dependabot-auto-merge.yml index 70d8e7bda..1d4d5085b 100644 --- a/.github/workflows/dependabot-auto-merge.yml +++ b/.github/workflows/dependabot-auto-merge.yml @@ -14,7 +14,7 @@ jobs: - name: Dependabot metadata id: metadata - uses: dependabot/fetch-metadata@v1.6.0 + uses: dependabot/fetch-metadata@v2.0.0 with: github-token: "${{ secrets.GITHUB_TOKEN }}" From 82767e7af4d06648e544fb8b8089d9aa6e6bf43f Mon Sep 17 00:00:00 2001 From: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> Date: Fri, 29 Mar 2024 14:31:37 +0100 Subject: [PATCH 156/175] rerun --- .github/workflows/run-tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index e12602421..ad72cbe09 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -14,7 +14,7 @@ jobs: stability: [prefer-lowest, prefer-stable] carbon: [2.72, 3.0] - name: P${{ matrix.php }} - ${{ matrix.stability }} - ${{ matrix.os }} - Carbon ${{ matrix.carbon }} + name: P${{ matrix.php }} - ${{ matrix.stability }} - Carbon ${{ matrix.carbon }} steps: - name: Checkout code From 4c2c092de2ba3c3cd7e58c7aa7b04250bb2c051c Mon Sep 17 00:00:00 2001 From: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> Date: Fri, 29 Mar 2024 14:34:17 +0100 Subject: [PATCH 157/175] run complete matrix --- .github/workflows/run-tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index ad72cbe09..868a13cfd 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -7,7 +7,7 @@ jobs: runs-on: ${{ matrix.os }} timeout-minutes: 5 strategy: - fail-fast: true + fail-fast: false matrix: os: [ubuntu-latest] php: [8.3, 8.2, 8.1] From 795598951ab28745f66886089a38193f825e6559 Mon Sep 17 00:00:00 2001 From: Olin <45310038+OlinB@users.noreply.github.com> Date: Tue, 2 Apr 2024 17:22:49 +0200 Subject: [PATCH 158/175] Fix the Holidays in French speaking Switzerland (#217) * correct Geneva holidays using Art. 32 from https://silgeneve.ch/legis/index.aspx as reference * add missing Vaud (Switzerland) holiday * add missing Neuchatel (Switzerland) holidays reference: https://www.ne.ch/themes/travail/Pages/jours-feries.aspx * add french translations to missing holidays * correct the Holidays for Fribourg (Switzerland) and add a special locale for the reformed part of Fribourg because it has different holidays source: https://www.fr.ch/travail-et-entreprises/employes/jours-feries * Add missing Italian translations for swiss holidays * Add the new regions to the REGIONS array * Tests and add 2 more missing holidays (CH) --- lang/switzerland/fr/holidays.json | 9 ++++- lang/switzerland/it/holidays.json | 9 ++++- src/Countries/Switzerland.php | 56 ++++++++++++++++++++++++++++++- 3 files changed, 71 insertions(+), 3 deletions(-) diff --git a/lang/switzerland/fr/holidays.json b/lang/switzerland/fr/holidays.json index 28a04b822..44123e041 100644 --- a/lang/switzerland/fr/holidays.json +++ b/lang/switzerland/fr/holidays.json @@ -1,7 +1,9 @@ { "Neujahr": "Nouvel An", + "Neujahrs nächster tag": "Lendemain du Nouvel An", "Berchtoldstag": "Saint-Berthold", "Heilige Drei Könige": "Épiphanie", + "Neuenburger Republik tag": "Instauration de la République de Neuchâtel", "Josefstag": "Saint-Joseph", "Karfreitag": "Vendredi saint", "Ostermontag": "Lundi de Pâques", @@ -10,10 +12,15 @@ "Pfingstmontag": "Lundi de Pentecôte", "Fronleichnam": "Fête-Dieu", "Bundesfeier": "Fête nationale", + "Bundesfeier nächster tag": "Lendemain de la Fête nationale", "Maria Himmelfahrt": "Assomption", + "Genfer Fasten": "Jeûne genevois", "Buss- und Bettag": "Jeûne fédéral", + "Buss- und Bettag Montag": "Lundi du Jeûne fédéral", "Allerheiligen": "Toussaint", "Maria Empfängnis": "Immaculée Conception", "Weihnachtstag": "Noël", - "Stephanstag": "Saint-Étienne" + "Weihnachtsnächstertag": "Lendemain de Noël", + "Stephanstag": "Saint-Étienne", + "Genf Republik tag": "Instauration de la République de Genève" } diff --git a/lang/switzerland/it/holidays.json b/lang/switzerland/it/holidays.json index e62ec667e..11ab48f23 100644 --- a/lang/switzerland/it/holidays.json +++ b/lang/switzerland/it/holidays.json @@ -1,7 +1,9 @@ { "Neujahr": "Capodanno", + "Neujahrs nächster tag": "Il giorno dopo Capodanno", "Berchtoldstag": "San Silvestro", "Heilige Drei Könige": "Epifania", + "Neuenburger Republik tag": "Istituzione della Repubblica di Neuchâtel", "Josefstag": "San Giuseppe", "Karfreitag": "Venerdì Santo", "Ostermontag": "Lunedì di Pasqua", @@ -10,10 +12,15 @@ "Pfingstmontag": "Lunedì di Pentecoste", "Fronleichnam": "Corpus Domini", "Bundesfeier": "Festa nazionale", + "Bundesfeier nächster tag": "Il giorno dopo la festa nazionale", "Maria Himmelfahrt": "Assunzione", + "Genfer Fasten": "Jeûne genevois", "Buss- und Bettag": "Digiuno federale", + "Buss- und Bettag Montag": "Digiuno federale Lunedì", "Allerheiligen": "Ognissanti", "Maria Empfängnis": "Immacolata Concezione", "Weihnachtstag": "Natale", - "Stephanstag": "Santo Stefano" + "Weihnachtsnächstertag": "Il giorno dopo la festa di Natale", + "Stephanstag": "Santo Stefano", + "Genf Republik tag": "Istituzione della Repubblica di Ginevra" } diff --git a/src/Countries/Switzerland.php b/src/Countries/Switzerland.php index d9305fbf0..60b3b6881 100644 --- a/src/Countries/Switzerland.php +++ b/src/Countries/Switzerland.php @@ -19,6 +19,8 @@ class Switzerland extends Country implements HasTranslations 'ch-bs', 'ch-be', 'ch-fr', + 'ch-fr-c', + 'ch-fr-r', 'ch-ge', 'ch-gl', 'ch-gr', @@ -42,10 +44,14 @@ class Switzerland extends Country implements HasTranslations private const NEW_YEARS_DAY = 'Neujahr'; + private const NEW_YEARS_NEXT_DAY = 'Neujahrs nächster tag'; + private const BERCHTOLDS_DAY = 'Berchtoldstag'; private const THREE_KINGS_DAY = 'Heilige Drei Könige'; + private const NEUCHATEL_REPUBLIC_DAY = 'Neuenburger Republik tag'; + private const SAINT_JOSEPHS_DAY = 'Josefstag'; private const GOOD_FRIDAY = 'Karfreitag'; @@ -62,18 +68,28 @@ class Switzerland extends Country implements HasTranslations private const SWISS_NATIONAL_HOLIDAY = 'Bundesfeier'; + private const SWISS_NATIONAL_HOLIDAY_NEXT_DAY = 'Bundesfeier nächster tag'; + private const ASSUMPTION_DAY = 'Maria Himmelfahrt'; + private const GENEVA_DAY_OF_FASTING = 'Genfer Fasten'; + private const FEDERAL_DAY_OF_THANKSGIVING_REPENTANCE_AND_PRAYER = 'Buss- und Bettag'; + private const FEDERAL_DAY_OF_THANKSGIVING_REPENTANCE_AND_PRAYER_MONDAY = 'Buss- und Bettag Montag'; + private const ALL_SAINTS_DAY = 'Allerheiligen'; private const IMMACULATE_CONCEPTION = 'Maria Empfängnis'; private const CHRISTMAS_DAY = 'Weihnachtstag'; + private const CHRISTMAS_NEXT_DAY = 'Weihnachtsnächstertag'; + private const SAINT_STEPHENS_DAY = 'Stephanstag'; + private const GENEVA_REPUBLIC_DAY = 'Genf Republik tag'; + public function __construct(protected ?string $region = null) { if ($region !== null && ! in_array($region, self::REGIONS)) { @@ -110,19 +126,26 @@ public function regionalHolidays(int $year): array ]; $regionallyDifferentHolidays = [ + self::NEW_YEARS_NEXT_DAY => '01-02', self::BERCHTOLDS_DAY => '01-02', self::THREE_KINGS_DAY => '01-06', + self::NEUCHATEL_REPUBLIC_DAY => '03-01', self::SAINT_JOSEPHS_DAY => '03-19', self::GOOD_FRIDAY => $easter->subDays(2), self::EASTER_MONDAY => $easter->addDay(), self::LABOUR_DAY => '05-01', self::WHIT_MONDAY => $easter->addDays(50), self::CORPUS_CHRISTI => $easter->addDays(60), + self::SWISS_NATIONAL_HOLIDAY_NEXT_DAY => '08-02', self::ASSUMPTION_DAY => '08-15', + self::GENEVA_DAY_OF_FASTING => (new CarbonImmutable('first sunday of September '.$year, 'Europe/Zurich'))->addDays(4), // Thursday after the first Sunday of September self::FEDERAL_DAY_OF_THANKSGIVING_REPENTANCE_AND_PRAYER => new CarbonImmutable('third sunday of September '.$year, 'Europe/Zurich'), + self::FEDERAL_DAY_OF_THANKSGIVING_REPENTANCE_AND_PRAYER_MONDAY => (new CarbonImmutable('third sunday of September '.$year, 'Europe/Zurich'))->addDay(), self::ALL_SAINTS_DAY => '11-01', self::IMMACULATE_CONCEPTION => '12-08', self::SAINT_STEPHENS_DAY => '12-26', + self::CHRISTMAS_NEXT_DAY => '12-26', + self::GENEVA_REPUBLIC_DAY => '12-31', ]; $currentRegion = match ($this->region) { @@ -163,13 +186,26 @@ public function regionalHolidays(int $year): array self::WHIT_MONDAY, self::SAINT_STEPHENS_DAY, ], - 'ch-fr' => [ + 'ch-fr', 'ch-fr-c' => [ // Catholic part of the canton is the default + self::GOOD_FRIDAY, + self::CORPUS_CHRISTI, + self::ASSUMPTION_DAY, + self::ALL_SAINTS_DAY, + self::IMMACULATE_CONCEPTION, + ], + 'ch-fr-r' => [ // Reformed part of the canton has special legislation for holidays + self::NEW_YEARS_NEXT_DAY, self::GOOD_FRIDAY, + self::EASTER_MONDAY, + self::WHIT_MONDAY, + self::SAINT_STEPHENS_DAY, ], 'ch-ge' => [ self::GOOD_FRIDAY, self::EASTER_MONDAY, self::WHIT_MONDAY, + self::GENEVA_DAY_OF_FASTING, + self::GENEVA_REPUBLIC_DAY, ], 'ch-gl' => [ self::GOOD_FRIDAY, @@ -198,6 +234,7 @@ public function regionalHolidays(int $year): array self::SAINT_STEPHENS_DAY, ], 'ch-ne' => [ + self::NEUCHATEL_REPUBLIC_DAY, self::GOOD_FRIDAY, self::LABOUR_DAY, ], @@ -269,6 +306,7 @@ public function regionalHolidays(int $year): array self::GOOD_FRIDAY, self::EASTER_MONDAY, self::WHIT_MONDAY, + self::FEDERAL_DAY_OF_THANKSGIVING_REPENTANCE_AND_PRAYER_MONDAY, ], 'ch-vs' => [ self::SAINT_JOSEPHS_DAY, @@ -301,6 +339,22 @@ public function regionalHolidays(int $year): array ARRAY_FILTER_USE_KEY ); + // Some holidays only happen in some years in some regions + if (in_array($this->region, ['ch-ge', 'ch-ne']) && + (new CarbonImmutable("{$year}-01-01", 'Europe/Zurich'))->isSunday()) { + $regionalHolidays[self::NEW_YEARS_NEXT_DAY] = '01-02'; + } + + if (in_array($this->region, ['ch-ge']) && + (new CarbonImmutable("{$year}-08-01", 'Europe/Zurich'))->isSunday()) { + $regionalHolidays[self::SWISS_NATIONAL_HOLIDAY_NEXT_DAY] = '08-02'; + } + + if (in_array($this->region, ['ch-ge', 'ch-ne']) && + (new CarbonImmutable("{$year}-12-25", 'Europe/Zurich'))->isSunday()) { + $regionalHolidays[self::CHRISTMAS_NEXT_DAY] = '12-26'; + } + return array_merge($regionalHolidays, $sharedHolidays); } From 3f2f02537e109a464525256b02dffd9462ae20b8 Mon Sep 17 00:00:00 2001 From: Nielsvanpach Date: Tue, 2 Apr 2024 15:23:40 +0000 Subject: [PATCH 159/175] Update CHANGELOG --- CHANGELOG.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index cecec3255..1bb841704 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,20 @@ All notable changes to `holidays` will be documented in this file. +## 1.9.1 - 2024-04-02 + +### What's Changed + +* Bump dependabot/fetch-metadata from 1.6.0 to 2.0.0 by @dependabot in https://github.com/spatie/holidays/pull/215 +* Fix the Holidays in French speaking Switzerland by @OlinB in https://github.com/spatie/holidays/pull/217 + +### New Contributors + +* @dependabot made their first contribution in https://github.com/spatie/holidays/pull/215 +* @OlinB made their first contribution in https://github.com/spatie/holidays/pull/217 + +**Full Changelog**: https://github.com/spatie/holidays/compare/1.9.0...1.9.1 + ## 1.9.0 - 2024-03-22 ### What's Changed From c08108759af3d1ad31ac738207847a060c765cc5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=CA=8D=E1=B4=99=2E=CF=8Eo=C5=81=C6=92?= <4011175+mr-wolf-gb@users.noreply.github.com> Date: Wed, 3 Apr 2024 08:36:24 +0100 Subject: [PATCH 160/175] add Tunisia Holidays (#109) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * add Tunisia Holidays * fix Tunisia Hijri Holidays * fix PHPStan error * sync latest commits * change Hijri Dates to generated Like in turkey holidays * minor fixes * minor fixes * fix phpstan error * fix phpstan error * implement turkey method as trait for Hijri holidays * minor fix * move tunisia translations to correct dir * Update src/Countries/Tunisia.php Co-authored-by: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> * Update src/Countries/Tunisia.php Co-authored-by: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> * Update tests/Countries/TunisiaTest.php Co-authored-by: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> * Update tests/Countries/TunisiaTest.php Co-authored-by: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> * remove HijriCalendar * Fix phpstan fail test * Fix phpstan Ternary operator condition is always true. * Fix code to use IslamicCalendar * Fix translation add Araft day fix totalDays for tunisia --------- Co-authored-by: ʍᴙ.ώoŁƒ Co-authored-by: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> --- lang/tunisia/ar/holidays.json | 22 ++ lang/tunisia/en/holidays.json | 22 ++ lang/tunisia/fr/holidays.json | 22 ++ src/Countries/Tunisia.php | 279 ++++++++++++++++++ ...olidays_with_data_set___2024____2024_.snap | 62 ++++ ...olidays_with_data_set___2025____2025_.snap | 62 ++++ tests/Countries/TunisiaTest.php | 18 ++ 7 files changed, 487 insertions(+) create mode 100644 lang/tunisia/ar/holidays.json create mode 100644 lang/tunisia/en/holidays.json create mode 100644 lang/tunisia/fr/holidays.json create mode 100644 src/Countries/Tunisia.php create mode 100644 tests/.pest/snapshots/Countries/TunisiaTest/it_can_calculate_tunisia_holidays_with_data_set___2024____2024_.snap create mode 100644 tests/.pest/snapshots/Countries/TunisiaTest/it_can_calculate_tunisia_holidays_with_data_set___2025____2025_.snap create mode 100644 tests/Countries/TunisiaTest.php diff --git a/lang/tunisia/ar/holidays.json b/lang/tunisia/ar/holidays.json new file mode 100644 index 000000000..c0f4dca3e --- /dev/null +++ b/lang/tunisia/ar/holidays.json @@ -0,0 +1,22 @@ +{ + "New Year's Day'": "رأس السنة الميلادية", + "Independence Day": "عيد الاستقلال", + "Martyrs' Day": "عيد الشهداء", + "Labour Day": "عيد الشغل", + "Republic Day": "عيد الجمهورية", + "Women's Day": "عيد المرأة", + "Evacuation Day": "عيد الجلاء", + "Revolution and Youth Day": "عيد الثورة والشباب", + "Eid al-Fitr": "عيد الفطر", + "Eid al-Fitr Day 2": "عيد الفطر اليوم الثاني", + "Eid al-Fitr Day 3": "عيد الفطر اليوم الثالث", + "Eid al-Adha": "عيد الأضحى", + "Eid al-Adha Day 2": "عيد الأضحى اليوم الثاني", + "Eid al-Adha Day 3": "عيد الأضحى اليوم الثالث", + "Eid al-Adha Day 4": "عيد الأضحى اليوم الرابع", + "Islamic New Year": "رأس السنة الهجرية", + "Birthday of the Prophet Muhammad": "المولد النبوي الشريف", + "Arafat Day": "يوم عرفة (وقفة عيد الأضحى)", + "Day": "يوم" +} + diff --git a/lang/tunisia/en/holidays.json b/lang/tunisia/en/holidays.json new file mode 100644 index 000000000..9a3632685 --- /dev/null +++ b/lang/tunisia/en/holidays.json @@ -0,0 +1,22 @@ +{ + "New Year's Day'": "New Year's Day", + "Independence Day": "Independence Day", + "Martyrs' Day": "Martyrs' Day", + "Labour Day": "Labour Day", + "Republic Day": "Republic Day", + "Women's Day": "Women's Day", + "Evacuation Day": "Evacuation Day", + "Revolution and Youth Day": "Revolution and Youth Day", + "Eid al-Fitr": "Eid al-Fitr day 1", + "Eid al-Fitr Day 2": "Eid al-Fitr day 2", + "Eid al-Fitr Day 3": "Eid al-Fitr day 3", + "Eid al-Adha": "Eid al-Adha day 1", + "Eid al-Adha Day 2": "Eid al-Adha day 2", + "Eid al-Adha Day 3": "Eid al-Adha day 3", + "Eid al-Adha Day 4": "Eid al-Adha day 4", + "Islamic New Year": "Islamic new year", + "Birthday of the Prophet Muhammad": "Birthday of the Prophet Mohamed", + "Arafat Day": "Arafat Day", + "Day": "Day" +} + diff --git a/lang/tunisia/fr/holidays.json b/lang/tunisia/fr/holidays.json new file mode 100644 index 000000000..59d104fa6 --- /dev/null +++ b/lang/tunisia/fr/holidays.json @@ -0,0 +1,22 @@ +{ + "New Year's Day'": "Jour de l'An", + "Independence Day": "Fête de l'indépendance", + "Martyrs' Day": "Fête des Martyrs", + "Labour Day": "Fête du Travail", + "Republic Day": "Fête de la République", + "Women's Day": "Fête de la femme", + "Evacuation Day": "Fête d'évacuation", + "Revolution and Youth Day": "Fête de la Révolution et de la Jeunesse", + "Eid al-Fitr": "Eid al-Fitr 1er jour", + "Eid al-Fitr Day 2": "Eid al-Fitr 2e jour", + "Eid al-Fitr Day 3": "Eid al-Fitr 3e jour", + "Eid al-Adha": "Eid al-Adha", + "Eid al-Adha Day 2": "Eid al-Adha", + "Eid al-Adha Day 3": "Eid al-Adha", + "Eid al-Adha Day 4": "Eid al-Adha", + "Islamic New Year": "Nouvel an islamique", + "Birthday of the Prophet Muhammad": "Anniversaire du prophète Mohamed", + "Arafat Day": "Arafat Day", + "Day": "Jour" +} + diff --git a/src/Countries/Tunisia.php b/src/Countries/Tunisia.php new file mode 100644 index 000000000..a6bac81d2 --- /dev/null +++ b/src/Countries/Tunisia.php @@ -0,0 +1,279 @@ + '11-04', + 2006 => '10-24', + 2007 => '10-13', + 2008 => '10-02', + 2009 => '09-21', + 2010 => '09-10', + 2011 => '08-30', + 2012 => '08-19', + 2013 => '08-08', + 2014 => '07-28', + 2015 => '07-17', + 2016 => '07-07', + 2017 => '06-26', + 2018 => '06-15', + 2019 => '06-05', + 2020 => '05-24', + 2021 => '05-13', + 2022 => '05-02', + 2023 => '04-20', + 2024 => '04-10', + 2025 => '03-31', + 2026 => '03-21', + 2027 => '03-10', + 2028 => '02-27', + 2029 => '02-15', + 2030 => '02-04', + 2031 => '01-25', + 2032 => '01-15', + 2033 => '01-03', + 2034 => '12-13', + 2035 => '12-02', + 2036 => '11-20', + 2037 => '11-09', + ]; + + protected const arafat = [ + 2005 => '01-21', + 2006 => '01-10', + 2007 => '01-01', + 2008 => '12-09', + 2009 => '11-26', + 2010 => '11-15', + 2011 => '11-05', + 2012 => '10-25', + 2013 => '10-15', + 2014 => '10-04', + 2015 => '09-23', + 2016 => '09-11', + 2017 => '08-31', + 2018 => '08-20', + 2019 => '08-10', + 2020 => '07-30', + 2021 => '07-19', + 2022 => '07-09', + 2023 => '06-27', + 2024 => '06-16', + 2025 => '06-06', + 2026 => '05-26', + 2027 => '05-16', + 2028 => '05-05', + 2029 => '04-24', + 2030 => '04-13', + 2031 => '04-02', + 2032 => '03-21', + 2033 => '03-11', + 2034 => '03-01', + 2035 => '02-18', + 2036 => '02-07', + 2037 => '01-26', + ]; + protected const eidAlAdha = [ + 2005 => '01-22', + 2006 => '01-11', + 2007 => '01-02', + 2008 => '12-10', + 2009 => '11-27', + 2010 => '11-16', + 2011 => '11-06', + 2012 => '10-26', + 2013 => '10-16', + 2014 => '10-05', + 2015 => '09-24', + 2016 => '09-12', + 2017 => '08-31', + 2018 => '08-21', + 2019 => '08-11', + 2020 => '07-31', + 2021 => '07-20', + 2022 => '07-09', + 2023 => '06-28', + 2024 => '06-17', + 2025 => '06-07', + 2026 => '05-27', + 2027 => '05-17', + 2028 => '05-06', + 2029 => '04-25', + 2030 => '04-14', + 2031 => '04-03', + 2032 => '03-22', + 2033 => '03-12', + 2034 => '03-02', + 2035 => '02-19', + 2036 => '02-08', + 2037 => '01-27', + ]; + protected const islamicNewYear = [ + 2005 => '02-10', + 2006 => '01-31', + 2007 => '01-20', + 2008 => '01-10', + 2009 => '12-18', + 2010 => '12-07', + 2011 => '11-27', + 2012 => '11-15', + 2013 => '11-05', + 2014 => '10-25', + 2015 => '10-14', + 2016 => '10-03', + 2017 => '09-22', + 2018 => '09-11', + 2019 => '08-31', + 2020 => '08-20', + 2021 => '08-09', + 2022 => '07-30', + 2023 => '07-19', + 2024 => '07-08', + 2025 => '06-06', + 2026 => '06-17', + 2027 => '06-07', + 2028 => '05-26', + 2029 => '05-15', + 2030 => '05-05', + 2031 => '04-24', + 2032 => '04-12', + 2033 => '04-01', + 2034 => '03-22', + 2035 => '03-12', + 2036 => '02-29', + 2037 => '02-17', + ]; + protected const ashura = [ + 2005 => '02-19', + 2006 => '02-09', + 2007 => '01-29', + 2008 => '01-19', + 2009 => '12-27', + 2010 => '12-16', + 2011 => '12-06', + 2012 => '11-25', + 2013 => '11-15', + 2014 => '11-04', + 2015 => '10-24', + 2016 => '10-13', + 2017 => '10-02', + 2018 => '09-21', + 2019 => '09-10', + 2020 => '08-30', + 2021 => '08-19', + 2022 => '08-08', + 2023 => '07-28', + 2024 => '07-17', + 2025 => '07-07', + 2026 => '06-26', + 2027 => '06-15', + 2028 => '06-04', + 2029 => '05-24', + 2030 => '05-13', + 2031 => '05-02', + 2032 => '04-20', + 2033 => '04-10', + 2034 => '03-30', + 2035 => '03-19', + 2036 => '03-08', + 2037 => '02-25', + ]; + protected const prophetMuhammadBirthday = [ + 2005 => '04-21', + 2006 => '04-11', + 2007 => '03-31', + 2008 => '03-20', + 2009 => '03-09', + 2010 => '02-26', + 2011 => '02-16', + 2012 => '02-05', + 2013 => '01-24', + 2014 => '01-13', + 2015 => '12-23', + 2016 => '12-12', + 2017 => '12-01', + 2018 => '11-20', + 2019 => '11-09', + 2020 => '10-29', + 2021 => '10-21', + 2022 => '10-08', + 2023 => '09-28', + 2024 => '09-16', + 2025 => '09-06', + 2026 => '08-26', + 2027 => '08-15', + 2028 => '08-04', + 2029 => '07-25', + 2030 => '07-14', + 2031 => '07-03', + 2032 => '06-21', + 2033 => '06-10', + 2034 => '05-31', + 2035 => '05-21', + 2036 => '05-09', + 2037 => '04-29', + ]; + + /** + * @return string + */ + public function countryCode(): string + { + return 'tn'; + } + + public function defaultLocale(): string + { + return 'en'; + } + + protected function allHolidays(int $year): array + { + $revolutionHoliday = []; + + if (2022 > $year && $year >= 2011) { + $revolutionHoliday['Revolution and Youth Day'] = '01-14'; + } + + if ($year >= 2022) { + $revolutionHoliday['Revolution and Youth Day'] = '12-17'; + } + + return array_merge([ + 'New Year\'s Day' => '01-01', + 'Independence Day' => '03-20', + 'Martyrs\' Day' => '04-09', + 'Labour Day' => '05-01', + 'Republic Day' => '07-25', + 'Women\'s Day' => '08-13', + 'Evacuation Day' => '10-15', + ], $revolutionHoliday, $this->islamicHolidays($year)); + } + + public function islamicHolidays(int $year): array + { + $eidAlFitr = $this->eidAlFitr(year: $year, totalDays: 2); + $eidAlAdha = $this->eidAlAdha(year: $year, totalDays: 2); + + return array_merge( + [ + 'Arafat Day' => $this->arafat($year), + 'Islamic New Year' => $this->islamicNewYear($year), + 'Birthday of the Prophet Muhammad' => $this->prophetMuhammadBirthday($year), + ], + $this->convertPeriods(name: 'Eid al-Fitr', year: $year, period: $eidAlFitr[0]), + $this->convertPeriods(name: 'Eid al-Adha', year: $year, period: $eidAlAdha[0]), + ); + } + +} diff --git a/tests/.pest/snapshots/Countries/TunisiaTest/it_can_calculate_tunisia_holidays_with_data_set___2024____2024_.snap b/tests/.pest/snapshots/Countries/TunisiaTest/it_can_calculate_tunisia_holidays_with_data_set___2024____2024_.snap new file mode 100644 index 000000000..ea825b988 --- /dev/null +++ b/tests/.pest/snapshots/Countries/TunisiaTest/it_can_calculate_tunisia_holidays_with_data_set___2024____2024_.snap @@ -0,0 +1,62 @@ +[ + { + "name": "New Year's Day", + "date": "2024-01-01" + }, + { + "name": "Independence Day", + "date": "2024-03-20" + }, + { + "name": "Martyrs' Day", + "date": "2024-04-09" + }, + { + "name": "Eid al-Fitr day 1", + "date": "2024-04-10" + }, + { + "name": "Eid al-Fitr day 2", + "date": "2024-04-11" + }, + { + "name": "Labour Day", + "date": "2024-05-01" + }, + { + "name": "Arafat Day", + "date": "2024-06-16" + }, + { + "name": "Eid al-Adha day 1", + "date": "2024-06-17" + }, + { + "name": "Eid al-Adha day 2", + "date": "2024-06-18" + }, + { + "name": "Islamic new year", + "date": "2024-07-08" + }, + { + "name": "Republic Day", + "date": "2024-07-25" + }, + { + "name": "Women's Day", + "date": "2024-08-13" + }, + { + "name": "Birthday of the Prophet Mohamed", + "date": "2024-09-16" + }, + { + "name": "Evacuation Day", + "date": "2024-10-15" + }, + { + "name": "Revolution and Youth Day", + "date": "2024-12-17" + } +] \ No newline at end of file diff --git a/tests/.pest/snapshots/Countries/TunisiaTest/it_can_calculate_tunisia_holidays_with_data_set___2025____2025_.snap b/tests/.pest/snapshots/Countries/TunisiaTest/it_can_calculate_tunisia_holidays_with_data_set___2025____2025_.snap new file mode 100644 index 000000000..8074f3583 --- /dev/null +++ b/tests/.pest/snapshots/Countries/TunisiaTest/it_can_calculate_tunisia_holidays_with_data_set___2025____2025_.snap @@ -0,0 +1,62 @@ +[ + { + "name": "New Year's Day", + "date": "2025-01-01" + }, + { + "name": "Independence Day", + "date": "2025-03-20" + }, + { + "name": "Eid al-Fitr day 1", + "date": "2025-03-31" + }, + { + "name": "Eid al-Fitr day 2", + "date": "2025-04-01" + }, + { + "name": "Martyrs' Day", + "date": "2025-04-09" + }, + { + "name": "Labour Day", + "date": "2025-05-01" + }, + { + "name": "Arafat Day", + "date": "2025-06-06" + }, + { + "name": "Islamic new year", + "date": "2025-06-06" + }, + { + "name": "Eid al-Adha day 1", + "date": "2025-06-07" + }, + { + "name": "Eid al-Adha day 2", + "date": "2025-06-08" + }, + { + "name": "Republic Day", + "date": "2025-07-25" + }, + { + "name": "Women's Day", + "date": "2025-08-13" + }, + { + "name": "Birthday of the Prophet Mohamed", + "date": "2025-09-06" + }, + { + "name": "Evacuation Day", + "date": "2025-10-15" + }, + { + "name": "Revolution and Youth Day", + "date": "2025-12-17" + } +] \ No newline at end of file diff --git a/tests/Countries/TunisiaTest.php b/tests/Countries/TunisiaTest.php new file mode 100644 index 000000000..a241fd2ec --- /dev/null +++ b/tests/Countries/TunisiaTest.php @@ -0,0 +1,18 @@ +get(); + + expect($holidays) + ->toBeArray() + ->not()->toBeEmpty(); + + expect(formatDates($holidays))->toMatchSnapshot(); +})->with([2024, 2025]); From 773fc670431a1f1996306116ac9107f03e0c86ca Mon Sep 17 00:00:00 2001 From: Nielsvanpach Date: Wed, 3 Apr 2024 07:36:50 +0000 Subject: [PATCH 161/175] Fix styling --- src/Countries/Tunisia.php | 10 +++++----- tests/Countries/TunisiaTest.php | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Countries/Tunisia.php b/src/Countries/Tunisia.php index a6bac81d2..38d9f61e1 100644 --- a/src/Countries/Tunisia.php +++ b/src/Countries/Tunisia.php @@ -83,6 +83,7 @@ class Tunisia extends Country implements HasTranslations, Islamic 2036 => '02-07', 2037 => '01-26', ]; + protected const eidAlAdha = [ 2005 => '01-22', 2006 => '01-11', @@ -118,6 +119,7 @@ class Tunisia extends Country implements HasTranslations, Islamic 2036 => '02-08', 2037 => '01-27', ]; + protected const islamicNewYear = [ 2005 => '02-10', 2006 => '01-31', @@ -153,6 +155,7 @@ class Tunisia extends Country implements HasTranslations, Islamic 2036 => '02-29', 2037 => '02-17', ]; + protected const ashura = [ 2005 => '02-19', 2006 => '02-09', @@ -188,6 +191,7 @@ class Tunisia extends Country implements HasTranslations, Islamic 2036 => '03-08', 2037 => '02-25', ]; + protected const prophetMuhammadBirthday = [ 2005 => '04-21', 2006 => '04-11', @@ -224,9 +228,6 @@ class Tunisia extends Country implements HasTranslations, Islamic 2037 => '04-29', ]; - /** - * @return string - */ public function countryCode(): string { return 'tn'; @@ -241,7 +242,7 @@ protected function allHolidays(int $year): array { $revolutionHoliday = []; - if (2022 > $year && $year >= 2011) { + if ($year < 2022 && $year >= 2011) { $revolutionHoliday['Revolution and Youth Day'] = '01-14'; } @@ -275,5 +276,4 @@ public function islamicHolidays(int $year): array $this->convertPeriods(name: 'Eid al-Adha', year: $year, period: $eidAlAdha[0]), ); } - } diff --git a/tests/Countries/TunisiaTest.php b/tests/Countries/TunisiaTest.php index a241fd2ec..bc0bf160a 100644 --- a/tests/Countries/TunisiaTest.php +++ b/tests/Countries/TunisiaTest.php @@ -6,7 +6,7 @@ use Spatie\Holidays\Holidays; it('can calculate tunisia holidays', function ($year) { - CarbonImmutable::setTestNow($year . '-01-01'); + CarbonImmutable::setTestNow($year.'-01-01'); $holidays = Holidays::for(country: 'tn')->get(); From bfa7b5f5af51a629c99c4057ac7ac600ce948237 Mon Sep 17 00:00:00 2001 From: Elvis Fernando Date: Thu, 11 Apr 2024 00:55:22 -0500 Subject: [PATCH 162/175] Add holidays for Ecuador (#218) * Add holidays for Ecuador * Get nearest day of holiday * Fix christmas holiday * Add return type * Use observedChristmasDay * Add translations * Update src/Countries/Ecuador.php Co-authored-by: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> * Update src/Countries/Ecuador.php Co-authored-by: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> * Update src/Countries/Ecuador.php Co-authored-by: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> * Fix syntax * Move holiday to Monday, not Tuesday * Test translation * Set default lang to es * Rename snapshot --------- Co-authored-by: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> --- lang/ecuador/es/holidays.json | 13 +++ src/Countries/Ecuador.php | 79 +++++++++++++++++++ .../it_can_calculate_ecuador_holidays.snap | 46 +++++++++++ ...dor_holidays_with_english_translation.snap | 46 +++++++++++ tests/Countries/EcuadorTest.php | 31 ++++++++ 5 files changed, 215 insertions(+) create mode 100644 lang/ecuador/es/holidays.json create mode 100644 src/Countries/Ecuador.php create mode 100644 tests/.pest/snapshots/Countries/EcuadorTest/it_can_calculate_ecuador_holidays.snap create mode 100644 tests/.pest/snapshots/Countries/EcuadorTest/it_can_calculate_ecuador_holidays_with_english_translation.snap create mode 100644 tests/Countries/EcuadorTest.php diff --git a/lang/ecuador/es/holidays.json b/lang/ecuador/es/holidays.json new file mode 100644 index 000000000..1c60a1f3e --- /dev/null +++ b/lang/ecuador/es/holidays.json @@ -0,0 +1,13 @@ +{ + "New Year's Day": "Año Nuevo", + "Holy Friday": "Viernes Santo", + "Carnival Monday": "Lunes de Carnaval", + "Carnival Tuesday": "Martes de Carnaval", + "Labor Day": "Día del Trabajo", + "Battle of Pichincha": "Batalla de Pichincha", + "Independence Day": "Primer Grito de la Independencia", + "Independence Of Guayaquil": "Independencia de Guayaquil", + "All Souls' Day": "Día de Los Difuntos", + "Independence Of Cuenca": "Independencia de Cuenca", + "Christmas": "Navidad" +} \ No newline at end of file diff --git a/src/Countries/Ecuador.php b/src/Countries/Ecuador.php new file mode 100644 index 000000000..f0017bf9c --- /dev/null +++ b/src/Countries/Ecuador.php @@ -0,0 +1,79 @@ + '01-01', + ], $this->variableHolidays($year)); + } + + public function nearestDay(int $year, int $month, int $day): CarbonImmutable + { + $date = CarbonImmutable::createFromDate($year, $month, $day); + + if($date->is('Tuesday') || $date->is('Saturday')) { + return $date->subDay(); + } + + if($date->is('Sunday')) { + return $date->addDay(); + } + + if($date->is('Wednesday') || $date->is('Thursday')) { + return $date->next(CarbonImmutable::FRIDAY); + } + + return $date; + } + + public function getChristmasHoliday(int $year): CarbonImmutable + { + if($year === 2022) { + return $this->sundayToNextMonday('12-25', $year); + } + + return CarbonImmutable::createFromDate($year, 12, 25); + } + + /** @return array */ + protected function variableHolidays(int $year): array + { + $easter = $this->easter($year); + $ashWednesday = $easter->subDays(46); + + return [ + 'Holy Friday' => $easter->subDays(2), + 'Carnival Monday' => $ashWednesday->subDays(2), + 'Carnival Tuesday' => $ashWednesday->subDay(), + 'Labor Day' => $this->nearestDay($year, 5, 1), + 'Battle of Pichincha' => $this->nearestDay($year, 5, 24), + 'Independence Day' => $this->nearestDay($year, 8, 10), + 'Independence Of Guayaquil' => $this->nearestDay($year, 10, 9), + 'All Souls\' Day' => $this->nearestDay($year, 11, 2), + 'Independence Of Cuenca' => $this->nearestDay($year, 11, 3), + 'Christmas' => $this->getChristmasHoliday($year), + ]; + } +} \ No newline at end of file diff --git a/tests/.pest/snapshots/Countries/EcuadorTest/it_can_calculate_ecuador_holidays.snap b/tests/.pest/snapshots/Countries/EcuadorTest/it_can_calculate_ecuador_holidays.snap new file mode 100644 index 000000000..41f564bb7 --- /dev/null +++ b/tests/.pest/snapshots/Countries/EcuadorTest/it_can_calculate_ecuador_holidays.snap @@ -0,0 +1,46 @@ +[ + { + "name": "A\u00f1o Nuevo", + "date": "2024-01-01" + }, + { + "name": "Lunes de Carnaval", + "date": "2024-02-12" + }, + { + "name": "Martes de Carnaval", + "date": "2024-02-13" + }, + { + "name": "Viernes Santo", + "date": "2024-03-29" + }, + { + "name": "D\u00eda del Trabajo", + "date": "2024-05-03" + }, + { + "name": "Batalla de Pichincha", + "date": "2024-05-24" + }, + { + "name": "Primer Grito de la Independencia", + "date": "2024-08-09" + }, + { + "name": "Independencia de Guayaquil", + "date": "2024-10-11" + }, + { + "name": "D\u00eda de Los Difuntos", + "date": "2024-11-01" + }, + { + "name": "Independencia de Cuenca", + "date": "2024-11-04" + }, + { + "name": "Navidad", + "date": "2024-12-25" + } +] \ No newline at end of file diff --git a/tests/.pest/snapshots/Countries/EcuadorTest/it_can_calculate_ecuador_holidays_with_english_translation.snap b/tests/.pest/snapshots/Countries/EcuadorTest/it_can_calculate_ecuador_holidays_with_english_translation.snap new file mode 100644 index 000000000..b542dfd1e --- /dev/null +++ b/tests/.pest/snapshots/Countries/EcuadorTest/it_can_calculate_ecuador_holidays_with_english_translation.snap @@ -0,0 +1,46 @@ +[ + { + "name": "New Year's Day", + "date": "2024-01-01" + }, + { + "name": "Carnival Monday", + "date": "2024-02-12" + }, + { + "name": "Carnival Tuesday", + "date": "2024-02-13" + }, + { + "name": "Holy Friday", + "date": "2024-03-29" + }, + { + "name": "Labor Day", + "date": "2024-05-03" + }, + { + "name": "Battle of Pichincha", + "date": "2024-05-24" + }, + { + "name": "Independence Day", + "date": "2024-08-09" + }, + { + "name": "Independence Of Guayaquil", + "date": "2024-10-11" + }, + { + "name": "All Souls' Day", + "date": "2024-11-01" + }, + { + "name": "Independence Of Cuenca", + "date": "2024-11-04" + }, + { + "name": "Christmas", + "date": "2024-12-25" + } +] \ No newline at end of file diff --git a/tests/Countries/EcuadorTest.php b/tests/Countries/EcuadorTest.php new file mode 100644 index 000000000..9de016443 --- /dev/null +++ b/tests/Countries/EcuadorTest.php @@ -0,0 +1,31 @@ +get(); + + expect($holidays) + ->toBeArray() + ->not()->toBeEmpty(); + + expect(formatDates($holidays))->toMatchSnapshot(); +}); + +it('can calculate ecuador holidays with english translation', function () { + CarbonImmutable::setTestNow('2024-01-01'); + + $holidays = Holidays::for(country: 'ec', locale: 'en')->get(); + + expect($holidays) + ->toBeArray() + ->not()->toBeEmpty(); + + expect(formatDates($holidays))->toMatchSnapshot(); +}); + From 89a839cb6424552a29a76f5a8f52e48837ef89f4 Mon Sep 17 00:00:00 2001 From: Nielsvanpach Date: Thu, 11 Apr 2024 05:55:44 +0000 Subject: [PATCH 163/175] Fix styling --- src/Countries/Ecuador.php | 22 +++++++++++----------- tests/Countries/EcuadorTest.php | 1 - 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/src/Countries/Ecuador.php b/src/Countries/Ecuador.php index f0017bf9c..7324026fa 100644 --- a/src/Countries/Ecuador.php +++ b/src/Countries/Ecuador.php @@ -33,15 +33,15 @@ public function nearestDay(int $year, int $month, int $day): CarbonImmutable { $date = CarbonImmutable::createFromDate($year, $month, $day); - if($date->is('Tuesday') || $date->is('Saturday')) { + if ($date->is('Tuesday') || $date->is('Saturday')) { return $date->subDay(); } - if($date->is('Sunday')) { + if ($date->is('Sunday')) { return $date->addDay(); } - if($date->is('Wednesday') || $date->is('Thursday')) { + if ($date->is('Wednesday') || $date->is('Thursday')) { return $date->next(CarbonImmutable::FRIDAY); } @@ -50,7 +50,7 @@ public function nearestDay(int $year, int $month, int $day): CarbonImmutable public function getChristmasHoliday(int $year): CarbonImmutable { - if($year === 2022) { + if ($year === 2022) { return $this->sundayToNextMonday('12-25', $year); } @@ -67,13 +67,13 @@ protected function variableHolidays(int $year): array 'Holy Friday' => $easter->subDays(2), 'Carnival Monday' => $ashWednesday->subDays(2), 'Carnival Tuesday' => $ashWednesday->subDay(), - 'Labor Day' => $this->nearestDay($year, 5, 1), - 'Battle of Pichincha' => $this->nearestDay($year, 5, 24), - 'Independence Day' => $this->nearestDay($year, 8, 10), - 'Independence Of Guayaquil' => $this->nearestDay($year, 10, 9), - 'All Souls\' Day' => $this->nearestDay($year, 11, 2), - 'Independence Of Cuenca' => $this->nearestDay($year, 11, 3), + 'Labor Day' => $this->nearestDay($year, 5, 1), + 'Battle of Pichincha' => $this->nearestDay($year, 5, 24), + 'Independence Day' => $this->nearestDay($year, 8, 10), + 'Independence Of Guayaquil' => $this->nearestDay($year, 10, 9), + 'All Souls\' Day' => $this->nearestDay($year, 11, 2), + 'Independence Of Cuenca' => $this->nearestDay($year, 11, 3), 'Christmas' => $this->getChristmasHoliday($year), ]; } -} \ No newline at end of file +} diff --git a/tests/Countries/EcuadorTest.php b/tests/Countries/EcuadorTest.php index 9de016443..bd1954510 100644 --- a/tests/Countries/EcuadorTest.php +++ b/tests/Countries/EcuadorTest.php @@ -28,4 +28,3 @@ expect(formatDates($holidays))->toMatchSnapshot(); }); - From d0f43a88470e70ccbfd107acf255f5d69e4a5402 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 15 Apr 2024 15:46:54 +0000 Subject: [PATCH 164/175] Bump aglipanci/laravel-pint-action from 2.3.1 to 2.4 Bumps [aglipanci/laravel-pint-action](https://github.com/aglipanci/laravel-pint-action) from 2.3.1 to 2.4. - [Release notes](https://github.com/aglipanci/laravel-pint-action/releases) - [Commits](https://github.com/aglipanci/laravel-pint-action/compare/2.3.1...2.4) --- updated-dependencies: - dependency-name: aglipanci/laravel-pint-action dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- .github/workflows/fix-php-code-style-issues.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/fix-php-code-style-issues.yml b/.github/workflows/fix-php-code-style-issues.yml index 30e62c774..aebce91bc 100644 --- a/.github/workflows/fix-php-code-style-issues.yml +++ b/.github/workflows/fix-php-code-style-issues.yml @@ -17,7 +17,7 @@ jobs: ref: ${{ github.head_ref }} - name: Fix PHP code style issues - uses: aglipanci/laravel-pint-action@2.3.1 + uses: aglipanci/laravel-pint-action@2.4 - name: Commit changes uses: stefanzweifel/git-auto-commit-action@v5 From 16e9d20f0f4e313481c53c2f233c93f1f159d12c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrik=20Stri=C5=A1ovsk=C3=BD?= Date: Mon, 29 Apr 2024 09:24:26 +0200 Subject: [PATCH 165/175] feat: remove canceled day of the rest from `Slovakia` country (#223) --- src/Countries/Slovakia.php | 1 - .../SlovakiaTest/it_can_calculate_slovak_holidays.snap | 4 ---- 2 files changed, 5 deletions(-) diff --git a/src/Countries/Slovakia.php b/src/Countries/Slovakia.php index 32d21dccb..e95a31fe4 100644 --- a/src/Countries/Slovakia.php +++ b/src/Countries/Slovakia.php @@ -20,7 +20,6 @@ protected function allHolidays(int $year): array 'Deň víťazstva nad fašizmom' => '05-08', 'Sviatok svätého Cyrila a Metoda' => '07-05', 'Výročie Slovenského národného povstania' => '08-29', - 'Deň Ústavy Slovenskej republiky' => '09-01', 'Sedembolestná Panna Mária' => '09-15', 'Sviatok všetkých svätých' => '11-01', 'Deň boja za slobodu a demokraciu' => '11-17', diff --git a/tests/.pest/snapshots/Countries/SlovakiaTest/it_can_calculate_slovak_holidays.snap b/tests/.pest/snapshots/Countries/SlovakiaTest/it_can_calculate_slovak_holidays.snap index ac07602fd..f3eb30ccb 100644 --- a/tests/.pest/snapshots/Countries/SlovakiaTest/it_can_calculate_slovak_holidays.snap +++ b/tests/.pest/snapshots/Countries/SlovakiaTest/it_can_calculate_slovak_holidays.snap @@ -31,10 +31,6 @@ "name": "V\u00fdro\u010die Slovensk\u00e9ho n\u00e1rodn\u00e9ho povstania", "date": "2024-08-29" }, - { - "name": "De\u0148 \u00dastavy Slovenskej republiky", - "date": "2024-09-01" - }, { "name": "Sedembolestn\u00e1 Panna M\u00e1ria", "date": "2024-09-15" From 819b3fdf1157862f2262155a8677f1c74f6038d3 Mon Sep 17 00:00:00 2001 From: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> Date: Mon, 29 Apr 2024 09:39:04 +0200 Subject: [PATCH 166/175] fix phpstan --- .github/workflows/run-tests.yml | 2 +- src/Countries/Ecuador.php | 15 ++++++++++----- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index 868a13cfd..c98139708 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -12,7 +12,7 @@ jobs: os: [ubuntu-latest] php: [8.3, 8.2, 8.1] stability: [prefer-lowest, prefer-stable] - carbon: [2.72, 3.0] + carbon: [2.72, 3.2] name: P${{ matrix.php }} - ${{ matrix.stability }} - Carbon ${{ matrix.carbon }} diff --git a/src/Countries/Ecuador.php b/src/Countries/Ecuador.php index 7324026fa..e3892c4bb 100644 --- a/src/Countries/Ecuador.php +++ b/src/Countries/Ecuador.php @@ -3,6 +3,7 @@ namespace Spatie\Holidays\Countries; use Carbon\CarbonImmutable; +use Carbon\CarbonInterface; use Spatie\Holidays\Concerns\Observable; use Spatie\Holidays\Concerns\Translatable; use Spatie\Holidays\Contracts\HasTranslations; @@ -29,7 +30,7 @@ protected function allHolidays(int $year): array ], $this->variableHolidays($year)); } - public function nearestDay(int $year, int $month, int $day): CarbonImmutable + public function nearestDay(int $year, int $month, int $day): CarbonInterface { $date = CarbonImmutable::createFromDate($year, $month, $day); @@ -42,22 +43,26 @@ public function nearestDay(int $year, int $month, int $day): CarbonImmutable } if ($date->is('Wednesday') || $date->is('Thursday')) { - return $date->next(CarbonImmutable::FRIDAY); + return $date->next(CarbonInterface::FRIDAY); } return $date; } - public function getChristmasHoliday(int $year): CarbonImmutable + public function getChristmasHoliday(int $year): CarbonInterface { if ($year === 2022) { - return $this->sundayToNextMonday('12-25', $year); + $observedChristmasDay = $this->sundayToNextMonday('12-25', $year); + + if ($observedChristmasDay !== null ) { + return $observedChristmasDay; + } } return CarbonImmutable::createFromDate($year, 12, 25); } - /** @return array */ + /** @return array */ protected function variableHolidays(int $year): array { $easter = $this->easter($year); From 7d93b353acdacc7de2decc2c295efefdac28276b Mon Sep 17 00:00:00 2001 From: Nielsvanpach Date: Mon, 29 Apr 2024 07:39:33 +0000 Subject: [PATCH 167/175] Fix styling --- src/Countries/Ecuador.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Countries/Ecuador.php b/src/Countries/Ecuador.php index e3892c4bb..c36412189 100644 --- a/src/Countries/Ecuador.php +++ b/src/Countries/Ecuador.php @@ -54,7 +54,7 @@ public function getChristmasHoliday(int $year): CarbonInterface if ($year === 2022) { $observedChristmasDay = $this->sundayToNextMonday('12-25', $year); - if ($observedChristmasDay !== null ) { + if ($observedChristmasDay !== null) { return $observedChristmasDay; } } From 60cc5142cefc39f840d6cde95dfc5c72e9f114a3 Mon Sep 17 00:00:00 2001 From: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> Date: Mon, 29 Apr 2024 10:23:58 +0200 Subject: [PATCH 168/175] fix naming of translation files --- .../en/holidays.json | 0 src/Concerns/Translatable.php | 10 +++++++++- 2 files changed, 9 insertions(+), 1 deletion(-) rename lang/{bosniaAndHerzegovina => bosnia-and-herzegovina}/en/holidays.json (100%) diff --git a/lang/bosniaAndHerzegovina/en/holidays.json b/lang/bosnia-and-herzegovina/en/holidays.json similarity index 100% rename from lang/bosniaAndHerzegovina/en/holidays.json rename to lang/bosnia-and-herzegovina/en/holidays.json diff --git a/src/Concerns/Translatable.php b/src/Concerns/Translatable.php index afd9f2084..3c13a6a1f 100644 --- a/src/Concerns/Translatable.php +++ b/src/Concerns/Translatable.php @@ -14,7 +14,8 @@ public function translate(string $country, string $name, ?string $locale = null) $locale = $locale ?? $this->defaultLocale(); - $countryName = strtolower($country); + $countryName = $this->toHyphenSeparated($country); + $filePath = __DIR__."/../../lang/{$countryName}/{$locale}/holidays.json"; if (file_exists($filePath)) { @@ -32,4 +33,11 @@ public function translate(string $country, string $name, ?string $locale = null) return $data[$name] ?? $name; } + + protected function toHyphenSeparated(string $text): string + { + return strtolower( + preg_replace('/(?<=\\w)(?=[A-Z])/', '-$1', $text) + ); + } } From fac8a4b068269996777cf758fa04307202c6b635 Mon Sep 17 00:00:00 2001 From: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> Date: Mon, 29 Apr 2024 10:27:59 +0200 Subject: [PATCH 169/175] phpstan fixes --- src/Concerns/Translatable.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/Concerns/Translatable.php b/src/Concerns/Translatable.php index 3c13a6a1f..8599863e3 100644 --- a/src/Concerns/Translatable.php +++ b/src/Concerns/Translatable.php @@ -36,8 +36,12 @@ public function translate(string $country, string $name, ?string $locale = null) protected function toHyphenSeparated(string $text): string { - return strtolower( - preg_replace('/(?<=\\w)(?=[A-Z])/', '-$1', $text) - ); + $toHyphens = preg_replace('/(?<=\\w)(?=[A-Z])/', '-$1', $text); + + if ($toHyphens === null) { + return strtolower($text); + } + + return strtolower($toHyphens); } } From bf6bfcab151399706823c65ba3554ffa172d295e Mon Sep 17 00:00:00 2001 From: Nielsvanpach Date: Mon, 29 Apr 2024 08:31:45 +0000 Subject: [PATCH 170/175] Update CHANGELOG --- CHANGELOG.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1bb841704..0c6aadb49 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,22 @@ All notable changes to `holidays` will be documented in this file. +## 1.10.0 - 2024-04-29 + +### What's Changed + +* add Tunisia Holidays by @mr-wolf-gb in https://github.com/spatie/holidays/pull/109 +* Add holidays for Ecuador by @insoutt in https://github.com/spatie/holidays/pull/218 +* Bump aglipanci/laravel-pint-action from 2.3.1 to 2.4 by @dependabot in https://github.com/spatie/holidays/pull/221 +* feat: remove canceled day of the rest from `Slovakia` country by @patressz in https://github.com/spatie/holidays/pull/223 + +### New Contributors + +* @mr-wolf-gb made their first contribution in https://github.com/spatie/holidays/pull/109 +* @insoutt made their first contribution in https://github.com/spatie/holidays/pull/218 + +**Full Changelog**: https://github.com/spatie/holidays/compare/1.9.1...1.10.0 + ## 1.9.1 - 2024-04-02 ### What's Changed From 9b1817b4f48f90cf1e94bafca2d65d399046b6d0 Mon Sep 17 00:00:00 2001 From: Eden <51815044+jws1837@users.noreply.github.com> Date: Mon, 29 Apr 2024 18:33:24 +0900 Subject: [PATCH 171/175] Add holidays for korea (#222) --- src/Countries/Korea.php | 76 ++++++++++++ .../it_can_calculate_korean_holidays.snap | 62 ++++++++++ tests/Countries/KoreaTest.php | 115 ++++++++++++++++++ 3 files changed, 253 insertions(+) create mode 100644 src/Countries/Korea.php create mode 100644 tests/.pest/snapshots/Countries/KoreaTest/it_can_calculate_korean_holidays.snap create mode 100644 tests/Countries/KoreaTest.php diff --git a/src/Countries/Korea.php b/src/Countries/Korea.php new file mode 100644 index 000000000..349982b51 --- /dev/null +++ b/src/Countries/Korea.php @@ -0,0 +1,76 @@ + '01-01', + '3ㆍ1절' => '03-01', + '어린이날' => '05-05', + '현충일' => '06-06', + '광복절' => '08-15', + '개천절' => '10-03', + '한글날' => '10-09', + '크리스마스' => '12-15', + ], $this->variableHolidays($year)); + } + + /** @return array */ + protected function variableHolidays(int $year): array + { + $this->setChineseCalendarTimezone('Asia/Seoul'); + + return array_merge( + $this->getLunarNewYearHoliday($year), + $this->getLunarBuddhasBirthday($year), + $this->getLunarChuseok($year), + ); + } + + /** @return array */ + protected function getLunarNewYearHoliday(int $year): array + { + $firstOfJanInChineseCalendar = $this->chineseToGregorianDate('01-01', $year); + + return [ + '설날 연휴 1' => $firstOfJanInChineseCalendar->subDay(), + '설날' => $firstOfJanInChineseCalendar, + '설날 연휴 2' => $firstOfJanInChineseCalendar->addDay(), + ]; + } + + /** @return array */ + protected function getLunarBuddhasBirthday(int $year): array + { + $BuddhasBirthdayInChineseCalendar = $this->chineseToGregorianDate('04-08', $year); + + return [ + '부처님 오신날' => $BuddhasBirthdayInChineseCalendar, + ]; + } + + /** @return array */ + protected function getLunarChuseok(int $year): array + { + $chuseokInChineseCalendar = $this->chineseToGregorianDate('08-15', $year); + + return [ + '추석 연휴 1' => $chuseokInChineseCalendar->subDay(), + '추석' => $chuseokInChineseCalendar, + '추석 연휴 2' => $chuseokInChineseCalendar->addDay(), + ]; + } +} diff --git a/tests/.pest/snapshots/Countries/KoreaTest/it_can_calculate_korean_holidays.snap b/tests/.pest/snapshots/Countries/KoreaTest/it_can_calculate_korean_holidays.snap new file mode 100644 index 000000000..b7dc1a0e7 --- /dev/null +++ b/tests/.pest/snapshots/Countries/KoreaTest/it_can_calculate_korean_holidays.snap @@ -0,0 +1,62 @@ +[ + { + "name": "\uc2e0\uc815", + "date": "2024-01-01" + }, + { + "name": "\uc124\ub0a0 \uc5f0\ud734 1", + "date": "2024-02-09" + }, + { + "name": "\uc124\ub0a0", + "date": "2024-02-10" + }, + { + "name": "\uc124\ub0a0 \uc5f0\ud734 2", + "date": "2024-02-11" + }, + { + "name": "3\u318d1\uc808", + "date": "2024-03-01" + }, + { + "name": "\uc5b4\ub9b0\uc774\ub0a0", + "date": "2024-05-05" + }, + { + "name": "\ubd80\ucc98\ub2d8 \uc624\uc2e0\ub0a0", + "date": "2024-05-15" + }, + { + "name": "\ud604\ucda9\uc77c", + "date": "2024-06-06" + }, + { + "name": "\uad11\ubcf5\uc808", + "date": "2024-08-15" + }, + { + "name": "\ucd94\uc11d \uc5f0\ud734 1", + "date": "2024-09-16" + }, + { + "name": "\ucd94\uc11d", + "date": "2024-09-17" + }, + { + "name": "\ucd94\uc11d \uc5f0\ud734 2", + "date": "2024-09-18" + }, + { + "name": "\uac1c\ucc9c\uc808", + "date": "2024-10-03" + }, + { + "name": "\ud55c\uae00\ub0a0", + "date": "2024-10-09" + }, + { + "name": "\ud06c\ub9ac\uc2a4\ub9c8\uc2a4", + "date": "2024-12-15" + } +] \ No newline at end of file diff --git a/tests/Countries/KoreaTest.php b/tests/Countries/KoreaTest.php new file mode 100644 index 000000000..eeaa9fede --- /dev/null +++ b/tests/Countries/KoreaTest.php @@ -0,0 +1,115 @@ +get(); + + expect($holidays) + ->toBeArray() + ->not()->toBeEmpty(); + + expect(formatDates($holidays))->toMatchSnapshot(); +}); + +it('can calculate the Lunar New Year holiday', function ($year, $expectedHoliday) { + CarbonImmutable::setTestNow("{$year}-01-01"); + + $holidays = Holidays::for(country: 'kr')->get(); + + expect($holidays) + ->toBeArray() + ->not()->toBeEmpty(); + + $lunarNewYearHoliday = array_map(fn($date) => $date['date'], formatDates($holidays)); + + expect($lunarNewYearHoliday)->toContain(...$expectedHoliday); +})->with([ + [ + 'year' => 2024, 'expected_holiday' => [ + '2024-02-09', '2024-02-10', '2024-02-11' + ] + ], + [ + 'year' => 2023, 'expected_holiday' => [ + '2023-01-21', '2023-01-22', '2023-01-23' + ] + ], + [ + 'year' => 2022, 'expected_holiday' => [ + '2022-01-31', '2022-02-01', '2022-02-02' + ] + ], + [ + 'year' => 2021, 'expected_holiday' => [ + '2021-02-11', '2021-02-12', '2021-02-13' + ] + ], + [ + 'year' => 2020, 'expected_holiday' => [ + '2020-01-24', '2020-01-25', '2020-01-26' + ] + ], +]); + +it('can calculate the holiday of Lunar Buddha\'s Birthday', function ($year, $expectedHoliday) { + CarbonImmutable::setTestNow("{$year}-01-01"); + + $holidays = Holidays::for(country: 'kr')->get(); + expect($holidays) + ->toBeArray() + ->not()->toBeEmpty(); + + $dates = array_map(fn($date) => $date['date'], formatDates($holidays)); + + expect($dates)->toContain(...$expectedHoliday); +})->with([ + ['year' => 2024, 'expected_holiday' => ['2024-05-15']], + ['year' => 2023, 'expected_holiday' => ['2023-05-26']], + ['year' => 2022, 'expected_holiday' => ['2022-05-08']] +]); + +it('can calculate the Lunar Chuseok holiday', function ($year, $expectedHoliday) { + CarbonImmutable::setTestNow("{$year}-01-01"); + + $holidays = Holidays::for(country: 'kr')->get(); + + expect($holidays) + ->toBeArray() + ->not()->toBeEmpty(); + + $lunarNewYearHoliday = array_map(fn($date) => $date['date'], formatDates($holidays)); + + expect($lunarNewYearHoliday)->toContain(...$expectedHoliday); +})->with([ + [ + 'year' => 2024, 'expected_holiday' => [ + '2024-09-16', '2024-09-17', '2024-09-18' + ] + ], + [ + 'year' => 2023, 'expected_holiday' => [ + '2023-09-28', '2023-09-29', '2023-09-30' + ] + ], + [ + 'year' => 2022, 'expected_holiday' => [ + '2022-09-09', '2022-09-10', '2022-09-11' + ] + ], + [ + 'year' => 2021, 'expected_holiday' => [ + '2021-09-20', '2021-09-21', '2021-09-22' + ] + ], + [ + 'year' => 2020, 'expected_holiday' => [ + '2020-09-30', '2020-10-01', '2020-10-02' + ] + ] +]); From aa2721c862876979c9af768917e6025390008fd6 Mon Sep 17 00:00:00 2001 From: Nielsvanpach Date: Mon, 29 Apr 2024 09:33:49 +0000 Subject: [PATCH 172/175] Fix styling --- tests/Countries/KoreaTest.php | 50 +++++++++++++++++------------------ 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/tests/Countries/KoreaTest.php b/tests/Countries/KoreaTest.php index eeaa9fede..56d42d0c0 100644 --- a/tests/Countries/KoreaTest.php +++ b/tests/Countries/KoreaTest.php @@ -26,34 +26,34 @@ ->toBeArray() ->not()->toBeEmpty(); - $lunarNewYearHoliday = array_map(fn($date) => $date['date'], formatDates($holidays)); + $lunarNewYearHoliday = array_map(fn ($date) => $date['date'], formatDates($holidays)); expect($lunarNewYearHoliday)->toContain(...$expectedHoliday); })->with([ [ 'year' => 2024, 'expected_holiday' => [ - '2024-02-09', '2024-02-10', '2024-02-11' - ] + '2024-02-09', '2024-02-10', '2024-02-11', + ], ], [ 'year' => 2023, 'expected_holiday' => [ - '2023-01-21', '2023-01-22', '2023-01-23' - ] + '2023-01-21', '2023-01-22', '2023-01-23', + ], ], [ 'year' => 2022, 'expected_holiday' => [ - '2022-01-31', '2022-02-01', '2022-02-02' - ] + '2022-01-31', '2022-02-01', '2022-02-02', + ], ], [ 'year' => 2021, 'expected_holiday' => [ - '2021-02-11', '2021-02-12', '2021-02-13' - ] + '2021-02-11', '2021-02-12', '2021-02-13', + ], ], [ 'year' => 2020, 'expected_holiday' => [ - '2020-01-24', '2020-01-25', '2020-01-26' - ] + '2020-01-24', '2020-01-25', '2020-01-26', + ], ], ]); @@ -65,13 +65,13 @@ ->toBeArray() ->not()->toBeEmpty(); - $dates = array_map(fn($date) => $date['date'], formatDates($holidays)); + $dates = array_map(fn ($date) => $date['date'], formatDates($holidays)); expect($dates)->toContain(...$expectedHoliday); })->with([ ['year' => 2024, 'expected_holiday' => ['2024-05-15']], ['year' => 2023, 'expected_holiday' => ['2023-05-26']], - ['year' => 2022, 'expected_holiday' => ['2022-05-08']] + ['year' => 2022, 'expected_holiday' => ['2022-05-08']], ]); it('can calculate the Lunar Chuseok holiday', function ($year, $expectedHoliday) { @@ -83,33 +83,33 @@ ->toBeArray() ->not()->toBeEmpty(); - $lunarNewYearHoliday = array_map(fn($date) => $date['date'], formatDates($holidays)); + $lunarNewYearHoliday = array_map(fn ($date) => $date['date'], formatDates($holidays)); expect($lunarNewYearHoliday)->toContain(...$expectedHoliday); })->with([ [ 'year' => 2024, 'expected_holiday' => [ - '2024-09-16', '2024-09-17', '2024-09-18' - ] + '2024-09-16', '2024-09-17', '2024-09-18', + ], ], [ 'year' => 2023, 'expected_holiday' => [ - '2023-09-28', '2023-09-29', '2023-09-30' - ] + '2023-09-28', '2023-09-29', '2023-09-30', + ], ], [ 'year' => 2022, 'expected_holiday' => [ - '2022-09-09', '2022-09-10', '2022-09-11' - ] + '2022-09-09', '2022-09-10', '2022-09-11', + ], ], [ 'year' => 2021, 'expected_holiday' => [ - '2021-09-20', '2021-09-21', '2021-09-22' - ] + '2021-09-20', '2021-09-21', '2021-09-22', + ], ], [ 'year' => 2020, 'expected_holiday' => [ - '2020-09-30', '2020-10-01', '2020-10-02' - ] - ] + '2020-09-30', '2020-10-01', '2020-10-02', + ], + ], ]); From c514a49ebed7831891930876a5264b1ec06af527 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9as=20Lundgren?= <1066486+adevade@users.noreply.github.com> Date: Mon, 29 Apr 2024 13:47:09 +0200 Subject: [PATCH 173/175] Use leading zero in day (#224) --- src/Countries/Sweden.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Countries/Sweden.php b/src/Countries/Sweden.php index fce4f7135..1930b154a 100644 --- a/src/Countries/Sweden.php +++ b/src/Countries/Sweden.php @@ -17,8 +17,8 @@ protected function allHolidays(int $year): array return array_merge([ 'Nyårsdagen' => '01-01', 'Trettondedag jul' => '01-06', - 'Första maj' => '05-1', - 'Nationaldagen' => '06-6', + 'Första maj' => '05-01', + 'Nationaldagen' => '06-06', 'Juldagen' => '12-25', 'Annandag jul' => '12-26', ], $this->variableHolidays($year)); From d185dc918d0a467e2297f65f40a1ed2c01a9d935 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 29 Apr 2024 15:34:13 +0000 Subject: [PATCH 174/175] Bump dependabot/fetch-metadata from 2.0.0 to 2.1.0 Bumps [dependabot/fetch-metadata](https://github.com/dependabot/fetch-metadata) from 2.0.0 to 2.1.0. - [Release notes](https://github.com/dependabot/fetch-metadata/releases) - [Commits](https://github.com/dependabot/fetch-metadata/compare/v2.0.0...v2.1.0) --- updated-dependencies: - dependency-name: dependabot/fetch-metadata dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- .github/workflows/dependabot-auto-merge.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/dependabot-auto-merge.yml b/.github/workflows/dependabot-auto-merge.yml index 1d4d5085b..056063f4a 100644 --- a/.github/workflows/dependabot-auto-merge.yml +++ b/.github/workflows/dependabot-auto-merge.yml @@ -14,7 +14,7 @@ jobs: - name: Dependabot metadata id: metadata - uses: dependabot/fetch-metadata@v2.0.0 + uses: dependabot/fetch-metadata@v2.1.0 with: github-token: "${{ secrets.GITHUB_TOKEN }}" From b7ef716c0f94e4312734beb57ffb26bacd6fa040 Mon Sep 17 00:00:00 2001 From: Stavros Date: Tue, 30 Apr 2024 12:52:53 +0300 Subject: [PATCH 175/175] Add greece holidays (#226) * move 1st may fix * 1st May fix * updates * no true in_array * Update src/Countries/Greece.php --------- Co-authored-by: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> --- src/Countries/Greece.php | 11 ++++++----- .../it_can_calculate_hellenic_holidays.snap | 8 ++++---- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/Countries/Greece.php b/src/Countries/Greece.php index 290a34f10..c14bdd890 100644 --- a/src/Countries/Greece.php +++ b/src/Countries/Greece.php @@ -29,16 +29,17 @@ protected function allHolidays(int $year): array /** @return array */ protected function variableHolidays(int $year): array { - $orthodoxEaster = $this->orthodoxEaster($year); + $orthodoxEaster = $this->orthodoxEaster($year); + $megaliTetarti = $orthodoxEaster->copy()->subDays(4); + $megaliPempti = $orthodoxEaster->copy()->subDays(3); $megaliParaskevi = $orthodoxEaster->copy()->subDays(2); $megaloSavvato = $orthodoxEaster->copy()->subDay(); $deuteraPasha = $orthodoxEaster->copy()->addDay(); + $protomagia = CarbonImmutable::createFromDate($year, 5, 1)->startOfDay(); - $protomagia = CarbonImmutable::createFromDate($year, 5, 1); - $moveProtomagia = [$megaliParaskevi, $megaloSavvato, $orthodoxEaster, $deuteraPasha]; - - if (in_array($protomagia, $moveProtomagia, true)) { + $moveProtomagia = [$megaliTetarti, $megaliPempti, $megaliParaskevi, $megaloSavvato, $orthodoxEaster, $deuteraPasha]; + if (in_array($protomagia, $moveProtomagia)) { $protomagia = $orthodoxEaster->copy()->addDays(2); } diff --git a/tests/.pest/snapshots/Countries/GreeceTest/it_can_calculate_hellenic_holidays.snap b/tests/.pest/snapshots/Countries/GreeceTest/it_can_calculate_hellenic_holidays.snap index 00c8075cc..6d0af90fb 100644 --- a/tests/.pest/snapshots/Countries/GreeceTest/it_can_calculate_hellenic_holidays.snap +++ b/tests/.pest/snapshots/Countries/GreeceTest/it_can_calculate_hellenic_holidays.snap @@ -15,10 +15,6 @@ "name": "25\u03b7 \u039c\u03b1\u03c1\u03c4\u03af\u03bf\u03c5", "date": "2024-03-25" }, - { - "name": "\u03a0\u03c1\u03c9\u03c4\u03bf\u03bc\u03b1\u03b3\u03b9\u03ac", - "date": "2024-05-01" - }, { "name": "\u039c\u03b5\u03b3\u03ac\u03bb\u03b7 \u03a0\u03b1\u03c1\u03b1\u03c3\u03ba\u03b5\u03c5\u03ae", "date": "2024-05-03" @@ -31,6 +27,10 @@ "name": "\u0394\u03b5\u03c5\u03c4\u03ad\u03c1\u03b1 \u03c4\u03bf\u03c5 \u03a0\u03ac\u03c3\u03c7\u03b1", "date": "2024-05-06" }, + { + "name": "\u03a0\u03c1\u03c9\u03c4\u03bf\u03bc\u03b1\u03b3\u03b9\u03ac", + "date": "2024-05-07" + }, { "name": "\u0391\u03b3\u03af\u03bf\u03c5 \u03a0\u03bd\u03b5\u03cd\u03bc\u03b1\u03c4\u03bf\u03c2", "date": "2024-06-24"