1 | <?php |
||
12 | class StaticFilter |
||
13 | { |
||
14 | protected static $easterByYear = []; // cache of Easter DateTimeImmutable objects, indexed by year |
||
15 | |||
16 | /** |
||
17 | * Returns true if $dt is on a Saturday or Sunday, false otherwise |
||
18 | * |
||
19 | * @param \DateTimeInterface $dt |
||
20 | * @return bool |
||
21 | */ |
||
22 | 22 | public static function isWeekend(\DateTimeInterface $dt) |
|
23 | { |
||
24 | 22 | return in_array($dt->format('w'), [0, 6]); |
|
25 | } |
||
26 | |||
27 | /** |
||
28 | * Returns true if $dt is the Monday after Western Easter, false otherwise |
||
29 | * |
||
30 | * @param \DateTimeInterface $dt |
||
31 | * @return bool |
||
32 | */ |
||
33 | 26 | public static function isEasterMonday(\DateTimeInterface $dt) |
|
34 | { |
||
35 | 26 | $easterMonday = static::getEasterDateTimeForYear($dt->format('Y'))->add(new \DateInterval('P1D')); |
|
36 | 26 | return $easterMonday->format('m') === $dt->format('m') && $easterMonday->format('d') === $dt->format('d'); |
|
37 | } |
||
38 | |||
39 | /** |
||
40 | * Returns true if $dt is the Friday before Western Easter, false otherwise |
||
41 | * |
||
42 | * @param \DateTimeInterface $dt |
||
43 | * @return bool |
||
44 | */ |
||
45 | 26 | public static function isGoodFriday(\DateTimeInterface $dt) |
|
46 | { |
||
47 | 26 | $goodFriday = static::getEasterDateTimeForYear($dt->format('Y'))->sub(new \DateInterval('P2D')); |
|
48 | 26 | return $goodFriday->format('m') === $dt->format('m') && $goodFriday->format('d') === $dt->format('d'); |
|
49 | } |
||
50 | |||
51 | /** |
||
52 | * Gets an immutable DateTime object set to midnight UTC of Western Easter |
||
53 | * for a given year. Built because HHVM doesn't include easter_date() or |
||
54 | * easter_day(). Credit to https://www.drupal.org/node/1180480 for the |
||
55 | * original implementation. |
||
56 | * |
||
57 | * To get a runtime-agnostic result comparable to PHP4+'s easter_date(), |
||
58 | * call getTimestamp() on the returned value of this function. |
||
59 | * |
||
60 | * @param int $year |
||
61 | * @return \DateTimeImmutable |
||
62 | */ |
||
63 | 34 | public static function getEasterDateTimeForYear($year) { |
|
91 | } |
||
92 |