Skip to content

Commit

Permalink
add holidays for scotland and northern ireland
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonBarrettACT committed Jan 18, 2024
1 parent 7ad1f80 commit 80df9e2
Show file tree
Hide file tree
Showing 28 changed files with 1,038 additions and 26 deletions.
4 changes: 1 addition & 3 deletions src/Countries/England.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@

namespace Spatie\Holidays\Countries;

use Carbon\CarbonImmutable;

class England extends Wales
{
public function countryCode(): string
{
return 'en';
return 'gb-eng';
}
}
88 changes: 88 additions & 0 deletions src/Countries/NorthernIreland.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
<?php

namespace Spatie\Holidays\Countries;

use Carbon\CarbonImmutable;

class NorthernIreland extends Wales
{
public function countryCode(): string
{
return 'gb-nir';
}

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];
}

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];
}

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<string, CarbonImmutable> */
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<string, CarbonImmutable> */
protected function variableHolidays(int $year): array
{
$easterSunday = CarbonImmutable::createFromTimestamp(easter_date($year))
->setTimezone('Europe/London');

$goodFriday = $easterSunday->subDays(2);
$easterMonday = $easterSunday->addDay();

return [
'Good Friday' => $goodFriday,
'Easter Monday' => $easterMonday,
];
}
}
92 changes: 92 additions & 0 deletions src/Countries/Scotland.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
<?php

namespace Spatie\Holidays\Countries;

use Carbon\CarbonImmutable;

class Scotland extends Wales
{
public function countryCode(): string
{
return 'gb-sct';
}

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];
}

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];
}

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<string, CarbonImmutable> */
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<string, CarbonImmutable> */
protected function variableHolidays(int $year): array
{
$easterSunday = CarbonImmutable::createFromTimestamp(easter_date($year))
->setTimezone('Europe/London');

$goodFriday = $easterSunday->subDays(2);

return [
'Good Friday' => $goodFriday,
];
}
}
48 changes: 40 additions & 8 deletions src/Countries/Wales.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ class Wales extends Country
{
public function countryCode(): string
{
return 'cy';
return 'gb-cym';
}

private function christmasDay(int $year): array
protected function christmasDay(int $year): array
{
$christmasDay = new CarbonImmutable($year . "-12-25", 'Europe/London');
$key = 'Christmas Day';
Expand All @@ -30,7 +30,7 @@ private function christmasDay(int $year): array
}


private function boxingDay(int $year): array
protected function boxingDay(int $year): array
{
$christmasDay = new CarbonImmutable($year . "-12-25", 'Europe/London');
$boxingDay = new CarbonImmutable($year . "-12-26", 'Europe/London');
Expand All @@ -50,33 +50,65 @@ private function boxingDay(int $year): array
}


private function newYearsDay(int $year): array
protected function newYearsDay(int $year): array
{
$newYearsDay = new CarbonImmutable($year . "-01-01", 'Europe/London');
$key = 'New Year\'s Day';

if ($newYearsDay->isSaturday() || $newYearsDay->isSunday()) {
if ($newYearsDay->isWeekend()) {
$key .= ' (substitute day)';
$newYearsDay = $newYearsDay->next('monday');
}

return [$key => $newYearsDay];
}

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')];
}

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<string, CarbonImmutable> */
protected function allHolidays(int $year): array
{
return array_merge(
$regularHolidays = array_merge(
$this->newYearsDay($year),
$this->earlyMayBankHoliday($year),
[
'Early May bank holiday' => new CarbonImmutable("first monday of may {$year}", 'Europe/London'),
'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));
$this->variableHolidays($year)
);

$oneOffHolidays = $this->oneOffHolidays($year);

return array_merge($regularHolidays, $oneOffHolidays);
}

/** @return array<string, CarbonImmutable> */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
"date": "2020-04-13"
},
{
"name": "Early May bank holiday",
"date": "2020-05-04"
"name": "Early May bank holiday (VE day)",
"date": "2020-05-08"
},
{
"name": "Spring bank holiday",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,18 @@
"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"
Expand Down
Original file line number Diff line number Diff line change
@@ -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"
}
]
Original file line number Diff line number Diff line change
@@ -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"
}
]
Loading

0 comments on commit 80df9e2

Please sign in to comment.