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

Added support for Germany #9

Merged
merged 5 commits into from
Apr 6, 2016
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
97 changes: 97 additions & 0 deletions src/Yasumi/Provider/Germany.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
<?php

/**
* This file is part of the Yasumi package.
*
* Copyright (c) 2015 - 2016 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\Provider;

use DateTime;
use DateTimeZone;
use Yasumi\Holiday;

/**
* Provider for all holidays in Germany.
*/
class Germany extends AbstractProvider
{
use CommonHolidays, ChristianHolidays;

/**
* Initialize holidays for Germany.
*/
public function initialize()
{
$this->timezone = 'Europe/Berlin';

// Add common holidays
$this->addHoliday($this->newYearsDay($this->year, $this->timezone, $this->locale));

// Add common Christian holidays (common in Germany)
$this->addHoliday($this->ascensionDay($this->year, $this->timezone, $this->locale));
$this->addHoliday($this->christmasDay($this->year, $this->timezone, $this->locale));
$this->addHoliday($this->easterMonday($this->year, $this->timezone, $this->locale));
$this->addHoliday($this->goodFriday($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.

Is Good Friday an official holiday, i.e. offices/shops are closed?

$this->addHoliday($this->internationalWorkersDay($this->year, $this->timezone, $this->locale));
$this->addHoliday($this->newYearsDay($this->year, $this->timezone, $this->locale));
$this->addHoliday($this->pentecostMonday($this->year, $this->timezone, $this->locale));
$this->addHoliday($this->secondChristmasDay($this->year, $this->timezone, $this->locale));

// Calculate other holidays
$this->calculateGermanUnityDay();
$this->calculateReformationDay();
}

/**
* German Unity Day
*
* The Day of German Unity (German: Tag der Deutschen Einheit) is the national day of Germany, celebrated on
* 3 October as a public holiday. It commemorates the anniversary of German reunification in 1990, when the
* goal of a united Germany that originated in the middle of the 19th century, was fulfilled again. Therefore,
* the name addresses neither the re-union nor the union, but the unity of Germany. The Day of German Unity on
* 3 October has been the German national holiday since 1990, when the reunification was formally completed. It
* is a legal holiday for the Federal Republic of Germany.
*
* @link https://en.wikipedia.org/wiki/German_Unity_Day
*/
public function calculateGermanUnityDay()
{
if ($this->year >= 1990) {
$this->addHoliday(new Holiday('germanUnityDay', ['de_DE' => 'Tag der Deutschen Einheit'],
new DateTime($this->year . '-10-3', new \DateTimeZone($this->timezone)), $this->locale));
}
}

/**
* Calculates the day of the reformation.
*
* Reformation Day is a religious holiday celebrated on October 31, alongside All Hallows' Eve, in remembrance
* of the Reformation. It is celebrated among various Protestants, especially by Lutheran and Reformed church
* communities.

* It is a civic holiday in the German states of Brandenburg, Mecklenburg-Vorpommern, Saxony, Saxony-Anhalt and
* Thuringia. Slovenia celebrates it as well due to the profound contribution of the Reformation to that nation's
* cultural development, although Slovenes are mainly Roman Catholics. With the increasing influence of
* Protestantism in Latin America (particularly newer groups such as various Evangelical Protestants, Pentecostals
* or Charismatics), it has been declared a national holiday in Chile in 2009.
*
* @link https://en.wikipedia.org/wiki/Reformation_Day
*/
public function calculateReformationDay()
{
/**
* @link https://de.wikipedia.org/wiki/Reformationstag#Ursprung_und_Geschichte
*/
if ($this->year == 2017) {
$this->addHoliday(new Holiday('reformationDay', [
'de_DE' => 'Reformationstag',
], new DateTime("$this->year-10-31", new DateTimeZone($this->timezone)), $this->locale));
}
}
}
3 changes: 2 additions & 1 deletion src/Yasumi/data/translations/allSaintsDay.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,6 @@
'fr_FR' => 'La Toussaint',
'es_ES' => 'Día de todos los Santos',
'sv_SE' => 'alla helgons dag',
'fi_FI' => 'Pyhäinpäivä'
'fi_FI' => 'Pyhäinpäivä',
'de_DE' => 'Allerheiligen'
];
3 changes: 2 additions & 1 deletion src/Yasumi/data/translations/ascensionDay.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,6 @@
'da_DK' => 'Kristi Himmelfartsdag',
'nb_NO' => 'Kristi himmelfartsdag',
'sv_SE' => 'Kristi himmelsfärds dag',
'fi_FI' => 'Helatorstai'
'fi_FI' => 'Helatorstai',
'de_DE' => 'Christi Himmelfahrt'
];
3 changes: 2 additions & 1 deletion src/Yasumi/data/translations/assumptionOfMary.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@
'nl_BE' => 'Onze Lieve Vrouw hemelvaart',
'it_IT' => 'Assunzione di Maria Vergine',
'fr_FR' => 'L\'Assomption de Marie',
'es_ES' => 'Asunción de la Virgen María'
'es_ES' => 'Asunción de la Virgen María',
'de_DE' => 'Mariä Himmelfahrt'
];
3 changes: 2 additions & 1 deletion src/Yasumi/data/translations/christmasDay.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,6 @@
'da_DK' => '1. Juledag',
'nb_NO' => 'Første juledag',
'sv_SE' => 'juldagen',
'fi_FI' => 'Joulupäivä'
'fi_FI' => 'Joulupäivä',
'de_DE' => '1. Weihnachtsfeiertag'
];
3 changes: 2 additions & 1 deletion src/Yasumi/data/translations/corpusChristi.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@
// Translation for Corpus Christi
return [
'en_US' => 'Corpus Christi',
'es_ES' => 'Corpus Christi'
'es_ES' => 'Corpus Christi',
'de_DE' => 'Fronleichnam'
];
3 changes: 2 additions & 1 deletion src/Yasumi/data/translations/easterMonday.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,6 @@
'da_DK' => '2. Påskedag',
'nb_NO' => 'Andre påskedag',
'sv_SE' => 'annandag påsk',
'fi_FI' => '2. pääsiäispäivä'
'fi_FI' => '2. pääsiäispäivä',
'de_DE' => 'Ostermontag'
];
4 changes: 2 additions & 2 deletions src/Yasumi/data/translations/epiphany.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@
'it_IT' => 'Epifania',
'es_ES' => 'Día de Reyes',
'sv_SE' => 'trettondedag jul',
'fi_FI' => 'Loppiainen'

