Skip to content

Commit 9d237e6

Browse files
authored
Merge pull request #27 from agilov/ortodox_easter
Orthodox Easter
2 parents 5cc1cf5 + ae594e6 commit 9d237e6

File tree

3 files changed

+62
-21
lines changed

3 files changed

+62
-21
lines changed

src/Provider/AbstractEaster.php

+47-12
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,53 @@
77
*/
88
abstract class AbstractEaster extends AbstractProvider
99
{
10+
/**
11+
* Creating easter sunday
12+
*
13+
* @param $year
14+
* @return \DateTime
15+
*/
16+
private function createSunday($year)
17+
{
18+
$easterSunday = new \DateTime('21.03.' . $year);
19+
$easterSunday->modify(sprintf('+%d days', easter_days($year)));
20+
21+
return $easterSunday;
22+
}
23+
24+
/**
25+
* Creating Orthodox easter sunday
26+
*
27+
* @param $year
28+
* @return \DateTime
29+
*/
30+
private function createOrthodoxSunday($year)
31+
{
32+
$a = $year % 4;
33+
$b = $year % 7;
34+
$c = $year % 19;
35+
$d = (19 * $c + 15) % 30;
36+
$e = (2 * $a + 4 * $b - $d + 34) % 7;
37+
$month = floor(($d + $e + 114) / 31);
38+
$day = (($d + $e + 114) % 31) + 1;
39+
40+
$sunday = mktime(0, 0, 0, $month, $day + 13, $year);
41+
42+
return new \DateTime(date('Y-m-d', $sunday));
43+
}
1044

1145
/**
1246
* Returns all dates calculated by easter sunday
1347
*
1448
* @param int $year
49+
* @param boolean $orthodox
1550
*
1651
* @return \DateTime[]
1752
*/
18-
protected function getEasterDates($year)
53+
protected function getEasterDates($year, $orthodox = false)
1954
{
20-
$easterSunday = new \DateTime('21.03.'.$year);
21-
$easterSunday->modify(sprintf('+%d days', easter_days($year)));
55+
$easterSunday = $orthodox ? $this->createOrthodoxSunday($year) : $this->createSunday($year);
56+
2257
$easterSunday->setTimezone(new \DateTimeZone(date_default_timezone_get()));
2358

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

4580
return array(
46-
'maundyThursday' => $maundyThursday,
47-
'easterSunday' => $easterSunday,
48-
'easterMonday' => $easterMonday,
49-
'saturday' => $saturday,
50-
'goodFriday' => $goodFriday,
51-
'ascensionDay' => $ascensionDay,
81+
'maundyThursday' => $maundyThursday,
82+
'easterSunday' => $easterSunday,
83+
'easterMonday' => $easterMonday,
84+
'saturday' => $saturday,
85+
'goodFriday' => $goodFriday,
86+
'ascensionDay' => $ascensionDay,
5287
'pentecostSaturday' => $pentecostSaturday,
53-
'pentecostSunday' => $pentecostSunday,
54-
'pentecostMonday' => $pentecostMonday,
55-
'corpusChristi' => $corpusChristi
88+
'pentecostSunday' => $pentecostSunday,
89+
'pentecostMonday' => $pentecostMonday,
90+
'corpusChristi' => $corpusChristi
5691
);
5792
}
5893

src/Provider/RO.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ class RO extends AbstractEaster
2020
*/
2121
public function getHolidaysByYear($year)
2222
{
23-
$easter = $this->getEasterDates($year);
23+
// make i
24+
$easter = $this->getEasterDates($year, true);
2425

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

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

test/Provider/ROTest.php

+12-8
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ public function setUp()
1818
/**
1919
* Provides some test dates and the expectation
2020
*
21+
* vendor/bin/phpunit --filter ROTest
22+
*
2123
* @return array
2224
*/
2325
public function dateProvider()
@@ -40,16 +42,18 @@ public function dateProvider()
4042
array('2018-12-26', null, array('name' => 'Crăciunul')),
4143

4244
// Easter dates 2018
43-
array('2018-04-01', null, array('name' => 'Paștele')),
44-
array('2018-04-02', null, array('name' => 'Paștele')),
45-
array('2018-05-20', null, array('name' => 'Rusaliile')),
46-
array('2018-05-21', null, array('name' => 'Rusaliile')),
45+
array('2018-04-06', null, array('name' => 'Paștele')),
46+
array('2018-04-08', null, array('name' => 'Paștele')),
47+
array('2018-04-09', null, array('name' => 'Paștele')),
48+
array('2018-05-27', null, array('name' => 'Rusaliile')),
49+
array('2018-05-28', null, array('name' => 'Rusaliile')),
4750

4851
// Easter dates 2019
49-
array('2019-04-21', null, array('name' => 'Paștele')),
50-
array('2019-04-22', null, array('name' => 'Paștele')),
51-
array('2019-06-09', null, array('name' => 'Rusaliile')),
52-
array('2019-06-10', null, array('name' => 'Rusaliile')),
52+
array('2019-04-26', null, array('name' => 'Paștele')),
53+
array('2019-04-28', null, array('name' => 'Paștele')),
54+
array('2019-04-29', null, array('name' => 'Paștele')),
55+
array('2019-06-16', null, array('name' => 'Rusaliile')),
56+
array('2019-06-17', null, array('name' => 'Rusaliile')),
5357
);
5458
}
5559
}

0 commit comments

Comments
 (0)