Skip to content

Commit

Permalink
Refactored calculation for substitution to each holidays’ calculation.
Browse files Browse the repository at this point in the history
Only a few holidays are affected by this. Adjusted the unit tests
accordingly.
  • Loading branch information
stelgenhof committed Dec 12, 2016
1 parent 0065ce2 commit 49a8d13
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 10 deletions.
34 changes: 26 additions & 8 deletions src/Yasumi/Provider/Ireland.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,9 @@ public function initialize()

//$this->addHoliday($this->epiphany($this->year, $this->timezone, $this->locale));
//$this->addHoliday($this->assumptionOfMary($this->year, $this->timezone, $this->locale));
//
//
//$this->addHoliday($this->internationalWorkersDay($this->year, $this->timezone, $this->locale));
//$this->addHoliday($this->ascensionDay($this->year, $this->timezone, $this->locale));
//$this->addHoliday($this->pentecost($this->year, $this->timezone, $this->locale, Holiday::TYPE_OBSERVANCE));

//$this->addHoliday($this->pentecostMonday($this->year, $this->timezone, $this->locale));
//$this->addHoliday($this->corpusChristi($this->year, $this->timezone, $this->locale, Holiday::TYPE_NATIONAL));
//$this->addHoliday($this->allSaintsDay($this->year, $this->timezone, $this->locale));
Expand All @@ -68,7 +65,7 @@ public function initialize()
$this->calculateStPatricksDay();

// Determine whether any of the holidays is substituted on another day
$this->calculateSubstituteHolidays();
//$this->calculateSubstituteHolidays();
}

/**
Expand All @@ -86,7 +83,18 @@ public function calculateNewYearsDay()
return;
}

$this->addHoliday($this->newYearsDay($this->year, $this->timezone, $this->locale));
$holiday = $this->newYearsDay($this->year, $this->timezone, $this->locale);
$this->addHoliday($holiday);

// Substitute holiday is on the next available weekday if a holiday falls on a Saturday or Sunday
if (in_array($holiday->format('w'), [0, 6])) {
$substituteHoliday = clone $holiday;
$substituteHoliday->modify('next monday');

$this->addHoliday(new Holiday('substituteHoliday:' . $substituteHoliday->shortName, [
'en_IE' => $substituteHoliday->getName() . ' observed',
], $substituteHoliday, $this->locale));
}
}

/**
Expand All @@ -103,10 +111,20 @@ public function calculateStPatricksDay()
if ($this->year < 1903) {
return;
}
$holiday = new Holiday('stPatricksDay', ['en_IE' => 'St. Patrick\'s Day', 'ga_IE' => 'Lá Fhéile Pádraig'],
new DateTime($this->year . '-3-17', new DateTimeZone($this->timezone)), $this->locale);

$this->addHoliday(new Holiday('stPatricksDay',
['en_IE' => 'St. Patrick\'s Day', 'ga_IE' => 'Lá Fhéile Pádraig'],
new DateTime($this->year . '-3-17', new DateTimeZone($this->timezone)), $this->locale));
$this->addHoliday($holiday);

// Substitute holiday is on the next available weekday if a holiday falls on a Saturday or Sunday
if (in_array($holiday->format('w'), [0, 6])) {
$substituteHoliday = clone $holiday;
$substituteHoliday->modify('next monday');

$this->addHoliday(new Holiday('substituteHoliday:' . $substituteHoliday->shortName, [
'en_IE' => $substituteHoliday->getName() . ' observed',
], $substituteHoliday, $this->locale));
}
}

/**
Expand Down
2 changes: 1 addition & 1 deletion tests/Ireland/NewYearsDayTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public function testHoliday($year, $expected)

// Whenever any public holiday falls on a Sunday, the Monday following on it shall be a public holiday.
if (in_array($date->format('w'), [0, 6])) {
$date->add(new DateInterval('P1D'));
$date->modify('next monday');
$this->assertHoliday(self::REGION, 'substituteHoliday:' . self::HOLIDAY, $year, $date);
}
}
Expand Down
2 changes: 1 addition & 1 deletion tests/Ireland/StPatricksDayTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public function testHoliday($year, $expected)

// Whenever any public holiday falls on a Sunday, the Monday following on it shall be a public holiday.
if (in_array($date->format('w'), [0, 6])) {
$date->add(new DateInterval('P1D'));
$date->modify('next monday');
$this->assertHoliday(self::REGION, 'substituteHoliday:' . self::HOLIDAY, $year, $date);
}
}
Expand Down

0 comments on commit 49a8d13

Please sign in to comment.