Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add observed holidays for Denmark #104

Merged
merged 1 commit into from
May 13, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this change be excluded from this PR since it isn't related to Denmark?

Copy link
Contributor Author

@c960657 c960657 May 10, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both Denmark and Latvia (and many other countries) celebrate New Year's Eve, so I moved newYearsEve() to CommonHolidays to allow reuse. So there is no reason to keep a duplicate implementation in the Latvia class.

}

/**
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
1 change: 1 addition & 0 deletions src/Yasumi/data/translations/christmasEve.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
return [
'cs_CZ' => 'Štědrý den',
'cy_GB' => 'Noswyl Nadolig',
'da_DK' => 'Juleaften',
'de_CH' => 'Heiliger Abend',
'en_US' => 'Christmas Eve',
'et_EE' => 'Jõululaupäev',
Expand Down
1 change: 1 addition & 0 deletions src/Yasumi/data/translations/internationalWorkersDay.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
return [
'bs_Latn_BA' => 'Praznik rada',
'cs_CZ' => 'Svátek práce',
'da_DK' => 'Første maj',
'de_AT' => 'Staatsfeiertag',
'de_CH' => 'Tag der Arbeit',
'de_DE' => 'Tag der Arbeit',
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'
];
1 change: 1 addition & 0 deletions src/Yasumi/data/translations/summerTime.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

// Translations for daylight saving time start.
return [
'da_DK' => 'Sommertid starter',
'en_US' => 'Summertime',
'nl_NL' => 'Zomertijd',
];
1 change: 1 addition & 0 deletions src/Yasumi/data/translations/winterTime.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

// Translations for daylight saving time end.
return [
'da_DK' => 'Sommertid slutter',
'en_US' => 'Wintertime',
'nl_NL' => 'Wintertijd',
];
72 changes: 72 additions & 0 deletions tests/Denmark/ChristmasEveTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<?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>
*/

namespace Yasumi\tests\Denmark;

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

/**
* Class for testing Christmas Eve in Denmark.
*/
class ChristmasEveTest extends DenmarkBaseTestCase implements YasumiTestCaseInterface
{
/**
* The name of the holiday to be tested
*/
const HOLIDAY = 'christmasEve';

/**
* Tests the holiday defined in this test.
*
* @dataProvider HolidayDataProvider
*
* @param int $year the year for which the holiday defined in this test needs to be tested
* @param DateTime $expected the expected date
*/
public function testHoliday($year, $expected)
{
$this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected);
}

/**
* Returns a list of random test dates used for assertion of the holiday defined in this test
*
* @return array list of test dates for the holiday defined in this test
*/
public function HolidayDataProvider(): array
{
return $this->generateRandomDates(12, 24, self::TIMEZONE);
}

/**
* Tests the translated name of the holiday defined in this test.
*/
public function testTranslation()
{
$this->assertTranslatedHolidayName(
self::REGION,
self::HOLIDAY,
$this->generateRandomYear(),
[self::LOCALE => 'Juleaften']
);
}

/**
* Tests type of the holiday defined in this test.
*/
public function testHolidayType()
{
$this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_OBSERVANCE);
}
}
86 changes: 86 additions & 0 deletions tests/Denmark/ConstitutionDayTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
<?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>
*/

namespace Yasumi\tests\Denmark;

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

/**
* Class for testing the Constitution Day of Denmark.
*/
class ConstitutionDayTest extends DenmarkBaseTestCase implements YasumiTestCaseInterface
{
/**
* The name of the holiday to be tested
*/
const HOLIDAY = 'constitutionDay';

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

/**
* Tests the holiday defined in this test on or after establishment.
*/
public function testHolidayOnAfterEstablishment()
{
$year = 2077;
$this->assertHoliday(
self::REGION,
self::HOLIDAY,
$year,
new DateTime("$year-6-5", new DateTimeZone(self::TIMEZONE))
);
}

/**
* Tests the holiday defined in this test before establishment.
*/
public function testHolidayBeforeEstablishment()
{
$this->assertNotHoliday(
self::REGION,
self::HOLIDAY,
$this->generateRandomYear(1000, self::ESTABLISHMENT_YEAR - 1)
);
}

/**
* Tests the translated name of the holiday defined in this test.
*/
public function testTranslation()
{
$this->assertTranslatedHolidayName(
self::REGION,
self::HOLIDAY,
$this->generateRandomYear(self::ESTABLISHMENT_YEAR),
[self::LOCALE => 'Grundlovsdag']
);
}

/**
* Tests type of the holiday defined in this test.
*/
public function testHolidayType()
{
$this->assertHolidayType(
self::REGION,
self::HOLIDAY,
$this->generateRandomYear(self::ESTABLISHMENT_YEAR),
Holiday::TYPE_OBSERVANCE
);
}
}
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);
}
}
Loading