Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add England, Wales, Scotland, Northern Ireland #166

Merged
merged 13 commits into from Sep 19, 2019
2 changes: 2 additions & 0 deletions CHANGELOG.md
Expand Up @@ -13,6 +13,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p
- Observance holidays for Sweden [\#172](https://github.com/azuyalabs/yasumi/pull/172) ([c960657](https://github.com/c960657))
- Added additional code style fixers and aligning StyleCI settings with PHP-CS.
- Included extra requirement for some PHP Extensions in the composer file.
- Holiday providers for England, Wales, Scotland and Northern Ireland [\#165](https://github.com/azuyalabs/yasumi/pull/165) ([c960657](https://github.com/c960657))
c960657 marked this conversation as resolved.
Show resolved Hide resolved
- Holiday providers for England, Wales, Scotland and Northern Ireland [\#166](https://github.com/azuyalabs/yasumi/pull/166) ([c960657](https://github.com/c960657))

### Changed
- Updated the translation for the All Saints holiday for the 'fr_FR' locale [\#152](https://github.com/azuyalabs/yasumi/pull/152) ([pioc92](https://github.com/pioc92))
Expand Down
10 changes: 6 additions & 4 deletions src/Yasumi/Provider/Romania.php
Expand Up @@ -135,10 +135,12 @@ private function calculateUnitedPrincipalitiesDay(): void
private function calculateStAndrewDay(): void
{
if ($this->year >= 2012) {
$this->addHoliday(new Holiday('stAndrewDay', [
'en_US' => 'Saint Andrew\'s Day',
'ro_RO' => 'Sfântul Andrei'
], new DateTime($this->year . '-11-30', new DateTimeZone($this->timezone)), $this->locale));
$this->addHoliday(new Holiday(
'stAndrewsDay',
[],
new DateTime($this->year . '-11-30', new DateTimeZone($this->timezone)),
$this->locale
));
}
}

Expand Down
16 changes: 8 additions & 8 deletions src/Yasumi/Provider/UnitedKingdom.php
Expand Up @@ -33,6 +33,8 @@ class UnitedKingdom extends AbstractProvider
*/
public const ID = 'GB';

public $timezone = 'Europe/London';

/**
* Initialize holidays for the United Kingdom.
*
Expand All @@ -43,8 +45,6 @@ class UnitedKingdom extends AbstractProvider
*/
public function initialize(): void
{
$this->timezone = 'Europe/London';

// Add common holidays
$this->calculateNewYearsDay();
$this->calculateMayDayBankHoliday();
Expand Down Expand Up @@ -74,7 +74,7 @@ public function initialize(): void
* @throws UnknownLocaleException
* @throws \Exception
*/
private function calculateNewYearsDay(): void
protected function calculateNewYearsDay(): void
{
// Before 1871 it was not an observed or statutory holiday
if ($this->year < 1871) {
Expand Down Expand Up @@ -113,7 +113,7 @@ private function calculateNewYearsDay(): void
* @throws UnknownLocaleException
* @throws \Exception
*/
private function calculateMayDayBankHoliday(): void
protected function calculateMayDayBankHoliday(): void
{
// From 1978, by Royal Proclamation annually
if ($this->year < 1978) {
Expand Down Expand Up @@ -158,7 +158,7 @@ private function calculateMayDayBankHoliday(): void
* @throws UnknownLocaleException
* @throws \Exception
*/
private function calculateSpringBankHoliday(): void
protected function calculateSpringBankHoliday(): void
{
// Statutory bank holiday from 1971, following a trial period from 1965 to 1970.
if ($this->year < 1965) {
Expand Down Expand Up @@ -204,7 +204,7 @@ private function calculateSpringBankHoliday(): void
* @throws UnknownLocaleException
* @throws \Exception
*/
private function calculateSummerBankHoliday(): void
protected function calculateSummerBankHoliday(): void
{
if ($this->year < 1871) {
return;
Expand Down Expand Up @@ -268,12 +268,12 @@ private function calculateSummerBankHoliday(): void
* @throws UnknownLocaleException
* @throws \Exception
*/
private function calculateChristmasHolidays(): void
protected function calculateChristmasHolidays($type = Holiday::TYPE_OFFICIAL): void
{
$christmasDay = new DateTime("$this->year-12-25", new DateTimeZone($this->timezone));
$boxingDay = new DateTime("$this->year-12-26", new DateTimeZone($this->timezone));

$this->addHoliday(new Holiday('christmasDay', [], $christmasDay, $this->locale));
$this->addHoliday(new Holiday('christmasDay', [], $christmasDay, $this->locale, $type));
$this->addHoliday(new Holiday('secondChristmasDay', [], $boxingDay, $this->locale, Holiday::TYPE_BANK));

$substituteChristmasDay = clone $christmasDay;
Expand Down
34 changes: 34 additions & 0 deletions src/Yasumi/Provider/UnitedKingdom/England.php
@@ -0,0 +1,34 @@
<?php
/**
* This file is part of the Yasumi package.
*
* Copyright (c) 2015 - 2019 AzuyaLabs
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @author Sacha Telgenhof <me@sachatelgenhof.com>
*/

namespace Yasumi\Provider\UnitedKingdom;

use Yasumi\Holiday;
use Yasumi\Provider\UnitedKingdom;

/**
* Provider for all holidays in England (United Kingdom).
*
* England is a country that is part of the United Kingdom. It covers an area of 130,279 square kilometres
* (50,301 sq mi), and has a population of 5,619,400. London, England's capital, is also the capital of
* and the largest city in the United Kingdom.
*
* @link https://en.wikipedia.org/wiki/England
*/
class England extends UnitedKingdom
{
/**
* Code to identify this Holiday Provider. Typically this is the ISO3166 code corresponding to the respective
* country or sub-region.
*/
public const ID = 'GB-ENG';
}
148 changes: 148 additions & 0 deletions src/Yasumi/Provider/UnitedKingdom/NorthernIreland.php
@@ -0,0 +1,148 @@
<?php
/**
* This file is part of the Yasumi package.
*
* Copyright (c) 2015 - 2019 AzuyaLabs
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @author Sacha Telgenhof <me@sachatelgenhof.com>
*/

namespace Yasumi\Provider\UnitedKingdom;

use DateTime;
use DateTimeZone;
use Yasumi\Holiday;
use Yasumi\Provider\UnitedKingdom;

/**
* Provider for all holidays in Northern Ireland (United Kingdom).
*
* Northern Ireland is a country that is part of the United Kingdom. It covers an area of 14,130 square kilometres
* (5,460 sq mi), and has a population of 1,885,400. Belfast, Northern Ireland's capital and largest city,
* is the 12th largest city in the United Kingdom.
*
* @link https://en.wikipedia.org/wiki/Northern_Ireland
*/
class NorthernIreland extends UnitedKingdom
{
/**
* Code to identify this Holiday Provider. Typically this is the ISO3166 code corresponding to the respective
* country or sub-region.
*/
public const ID = 'GB-NIR';

public $timezone = 'Europe/Belfast';

/**
* Initialize holidays for Northern Ireland (United Kingdom).
*
* @throws \Yasumi\Exception\InvalidDateException
* @throws \InvalidArgumentException
* @throws \Yasumi\Exception\UnknownLocaleException
* @throws \Exception
*/
public function initialize(): void
{
parent::initialize();

$this->calculateStPatricksDay();
$this->calculateBattleOfTheBoyne();
}

/**
* St. Patrick's Day.
*
* Saint Patrick's Day, or the Feast of Saint Patrick (Irish: Lá Fhéile Pádraig, "the Day of the Festival of
* Patrick"), is a cultural and religious celebration held on 17 March, the traditional death date of Saint Patrick
* (c. AD 385–461), the foremost patron saint of Ireland. Saint Patrick's Day is a public holiday in the Republic
* of Ireland, Northern Ireland, the Canadian province of Newfoundland and Labrador, and the British Overseas
* Territory of Montserrat.
*
* @link https://en.wikipedia.org/wiki/Saint_Patrick%27s_Day
*
* @throws \Yasumi\Exception\InvalidDateException
* @throws \InvalidArgumentException
* @throws \Yasumi\Exception\UnknownLocaleException
* @throws \Exception
* @throws \Exception
*/
private function calculateStPatricksDay(): void
{
if ($this->year < 1971) {
return;
}

$holiday = new Holiday(
'stPatricksDay',
['en_GB' => 'St. Patrick\'s Day'],
new DateTime($this->year . '-3-17', new DateTimeZone($this->timezone)),
$this->locale,
Holiday::TYPE_BANK
);

$this->addHoliday($holiday);

// Substitute holiday is on the next available weekday if a holiday falls on a Saturday or Sunday
if (\in_array((int)$holiday->format('w'), [0, 6], true)) {
$substituteHoliday = clone $holiday;
$substituteHoliday->modify('next monday');

$this->addHoliday(new Holiday(
'substituteHoliday:' . $substituteHoliday->shortName,
['en_GB' => $substituteHoliday->getName() . ' (substitute day)'],
$substituteHoliday,
$this->locale,
Holiday::TYPE_BANK
));
}
}

/**
* Battle of the Boyne.
*
* Orangemen's Day, also called The Twelfth or Glorious Twelfth) celebrates the Glorious Revolution (1688)
* and victory of Protestant King William of Orange over Catholic king James II at the Battle of the
* Boyne (1690), which began the Protestant Ascendancy in Ireland.
*
* @link https://en.wikipedia.org/wiki/The_Twelfth
*
* @throws \Yasumi\Exception\InvalidDateException
* @throws \InvalidArgumentException
* @throws \Yasumi\Exception\UnknownLocaleException
* @throws \Exception
* @throws \Exception
*/
private function calculateBattleOfTheBoyne(): void
{
if ($this->year < 1926) {
return;
}

$holiday = new Holiday(
'battleOfTheBoyne',
['en_GB' => 'Battle of the Boyne'],
new DateTime($this->year . '-7-12', new DateTimeZone($this->timezone)),
$this->locale,
Holiday::TYPE_BANK
);

$this->addHoliday($holiday);

// Substitute holiday is on the next available weekday if a holiday falls on a Saturday or Sunday
if (\in_array((int)$holiday->format('w'), [0, 6], true)) {
$substituteHoliday = clone $holiday;
$substituteHoliday->modify('next monday');

$this->addHoliday(new Holiday(
'substituteHoliday:' . $substituteHoliday->shortName,
c960657 marked this conversation as resolved.
Show resolved Hide resolved
['en_GB' => $substituteHoliday->getName() . ' (substitute day)'],
$substituteHoliday,
$this->locale,
Holiday::TYPE_BANK
));
}
}
}