Skip to content

Commit

Permalink
cleanup Wales related countries
Browse files Browse the repository at this point in the history
  • Loading branch information
Nielsvanpach committed Feb 9, 2024
1 parent a564053 commit 8e8a4a1
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 114 deletions.
76 changes: 26 additions & 50 deletions src/Countries/NorthernIreland.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, CarbonInterface> */
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<string, CarbonInterface> */
private function battleOfTheBoyne(int $year): array
/** @return array<string, string|CarbonInterface> */
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<string, 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 $holidays;
}
}
109 changes: 45 additions & 64 deletions src/Countries/Scotland.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,84 +12,65 @@ public function countryCode(): string
return 'gb-sct';
}

/** @return array<string, CarbonInterface> */
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<string, CarbonInterface> */
private function stAndrewsDay(int $year): array
/** @return array<string, string|CarbonInterface> */
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<string, CarbonInterface> */
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<string, CarbonInterface> */
protected function allHolidays(int $year): array
/** @return array<string, string|CarbonImmutable> */
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<string, CarbonImmutable> */
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,
};
}
}

0 comments on commit 8e8a4a1

Please sign in to comment.