Skip to content

Commit

Permalink
Add observed holidays for Denmark
Browse files Browse the repository at this point in the history
  • Loading branch information
c960657 committed Apr 21, 2018
1 parent c56cad5 commit 3176a94
Show file tree
Hide file tree
Showing 6 changed files with 102 additions and 18 deletions.
31 changes: 31 additions & 0 deletions src/Yasumi/Provider/CommonHolidays.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
44 changes: 42 additions & 2 deletions src/Yasumi/Provider/Denmark.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

/**
Expand Down Expand Up @@ -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
));
}
}
}
13 changes: 1 addition & 12 deletions src/Yasumi/Provider/Latvia.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

/**
Expand Down Expand Up @@ -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))));
}
}
2 changes: 1 addition & 1 deletion src/Yasumi/Provider/Norway.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 18 additions & 0 deletions src/Yasumi/data/translations/newYearsEve.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php
/**
* This file is part of the Yasumi package.
*
* Copyright (c) 2015 - 2018 AzuyaLabs
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @author Sacha Telgenhof <stelgenhof@gmail.com>
*/

// Translations for New Year's Eve
return [
'en_US' => 'New Year\'s Eve',
'da_DK' => 'Nytårsaften',
'lv_LV' => 'Vecgada vakars'
];
12 changes: 9 additions & 3 deletions tests/Denmark/DenmarkTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,21 @@ 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);
}

/**
* Tests if all seasonal holidays in Denmark are defined by the provider class
*/
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);
}

/**
Expand All @@ -81,6 +87,6 @@ public function testOtherHolidays()
*/
protected function setUp()
{
$this->year = $this->generateRandomYear(1686);
$this->year = $this->generateRandomYear(1849);
}
}

0 comments on commit 3176a94

Please sign in to comment.