diff --git a/src/Yasumi/Provider/CommonHolidays.php b/src/Yasumi/Provider/CommonHolidays.php index 75bcebaf2..005191665 100644 --- a/src/Yasumi/Provider/CommonHolidays.php +++ b/src/Yasumi/Provider/CommonHolidays.php @@ -23,6 +23,37 @@ */ trait CommonHolidays { + /** + * New Year's Eve. + * + * New Year's Eve is observed on December 31, the last day of the year on the modern Gregorian calendar as well as + * the Julian calendar. In present day, with most countries now using the Gregorian calendar as their de facto calendar, + * New Year's Eve is probably the most celebrated holiday, often observed with fireworks at the stroke of midnight as + * the new year starts in each time zone. + * + * @link http://en.wikipedia.org/wiki/New_Year%27s_Eve + * + * @param int $year the year for which New Year's Eve need to be created + * @param string $timezone the timezone in which New Year's Eve is celebrated + * @param string $locale the locale for which New Year's Eve 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 + */ + public function newYearsEve( + int $year, + string $timezone, + string $locale, + string $type = Holiday::TYPE_OFFICIAL + ): Holiday { + return new Holiday('newYearsEve', [], new DateTime("$year-12-31", new DateTimeZone($timezone)), $locale, $type); + } + /** * New Year's Day. * diff --git a/src/Yasumi/Provider/Denmark.php b/src/Yasumi/Provider/Denmark.php index 84b1f7292..f84c14571 100644 --- a/src/Yasumi/Provider/Denmark.php +++ b/src/Yasumi/Provider/Denmark.php @@ -55,9 +55,21 @@ public function initialize() $this->addHoliday($this->pentecostMonday($this->year, $this->timezone, $this->locale)); $this->addHoliday($this->christmasDay($this->year, $this->timezone, $this->locale)); $this->addHoliday($this->secondChristmasDay($this->year, $this->timezone, $this->locale)); - - // Calculate other holidays $this->calculateGreatPrayerDay(); + + $this->addHoliday($this->internationalWorkersDay($this->year, $this->timezone, $this->locale, Holiday::TYPE_OBSERVANCE)); + $this->addHoliday($this->christmasEve($this->year, $this->timezone, $this->locale, Holiday::TYPE_OBSERVANCE)); + $this->addHoliday($this->newYearsEve($this->year, $this->timezone, $this->locale, Holiday::TYPE_OBSERVANCE)); + $this->calculateConstitutionDay(); + + $summerTime = $this->summerTime($this->year, $this->timezone, $this->locale); + if ($summerTime) { + $this->addHoliday($summerTime); + } + $winterTime = $this->winterTime($this->year, $this->timezone, $this->locale); + if ($winterTime) { + $this->addHoliday($winterTime); + } } /** @@ -89,4 +101,32 @@ public function calculateGreatPrayerDay() )); } } + + /** + * Constitution Day + * + * Denmark’s Constitution Day is June 5 and commemorates the signing of Denmark's constitution + * on June 5 1849, when Denmark peacefully became as a constitutional monarchy. + * + * While not a public holiday, some companies and public offices are closed. Traditionally, + * members of parliament gives political speeches around the country. + * + * @link https://en.wikipedia.org/wiki/Constitution_Day_(Denmark) + * + * @throws \Yasumi\Exception\InvalidDateException + * @throws \InvalidArgumentException + * @throws \Yasumi\Exception\UnknownLocaleException + */ + public function calculateConstitutionDay() + { + if ($this->year >= 1849) { + $this->addHoliday(new Holiday( + 'constitutionDay', + ['da_DK' => 'Grundlovsdag'], + new DateTime("$this->year-6-5", new DateTimeZone($this->timezone)), + $this->locale, + Holiday::TYPE_OBSERVANCE + )); + } + } } diff --git a/src/Yasumi/Provider/Latvia.php b/src/Yasumi/Provider/Latvia.php index bcbac40a4..5662cdf19 100644 --- a/src/Yasumi/Provider/Latvia.php +++ b/src/Yasumi/Provider/Latvia.php @@ -57,7 +57,7 @@ public function initialize() $this->addHoliday($this->christmasEve($this->year, $this->timezone, $this->locale, Holiday::TYPE_OFFICIAL)); $this->addHoliday($this->christmasDay($this->year, $this->timezone, $this->locale)); $this->addHoliday($this->secondChristmasDay($this->year, $this->timezone, $this->locale)); - $this->addNewYearsEve(); + $this->addHoliday($this->newYearsEve($this->year, $this->timezone, $this->locale)); } /** @@ -116,15 +116,4 @@ private function addProclamationDay() ], $date)); } } - - /** - * @throws \InvalidArgumentException - */ - private function addNewYearsEve() - { - $this->addHoliday(new Holiday('newYearsEve', [ - 'en_US' => 'New Year\'s Eve', - 'lv_LV' => 'Vecgada vakars' - ], new \DateTime("{$this->year}-12-31", new \DateTimeZone($this->timezone)))); - } } diff --git a/src/Yasumi/Provider/Norway.php b/src/Yasumi/Provider/Norway.php index 5efa7c115..072d057e6 100644 --- a/src/Yasumi/Provider/Norway.php +++ b/src/Yasumi/Provider/Norway.php @@ -70,7 +70,7 @@ public function initialize() * coalition with Sweden, proceeded by nearly 400 years of Danish rule. The Norwegian Parliament, known as * Stortinget, held the first May 17 celebrations in 1836, and since it has been regarded as Norway’s National Day. * - * @link https://en.wikipedia.org/wiki/Store_Bededag + * @link https://en.wikipedia.org/wiki/Norwegian_Constitution_Day * * @throws \Yasumi\Exception\InvalidDateException * @throws \InvalidArgumentException diff --git a/src/Yasumi/data/translations/newYearsEve.php b/src/Yasumi/data/translations/newYearsEve.php new file mode 100755 index 000000000..5d1154da0 --- /dev/null +++ b/src/Yasumi/data/translations/newYearsEve.php @@ -0,0 +1,18 @@ + + */ + +// Translations for New Year's Eve +return [ + 'en_US' => 'New Year\'s Eve', + 'da_DK' => 'Nytårsaften', + 'lv_LV' => 'Vecgada vakars' +]; diff --git a/tests/Denmark/DenmarkTest.php b/tests/Denmark/DenmarkTest.php index ce0f08c50..d8c0b242d 100644 --- a/tests/Denmark/DenmarkTest.php +++ b/tests/Denmark/DenmarkTest.php @@ -49,7 +49,12 @@ public function testOfficialHolidays() */ public function testObservedHolidays() { - $this->assertDefinedHolidays([], self::REGION, $this->year, Holiday::TYPE_OBSERVANCE); + $this->assertDefinedHolidays([ + 'internationalWorkersDay', + 'constitutionDay', + 'christmasEve', + 'newYearsEve', + ], self::REGION, $this->year, Holiday::TYPE_OBSERVANCE); } /** @@ -57,7 +62,8 @@ public function testObservedHolidays() */ public function testSeasonalHolidays() { - $this->assertDefinedHolidays([], self::REGION, $this->year, Holiday::TYPE_SEASON); + $year = $this->generateRandomYear(1980, 2037); + $this->assertDefinedHolidays(['summerTime', 'winterTime'], self::REGION, $year, Holiday::TYPE_SEASON); } /** @@ -81,6 +87,6 @@ public function testOtherHolidays() */ protected function setUp() { - $this->year = $this->generateRandomYear(1686); + $this->year = $this->generateRandomYear(1849); } }