generated from spatie/package-skeleton-php
-
-
Notifications
You must be signed in to change notification settings - Fork 198
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add holidays for scotland and northern ireland
- Loading branch information
1 parent
7ad1f80
commit 80df9e2
Showing
28 changed files
with
1,038 additions
and
26 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
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,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, | ||
]; | ||
} | ||
} |
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,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, | ||
]; | ||
} | ||
} |
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
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
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
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" | ||
} | ||
] |
34 changes: 34 additions & 0 deletions
34
...est/snapshots/Countries/NorthernIrelandTest/it_can_calculate_northern_irish_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.