1
|
|
|
<?php |
|
|
|
|
2
|
|
|
/** |
3
|
|
|
* If ext/calendar is not installed, then provide the necessary shims. |
4
|
|
|
* |
5
|
|
|
* @author Greg Roach <[email protected]> |
6
|
|
|
* @copyright (c) 2014-2017 Greg Roach |
7
|
|
|
* @license This program is free software: you can redistribute it and/or modify |
8
|
|
|
* it under the terms of the GNU General Public License as published by |
9
|
|
|
* the Free Software Foundation, either version 3 of the License, or |
10
|
|
|
* (at your option) any later version. |
11
|
|
|
* |
12
|
|
|
* This program is distributed in the hope that it will be useful, |
13
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
14
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15
|
|
|
* GNU General Public License for more details. |
16
|
|
|
* |
17
|
|
|
* You should have received a copy of the GNU General Public License |
18
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
19
|
|
|
*/ |
20
|
|
|
|
21
|
|
|
use Fisharebest\ExtCalendar\Shim; |
22
|
|
|
|
23
|
|
|
if (!defined('CAL_GREGORIAN')) { |
24
|
|
|
Shim::create(); |
25
|
|
|
|
26
|
|
|
define('CAL_GREGORIAN', 0); |
27
|
|
|
define('CAL_JULIAN', 1); |
28
|
|
|
define('CAL_JEWISH', 2); |
29
|
|
|
define('CAL_FRENCH', 3); |
30
|
|
|
define('CAL_NUM_CALS', 4); |
31
|
|
|
define('CAL_DOW_DAYNO', 0); |
32
|
|
|
define('CAL_DOW_SHORT', Shim::shouldEmulateBug67960() ? 1 : 2); |
33
|
|
|
define('CAL_DOW_LONG', Shim::shouldEmulateBug67960() ? 2 : 1); |
34
|
|
|
define('CAL_MONTH_GREGORIAN_SHORT', 0); |
35
|
|
|
define('CAL_MONTH_GREGORIAN_LONG', 1); |
36
|
|
|
define('CAL_MONTH_JULIAN_SHORT', 2); |
37
|
|
|
define('CAL_MONTH_JULIAN_LONG', 3); |
38
|
|
|
define('CAL_MONTH_JEWISH', 4); |
39
|
|
|
define('CAL_MONTH_FRENCH', 5); |
40
|
|
|
define('CAL_EASTER_DEFAULT', 0); |
41
|
|
|
define('CAL_EASTER_ROMAN', 1); |
42
|
|
|
define('CAL_EASTER_ALWAYS_GREGORIAN', 2); |
43
|
|
|
define('CAL_EASTER_ALWAYS_JULIAN', 3); |
44
|
|
|
define('CAL_JEWISH_ADD_ALAFIM_GERESH', 2); |
45
|
|
|
define('CAL_JEWISH_ADD_ALAFIM', 4); |
46
|
|
|
define('CAL_JEWISH_ADD_GERESHAYIM', 8); |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @param integer $calendar_id |
50
|
|
|
* @param integer $month |
51
|
|
|
* @param integer $year |
52
|
|
|
* |
53
|
|
|
* @return integer|boolean |
54
|
|
|
*/ |
55
|
|
|
|
56
|
|
|
function cal_days_in_month($calendar_id, $month, $year) { |
|
|
|
|
57
|
|
|
return Shim::calDaysInMonth($calendar_id, $month, $year); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* @param integer $julian_day |
62
|
|
|
* @param integer $calendar_id |
63
|
|
|
* |
64
|
|
|
* @return array|boolean |
65
|
|
|
*/ |
66
|
|
|
function cal_from_jd($julian_day, $calendar_id) { |
|
|
|
|
67
|
|
|
return Shim::calFromJd($julian_day, $calendar_id); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* @param integer $calendar_id |
72
|
|
|
* |
73
|
|
|
* @return array|boolean |
|
|
|
|
74
|
|
|
*/ |
75
|
|
|
function cal_info($calendar_id = -1) { |
|
|
|
|
76
|
|
|
return Shim::calInfo($calendar_id); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* @param integer $calendar_id |
81
|
|
|
* @param integer $month |
82
|
|
|
* @param integer $day |
83
|
|
|
* @param integer $year |
84
|
|
|
* |
85
|
|
|
* @return integer|boolean |
86
|
|
|
*/ |
87
|
|
|
function cal_to_jd($calendar_id, $month, $day, $year) { |
|
|
|
|
88
|
|
|
return Shim::calToJd($calendar_id, $month, $day, $year); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* @param integer|null $year |
93
|
|
|
* |
94
|
|
|
* @return integer|boolean |
|
|
|
|
95
|
|
|
*/ |
96
|
|
|
function easter_date($year = null) { |
|
|
|
|
97
|
|
|
return Shim::easterDate($year ? $year : (int)date('Y')); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* @param integer|null $year |
102
|
|
|
* @param integer $method |
103
|
|
|
* |
104
|
|
|
* @return integer |
105
|
|
|
*/ |
106
|
|
|
function easter_days($year = null, $method = CAL_EASTER_DEFAULT) { |
|
|
|
|
107
|
|
|
return Shim::easterDays($year ? $year : (int)date('Y'), $method); |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* @param integer $month |
112
|
|
|
* @param integer $day |
113
|
|
|
* @param integer $year |
114
|
|
|
* |
115
|
|
|
* @return integer |
116
|
|
|
*/ |
117
|
|
|
function FrenchToJD($month, $day, $year) { |
|
|
|
|
118
|
|
|
return Shim::frenchToJd($month, $day, $year); |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
/** |
122
|
|
|
* @param integer $month |
123
|
|
|
* @param integer $day |
124
|
|
|
* @param integer $year |
125
|
|
|
* |
126
|
|
|
* @return integer |
127
|
|
|
*/ |
128
|
|
|
function GregorianToJD($month, $day, $year) { |
|
|
|
|
129
|
|
|
return Shim::gregorianToJd($month, $day, $year); |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
/** |
133
|
|
|
* @param integer $julian_day |
134
|
|
|
* @param integer $mode |
135
|
|
|
* |
136
|
|
|
* @return integer|string |
137
|
|
|
*/ |
138
|
|
|
function JDDayOfWeek($julian_day, $mode = CAL_DOW_DAYNO) { |
|
|
|
|
139
|
|
|
return Shim::jdDayOfWeek($julian_day, $mode); |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
/** |
143
|
|
|
* @param integer $julian_day |
144
|
|
|
* @param integer $mode |
145
|
|
|
* |
146
|
|
|
* @return string |
147
|
|
|
*/ |
148
|
|
|
function JDMonthName($julian_day, $mode) { |
|
|
|
|
149
|
|
|
return Shim::jdMonthName($julian_day, $mode); |
150
|
|
|
} |
151
|
|
|
|
152
|
|
|
/** |
153
|
|
|
* @param integer $julian_day |
154
|
|
|
* |
155
|
|
|
* @return string |
156
|
|
|
*/ |
157
|
|
|
function JDToFrench($julian_day) { |
|
|
|
|
158
|
|
|
return Shim::jdToFrench($julian_day); |
159
|
|
|
} |
160
|
|
|
|
161
|
|
|
/** |
162
|
|
|
* @param integer $julian_day |
163
|
|
|
* |
164
|
|
|
* @return string |
165
|
|
|
*/ |
166
|
|
|
function JDToGregorian($julian_day) { |
|
|
|
|
167
|
|
|
return Shim::jdToGregorian($julian_day); |
168
|
|
|
} |
169
|
|
|
|
170
|
|
|
/** |
171
|
|
|
* @param integer $julian_day |
172
|
|
|
* @param boolean $hebrew |
173
|
|
|
* @param integer $flags |
174
|
|
|
* |
175
|
|
|
* @return string|boolean |
176
|
|
|
*/ |
177
|
|
|
function jdtojewish($julian_day, $hebrew = false, $flags = 0) { |
178
|
|
|
return Shim::jdToJewish($julian_day, $hebrew, $flags); |
179
|
|
|
} |
180
|
|
|
|
181
|
|
|
/** |
182
|
|
|
* @param integer $julian_day |
183
|
|
|
* |
184
|
|
|
* @return string |
185
|
|
|
*/ |
186
|
|
|
function JDToJulian($julian_day) { |
|
|
|
|
187
|
|
|
return Shim::jdToJulian($julian_day); |
188
|
|
|
} |
189
|
|
|
|
190
|
|
|
/** |
191
|
|
|
* @param integer $julian_day |
192
|
|
|
* |
193
|
|
|
* @return integer|false |
194
|
|
|
*/ |
195
|
|
|
function jdtounix($julian_day) { |
196
|
|
|
return Shim::jdToUnix($julian_day); |
197
|
|
|
} |
198
|
|
|
|
199
|
|
|
/** |
200
|
|
|
* @param integer $month |
201
|
|
|
* @param integer $day |
202
|
|
|
* @param integer $year |
203
|
|
|
* |
204
|
|
|
* @return integer |
205
|
|
|
*/ |
206
|
|
|
function JewishToJD($month, $day, $year) { |
|
|
|
|
207
|
|
|
return Shim::jewishToJd($month, $day, $year); |
208
|
|
|
} |
209
|
|
|
|
210
|
|
|
/** |
211
|
|
|
* @param integer $month |
212
|
|
|
* @param integer $day |
213
|
|
|
* @param integer $year |
214
|
|
|
* |
215
|
|
|
* @return integer |
216
|
|
|
*/ |
217
|
|
|
function JulianToJD($month, $day, $year) { |
|
|
|
|
218
|
|
|
return Shim::julianToJd($month, $day, $year); |
219
|
|
|
} |
220
|
|
|
|
221
|
|
|
/** |
222
|
|
|
* @param integer|null $timestamp |
223
|
|
|
* |
224
|
|
|
* @return false|integer |
225
|
|
|
*/ |
226
|
|
|
function unixtojd($timestamp = null) { |
227
|
|
|
return Shim::unixToJd($timestamp ? $timestamp : time()); |
228
|
|
|
} |
229
|
|
|
} |
230
|
|
|
|
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.