Skip to content

Commit

Permalink
Merge branch 'develop' into default-locale-deprecate
Browse files Browse the repository at this point in the history
  • Loading branch information
c960657 authored Aug 18, 2019
2 parents b4ca632 + 51c064c commit ecaf65c
Show file tree
Hide file tree
Showing 7 changed files with 191 additions and 52 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p
- Holiday Provider for South Korea. [\#156](https://github.com/azuyalabs/yasumi/pull/156) ([blood72](https://github.com/blood72))
- Translation for the Easter holiday for the 'fr_FR' locale [\#146](https://github.com/azuyalabs/yasumi/pull/146) ([pioc92](https://github.com/pioc92))
- Translation for the Pentecoste holiday for the 'fr_FR' locale [\#145](https://github.com/azuyalabs/yasumi/pull/145) ([pioc92](https://github.com/pioc92))
- Late Summer Bank Holiday in United Kingdom prior to 1965 [\#161](https://github.com/azuyalabs/yasumi/pull/161) ([c960657](https://github.com/c960657))
- Added `Yasumi::setDefaultLocale()` and `Yasumi::getDefaultLocale()`. [\#123](https://github.com/azuyalabs/yasumi/pull/123) ([c960657](https://github.com/c960657))
- Added optional $argument for `Holiday::getName($locale)` for overriding the default locale. [\#123](https://github.com/azuyalabs/yasumi/pull/123) ([c960657](https://github.com/c960657))

Expand All @@ -20,6 +21,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p
- Updated the translation for the Assumption of Mary holiday for the 'fr_FR' locale [\#155](https://github.com/azuyalabs/yasumi/pull/155) ([pioc92](https://github.com/pioc92))

### Fixed
- Late Summer Bank Holiday in 1968 and 1969 in United Kingdom [\#161](https://github.com/azuyalabs/yasumi/pull/161) ([c960657](https://github.com/c960657))
- Fixed one-off exceptions for May Day Bank Holiday in 1995 and 2020 and Spring Bank Holiday in 2002 and 2012 (United Kingdom) [\#160](https://github.com/azuyalabs/yasumi/pull/160) ([c960657](https://github.com/c960657))

### Removed

Expand Down
44 changes: 18 additions & 26 deletions src/Yasumi/Provider/Finland.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,23 +84,20 @@ public function initialize(): void
*/
private function calculateStJohnsDay(): void
{
$translation = ['fi_FI' => 'Juhannuspäivä'];
$shortName = 'stJohnsDay';
$date = new DateTime("$this->year-6-24", new DateTimeZone($this->timezone)); // Default date

if ($this->year < 1955) {
$this->addHoliday(new Holiday($shortName, $translation, $date, $this->locale));
$this->addHoliday(new Holiday(
'stJohnsDay',
[],
new DateTime("$this->year-6-24", new DateTimeZone($this->timezone)),
$this->locale
));
} else {

// Check between the 20th and 26th day which one is a Saturday
for ($d = 20; $d <= 26; ++$d) {
$date->setDate($this->year, 6, $d);
if ($date->format('l') === 'Saturday') {
break;
}
}

$this->addHoliday(new Holiday($shortName, $translation, $date, $this->locale));
$this->addHoliday(new Holiday(
'stJohnsDay',
[],
new DateTime("$this->year-6-20 this saturday", new DateTimeZone($this->timezone)),
$this->locale
));
}
}

Expand Down Expand Up @@ -128,17 +125,12 @@ private function calculateStJohnsDay(): void
*/
private function calculateAllSaintsDay(): void
{
$date = new DateTime("$this->year-10-31", new DateTimeZone($this->timezone));

// Check between 31 October and 6th of November the day that is a Saturday
for ($d = 0; $d <= 7; ++$d) {
if ($date->format('l') === 'Saturday') {
break;
}
$date->add(new DateInterval('P1D'));
}

$this->addHoliday(new Holiday('allSaintsDay', [], $date, $this->locale));
$this->addHoliday(new Holiday(
'allSaintsDay',
[],
new DateTime("$this->year-10-31 this saturday", new DateTimeZone($this->timezone)),
$this->locale
));
}

/**
Expand Down
34 changes: 12 additions & 22 deletions src/Yasumi/Provider/Sweden.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,17 +84,12 @@ public function initialize(): void
*/
private function calculateStJohnsDay(): void
{
$date = new DateTime("$this->year-6-20", new DateTimeZone($this->timezone)); // Default date

// Check between the 20th and 26th day which one is a Saturday
for ($d = 0; $d <= 7; ++$d) {
if ($date->format('l') === 'Saturday') {
break;
}
$date->add(new DateInterval('P1D'));
}

$this->addHoliday(new Holiday('stJohnsDay', ['sv_SE' => 'midsommardagen'], $date, $this->locale));
$this->addHoliday(new Holiday(
'stJohnsDay',
[],
new DateTime("$this->year-6-20 this saturday", new DateTimeZone($this->timezone)),
$this->locale
));
}

/**
Expand All @@ -120,17 +115,12 @@ private function calculateStJohnsDay(): void
*/
private function calculateAllSaintsDay(): void
{
$date = new DateTime("$this->year-10-31", new DateTimeZone($this->timezone));

// Check between 31 October and 6th of November the day that is a Saturday
for ($d = 0; $d <= 7; ++$d) {
if ($date->format('l') === 'Saturday') {
break;
}
$date->add(new DateInterval('P1D'));
}

$this->addHoliday(new Holiday('allSaintsDay', [], $date, $this->locale));
$this->addHoliday(new Holiday(
'allSaintsDay',
[],
new DateTime("$this->year-10-31 this saturday", new DateTimeZone($this->timezone)),
$this->locale
));
}

/**
Expand Down
57 changes: 55 additions & 2 deletions src/Yasumi/Provider/UnitedKingdom.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,19 @@ private function calculateMayDayBankHoliday(): void
return;
}

// Moved to 8 May to commemorate the 50th (1995) and 75th (2020) anniversary of VE Day.
if ($this->year == 1995 || $this->year == 2020) {
$this->addHoliday(new Holiday(
'mayDayBankHoliday',
['en_GB' => 'May Day Bank Holiday'],
new DateTime("$this->year-5-8", new DateTimeZone($this->timezone)),
$this->locale,
Holiday::TYPE_BANK
));

return;
}

$this->addHoliday(new Holiday(
'mayDayBankHoliday',
['en_GB' => 'May Day Bank Holiday'],
Expand Down Expand Up @@ -150,6 +163,20 @@ private function calculateSpringBankHoliday(): void
return;
}

// Moved to 4 June for the celebration of the Golden (2002) and Diamond (2012) Jubilee
// of Elizabeth II.
if ($this->year == 2002 || $this->year == 2012) {
$this->addHoliday(new Holiday(
'springBankHoliday',
['en_GB' => 'Spring Bank Holiday'],
new DateTime("$this->year-6-4", new DateTimeZone($this->timezone)),
$this->locale,
Holiday::TYPE_BANK
));

return;
}

$this->addHoliday(new Holiday(
'springBankHoliday',
['en_GB' => 'Spring Bank Holiday'],
Expand All @@ -162,7 +189,7 @@ private function calculateSpringBankHoliday(): void
/**
* The Summer Bank holiday, also known as the Late Summer bank holiday, is a time for people in the United Kingdom
* to have a day off work or school. It falls on the last Monday of August replacing the first Monday in August
* (formerly commonly known as "August Bank Holiday".
* (formerly commonly known as "August Bank Holiday").
*
* Many organizations, businesses and schools are closed. Stores may be open or closed, according to local custom.
* Public transport systems often run to a holiday timetable.
Expand All @@ -177,8 +204,34 @@ private function calculateSpringBankHoliday(): void
*/
private function calculateSummerBankHoliday(): void
{
// Statutory bank holiday from 1971, following a trial period from 1965 to 1970.
if ($this->year < 1871) {
return;
}

if ($this->year < 1965) {
$this->addHoliday(new Holiday(
'summerBankHoliday',
['en_GB' => 'August Bank Holiday'],
new DateTime("first monday of august $this->year", new DateTimeZone($this->timezone)),
$this->locale,
Holiday::TYPE_BANK
));

return;
}

// Statutory bank holiday from 1971, following a trial period from 1965 to 1970.
// During the trial period, the definition was different than today, causing exceptions
// in 1968 and 1969.
if ($this->year == 1968 || $this->year == 1969) {
$this->addHoliday(new Holiday(
'summerBankHoliday',
['en_GB' => 'Summer Bank Holiday'],
new DateTime("first monday of september $this->year", new DateTimeZone($this->timezone)),
$this->locale,
Holiday::TYPE_BANK
));

return;
}

Expand Down
21 changes: 21 additions & 0 deletions tests/UnitedKingdom/MayDayBankHolidayTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,27 @@ public function testHoliday()
);
}

/**
* Tests the holiday exception in 1995 and 2020.
* @throws \ReflectionException
*/
public function testHolidayExceptions()
{
$this->assertHoliday(
self::REGION,
self::HOLIDAY,
1995,
new DateTime("1995-5-8", new DateTimeZone(self::TIMEZONE))
);

$this->assertHoliday(
self::REGION,
self::HOLIDAY,
2020,
new DateTime("2020-5-8", new DateTimeZone(self::TIMEZONE))
);
}

/**
* Tests the holiday defined in this test before establishment.
* @throws \ReflectionException
Expand Down
21 changes: 21 additions & 0 deletions tests/UnitedKingdom/SpringBankHolidayTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,27 @@ public function testHoliday()
);
}

/**
* Tests the holiday exceptions in 2002 and 2012.
* @throws \ReflectionException
*/
public function testHolidayException()
{
$this->assertHoliday(
self::REGION,
self::HOLIDAY,
2002,
new DateTime("2002-6-4", new DateTimeZone(self::TIMEZONE))
);

$this->assertHoliday(
self::REGION,
self::HOLIDAY,
2012,
new DateTime("2012-6-4", new DateTimeZone(self::TIMEZONE))
);
}

/**
* Tests the holiday defined in this test before establishment.
* @throws \ReflectionException
Expand Down
63 changes: 61 additions & 2 deletions tests/UnitedKingdom/SummerBankHolidayTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class SummerBankHolidayTest extends UnitedKingdomBaseTestCase implements YasumiT
/**
* The year in which the holiday was first established
*/
public const ESTABLISHMENT_YEAR = 1965;
public const ESTABLISHMENT_YEAR = 1871;

/**
* Tests the holiday defined in this test.
Expand All @@ -39,7 +39,7 @@ class SummerBankHolidayTest extends UnitedKingdomBaseTestCase implements YasumiT
*/
public function testHoliday()
{
$year = $this->generateRandomYear(self::ESTABLISHMENT_YEAR);
$year = $this->generateRandomYear(1970);
$this->assertHoliday(
self::REGION,
self::HOLIDAY,
Expand All @@ -48,6 +48,65 @@ public function testHoliday()
);
}

/**
* Tests the holiday exception in 2020.
* @throws \ReflectionException
*/
public function testHolidayBefore1965()
{
$year = $this->generateRandomYear(self::ESTABLISHMENT_YEAR, 1967);
$this->assertHoliday(
self::REGION,
self::HOLIDAY,
$year,
new DateTime("first monday of august $year", new DateTimeZone(self::TIMEZONE))
);
}

/**
* Tests the holiday during trial period in 1965-1970.
* @throws \ReflectionException
*/
public function testHolidayTrialPeriod()
{
$this->assertHoliday(
self::REGION,
self::HOLIDAY,
1965,
new DateTime("1965-8-30", new DateTimeZone(self::TIMEZONE))
);
$this->assertHoliday(
self::REGION,
self::HOLIDAY,
1966,
new DateTime("1966-8-29", new DateTimeZone(self::TIMEZONE))
);
$this->assertHoliday(
self::REGION,
self::HOLIDAY,
1967,
new DateTime("1967-8-28", new DateTimeZone(self::TIMEZONE))
);
$this->assertHoliday(
self::REGION,
self::HOLIDAY,
1968,
new DateTime("1968-9-2", new DateTimeZone(self::TIMEZONE))
);
$this->assertHoliday(
self::REGION,
self::HOLIDAY,
1969,
new DateTime("1969-9-1", new DateTimeZone(self::TIMEZONE))
);
$this->assertHoliday(
self::REGION,
self::HOLIDAY,
1970,
new DateTime("1970-8-31", new DateTimeZone(self::TIMEZONE))
);
}

/**
* Tests the holiday defined in this test before establishment.
* @throws \ReflectionException
Expand Down

0 comments on commit ecaf65c

Please sign in to comment.