Skip to content

Commit

Permalink
Added Christmas Day.
Browse files Browse the repository at this point in the history
  • Loading branch information
stelgenhof committed Dec 16, 2016
1 parent 2e9e914 commit 55fc857
Show file tree
Hide file tree
Showing 3 changed files with 113 additions and 3 deletions.
29 changes: 27 additions & 2 deletions src/Yasumi/Provider/Ireland.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@ public function initialize()
$this->addHoliday($this->easterMonday($this->year, $this->timezone, $this->locale));
$this->addHoliday($this->pentecost($this->year, $this->timezone, $this->locale, Holiday::TYPE_OBSERVANCE));
$this->calculatePentecostMonday();

//$this->addHoliday($this->christmasDay($this->year, $this->timezone, $this->locale));
$this->calculateChristmasDay();
//$this->addHoliday($this->secondChristmasDay($this->year, $this->timezone, $this->locale));

// Calculate other holidays
Expand Down Expand Up @@ -207,4 +206,30 @@ public function calculateOctoberHoliday()
['en_IE' => 'October Holiday', 'ga_IE' => 'Lá Saoire i mí Dheireadh Fómhair'],
new DateTime("previous monday $this->year-11-01", new DateTimeZone($this->timezone)), $this->locale));
}

/**
* Christmas Day.
*
* Most people in Ireland start Christmas celebrations on Christmas Eve (Oíche Nollag), including taking time
* off work.
*
* @link http://www.irishstatutebook.ie/eli/1973/act/25/schedule/1/enacted/en/html#sched1
*/
public function calculateChristmasDay()
{
$holiday = new Holiday('christmasDay', ['en_IE' => 'Christmas Day', 'ga_IE' => 'Lá Nollag'],
new DateTime($this->year . '-12-25', new DateTimeZone($this->timezone)), $this->locale);

$this->addHoliday($holiday);

// Whenever Christmas Day does not fall on a weekday, the Tuesday following on it shall be a public holiday.
if (in_array($holiday->format('w'), [0, 6])) {
$substituteHoliday = clone $holiday;
$substituteHoliday->modify('next tuesday');

$this->addHoliday(new Holiday('substituteHoliday:' . $substituteHoliday->shortName, [
'en_IE' => $substituteHoliday->getName() . ' observed',
], $substituteHoliday, $this->locale));
}
}
}
85 changes: 85 additions & 0 deletions tests/Ireland/ChristmasDayTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
<?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 <[email protected]>
*/

namespace Yasumi\tests\Ireland;

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

/**
* Class containing tests for Christmas Day in Ireland.
*/
class ChristmasDayTest extends IrelandBaseTestCase implements YasumiTestCaseInterface
{
/**
* The name of the holiday to be tested
*/
const HOLIDAY = 'christmasDay';

/**
* 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)
{
$date = new DateTime($expected, new DateTimeZone(self::TIMEZONE));
$this->assertHoliday(self::REGION, self::HOLIDAY, $year, $date);

if (in_array($date->format('w'), [0, 6])) {
$date->modify('next tuesday');
$this->assertHoliday(self::REGION, 'substituteHoliday:' . self::HOLIDAY, $year, $date);
}
}

/**
* 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()
{
$data = [];

for ($y = 0; $y < self::TEST_ITERATIONS; $y++) {
$year = $this->generateRandomYear();
$date = new DateTime("$year-12-25", new DateTimeZone(self::TIMEZONE));
$data[] = [$year, $date->format('Y-m-d')];
}

return $data;
}

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

/**
* Tests type of the holiday defined in this test.
*/
public function testHolidayType()
{
$this->assertHolidayType(self::REGION, self::HOLIDAY, $this->generateRandomYear(), Holiday::TYPE_NATIONAL);
}
}
2 changes: 1 addition & 1 deletion tests/Ireland/IrelandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class IrelandTest extends IrelandBaseTestCase
*/
public function testNationalHolidays()
{
$nationalHolidays = ['easter', 'easterMonday', 'augustHoliday'];
$nationalHolidays = ['easter', 'easterMonday', 'augustHoliday', 'christmasDay'];
if ($this->year >= 1974) {
$nationalHolidays[] = 'newYearsDay';
$nationalHolidays[] = 'juneHoliday';
Expand Down

0 comments on commit 55fc857

Please sign in to comment.