| 80 | | if (isset($this->conditions['weekend'])) |
| | 83 | // Test basic conditions first |
| | 84 | if (isset($this->conditions[$key]) AND $this->conditions[$key] !== $value) |
| | 85 | return FALSE; |
| | 86 | |
| | 87 | // Condition has been tested |
| | 88 | $tested[$key] = TRUE; |
| | 89 | } |
| | 90 | |
| | 91 | if (isset($this->conditions['weekend'])) |
| | 92 | { |
| | 93 | // Weekday vs Weekend |
| | 94 | $condition['weekend'] = ($condition['day_of_week'] === 0 OR $condition['day_of_week'] === 6); |
| | 95 | } |
| | 96 | |
| | 97 | if (isset($this->conditions['first_day'])) |
| | 98 | { |
| | 99 | // First day of month |
| | 100 | $condition['first_day'] = ($condition['day'] === 1); |
| | 101 | } |
| | 102 | |
| | 103 | if (isset($this->conditions['last_day'])) |
| | 104 | { |
| | 105 | // Last day of month |
| | 106 | $condition['last_day'] = ($condition['day'] === (int) date('t', $timestamp)); |
| | 107 | } |
| | 108 | |
| | 109 | if (isset($this->conditions['occurrence'])) |
| | 110 | { |
| | 111 | // Get the occurance of the current day |
| | 112 | $condition['occurrence'] = $this->day_occurrence($timestamp); |
| | 113 | } |
| | 114 | |
| | 115 | if (isset($this->conditions['last_occurrence'])) |
| | 116 | { |
| | 117 | // Test if the next occurance of this date is next month |
| | 118 | $condition['last_occurrence'] = ((int) date('n', strtotime(date('Y/m/d', $timestamp).' +1 week')) !== $condition['month']); |
| | 119 | } |
| | 120 | |
| | 121 | if (isset($this->conditions['easter'])) |
| | 122 | { |
| | 123 | if ($condition['month'] === 3 OR $condition['month'] === 4) |
| 82 | | // Weekday vs weekend |
| 83 | | $condition['weekend'] = ($condition['day_of_week'] === 0 OR $condition['day_of_week'] === 6); |
| | 125 | // This algorithm is from Practical Astronomy With Your Calculator, 2nd Edition by Peter |
| | 126 | // Duffett-Smith. It was originally from Butcher's Ecclesiastical Calendar, published in |
| | 127 | // 1876. This algorithm has also been published in the 1922 book General Astronomy by |
| | 128 | // Spencer Jones; in The Journal of the British Astronomical Association (Vol.88, page |
| | 129 | // 91, December 1977); and in Astronomical Algorithms (1991) by Jean Meeus. |
| | 130 | |
| | 131 | /** |
| | 132 | * @todo I imagine Geert will have a party with this one... |
| | 133 | */ |
| | 134 | $a = $condition['year'] % 19; |
| | 135 | $b = (int) ($condition['year'] / 100); |
| | 136 | $c = $condition['year'] % 100; |
| | 137 | $d = (int) ($b / 4); |
| | 138 | $e = $b % 4; |
| | 139 | $f = (int) (($b + 8) / 25); |
| | 140 | $g = (int) (($b - $f + 1) / 3); |
| | 141 | $h = (19 * $a + $b - $d - $g + 15) % 30; |
| | 142 | $i = (int) ($c / 4); |
| | 143 | $k = $c % 4; |
| | 144 | $l = (32 + 2 * $e + 2 * $i - $h - $k) % 7; |
| | 145 | $m = (int) (($a + 11 * $h + 22 * $l) / 451); |
| | 146 | $p = ($h + $l - 7 * $m + 114) % 31; |
| | 147 | |
| | 148 | $month = (int) (($h + $l - 7 * $m + 114) / 31); |
| | 149 | $day = $p + 1; |
| | 150 | |
| | 151 | $condition['easter'] = ($condition['month'] === $month AND $condition['day'] === $day); |
| 88 | | // First day of month |
| 89 | | $condition['first_day'] = ($condition['day'] === 1); |
| 90 | | } |
| 91 | | |
| 92 | | if (isset($this->conditions['last_day'])) |
| 93 | | { |
| 94 | | // Last day of month |
| 95 | | $condition['last_day'] = ($condition['day'] === (int) date('t', $timestamp)); |
| 96 | | } |
| 97 | | |
| 98 | | if (isset($this->conditions['occurrence'])) |
| 99 | | { |
| 100 | | // Get the occurance of the current day |
| 101 | | $condition['occurrence'] = $this->day_occurrence($timestamp); |
| 102 | | } |
| 103 | | |
| 104 | | if (isset($this->conditions['last_occurrence'])) |
| 105 | | { |
| 106 | | // Test if the next occurance of this date is next month |
| 107 | | $condition['last_occurrence'] = ((int) date('n', strtotime(date('Y/m/d', $timestamp).' +1 week')) !== $condition['month']); |
| | 155 | // Easter can only happen in March or April |
| | 156 | $condition['easter'] = FALSE; |