'fi_FI' => 'Loppiainen',
'de_DE' => 'Heilige 3 Könige'
];
3 changes: 2 additions & 1 deletion src/Yasumi/data/translations/goodFriday.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,6 @@
'da_DK' => 'Langfredag',
'nb_NO' => 'Langfredag',
'sv_SE' => 'långfredagen',
'fi_FI' => 'Pitkäperjantai'
'fi_FI' => 'Pitkäperjantai',
'de_DE' => 'Karfreitag'
];
3 changes: 2 additions & 1 deletion src/Yasumi/data/translations/internationalWorkersDay.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,6 @@
'es_ES' => 'Día del Trabajador',
'nb_NO' => 'Arbeidernes dag',
'sv_SE' => 'Första maj',
'fi_FI' => 'Vappu'
'fi_FI' => 'Vappu',
'de_DE' => 'Tag der Arbeit'
];
5 changes: 3 additions & 2 deletions src/Yasumi/data/translations/newYearsDay.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,6 @@
'da_DK' => 'Nytårsdag',
'nb_NO' => 'Første nyttårsdag',
'sv_SE' => 'nyårsdagen',
'fi_FI' => 'Uudenvuodenpäivä'
];
'fi_FI' => 'Uudenvuodenpäivä',
'de_DE' => 'Neujahr'
];
3 changes: 2 additions & 1 deletion src/Yasumi/data/translations/pentecostMonday.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@
'nl_BE' => 'Pinkstermaandag',
'fr_FR' => 'Lundi de Pentecôte',
'da_DK' => '2. Pinsedag',
'nb_NO' => 'Andre pinsedag'
'nb_NO' => 'Andre pinsedag',
'de_DE' => 'Pfingstmontag'
];
4 changes: 2 additions & 2 deletions src/Yasumi/data/translations/secondChristmasDay.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@
'da_DK' => '2. Juledag',
'nb_NO' => 'Andre juledag',
'sv_SE' => 'annandag jul',
'fi_FI' => '2. joulupäivä'

'fi_FI' => '2. joulupäivä',
'de_DE' => '2. Weihnachtsfeiertag'
];
46 changes: 46 additions & 0 deletions tests/Germany/AscensionDayTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php
/**
* This file is part of the Yasumi package.
*
* Copyright (c) 2015 - 2016 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\Germany;

use DateTime;
use DateTimeZone;

/**
* Class for testing Ascension Day in Germany.
*/
class AscensionDayTest extends GermanyBaseTestCase
{
/**
* The name of the holiday to be tested
*/
const HOLIDAY = 'ascensionDay';

/**
* Tests Ascension Day.
*/
public function testAscensionDay()
{
$year = 1754;
$this->assertHoliday(self::REGION, 'ascensionDay', $year,
new DateTime("$year-5-23", new DateTimeZone(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 => 'Christi Himmelfahrt']);
}
}
58 changes: 58 additions & 0 deletions tests/Germany/ChristmasTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php
/**
* This file is part of the Yasumi package.
*
* Copyright (c) 2015 - 2016 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\Germany;

use DateTime;

/**
* Class for testing Christmas in Germany.
*/
class ChristmasTest extends GermanyBaseTestCase
{
/**
* The name of the holiday
*/
const HOLIDAY = 'christmasDay';

/**
* Tests Christmas Day.
*
* @dataProvider ChristmasDayDataProvider
*
* @param int $year the year for which Christmas Day needs to be tested
* @param DateTime $expected the expected date
*/
public function testChristmasDay($year, $expected)
{
$this->assertHoliday(self::REGION, self::HOLIDAY, $year, $expected);
}

/**
* Returns a list of random test dates used for assertion of Christmas Day.
*
* @return array list of test dates for Christmas Day
*/
public function ChristmasDayDataProvider()
{
return $this->generateRandomDates(12, 25, self::TIMEZONE);
}

/**
* Tests translated name of Christmas Day.
*/
public function testTranslation()
{
$this->assertTranslatedHolidayName(self::REGION, self::HOLIDAY, $this->generateRandomYear(),
[self::LOCALE => '1. Weihnachtsfeiertag']);
}
}
46 changes: 46 additions & 0 deletions tests/Germany/EasterMondayTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php
/**
* This file is part of the Yasumi package.
*
* Copyright (c) 2015 - 2016 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\Germany;

use DateTime;
use DateTimeZone;

/**
* Class containing tests for Easter Monday in Germany.
*/
class EasterMondayTest extends GermanyBaseTestCase
{
/**
* The name of the holiday to be tested
*/
const HOLIDAY = 'easterMonday';

/**
* Tests the holiday defined in this test.
*/
public function testHoliday()
{
$year = 2000;
$this->assertHoliday(self::REGION, self::HOLIDAY, $year,
new DateTime("$year-4-24", new DateTimeZone(self::TIMEZONE)));
}

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