generated from spatie/package-skeleton-php
-
-
Notifications
You must be signed in to change notification settings - Fork 196
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add wales, england, scotland and northern ireland (#162)
- Loading branch information
1 parent
b5bb47f
commit b41b7d1
Showing
34 changed files
with
1,750 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?php | ||
|
||
namespace Spatie\Holidays\Countries; | ||
|
||
class England extends Wales | ||
{ | ||
public function countryCode(): string | ||
{ | ||
return 'gb-eng'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
<?php | ||
|
||
namespace Spatie\Holidays\Countries; | ||
|
||
use Carbon\CarbonImmutable; | ||
|
||
class NorthernIreland extends Wales | ||
{ | ||
public function countryCode(): string | ||
{ | ||
return 'gb-nir'; | ||
} | ||
|
||
/** @return array<string, CarbonImmutable> */ | ||
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, CarbonImmutable> */ | ||
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<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 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 = $this->easter($year); | ||
|
||
$goodFriday = $easterSunday->subDays(2); | ||
$easterMonday = $easterSunday->addDay(); | ||
|
||
return [ | ||
'Good Friday' => $goodFriday, | ||
'Easter Monday' => $easterMonday, | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
<?php | ||
|
||
namespace Spatie\Holidays\Countries; | ||
|
||
use Carbon\CarbonImmutable; | ||
|
||
class Scotland extends Wales | ||
{ | ||
public function countryCode(): string | ||
{ | ||
return 'gb-sct'; | ||
} | ||
|
||
/** @return array<string, CarbonImmutable> */ | ||
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<string, CarbonImmutable> */ | ||
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<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 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 = $this->easter($year); | ||
|
||
$goodFriday = $easterSunday->subDays(2); | ||
|
||
return [ | ||
'Good Friday' => $goodFriday, | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
<?php | ||
|
||
namespace Spatie\Holidays\Countries; | ||
|
||
use Carbon\CarbonImmutable; | ||
|
||
class Wales extends Country | ||
{ | ||
public function countryCode(): string | ||
{ | ||
return 'gb-cym'; | ||
} | ||
|
||
/** @return array<string, CarbonImmutable> */ | ||
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<string, CarbonImmutable> */ | ||
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<string, CarbonImmutable> */ | ||
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<string, CarbonImmutable> */ | ||
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<string, CarbonImmutable> */ | ||
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<string, CarbonImmutable> */ | ||
protected function variableHolidays(int $year): array | ||
{ | ||
$easterSunday = $this->easter($year); | ||
|
||
$goodFriday = $easterSunday->subDays(2); | ||
$easterMonday = $easterSunday->addDay(); | ||
|
||
return [ | ||
'Good Friday' => $goodFriday, | ||
'Easter Monday' => $easterMonday, | ||
]; | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
tests/.pest/snapshots/Countries/EnglandTest/it_can_calculate_holidays_for_2020.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
] |
Oops, something went wrong.