Skip to content

Commit

Permalink
The Japanese Emperor will abdicate the throne on May 1st 2019. (#130)
Browse files Browse the repository at this point in the history
The Japanese Emperor will abdicate the throne on May 1st 2019.
Change Emperors Birthday to Feb 23th.
Add Coronation Day And Enthronement Proclamation Ceremony.
  • Loading branch information
cookie-maker authored and stelgenhof committed Mar 7, 2019
1 parent 2e95813 commit 025843a
Show file tree
Hide file tree
Showing 5 changed files with 342 additions and 9 deletions.
57 changes: 53 additions & 4 deletions src/Yasumi/Provider/Japan.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ public function initialize(): void
$this->calculateAutumnalEquinoxDay();
$this->calculateSubstituteHolidays();
$this->calculateBridgeHolidays();
$this->calculateCoronationDay();
$this->calculateEnthronementProclamationCeremony();
}

/**
Expand Down Expand Up @@ -210,18 +212,65 @@ private function calculateLaborThanksgivingDay(): void
}

/**
* Emperors Birthday. The Emperors Birthday is on December 23rd and celebrated as such since 1989.
* Prior to the death of Emperor Hirohito in 1989, this holiday was celebrated on April 29. See also "Shōwa Day".
* Emperors Birthday.
* The Emperors Birthday is on April 29rd and celebrated as such since 1949 to 1988.
* December 23rd and celebrated as such since 1989 to 2018.
* February 23rd and celebrated as such since 2020.(Coronation Day of the new Emperor, May 1, 2019)
*
* @throws \Exception
*/
private function calculateEmporersBirthday(): void
{
if ($this->year >= 1989) {
$emporersBirthday = false;
if ($this->year >=2020) {
$emporersBirthday = "$this->year-2-23";
} elseif ($this->year >= 1989 && $this->year <2019) {
$emporersBirthday = "$this->year-12-23";
} elseif ($this->year >= 1949 && $this->year <1988) {
$emporersBirthday = "$this->year-4-29";
}

if ($emporersBirthday) {
$this->addHoliday(new Holiday(
'emperorsBirthday',
['en_US' => 'Emperors Birthday', 'ja_JP' => '天皇誕生日'],
new DateTime("$this->year-12-23", new DateTimeZone($this->timezone)),
new DateTime($emporersBirthday, new DateTimeZone($this->timezone)),
$this->locale
));
}
}

/**
* Coronation Day. Coronation Day is The new Emperor Coronation.
* This holiday is only 2019.
*
* @throws \Exception
*/
private function calculateCoronationDay(): void
{
if ($this->year == 2019) {
$this->addHoliday(new Holiday(
'coronationDay',
['en_US' => 'Coronation Day', 'ja_JP' => '即位の日'],
new DateTime("$this->year-5-1", new DateTimeZone($this->timezone)),
$this->locale
));
}
}

/**
* Enthronement Proclamation Ceremony. Enthronement Proclamation Ceremony is The New Emperor enthronement ceremony.
* This holiday only 2019.
*
* @throws \Exception
*/
private function calculateEnthronementProclamationCeremony(): void
{
if ($this->year == 2019) {
$this->addHoliday(new Holiday(
'enthronementProclamationCeremony',
['en_US' => 'Enthronement Proclamation Ceremony', 'ja_JP' => '即位礼正殿の儀'],
new DateTime("$this->year-10-22", new DateTimeZone($this->timezone)),
$this->locale
));
}
Expand Down
105 changes: 105 additions & 0 deletions tests/Japan/CoronationDayTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
<?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 <[email protected]>
*/

namespace Yasumi\tests\Japan;

use DateTime;
use DateTimeZone;
use Yasumi\Holiday;
use Yasumi\tests\YasumiTestCaseInterface;

/**
* Class testing the Emperors Coronation day in Japan.
*/
class CoronationDayTest extends JapanBaseTestCase implements YasumiTestCaseInterface
{
/**
* The name of the holiday
*/
public const HOLIDAY = 'coronationDay';

/**
* The year in which the holiday was first established
*/
public const ESTABLISHMENT_YEAR = 2019;

/**
*
*
*
* @throws \Exception
* @throws \ReflectionException
*/
public function testEmperorsCoronationDay()
{
$this->assertHoliday(
self::REGION,
self::HOLIDAY,
2019,
new DateTime("2019-5-1", new DateTimeZone(self::TIMEZONE))
);
}


/**
* @throws \ReflectionException
*/
public function testEmperorsBirthdayBefore2019()
{
$this->assertNotHoliday(
self::REGION,
self::HOLIDAY,
$this->generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1)
);
}

/**
* @throws \ReflectionException
*/
public function testEmperorsBirthdayAfter2020()
{
$this->assertNotHoliday(
self::REGION,
self::HOLIDAY,
$this->generateRandomYear(self::ESTABLISHMENT_YEAR + 1)
);
}


/**
* Tests the translated name of the holiday defined in this test.
* @throws \ReflectionException
*/
public function testTranslation(): void
{
$this->assertTranslatedHolidayName(
self::REGION,
self::HOLIDAY,
2019,
[self::LOCALE => '即位の日']
);
}

/**
* Tests type of the holiday defined in this test.
* @throws \ReflectionException
*/
public function testHolidayType(): void
{
$this->assertHolidayType(
self::REGION,
self::HOLIDAY,
2019,
Holiday::TYPE_OFFICIAL
);
}
}
55 changes: 52 additions & 3 deletions tests/Japan/EmperorsBirthdayTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,36 @@ class EmperorsBirthdayTest extends JapanBaseTestCase implements YasumiTestCaseIn
/**
* The year in which the holiday was first established
*/
public const ESTABLISHMENT_YEAR = 1989;
public const ESTABLISHMENT_YEAR = 1949;
// public const ESTABLISHMENT_YEAR = 1989;

/**
* Tests the Emperors Birthday after 1989. The Emperors Birthday is on December 23rd and celebrated as such since
* Tests the Emperors Birthday after 1949 to 1988. The Emperors Birthday is on April 28rd and celebrated as such since
* 1949.
* @throws \Exception
* @throws \ReflectionException
*/
public function testEmperorsBirthdayOnAfter1949()
{
$year = $this->generateRandomYear(self::ESTABLISHMENT_YEAR, 1988);
$this->assertHoliday(
self::REGION,
self::HOLIDAY,
$year,
new DateTime("$year-4-29", new DateTimeZone(self::TIMEZONE))
);
}

/**
* Tests the Emperors Birthday after 1989 to 2018. The Emperors Birthday is on December 23rd and celebrated as such since
* 1989. Prior to the death of Emperor Hirohito in 1989, this holiday was celebrated on April 29. See also "Shōwa
* Day".
* @throws \Exception
* @throws \ReflectionException
*/
public function testEmperorsBirthdayOnAfter1989()
{
$year = 3012;
$year = $this->generateRandomYear(1989, 2018);
$this->assertHoliday(
self::REGION,
self::HOLIDAY,
Expand All @@ -50,6 +68,23 @@ public function testEmperorsBirthdayOnAfter1989()
);
}

/**
* Tests the Emperors Birthday after 2020. The Emperors Birthday is on February 23rd and celebrated as such since
* 2020.
* @throws \Exception
* @throws \ReflectionException
*/
public function testEmperorsBirthdayOnAfter2020()
{
$year = $this->generateRandomYear(2020);
$this->assertHoliday(
self::REGION,
self::HOLIDAY,
$year,
new DateTime("$year-2-23", new DateTimeZone(self::TIMEZONE))
);
}

/**
* Tests the Emperors Birthday after 1989 substituted next working day (when the Emperors Birthday falls on a
* Sunday)
Expand Down Expand Up @@ -82,6 +117,20 @@ public function testEmperorsBirthdayBefore1989()
);
}

/**
* Tests the Emperors Birthday at 2019.
*
* @throws \ReflectionException
*/
public function testEmperorsBirthdayAt2019()
{
$this->assertNotHoliday(
self::REGION,
self::HOLIDAY,
2019
);
}

/**
* Tests the translated name of the holiday defined in this test.
* @throws \ReflectionException
Expand Down
104 changes: 104 additions & 0 deletions tests/Japan/EnthronementProclamationCeremonyTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
<?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 <[email protected]>
*/

namespace Yasumi\tests\Japan;

use DateTime;
use DateTimeZone;
use Yasumi\Holiday;
use Yasumi\tests\YasumiTestCaseInterface;

/**
* Class testing the Emperors Coronation day in Japan.
*/
class EnthronementProclamationCeremonyTest extends JapanBaseTestCase implements YasumiTestCaseInterface
{
/**
* The name of the holiday
*/
public const HOLIDAY = 'enthronementProclamationCeremony';

/**
* The year in which the holiday was first established
*/
public const IMPLEMENT_YEAR = 2019;

/**
*
*
*
* @throws \Exception
* @throws \ReflectionException
*/
public function testEmperorsCoronationDay()
{
$this->assertHoliday(
self::REGION,
self::HOLIDAY,
2019,
new DateTime("2019-10-22", new DateTimeZone(self::TIMEZONE))
);
}


/**
* @throws \ReflectionException
*/
public function testEmperorsBirthdayBefore2019()
{
$this->assertNotHoliday(
self::REGION,
self::HOLIDAY,
$this->generateRandomYear(1000, self::IMPLEMENT_YEAR - 1)
);
}

/**
* @throws \ReflectionException
*/
public function testEmperorsBirthdayAfter2020()
{
$this->assertNotHoliday(
self::REGION,
self::HOLIDAY,
$this->generateRandomYear(self::IMPLEMENT_YEAR + 1)
);
}

/**
* Tests the translated name of the holiday defined in this test.
* @throws \ReflectionException
*/
public function testTranslation(): void
{
$this->assertTranslatedHolidayName(
self::REGION,
self::HOLIDAY,
2019,
[self::LOCALE => '即位礼正殿の儀']
);
}

/**
* Tests type of the holiday defined in this test.
* @throws \ReflectionException
*/
public function testHolidayType(): void
{
$this->assertHolidayType(
self::REGION,
self::HOLIDAY,
2019,
Holiday::TYPE_OFFICIAL
);
}
}
Loading

0 comments on commit 025843a

Please sign in to comment.