Skip to content

Commit

Permalink
Fixed Romanian Easter dates (Orthodox Easter in Romania)
Browse files Browse the repository at this point in the history
Added creating Orthodox Easter Sunday to AbstractEaster class
  • Loading branch information
agilov committed Mar 29, 2018
1 parent 95d1daf commit ae594e6
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 21 deletions.
59 changes: 47 additions & 12 deletions src/Provider/AbstractEaster.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,53 @@
*/
abstract class AbstractEaster extends AbstractProvider
{
/**
* Creating easter sunday
*
* @param $year
* @return \DateTime
*/
private function createSunday($year)
{
$easterSunday = new \DateTime('21.03.' . $year);
$easterSunday->modify(sprintf('+%d days', easter_days($year)));

return $easterSunday;
}

/**
* Creating Orthodox easter sunday
*
* @param $year
* @return \DateTime
*/
private function createOrthodoxSunday($year)
{
$a = $year % 4;
$b = $year % 7;
$c = $year % 19;
$d = (19 * $c + 15) % 30;
$e = (2 * $a + 4 * $b - $d + 34) % 7;
$month = floor(($d + $e + 114) / 31);
$day = (($d + $e + 114) % 31) + 1;

$sunday = mktime(0, 0, 0, $month, $day + 13, $year);

return new \DateTime(date('Y-m-d', $sunday));
}

/**
* Returns all dates calculated by easter sunday
*
* @param int $year
* @param boolean $orthodox
*
* @return \DateTime[]
*/
protected function getEasterDates($year)
protected function getEasterDates($year, $orthodox = false)
{
$easterSunday = new \DateTime('21.03.'.$year);
$easterSunday->modify(sprintf('+%d days', easter_days($year)));
$easterSunday = $orthodox ? $this->createOrthodoxSunday($year) : $this->createSunday($year);

$easterSunday->setTimezone(new \DateTimeZone(date_default_timezone_get()));

$easterMonday = clone $easterSunday;
Expand All @@ -43,16 +78,16 @@ protected function getEasterDates($year)
$corpusChristi->modify('+60 days');

return array(
'maundyThursday' => $maundyThursday,
'easterSunday' => $easterSunday,
'easterMonday' => $easterMonday,
'saturday' => $saturday,
'goodFriday' => $goodFriday,
'ascensionDay' => $ascensionDay,
'maundyThursday' => $maundyThursday,
'easterSunday' => $easterSunday,
'easterMonday' => $easterMonday,
'saturday' => $saturday,
'goodFriday' => $goodFriday,
'ascensionDay' => $ascensionDay,
'pentecostSaturday' => $pentecostSaturday,
'pentecostSunday' => $pentecostSunday,
'pentecostMonday' => $pentecostMonday,
'corpusChristi' => $corpusChristi
'pentecostSunday' => $pentecostSunday,
'pentecostMonday' => $pentecostMonday,
'corpusChristi' => $corpusChristi
);
}

Expand Down
4 changes: 3 additions & 1 deletion src/Provider/RO.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ class RO extends AbstractEaster
*/
public function getHolidaysByYear($year)
{
$easter = $this->getEasterDates($year);
// make i
$easter = $this->getEasterDates($year, true);

$holidays = array(
'01-01' => $this->createData('Anul Nou'),
Expand All @@ -35,6 +36,7 @@ public function getHolidaysByYear($year)
'12-26' => $this->createData('Crăciunul'),

// Easter dates
$easter['goodFriday']->format(self::DATE_FORMAT) => $this->createData('Paștele'),
$easter['easterSunday']->format(self::DATE_FORMAT) => $this->createData('Paștele'),
$easter['easterMonday']->format(self::DATE_FORMAT) => $this->createData('Paștele'),

Expand Down
20 changes: 12 additions & 8 deletions test/Provider/ROTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ public function setUp()
/**
* Provides some test dates and the expectation
*
* vendor/bin/phpunit --filter ROTest
*
* @return array
*/
public function dateProvider()
Expand All @@ -40,16 +42,18 @@ public function dateProvider()
array('2018-12-26', null, array('name' => 'Crăciunul')),

// Easter dates 2018
array('2018-04-01', null, array('name' => 'Paștele')),
array('2018-04-02', null, array('name' => 'Paștele')),
array('2018-05-20', null, array('name' => 'Rusaliile')),
array('2018-05-21', null, array('name' => 'Rusaliile')),
array('2018-04-06', null, array('name' => 'Paștele')),
array('2018-04-08', null, array('name' => 'Paștele')),
array('2018-04-09', null, array('name' => 'Paștele')),
array('2018-05-27', null, array('name' => 'Rusaliile')),
array('2018-05-28', null, array('name' => 'Rusaliile')),

// Easter dates 2019
array('2019-04-21', null, array('name' => 'Paștele')),
array('2019-04-22', null, array('name' => 'Paștele')),
array('2019-06-09', null, array('name' => 'Rusaliile')),
array('2019-06-10', null, array('name' => 'Rusaliile')),
array('2019-04-26', null, array('name' => 'Paștele')),
array('2019-04-28', null, array('name' => 'Paștele')),
array('2019-04-29', null, array('name' => 'Paștele')),
array('2019-06-16', null, array('name' => 'Rusaliile')),
array('2019-06-17', null, array('name' => 'Rusaliile')),
);
}
}

0 comments on commit ae594e6

Please sign in to comment.