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, + }; } }