From f756448be3d8b583677b02193d72f165c89edd0a Mon Sep 17 00:00:00 2001 From: Sebastian Gabbert Date: Tue, 12 Feb 2019 07:58:18 +0100 Subject: [PATCH] International Womens Day (#133) --- CHANGELOG.md | 4 +- src/Yasumi/Provider/CommonHolidays.php | 35 +++++++ src/Yasumi/Provider/Germany/Berlin.php | 17 ++++ src/Yasumi/Provider/Russia.php | 5 +- src/Yasumi/Provider/Ukraine.php | 25 +---- .../translations/internationalWomensDay.php | 20 ++++ .../Berlin/InternationalWomensDay2019Test.php | 99 +++++++++++++++++++ 7 files changed, 176 insertions(+), 29 deletions(-) create mode 100755 src/Yasumi/data/translations/internationalWomensDay.php create mode 100644 tests/Germany/Berlin/InternationalWomensDay2019Test.php diff --git a/CHANGELOG.md b/CHANGELOG.md index 48b948f1b..24ebb2705 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,6 +24,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p - Added Reformation Day as offical holiday since 2018 in Schleswig-Holstein (Germany). [#106](https://github.com/azuyalabs/yasumi/pull/106) ([HenningCash](https://github.com/HenningCash)) - Added Reformation Day as offical holiday since 2018 in Hamburg (Germany). [#108](https://github.com/azuyalabs/yasumi/pull/108) ([HenningCash](https://github.com/HenningCash)) - Added Reformation Day as offical holiday since 2018 in Bremen (Germany). [#116](https://github.com/azuyalabs/yasumi/issues/116) ([TalonTR](https://github.com/TalonTR)) +- Added International Women's Day as official holidy since 2019 in Berlin (Germany). [#133](https://github.com/azuyalabs/yasumi/pull/133) ([huehnerhose](https://github.com/huehnerhose)) - The (observed) holidays Lukkeloven, Constitution Day, New Year's Eve and Labour Day, as well as summertime and wintertime are included for Denmark [\#104](https://github.com/azuyalabs/yasumi/pull/104) ([c960657](https://github.com/c960657)) ### Changed @@ -37,7 +38,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p - Updated copyright year. - Upgraded various dependency packages. - Internal locale list updated based on CLDR v34. -- Refactored the Japan and USA Holiday Provider by moving the holiday calculations to private methods. This reduced the complexity of the initialize method. +- Refactored the Japan and USA Holiday Provider by moving the holiday calculations to private methods. This reduced the complexity of the initialize method. +- Changed individual added International Women's Day for Ukraine and Russia to common holiday. [#133](https://github.com/azuyalabs/yasumi/pull/133) ([huehnerhose](https://github.com/huehnerhose)) ### Fixed - Translation for Russia showed in English (except New Year's Day) as the proper locale was not in place. diff --git a/src/Yasumi/Provider/CommonHolidays.php b/src/Yasumi/Provider/CommonHolidays.php index ed7703844..7c6c62d67 100644 --- a/src/Yasumi/Provider/CommonHolidays.php +++ b/src/Yasumi/Provider/CommonHolidays.php @@ -397,6 +397,41 @@ public function armisticeDay( ); } + /** + * International Women's Day + * + * International Women's Day (IWD) is celebrated on March 8 every year.[3] It is a focal point in the movement for women's rights. + * + * @link https://en.wikipedia.org/wiki/International_Women%27s_Day + * + * @param int $year the year for which International Women's Day need to be created + * @param string $timezone the timezone in which International Women's Day is celebrated + * @param string $locale the locale for which International Women's Day need to be displayed in. + * @param string $type The type of holiday. Use the following constants: TYPE_OFFICIAL, TYPE_OBSERVANCE, + * TYPE_SEASON, TYPE_BANK or TYPE_OTHER. By default an official holiday is considered. + * + * @return \Yasumi\Holiday + * + * @throws \Yasumi\Exception\InvalidDateException + * @throws \Yasumi\Exception\UnknownLocaleException + * @throws \InvalidArgumentException + * @throws \Exception + */ + public function internationalWomensDay( + int $year, + string $timezone, + string $locale, + string $type = Holiday::TYPE_OFFICIAL + ): Holiday { + return new Holiday( + 'internationalWomensDay', + [], + new DateTime("$year-03-08", new DateTimeZone($timezone)), + $locale, + $type + ); + } + /** * Calculates daylight saving time transitions. * diff --git a/src/Yasumi/Provider/Germany/Berlin.php b/src/Yasumi/Provider/Germany/Berlin.php index f0f5f8e60..2d1896d44 100755 --- a/src/Yasumi/Provider/Germany/Berlin.php +++ b/src/Yasumi/Provider/Germany/Berlin.php @@ -31,4 +31,21 @@ class Berlin extends Germany * country or sub-region. */ public const ID = 'DE-BE'; + + /** + * Initialize holidays for Berlin (Germany). + * + * @throws \Yasumi\Exception\InvalidDateException + * @throws \InvalidArgumentException + * @throws \Yasumi\Exception\UnknownLocaleException + * @throws \Exception + */ + public function initialize(): void + { + parent::initialize(); + + if ($this->year >= 2019) { + $this->addHoliday($this->internationalWomensDay($this->year, $this->timezone, $this->locale)); + } + } } diff --git a/src/Yasumi/Provider/Russia.php b/src/Yasumi/Provider/Russia.php index 7db1e63bf..184056835 100644 --- a/src/Yasumi/Provider/Russia.php +++ b/src/Yasumi/Provider/Russia.php @@ -107,10 +107,7 @@ private function addDefenceOfTheFatherlandDay(): void */ private function addInternationalWomensDay(): void { - $this->addHoliday(new Holiday('internationalWomensDay', [ - 'en_US' => 'International Women\'s Day', - 'ru_RU' => 'Международный женский день' - ], new \DateTime("{$this->year}-03-08", new \DateTimeZone($this->timezone)), $this->locale)); + $this->addHoliday($this->internationalWomensDay($this->year, $this->timezone, $this->locale)); } /** diff --git a/src/Yasumi/Provider/Ukraine.php b/src/Yasumi/Provider/Ukraine.php index 22608a876..e5e2e3dea 100644 --- a/src/Yasumi/Provider/Ukraine.php +++ b/src/Yasumi/Provider/Ukraine.php @@ -47,6 +47,7 @@ public function initialize(): void // Add common holidays $this->addHoliday($this->newYearsDay($this->year, $this->timezone, $this->locale)); $this->addHoliday($this->internationalWorkersDay($this->year, $this->timezone, $this->locale)); + $this->addHoliday($this->internationalWomensDay($this->year, $this->timezone, $this->locale)); // Add Christian holidays $this->addHoliday($this->easter($this->year, $this->timezone, $this->locale)); @@ -54,7 +55,6 @@ public function initialize(): void // Add other holidays $this->calculateChristmasDay(); - $this->calculateInternationalWomensDay(); $this->calculateSecondInternationalWorkersDay(); $this->calculateVictoryDay(); $this->calculateConstitutionDay(); @@ -80,29 +80,6 @@ public function calculateChristmasDay(): void )); } - /** - * International Women's Day. - * - * International Women's Day (IWD), originally called International Working Women's Day, is celebrated on March 8 - * every year. - * - * @link https://en.wikipedia.org/wiki/International_Women%27s_Day - * - * @throws \Yasumi\Exception\InvalidDateException - * @throws \InvalidArgumentException - * @throws \Yasumi\Exception\UnknownLocaleException - * @throws \Exception - */ - public function calculateInternationalWomensDay(): void - { - $this->addHoliday(new Holiday( - 'internationalWomensDay', - ['uk_UA' => 'Міжнародний жіночий день', 'ru_UA' => 'Международный женский день'], - new \DateTime("$this->year-03-08", new \DateTimeZone($this->timezone)), - $this->locale - )); - } - /** * International Workers' Day. * diff --git a/src/Yasumi/data/translations/internationalWomensDay.php b/src/Yasumi/data/translations/internationalWomensDay.php new file mode 100755 index 000000000..56267a472 --- /dev/null +++ b/src/Yasumi/data/translations/internationalWomensDay.php @@ -0,0 +1,20 @@ + + */ + +// Translations for International Women's Day +return [ + 'de_DE' => 'Internationaler Frauentag', + 'en_US' => 'International Women\'s Day', + 'ru_RU' => 'Международный женский день', + 'uk_UA' => 'Міжнародний жіночий день', + 'ru_UA' => 'Международный женский день', +]; diff --git a/tests/Germany/Berlin/InternationalWomensDay2019Test.php b/tests/Germany/Berlin/InternationalWomensDay2019Test.php new file mode 100644 index 000000000..2977417a2 --- /dev/null +++ b/tests/Germany/Berlin/InternationalWomensDay2019Test.php @@ -0,0 +1,99 @@ + + */ + +namespace Yasumi\tests\Germany\Berlin; + +use DateTime; +use DateTimeZone; +use Yasumi\Holiday; +use Yasumi\tests\YasumiTestCaseInterface; + +/** + * Class containing tests for Reformation Day in Germany. + */ +class InternationalWomensDay2019Test extends BerlinBaseTestCase implements YasumiTestCaseInterface +{ + /** + * The name of the holiday to be tested + */ + public const HOLIDAY = 'internationalWomensDay'; + + /** + * The year in which the holiday was established + */ + public const ESTABLISHMENT_YEAR = 2019; + + /** + * Test the holiday defined in this test upon establishment + * @throws \Exception + * @throws \ReflectionException + */ + public function testHolidayOnEstablishment() + { + $this->assertHoliday( + self::REGION, + self::HOLIDAY, + self::ESTABLISHMENT_YEAR, + new DateTime(self::ESTABLISHMENT_YEAR . '-03-08', new DateTimeZone(self::TIMEZONE)) + ); + } + + /** + * Test the holiday defined in this test before establishment + * @throws \ReflectionException + */ + public function testHolidayBeforeEstablishment() + { + $this->assertNotHoliday( + self::REGION, + self::HOLIDAY, + $this->generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1) + ); + } + + /** + * Test the holiday defined in this test after completion + * @throws \ReflectionException + */ + public function testHolidayAfterCompletion() + { + $this->assertNotHoliday(self::REGION, self::HOLIDAY, $this->generateRandomYear(1900, 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, + $this->generateRandomYear(self::ESTABLISHMENT_YEAR, self::ESTABLISHMENT_YEAR), + [self::LOCALE => 'Internationaler Frauentag'] + ); + } + + /** + * Tests type of the holiday defined in this test. + * @throws \ReflectionException + */ + public function testHolidayType(): void + { + $this->assertHolidayType( + self::REGION, + self::HOLIDAY, + $this->generateRandomYear(self::ESTABLISHMENT_YEAR, self::ESTABLISHMENT_YEAR), + Holiday::TYPE_OFFICIAL + ); + } +}