Version Description
- Fix diagnosis leap year function ( bn_parsidate::IsLeapYear() )
Download this release
Release Info
Developer | man4toman |
Plugin | Parsi Date |
Version | 2.3.4 |
Comparing to | |
See all releases |
Code changes from version 2.3.3 to 2.3.4
- .gitignore +0 -1
- includes/parsidate.php +380 -352
- readme.txt +4 -1
- wp-parsidate.php +1 -1
.gitignore
DELETED
@@ -1 +0,0 @@
|
|
1 |
-
.idea/
|
|
includes/parsidate.php
CHANGED
@@ -6,370 +6,396 @@
|
|
6 |
* @package WP-Parsidate
|
7 |
* @subpackage DateConversation
|
8 |
*/
|
|
|
9 |
/*Special thanks to :
|
10 |
Reza Gholampanahi for convert function*/
|
11 |
|
12 |
-
class bn_parsidate
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
45 |
|
46 |
-
|
47 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
48 |
|
49 |
-
|
50 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
51 |
|
52 |
-
|
|
|
53 |
|
|
|
|
|
54 |
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
63 |
|
64 |
-
|
65 |
-
* bn_parsidate::IsLeapYear()
|
66 |
-
* check year is leap
|
67 |
-
*
|
68 |
-
* @param mixed $year
|
69 |
-
*
|
70 |
-
* @return boolean
|
71 |
-
*/
|
72 |
-
private function IsLeapYear( $year ) {
|
73 |
-
if ( ( ( $year % 4 ) == 0 && ( $year % 100 ) != 0 ) || ( ( $year % 400 ) == 0 ) && ( $year % 100 ) == 0 ) {
|
74 |
-
return true;
|
75 |
-
} else {
|
76 |
-
return false;
|
77 |
-
}
|
78 |
-
}
|
79 |
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
* @param string $date
|
86 |
-
* @param string $lang
|
87 |
-
*
|
88 |
-
* @return datetime
|
89 |
-
*/
|
90 |
-
public function persian_date( $format, $date = 'now', $lang = 'per' ) {
|
91 |
-
$j_days_in_month = array( 31, 62, 93, 124, 155, 186, 216, 246, 276, 306, 336, 365 );
|
92 |
-
$timestamp = is_numeric( $date ) && (int) $date == $date ? $date : strtotime( $date );
|
93 |
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
if ( $lang == 'per' ) {
|
229 |
-
return self::trim_number( $out );
|
230 |
-
} else {
|
231 |
-
return $out;
|
232 |
-
}
|
233 |
-
}
|
234 |
|
235 |
-
|
236 |
-
|
237 |
-
|
238 |
-
|
239 |
-
|
240 |
-
|
241 |
-
|
242 |
-
|
243 |
-
|
244 |
-
|
245 |
-
|
246 |
-
|
247 |
-
|
248 |
-
|
249 |
-
|
250 |
-
|
251 |
-
|
252 |
-
|
253 |
-
|
254 |
-
|
255 |
-
|
256 |
-
|
257 |
-
|
258 |
-
|
259 |
-
|
260 |
-
|
261 |
-
|
262 |
-
|
263 |
-
|
264 |
-
|
265 |
-
|
266 |
-
|
267 |
-
|
268 |
-
|
|
|
269 |
|
270 |
-
|
271 |
-
|
272 |
|
273 |
-
|
274 |
-
|
275 |
-
|
276 |
-
|
277 |
-
|
278 |
-
|
279 |
-
|
280 |
-
|
281 |
-
|
282 |
-
|
283 |
-
|
284 |
-
|
285 |
-
|
286 |
-
|
287 |
-
|
|
|
288 |
|
289 |
-
|
290 |
-
|
291 |
-
|
292 |
-
|
293 |
-
|
294 |
-
|
295 |
-
|
296 |
-
|
297 |
-
|
298 |
-
|
299 |
-
|
300 |
-
|
301 |
-
|
|
|
302 |
|
303 |
-
|
304 |
-
|
305 |
|
306 |
-
|
307 |
-
|
308 |
-
|
309 |
-
|
310 |
-
|
311 |
-
|
312 |
-
|
313 |
-
|
314 |
-
|
315 |
-
|
|
|
316 |
|
317 |
-
|
318 |
-
|
319 |
|
320 |
-
|
321 |
-
|
322 |
-
|
323 |
-
|
324 |
-
|
325 |
-
|
326 |
-
|
327 |
-
|
328 |
-
|
329 |
-
|
330 |
-
|
331 |
-
|
332 |
-
|
|
|
333 |
|
334 |
-
|
335 |
-
|
336 |
|
337 |
-
|
338 |
-
|
339 |
-
|
340 |
-
|
341 |
-
|
342 |
-
|
343 |
-
|
344 |
-
|
345 |
-
|
346 |
-
|
347 |
-
|
348 |
-
|
349 |
-
|
350 |
-
|
351 |
-
|
352 |
-
|
353 |
-
|
354 |
-
|
355 |
-
|
356 |
-
|
357 |
-
|
358 |
-
|
359 |
-
|
360 |
-
|
361 |
-
|
362 |
-
|
363 |
-
|
364 |
-
|
365 |
-
|
366 |
-
|
367 |
-
|
368 |
-
|
369 |
-
|
|
|
|
|
370 |
|
371 |
-
|
372 |
-
|
373 |
}
|
374 |
|
375 |
/*
|
@@ -383,13 +409,14 @@ class bn_parsidate {
|
|
383 |
* @param string $datetime
|
384 |
* @param string $lang
|
385 |
*
|
386 |
-
* @return
|
387 |
*/
|
388 |
-
function parsidate(
|
389 |
-
|
390 |
-
|
|
|
391 |
|
392 |
-
|
393 |
}
|
394 |
|
395 |
/**
|
@@ -399,11 +426,12 @@ function parsidate( $input, $datetime = 'now', $lang = 'per' ) {
|
|
399 |
* @param mixed $input
|
400 |
* @param mixed $datetime
|
401 |
*
|
402 |
-
* @return
|
403 |
*/
|
404 |
-
function gregdate(
|
405 |
-
|
406 |
-
|
|
|
407 |
|
408 |
-
|
409 |
}
|
6 |
* @package WP-Parsidate
|
7 |
* @subpackage DateConversation
|
8 |
*/
|
9 |
+
|
10 |
/*Special thanks to :
|
11 |
Reza Gholampanahi for convert function*/
|
12 |
|
13 |
+
class bn_parsidate
|
14 |
+
{
|
15 |
+
protected static $instance;
|
16 |
+
public $persian_month_names = array(
|
17 |
+
'',
|
18 |
+
'فروردین',
|
19 |
+
'اردیبهشت',
|
20 |
+
'خرداد',
|
21 |
+
'تیر',
|
22 |
+
'مرداد',
|
23 |
+
'شهریور',
|
24 |
+
'مهر',
|
25 |
+
'آبان',
|
26 |
+
'آذر',
|
27 |
+
'دی',
|
28 |
+
'بهمن',
|
29 |
+
'اسفند'
|
30 |
+
);
|
31 |
+
public $persian_short_month_names = array(
|
32 |
+
'',
|
33 |
+
'فرو',
|
34 |
+
'ارد',
|
35 |
+
'خرد',
|
36 |
+
'تیر',
|
37 |
+
'مرد',
|
38 |
+
'شهر',
|
39 |
+
'مهر',
|
40 |
+
'آبا',
|
41 |
+
'آذر',
|
42 |
+
'دی',
|
43 |
+
'بهم',
|
44 |
+
'اسف'
|
45 |
+
);
|
46 |
+
public $sesson = array('بهار', 'تابستان', 'پاییز', 'زمستان');
|
47 |
+
|
48 |
+
public $persian_day_names = array('یکشنبه', 'دوشنبه', 'سه شنبه', 'چهارشنبه', 'پنجشنبه', 'جمعه', 'شنبه');
|
49 |
+
public $persian_day_small = array('ی', 'د', 'س', 'چ', 'پ', 'ج', 'ش');
|
50 |
+
|
51 |
+
public $j_days_in_month = array(31, 31, 31, 31, 31, 31, 30, 30, 30, 30, 30, 29);
|
52 |
+
private $j_days_sum_month = array(0, 0, 31, 62, 93, 124, 155, 186, 216, 246, 276, 306, 336);
|
53 |
+
|
54 |
+
private $g_days_sum_month = array(0, 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334);
|
55 |
+
|
56 |
|
57 |
+
/**
|
58 |
+
* Constructor
|
59 |
+
*/
|
60 |
+
function __construct()
|
61 |
+
{
|
62 |
+
if ($this->IsLeapYear($this->persian_date("Y", time(), "eng"))) {
|
63 |
+
$this->j_days_in_month[11] = 30;
|
64 |
+
}
|
65 |
+
}
|
66 |
|
67 |
+
/**
|
68 |
+
* bn_parsidate::IsLeapYear()
|
69 |
+
* check year is leap
|
70 |
+
* Update in 2.3.4V
|
71 |
+
*
|
72 |
+
* @param mixed $year
|
73 |
+
*
|
74 |
+
* @return boolean
|
75 |
+
*/
|
76 |
+
public static function IsLeapYear($year)
|
77 |
+
{
|
78 |
+
// Update algorithm from https://goo.gl/wZCU76
|
79 |
+
$a = 0.025;
|
80 |
+
$b = 266;
|
81 |
+
if ($year > 0) {
|
82 |
+
$leapDays0 = (($year + 38) % 2820) * 0.24219 + $a; # 0.24219 ~ extra days of one year
|
83 |
+
$leapDays1 = (($year + 39) % 2820) * 0.24219 + $a; # 38 days is the difference of epoch to 2820-year cycle
|
84 |
+
} elseif ($year < 0) {
|
85 |
+
$leapDays0 = (($year + 39) % 2820) * 0.24219 + $a;
|
86 |
+
$leapDays1 = (($year + 40) % 2820) * 0.24219 + $a;
|
87 |
+
} else
|
88 |
+
return false;
|
89 |
|
90 |
+
$frac0 = intval(($leapDays0 - intval($leapDays0)) * 1000);
|
91 |
+
$frac1 = intval(($leapDays1 - intval($leapDays1)) * 1000);
|
92 |
|
93 |
+
return ($frac0 <= $b and $frac1 > $b);
|
94 |
+
}
|
95 |
|
96 |
+
/**
|
97 |
+
* bn_parsidate::persian_date()
|
98 |
+
* convert gregorian datetime to persian datetime
|
99 |
+
*
|
100 |
+
* @param mixed $format
|
101 |
+
* @param string $date
|
102 |
+
* @param string $lang
|
103 |
+
*
|
104 |
+
* @return datetime
|
105 |
+
*/
|
106 |
+
public function persian_date($format, $date = 'now', $lang = 'per')
|
107 |
+
{
|
108 |
+
$j_days_in_month = array(31, 62, 93, 124, 155, 186, 216, 246, 276, 306, 336, 365);
|
109 |
+
$timestamp = is_numeric($date) && (int)$date == $date ? $date : strtotime($date);
|
110 |
|
111 |
+
$date = getdate($timestamp);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
112 |
|
113 |
+
list($date['year'], $date['mon'], $date['mday']) = self::gregorian_to_persian($date['year'], $date['mon'], $date['mday']);
|
114 |
+
$date['mon'] = (int)$date['mon'];
|
115 |
+
$date['mday'] = (int)$date['mday'];
|
116 |
+
$out = '';
|
117 |
+
$this->j_days_in_month[11] = $this->IsLeapYear($date['year']) ? 30 : 29;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
118 |
|
119 |
+
for ($i = 0; $i < strlen($format); $i++) {
|
120 |
+
Switch ($format[$i]) {
|
121 |
+
//day
|
122 |
+
case 'd':
|
123 |
+
$out .= ($date['mday'] < 10) ? '0' . $date['mday'] : $date['mday'];
|
124 |
+
break;
|
125 |
+
case 'D':
|
126 |
+
$out .= $this->persian_day_small[$date['wday']];
|
127 |
+
break;
|
128 |
+
case 'l':
|
129 |
+
$out .= $this->persian_day_names[$date['wday']];
|
130 |
+
break;
|
131 |
+
case 'j':
|
132 |
+
$out .= $date['mday'];
|
133 |
+
break;
|
134 |
+
case 'N':
|
135 |
+
$out .= $this->week_day($date['wday']) + 1;
|
136 |
+
break;
|
137 |
+
case 'w':
|
138 |
+
$out .= $this->week_day($date['wday']);
|
139 |
+
break;
|
140 |
+
case 'z':
|
141 |
+
$out .= $this->j_days_in_month[$date['mon']] + $date['mday'];
|
142 |
+
break;
|
143 |
+
//week
|
144 |
+
case 'W':
|
145 |
+
$yday = $this->j_days_sum_month[$date['mon'] - 1] + $date['mday'];
|
146 |
+
$out .= intval($yday / 7);
|
147 |
+
break;
|
148 |
+
//month
|
149 |
+
case 'f':
|
150 |
+
$mon = $date['mon'];
|
151 |
+
switch ($mon) {
|
152 |
+
case($mon < 4):
|
153 |
+
$out .= $this->sesson[0];
|
154 |
+
break;
|
155 |
+
case($mon < 7):
|
156 |
+
$out .= $this->sesson[1];
|
157 |
+
break;
|
158 |
+
case($mon < 10):
|
159 |
+
$out .= $this->sesson[2];
|
160 |
+
break;
|
161 |
+
case($mon > 9):
|
162 |
+
$out .= $this->sesson[3];
|
163 |
+
break;
|
164 |
+
}
|
165 |
+
break;
|
166 |
+
case'F':
|
167 |
+
$out .= $this->persian_month_names[(int)$date['mon']];
|
168 |
+
break;
|
169 |
+
case'm':
|
170 |
+
$out .= ($date['mon'] < 10) ? '0' . $date['mon'] : $date['mon'];
|
171 |
+
break;
|
172 |
+
case'M':
|
173 |
+
$out .= $this->persian_short_month_names[(int)$date['mon']];
|
174 |
+
break;
|
175 |
+
case'n':
|
176 |
+
$out .= $date['mon'];
|
177 |
+
break;
|
178 |
+
case'S':
|
179 |
+
$out .= 'ام';
|
180 |
+
break;
|
181 |
+
case't':
|
182 |
+
$out .= $this->j_days_in_month[(int)$date['mon'] - 1];
|
183 |
+
break;
|
184 |
+
//year
|
185 |
+
case'L':
|
186 |
+
$out .= (($date['year'] % 4) == 0) ? 1 : 0;
|
187 |
+
break;
|
188 |
+
case'o':
|
189 |
+
case'Y':
|
190 |
+
$out .= $date['year'];
|
191 |
+
break;
|
192 |
+
case'y':
|
193 |
+
$out .= substr($date['year'], 2, 2);
|
194 |
+
break;
|
195 |
+
//time
|
196 |
+
case'a':
|
197 |
+
$out .= ($date['hours'] < 12) ? 'ق.ظ' : 'ب.ظ';
|
198 |
+
break;
|
199 |
+
case'A':
|
200 |
+
$out .= ($date['hours'] < 12) ? 'قبل از ظهر' : 'بعد از ظهر';
|
201 |
+
break;
|
202 |
+
case'B':
|
203 |
+
$out .= (int)(1 + ($date['mon'] / 3));
|
204 |
+
break;
|
205 |
+
case'g':
|
206 |
+
$out .= ($date['hours'] > 12) ? $date['hours'] - 12 : $date['hours'];
|
207 |
+
break;
|
208 |
+
case'G':
|
209 |
+
$out .= $date['hours'];
|
210 |
+
break;
|
211 |
+
case'h':
|
212 |
+
$hour = ($date['hours'] > 12) ? $date['hours'] - 12 : $date['hours'];
|
213 |
+
$out .= ($hour < 10) ? '0' . $hour : $hour;
|
214 |
+
break;
|
215 |
+
case'H':
|
216 |
+
$out .= ($date['hours'] < 10) ? '0' . $date['hours'] : $date['hours'];
|
217 |
+
break;
|
218 |
+
case'i':
|
219 |
+
$out .= ($date['minutes'] < 10) ? '0' . $date['minutes'] : $date['minutes'];
|
220 |
+
break;
|
221 |
+
case's':
|
222 |
+
$out .= ($date['seconds'] < 10) ? '0' . $date['seconds'] : $date['seconds'];
|
223 |
+
break;
|
224 |
+
//full date time
|
225 |
+
case'c':
|
226 |
+
$out = $date['year'] . '/' . $date['mon'] . '/' . $date['mday'] . ' ' . $date['hours'] . ':' . (($date['minutes'] < 10) ? '0' . $date['minutes'] : $date['minutes']) . ':' . (($date['seconds'] < 10) ? '0' . $date['seconds'] : $date['seconds']);//2004-02-12T15:19:21+00:00
|
227 |
+
break;
|
228 |
+
case'r':
|
229 |
+
$out = $this->persian_day_names[$date['wday']] . ',' . $date['mday'] . ' ' . $this->persian_month_names[(int)$date['mon']] . ' ' . $date['year'] . ' ' . $date['hours'] . ':' . (($date['minutes'] < 10) ? '0' . $date['minutes'] : $date['minutes']) . ':' . (($date['seconds'] < 10) ? '0' . $date['seconds'] : $date['seconds']);//Thu, 21 Dec 2000 16:01:07
|
230 |
+
break;
|
231 |
+
case'U':
|
232 |
+
$out = $timestamp;
|
233 |
+
break;
|
234 |
+
//others
|
235 |
+
case'e':
|
236 |
+
case'I':
|
237 |
+
case'O':
|
238 |
+
case'P':
|
239 |
+
case'T':
|
240 |
+
case'Z':
|
241 |
+
case'u':
|
242 |
+
break;
|
243 |
+
default:
|
244 |
+
$out .= $format[$i];
|
245 |
+
}
|
246 |
+
}
|
247 |
+
if ($lang == 'per') {
|
248 |
+
return self::trim_number($out);
|
249 |
+
} else {
|
250 |
+
return $out;
|
251 |
+
}
|
252 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
253 |
|
254 |
+
/**
|
255 |
+
* bn_parsidate::gregorian_to_persian()
|
256 |
+
* convert gregorian date to persian date
|
257 |
+
*
|
258 |
+
* @param mixed $gy
|
259 |
+
* @param mixed $gm
|
260 |
+
* @param mixed $gd
|
261 |
+
*
|
262 |
+
* @return array
|
263 |
+
*/
|
264 |
+
function gregorian_to_persian($gy, $gm, $gd)
|
265 |
+
{
|
266 |
+
$dayofyear = $this->g_days_sum_month[(int)$gm] + $gd;
|
267 |
+
if (self::IsLeapYear($gy) and $gm > 2) {
|
268 |
+
$dayofyear++;
|
269 |
+
}
|
270 |
+
$d_33 = (int)((($gy - 16) % 132) * 0.0305);
|
271 |
+
$leap = $gy % 4;
|
272 |
+
$a = (($d_33 == 1 or $d_33 == 2) and ($d_33 == $leap or $leap == 1)) ? 78 : (($d_33 == 3 and $leap == 0) ? 80 : 79);
|
273 |
+
$b = ($d_33 == 3 or $d_33 < ($leap - 1) or $leap == 0) ? 286 : 287;
|
274 |
+
if ((int)(($gy - 10) / 63) == 30) {
|
275 |
+
$b--;
|
276 |
+
$a++;
|
277 |
+
}
|
278 |
+
if ($dayofyear > $a) {
|
279 |
+
$jy = $gy - 621;
|
280 |
+
$jd = $dayofyear - $a;
|
281 |
+
} else {
|
282 |
+
$jy = $gy - 622;
|
283 |
+
$jd = $dayofyear + $b;
|
284 |
+
}
|
285 |
+
for ($i = 0; $i < 11 and $jd > $this->j_days_in_month[$i]; $i++) {
|
286 |
+
$jd -= $this->j_days_in_month[$i];
|
287 |
+
}
|
288 |
+
$jm = ++$i;
|
289 |
|
290 |
+
return array($jy, strlen($jm) == 1 ? '0' . $jm : $jm, strlen($jd) == 1 ? '0' . $jd : $jd);
|
291 |
+
}
|
292 |
|
293 |
+
/**
|
294 |
+
* Get day of the week shamsi/jalali
|
295 |
+
* @author Parsa Kafi
|
296 |
+
*
|
297 |
+
* @param int $wday
|
298 |
+
*
|
299 |
+
* @return int
|
300 |
+
*/
|
301 |
+
private function week_day($wday)
|
302 |
+
{
|
303 |
+
if ($wday == 6) {
|
304 |
+
return 0;
|
305 |
+
} else {
|
306 |
+
return ++$wday;
|
307 |
+
}
|
308 |
+
}
|
309 |
|
310 |
+
/**
|
311 |
+
* bn_parsidate::trim_number()
|
312 |
+
* convert english number to persian number
|
313 |
+
*
|
314 |
+
* @param mixed $num
|
315 |
+
* @param string $sp
|
316 |
+
*
|
317 |
+
* @return string
|
318 |
+
*/
|
319 |
+
public function trim_number($num, $sp = '٫')
|
320 |
+
{
|
321 |
+
$eng = array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '.');
|
322 |
+
$per = array('۰', '۱', '۲', '۳', '۴', '۵', '۶', '۷', '۸', '۹', $sp);
|
323 |
+
$number = filter_var($num, FILTER_SANITIZE_NUMBER_INT);
|
324 |
|
325 |
+
return empty($number) ? str_replace($per, $eng, $num) : str_replace($eng, $per, $num);
|
326 |
+
}
|
327 |
|
328 |
+
/**
|
329 |
+
* bn_parsidate::getInstance()
|
330 |
+
* create instance of bn_parsidate class
|
331 |
+
*
|
332 |
+
* @return instance
|
333 |
+
*/
|
334 |
+
public static function getInstance()
|
335 |
+
{
|
336 |
+
if (!isset(self::$instance)) {
|
337 |
+
self::$instance = new self();
|
338 |
+
}
|
339 |
|
340 |
+
return self::$instance;
|
341 |
+
}
|
342 |
|
343 |
+
/**
|
344 |
+
* bn_parsidate::gregurian_date()
|
345 |
+
* convert persian datetime to gregorian datetime
|
346 |
+
*
|
347 |
+
* @param mixed $format
|
348 |
+
* @param mixed $persiandate
|
349 |
+
*
|
350 |
+
* @return mixed
|
351 |
+
*/
|
352 |
+
public function gregurian_date($format, $persiandate)
|
353 |
+
{
|
354 |
+
preg_match_all('!\d+!', $persiandate, $matches);
|
355 |
+
$matches = $matches[0];
|
356 |
+
list($year, $mon, $day) = self::persian_to_gregorian($matches[0], $matches[1], $matches[2]);
|
357 |
|
358 |
+
return date($format, mktime((isset($matches[3]) ? $matches[3] : 0), (isset($matches[4]) ? $matches[4] : 0), (isset($matches[5]) ? $matches[5] : 0), $mon, $day, $year));
|
359 |
+
}
|
360 |
|
361 |
+
/**
|
362 |
+
* bn_parsidate::persian_to_gregorian()
|
363 |
+
* convert persian date to gregorian date
|
364 |
+
*
|
365 |
+
* @param mixed $jy
|
366 |
+
* @param mixed $jm
|
367 |
+
* @param mixed $jd
|
368 |
+
*
|
369 |
+
* @return array
|
370 |
+
*/
|
371 |
+
public function persian_to_gregorian($jy, $jm, $jd)
|
372 |
+
{
|
373 |
+
$this->j_days_in_month[11] = $this->IsLeapYear($jy) ? 30 : 29;
|
374 |
+
$doyj = ($jm - 2 > -1 ? $this->j_days_sum_month[(int)$jm] + $jd : $jd);
|
375 |
+
$d4 = ($jy + 1) % 4;
|
376 |
+
$d33 = (int)((($jy - 55) % 132) * .0305);
|
377 |
+
$a = ($d33 != 3 and $d4 <= $d33) ? 287 : 286;
|
378 |
+
$b = (($d33 == 1 or $d33 == 2) and ($d33 == $d4 or $d4 == 1)) ? 78 : (($d33 == 3 and $d4 == 0) ? 80 : 79);
|
379 |
+
if ((int)(($jy - 19) / 63) == 20) {
|
380 |
+
$a--;
|
381 |
+
$b++;
|
382 |
+
}
|
383 |
+
if ($doyj <= $a) {
|
384 |
+
$gy = $jy + 621;
|
385 |
+
$gd = $doyj + $b;
|
386 |
+
} else {
|
387 |
+
$gy = $jy + 622;
|
388 |
+
$gd = $doyj - $a;
|
389 |
+
}
|
390 |
+
foreach (array(0, 31, ($gy % 4 == 0) ? 29 : 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31) as $gm => $days) {
|
391 |
+
if ($gd <= $days) {
|
392 |
+
break;
|
393 |
+
}
|
394 |
+
$gd -= $days;
|
395 |
+
}
|
396 |
|
397 |
+
return array($gy, $gm, $gd);
|
398 |
+
}
|
399 |
}
|
400 |
|
401 |
/*
|
409 |
* @param string $datetime
|
410 |
* @param string $lang
|
411 |
*
|
412 |
+
* @return string
|
413 |
*/
|
414 |
+
function parsidate($input, $datetime = 'now', $lang = 'per')
|
415 |
+
{
|
416 |
+
$bndate = bn_parsidate::getInstance();
|
417 |
+
$bndate = $bndate->persian_date($input, $datetime, $lang);
|
418 |
|
419 |
+
return $bndate;
|
420 |
}
|
421 |
|
422 |
/**
|
426 |
* @param mixed $input
|
427 |
* @param mixed $datetime
|
428 |
*
|
429 |
+
* @return string
|
430 |
*/
|
431 |
+
function gregdate($input, $datetime)
|
432 |
+
{
|
433 |
+
$bndate = bn_parsidate::getInstance();
|
434 |
+
$bndate = $bndate->gregurian_date($input, $datetime);
|
435 |
|
436 |
+
return $bndate;
|
437 |
}
|
readme.txt
CHANGED
@@ -4,7 +4,7 @@ Donate link: http://forum.wp-parsi.com/
|
|
4 |
Tags: shamsi, wp-parsi, wpparsi, persian, parsi, farsi, jalali, date, calendar, i18n, l10n, Iran, Iranian, parsidate, rtl
|
5 |
Requires at least: 3.6
|
6 |
Tested up to: 4.8
|
7 |
-
Stable tag: 2.3.
|
8 |
|
9 |
Persian date support for WordPress
|
10 |
|
@@ -41,6 +41,9 @@ List of some features:
|
|
41 |
4. 'Jalali Date Calender' in action
|
42 |
|
43 |
== Changelog ==
|
|
|
|
|
|
|
44 |
= 2.3.3 =
|
45 |
* Fix WooCommerce Sale Price Dates (From/To)
|
46 |
|
4 |
Tags: shamsi, wp-parsi, wpparsi, persian, parsi, farsi, jalali, date, calendar, i18n, l10n, Iran, Iranian, parsidate, rtl
|
5 |
Requires at least: 3.6
|
6 |
Tested up to: 4.8
|
7 |
+
Stable tag: 2.3.4
|
8 |
|
9 |
Persian date support for WordPress
|
10 |
|
41 |
4. 'Jalali Date Calender' in action
|
42 |
|
43 |
== Changelog ==
|
44 |
+
= 2.3.4 =
|
45 |
+
* Fix diagnosis leap year function ( bn_parsidate::IsLeapYear() )
|
46 |
+
|
47 |
= 2.3.3 =
|
48 |
* Fix WooCommerce Sale Price Dates (From/To)
|
49 |
|
wp-parsidate.php
CHANGED
@@ -1,7 +1,7 @@
|
|
1 |
<?php
|
2 |
/**
|
3 |
* Plugin Name: WP-Parsidate
|
4 |
-
* Version: 2.3.
|
5 |
* Plugin URI: http://forum.wp-parsi.com/
|
6 |
* Description: Persian package for WordPress, Adds full RTL and Shamsi (Jalali) support for: posts, comments, pages, archives, search, categories, permalinks and all admin sections and TinyMce editor, lists, quick editor. This package has Jalali archive widget.
|
7 |
* Author: WP-Parsi Team
|
1 |
<?php
|
2 |
/**
|
3 |
* Plugin Name: WP-Parsidate
|
4 |
+
* Version: 2.3.4
|
5 |
* Plugin URI: http://forum.wp-parsi.com/
|
6 |
* Description: Persian package for WordPress, Adds full RTL and Shamsi (Jalali) support for: posts, comments, pages, archives, search, categories, permalinks and all admin sections and TinyMce editor, lists, quick editor. This package has Jalali archive widget.
|
7 |
* Author: WP-Parsi Team
|