|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Andegna\Holiday; |
|
4
|
|
|
|
|
5
|
|
|
use Andegna\Converter\FromJdnConverter; |
|
6
|
|
|
use Andegna\DateTimeFactory; |
|
7
|
|
|
use DateTimeZone; |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* Ethiopian Easter. |
|
11
|
|
|
*/ |
|
12
|
|
|
class Easter |
|
13
|
|
|
{ |
|
14
|
|
|
/** @var DateTimeZone */ |
|
15
|
|
|
private $dateTimeZone; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* Easter constructor. |
|
19
|
|
|
* |
|
20
|
|
|
* @param DateTimeZone $dateTimeZone |
|
21
|
|
|
*/ |
|
22
|
41 |
|
public function __construct(DateTimeZone $dateTimeZone = null) |
|
23
|
|
|
{ |
|
24
|
41 |
|
$this->dateTimeZone = $dateTimeZone; |
|
25
|
41 |
|
} |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* Get the easter date of a given Ethiopian year. |
|
29
|
|
|
* |
|
30
|
|
|
* @param $year int Ethiopian year |
|
31
|
|
|
* |
|
32
|
|
|
* @return \Andegna\DateTime |
|
33
|
|
|
*/ |
|
34
|
41 |
|
public function get(int $year) |
|
35
|
|
|
{ |
|
36
|
|
|
// convert the Ethiopian year to a Julian year |
|
37
|
|
|
// ሚያዝያ 1 is just a random day after the Gregorian new year |
|
38
|
41 |
|
$julian_year = (int) DateTimeFactory::of($year, 8, 1) |
|
39
|
41 |
|
->toGregorian()->format('Y'); |
|
40
|
|
|
|
|
41
|
|
|
// get the number of days from vernal equinox to the Easter in the given Julian year |
|
42
|
41 |
|
$days_after = easter_days($julian_year, CAL_EASTER_ALWAYS_JULIAN); |
|
43
|
|
|
|
|
44
|
|
|
// get the JDN of vernal equinox (March 21) in the given Julian year |
|
45
|
41 |
|
$jdn = juliantojd(3, 21, $julian_year); |
|
46
|
|
|
|
|
47
|
|
|
// add the number of days to Easter |
|
48
|
41 |
|
$jdn += $days_after; |
|
49
|
|
|
|
|
50
|
|
|
// create a Ethiopian Date to JDN converter |
|
51
|
41 |
|
$con = new FromJdnConverter($jdn); |
|
52
|
|
|
|
|
53
|
|
|
// create an Ethiopian date from the converter |
|
54
|
41 |
|
return DateTimeFactory::of($con->getYear(), $con->getMonth(), $con->getDay(), |
|
55
|
41 |
|
0, 0, 0, $this->dateTimeZone); |
|
56
|
|
|
} |
|
57
|
|
|
} |
|
58
|
|
|
|