@@ -7,35 +7,35 @@ discard block |
||
7 | 7 | */ |
8 | 8 | class DayOf |
9 | 9 | { |
10 | - /** |
|
11 | - * @var object |
|
12 | - */ |
|
10 | + /** |
|
11 | + * @var object |
|
12 | + */ |
|
13 | 13 | protected $date_time; |
14 | 14 | |
15 | - /** |
|
16 | - * @var array |
|
17 | - */ |
|
15 | + /** |
|
16 | + * @var array |
|
17 | + */ |
|
18 | 18 | protected $config; |
19 | 19 | |
20 | - /** |
|
21 | - * @var string |
|
22 | - */ |
|
23 | - protected $calendar_type; |
|
20 | + /** |
|
21 | + * @var string |
|
22 | + */ |
|
23 | + protected $calendar_type; |
|
24 | 24 | |
25 | 25 | /** |
26 | 26 | * @var int |
27 | 27 | */ |
28 | 28 | protected $day_of_week; |
29 | 29 | |
30 | - /** |
|
31 | - * Constructor of DayOf class |
|
32 | - */ |
|
30 | + /** |
|
31 | + * Constructor of DayOf class |
|
32 | + */ |
|
33 | 33 | public function __construct($date_time, $calendar_type = 'gregorian', $day_of_week = null) |
34 | 34 | { |
35 | 35 | |
36 | - $this->config = include __DIR__.'/CalendarSettings/' . ucfirst($calendar_type) . '.php'; |
|
36 | + $this->config = include __DIR__.'/CalendarSettings/' . ucfirst($calendar_type) . '.php'; |
|
37 | 37 | |
38 | - $this->calendar_type = $calendar_type; |
|
38 | + $this->calendar_type = $calendar_type; |
|
39 | 39 | |
40 | 40 | $this->date_time = $date_time; |
41 | 41 | |
@@ -46,11 +46,11 @@ discard block |
||
46 | 46 | } |
47 | 47 | |
48 | 48 | /** |
49 | - * Which day of year is current day. |
|
50 | - * |
|
51 | - * @since Aug, 03 2015 |
|
52 | - * @return integer |
|
53 | - */ |
|
49 | + * Which day of year is current day. |
|
50 | + * |
|
51 | + * @since Aug, 03 2015 |
|
52 | + * @return integer |
|
53 | + */ |
|
54 | 54 | public function year() |
55 | 55 | { |
56 | 56 | |
@@ -60,56 +60,56 @@ discard block |
||
60 | 60 | |
61 | 61 | |
62 | 62 | /** |
63 | - * Which day of week is current day. |
|
64 | - * |
|
65 | - * @since Aug, 09 2015 |
|
66 | - * @return integer |
|
67 | - */ |
|
63 | + * Which day of week is current day. |
|
64 | + * |
|
65 | + * @since Aug, 09 2015 |
|
66 | + * @return integer |
|
67 | + */ |
|
68 | 68 | public function week() |
69 | 69 | { |
70 | 70 | return $this->config[ 'day_of_week' ]( $this->date_time, $this->day_of_week ); |
71 | 71 | |
72 | 72 | } |
73 | 73 | |
74 | - /** |
|
75 | - * Return last day of current month |
|
76 | - * |
|
77 | - * @since Oct, 18 2016 |
|
78 | - * @return integer |
|
79 | - */ |
|
80 | - public function lastDayMonth() { |
|
74 | + /** |
|
75 | + * Return last day of current month |
|
76 | + * |
|
77 | + * @since Oct, 18 2016 |
|
78 | + * @return integer |
|
79 | + */ |
|
80 | + public function lastDayMonth() { |
|
81 | 81 | |
82 | - $days = 0; |
|
82 | + $days = 0; |
|
83 | 83 | |
84 | - switch ( $this->calendar_type ) { |
|
84 | + switch ( $this->calendar_type ) { |
|
85 | 85 | |
86 | - case 'gregorian': |
|
86 | + case 'gregorian': |
|
87 | 87 | |
88 | - $days = ( intval( $this->date_time->format( 'm' ) ) == 2 && |
|
89 | - $this->config[ 'leap_year' ]( $this->date_time->format( 'Y' )) ) ? |
|
90 | - $this->config[ 'month_days_number' ][ intval( $this->date_time->format( 'm' ) ) ] + 1 : |
|
91 | - $this->config[ 'month_days_number' ][ intval( $this->date_time->format( 'm' ) ) ]; |
|
88 | + $days = ( intval( $this->date_time->format( 'm' ) ) == 2 && |
|
89 | + $this->config[ 'leap_year' ]( $this->date_time->format( 'Y' )) ) ? |
|
90 | + $this->config[ 'month_days_number' ][ intval( $this->date_time->format( 'm' ) ) ] + 1 : |
|
91 | + $this->config[ 'month_days_number' ][ intval( $this->date_time->format( 'm' ) ) ]; |
|
92 | 92 | |
93 | - break; |
|
93 | + break; |
|
94 | 94 | |
95 | - case 'jalali': |
|
95 | + case 'jalali': |
|
96 | 96 | |
97 | - $days = ( intval( $this->date_time->format( 'm' ) ) == 12 && |
|
98 | - $this->config[ 'leap_year' ]( $this->date_time->format( 'Y' )) ) ? |
|
99 | - $this->config[ 'month_days_number' ][ intval( $this->date_time->format( 'm' ) ) ] + 1 : |
|
100 | - $this->config[ 'month_days_number' ][ intval( $this->date_time->format( 'm' ) ) ]; |
|
97 | + $days = ( intval( $this->date_time->format( 'm' ) ) == 12 && |
|
98 | + $this->config[ 'leap_year' ]( $this->date_time->format( 'Y' )) ) ? |
|
99 | + $this->config[ 'month_days_number' ][ intval( $this->date_time->format( 'm' ) ) ] + 1 : |
|
100 | + $this->config[ 'month_days_number' ][ intval( $this->date_time->format( 'm' ) ) ]; |
|
101 | 101 | |
102 | - break; |
|
102 | + break; |
|
103 | 103 | |
104 | - default: |
|
104 | + default: |
|
105 | 105 | |
106 | - $days = $this->config[ 'month_days_number' ][ intval( $this->date_time->format( 'm' ) ) ]; |
|
106 | + $days = $this->config[ 'month_days_number' ][ intval( $this->date_time->format( 'm' ) ) ]; |
|
107 | 107 | |
108 | - break; |
|
108 | + break; |
|
109 | 109 | |
110 | - } |
|
110 | + } |
|
111 | 111 | |
112 | - return $days; |
|
112 | + return $days; |
|
113 | 113 | |
114 | - } |
|
114 | + } |
|
115 | 115 | } |
@@ -118,30 +118,30 @@ discard block |
||
118 | 118 | |
119 | 119 | 'days_of_week' => array ( |
120 | 120 | |
121 | - 'Yekşeme', |
|
122 | - 'Dúşeme', |
|
123 | - 'Séşeme', |
|
124 | - 'Çúwarşeme', |
|
125 | - 'Péncşeme', |
|
126 | - 'Heyní', |
|
127 | - 'Şeme', |
|
121 | + 'Yekşeme', |
|
122 | + 'Dúşeme', |
|
123 | + 'Séşeme', |
|
124 | + 'Çúwarşeme', |
|
125 | + 'Péncşeme', |
|
126 | + 'Heyní', |
|
127 | + 'Şeme', |
|
128 | 128 | |
129 | 129 | ), |
130 | 130 | |
131 | 131 | 'start_day_of_week' => 'Şeme', |
132 | 132 | |
133 | 133 | 'month_days_number' => array( 1 => 31, |
134 | - 2 => 31, |
|
135 | - 3 => 31, |
|
136 | - 4 => 31, |
|
137 | - 5 => 31, |
|
138 | - 6 => 31, |
|
139 | - 7 => 30, |
|
140 | - 8 => 30, |
|
141 | - 9 => 30, |
|
142 | - 10 => 30, |
|
143 | - 11 => 30, |
|
144 | - 12 => 29 ), |
|
134 | + 2 => 31, |
|
135 | + 3 => 31, |
|
136 | + 4 => 31, |
|
137 | + 5 => 31, |
|
138 | + 6 => 31, |
|
139 | + 7 => 30, |
|
140 | + 8 => 30, |
|
141 | + 9 => 30, |
|
142 | + 10 => 30, |
|
143 | + 11 => 30, |
|
144 | + 12 => 29 ), |
|
145 | 145 | |
146 | 146 | /************************************************************ |
147 | 147 | * Day of year |
@@ -213,7 +213,7 @@ discard block |
||
213 | 213 | |
214 | 214 | foreach ($days as $key => $value) { |
215 | 215 | if ($day == $value) { |
216 | - return $key; |
|
216 | + return $key; |
|
217 | 217 | } |
218 | 218 | } |
219 | 219 | |
@@ -229,9 +229,9 @@ discard block |
||
229 | 229 | */ |
230 | 230 | 'leap_year' => function ($year) { |
231 | 231 | |
232 | - $a = 0.025; |
|
232 | + $a = 0.025; |
|
233 | 233 | |
234 | - $b = 266; |
|
234 | + $b = 266; |
|
235 | 235 | |
236 | 236 | if ($year > 0) { |
237 | 237 | $leapDays0 = (($year + 38) % 2820)*0.24219 + $a; |
@@ -245,8 +245,8 @@ discard block |
||
245 | 245 | return false; |
246 | 246 | } |
247 | 247 | |
248 | - $frac0 = intval(($leapDays0 - intval($leapDays0))*1000); |
|
249 | - $frac1 = intval(($leapDays1 - intval($leapDays1))*1000); |
|
248 | + $frac0 = intval(($leapDays0 - intval($leapDays0))*1000); |
|
249 | + $frac1 = intval(($leapDays1 - intval($leapDays1))*1000); |
|
250 | 250 | |
251 | 251 | if ($frac0 <= $b && $frac1 > $b) { |
252 | 252 | return true; |
@@ -266,4 +266,4 @@ discard block |
||
266 | 266 | */ |
267 | 267 | 'weekend' => array( 'friday' ) |
268 | 268 | |
269 | - ); |
|
269 | + ); |
@@ -5,7 +5,7 @@ discard block |
||
5 | 5 | |
6 | 6 | return array ( |
7 | 7 | |
8 | - /************************************************************ |
|
8 | + /************************************************************ |
|
9 | 9 | * Convert to |
10 | 10 | ************************************************************ |
11 | 11 | * |
@@ -13,19 +13,19 @@ discard block |
||
13 | 13 | * |
14 | 14 | *\_________________________________________________________/ |
15 | 15 | */ |
16 | - 'convert_to' => function ($date_time) { |
|
16 | + 'convert_to' => function ($date_time) { |
|
17 | 17 | |
18 | - $config = include 'Jalali.php'; |
|
18 | + $config = include 'Jalali.php'; |
|
19 | 19 | |
20 | - $date_time = Datium::create($date_time)->to('jalali')->object(); |
|
20 | + $date_time = Datium::create($date_time)->to('jalali')->object(); |
|
21 | 21 | |
22 | - $year = $date_time->format('Y'); |
|
22 | + $year = $date_time->format('Y'); |
|
23 | 23 | |
24 | - $month = $date_time->format('n'); |
|
24 | + $month = $date_time->format('n'); |
|
25 | 25 | |
26 | - $day = $date_time->format('d'); |
|
26 | + $day = $date_time->format('d'); |
|
27 | 27 | |
28 | - $temp_day = 0 ; |
|
28 | + $temp_day = 0 ; |
|
29 | 29 | |
30 | 30 | for ($i = 1; $i < $month; $i++) { |
31 | 31 | $temp_day += $config[ 'month_days_number' ][ $i ]; |
@@ -39,13 +39,13 @@ discard block |
||
39 | 39 | $temp_day++; |
40 | 40 | } |
41 | 41 | |
42 | - $_year = ( ( ( ( ( $year - 1 ) * 365.2422 ) + $temp_day ) - 119) / 354.3670 ) + 1; |
|
42 | + $_year = ( ( ( ( ( $year - 1 ) * 365.2422 ) + $temp_day ) - 119) / 354.3670 ) + 1; |
|
43 | 43 | |
44 | - $_year = explode('.', $_year); |
|
44 | + $_year = explode('.', $_year); |
|
45 | 45 | |
46 | - $year = $_year[0]; |
|
46 | + $year = $_year[0]; |
|
47 | 47 | |
48 | - $_month = $_year[1]; |
|
48 | + $_month = $_year[1]; |
|
49 | 49 | |
50 | 50 | $var_temp = '0.0'; |
51 | 51 | |
@@ -55,37 +55,37 @@ discard block |
||
55 | 55 | |
56 | 56 | $var_temp .= '1'; |
57 | 57 | |
58 | - $_month = $_month * $var_temp ; |
|
58 | + $_month = $_month * $var_temp ; |
|
59 | 59 | |
60 | - $_month = ( $_month * 12 ) + 1; |
|
60 | + $_month = ( $_month * 12 ) + 1; |
|
61 | 61 | |
62 | - $_month = explode('.', $_month); |
|
62 | + $_month = explode('.', $_month); |
|
63 | 63 | |
64 | - $month = $_month[0]; |
|
64 | + $month = $_month[0]; |
|
65 | 65 | |
66 | - $_day = $_month[1]; |
|
66 | + $_day = $_month[1]; |
|
67 | 67 | |
68 | - $var_temp = '0.0'; |
|
68 | + $var_temp = '0.0'; |
|
69 | 69 | |
70 | 70 | for ($i = strlen($_day); $i > 2; $i--) { |
71 | 71 | $var_temp .= '0' ; |
72 | 72 | } |
73 | 73 | |
74 | - $var_temp .= '1'; |
|
74 | + $var_temp .= '1'; |
|
75 | 75 | |
76 | - $_day = $_day * $var_temp; |
|
76 | + $_day = $_day * $var_temp; |
|
77 | 77 | |
78 | - $_day = ( $_day * 29.530 ); |
|
78 | + $_day = ( $_day * 29.530 ); |
|
79 | 79 | |
80 | - $_day = explode('.', $_day); |
|
80 | + $_day = explode('.', $_day); |
|
81 | 81 | |
82 | - $day = $_day[0]; |
|
82 | + $day = $_day[0]; |
|
83 | 83 | |
84 | 84 | $date_time->setDate($year, $month, $day); |
85 | 85 | |
86 | 86 | return $date_time; |
87 | 87 | |
88 | - }, |
|
88 | + }, |
|
89 | 89 | |
90 | 90 | /************************************************************ |
91 | 91 | * Convert From |
@@ -165,7 +165,7 @@ discard block |
||
165 | 165 | |
166 | 166 | 'Dhu al_Hijjah' |
167 | 167 | |
168 | - ), |
|
168 | + ), |
|
169 | 169 | |
170 | 170 | /************************************************************ |
171 | 171 | * Days of Week |
@@ -178,13 +178,13 @@ discard block |
||
178 | 178 | */ |
179 | 179 | 'days_of_week' => array ( |
180 | 180 | |
181 | - 'al-Aḥad', |
|
182 | - 'al-Ithnayn', |
|
183 | - 'ath-Thulatha\'', |
|
184 | - 'al-Arbi\'a', |
|
185 | - 'al-Khamees', |
|
186 | - 'al-Jumu\'ah', |
|
187 | - 'as-Sabt', |
|
181 | + 'al-Aḥad', |
|
182 | + 'al-Ithnayn', |
|
183 | + 'ath-Thulatha\'', |
|
184 | + 'al-Arbi\'a', |
|
185 | + 'al-Khamees', |
|
186 | + 'al-Jumu\'ah', |
|
187 | + 'as-Sabt', |
|
188 | 188 | ), |
189 | 189 | |
190 | 190 | 'numbers' => array( '0', '1', '2', '3', '4', '5', '6', '7', '8', '9'), |
@@ -199,17 +199,17 @@ discard block |
||
199 | 199 | |
200 | 200 | |
201 | 201 | 'month_days_number' => array( 1 => 30, |
202 | - 2 => 29, |
|
203 | - 3 => 30, |
|
204 | - 4 => 30, |
|
205 | - 5 => 29, |
|
206 | - 6 => 29, |
|
207 | - 7 => 30, |
|
208 | - 8 => 29, |
|
209 | - 9 => 30, |
|
210 | - 10 => 29, |
|
211 | - 11 => 30, |
|
212 | - 12 => 30 ), |
|
202 | + 2 => 29, |
|
203 | + 3 => 30, |
|
204 | + 4 => 30, |
|
205 | + 5 => 29, |
|
206 | + 6 => 29, |
|
207 | + 7 => 30, |
|
208 | + 8 => 29, |
|
209 | + 9 => 30, |
|
210 | + 10 => 29, |
|
211 | + 11 => 30, |
|
212 | + 12 => 30 ), |
|
213 | 213 | /************************************************************ |
214 | 214 | * Day of year |
215 | 215 | ************************************************************ |
@@ -218,7 +218,7 @@ discard block |
||
218 | 218 | * |
219 | 219 | *\_________________________________________________________/ |
220 | 220 | */ |
221 | - 'day_of_year' => function ($date_time) { |
|
221 | + 'day_of_year' => function ($date_time) { |
|
222 | 222 | |
223 | 223 | $result = null; |
224 | 224 | |
@@ -238,9 +238,9 @@ discard block |
||
238 | 238 | |
239 | 239 | return $result; |
240 | 240 | |
241 | - }, |
|
241 | + }, |
|
242 | 242 | |
243 | - /************************************************************ |
|
243 | + /************************************************************ |
|
244 | 244 | * Day of week |
245 | 245 | ************************************************************ |
246 | 246 | * |
@@ -248,9 +248,9 @@ discard block |
||
248 | 248 | * example : al-Aḥad = result is 1 |
249 | 249 | *\_________________________________________________________/ |
250 | 250 | */ |
251 | - 'day_of_week' => function ($date_time, $day_of_week) { |
|
251 | + 'day_of_week' => function ($date_time, $day_of_week) { |
|
252 | 252 | |
253 | - $days_of_week = array( |
|
253 | + $days_of_week = array( |
|
254 | 254 | 'al-Ithnayn', |
255 | 255 | 'ath-Thulatha\'', |
256 | 256 | 'al-Arbi\'a', |
@@ -258,9 +258,9 @@ discard block |
||
258 | 258 | 'al-Jumu\'ah', |
259 | 259 | 'as-Sabt', |
260 | 260 | 'al-Aḥad', |
261 | - ); |
|
261 | + ); |
|
262 | 262 | |
263 | - $days = array( |
|
263 | + $days = array( |
|
264 | 264 | 1 => 'al-Aḥad', |
265 | 265 | 2 => 'al-Ithnayn', |
266 | 266 | 3 => 'ath-Thulatha\'', |
@@ -268,7 +268,7 @@ discard block |
||
268 | 268 | 5 => 'al-Khamees', |
269 | 269 | 6 => 'al-Jumu\'ah', |
270 | 270 | 7 => 'as-Sabt', |
271 | - ); |
|
271 | + ); |
|
272 | 272 | |
273 | 273 | $configGregorian = include 'Gregorian.php'; |
274 | 274 | |
@@ -280,9 +280,9 @@ discard block |
||
280 | 280 | } |
281 | 281 | } |
282 | 282 | |
283 | - }, |
|
283 | + }, |
|
284 | 284 | |
285 | - /************************************************************ |
|
285 | + /************************************************************ |
|
286 | 286 | * Leap year |
287 | 287 | ************************************************************ |
288 | 288 | * |
@@ -290,7 +290,7 @@ discard block |
||
290 | 290 | * |
291 | 291 | *\_________________________________________________________/ |
292 | 292 | */ |
293 | - 'leap_year' => function ($year) { |
|
293 | + 'leap_year' => function ($year) { |
|
294 | 294 | $result = $this->year % 30; |
295 | 295 | |
296 | 296 | if (( 2 == $result ) |
@@ -307,7 +307,7 @@ discard block |
||
307 | 307 | ) { |
308 | 308 | return $result; |
309 | 309 | } |
310 | - }, |
|
310 | + }, |
|
311 | 311 | |
312 | 312 | /************************************************************ |
313 | 313 | * Weekend |