Completed
Push — master ( 22ef66...1cf508 )
by Afshin
02:12
created

JalaliDateHelper::jmktime()   C

Complexity

Conditions 8
Paths 14

Size

Total Lines 26
Code Lines 25

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 8
eloc 25
nc 14
nop 8
dl 0
loc 26
rs 5.3846
c 0
b 0
f 0

How to fix   Many Parameters   

Many Parameters

Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.

There are several approaches to avoid long parameter lists:

1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: afshin
5
 * Date: 11/16/17
6
 * Time: 11:19 AM
7
 */
8
9
namespace Core\Helpers;
10
11
class JalaliDate {
12
13
    public function jdate($format,$timestamp='',$none='',$time_zone='Asia/Tehran',$tr_num='fa'){
0 ignored issues
show
Unused Code introduced by
The parameter $none is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

13
    public function jdate($format,$timestamp='',/** @scrutinizer ignore-unused */ $none='',$time_zone='Asia/Tehran',$tr_num='fa'){

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
14
15
        $T_sec=0;/* <= رفع خطاي زمان سرور ، با اعداد '+' و '-' بر حسب ثانيه */
16
17
        if($time_zone!='local')date_default_timezone_set(($time_zone==='')?'Asia/Tehran':$time_zone);
18
        $ts=$T_sec+(($timestamp==='')?time():$this->tr_num($timestamp));
19
        $date=explode('_',date('H_i_j_n_O_P_s_w_Y',$ts));
20
        list($j_y,$j_m,$j_d)=$this->gregorian_to_jalali($date[8],$date[3],$date[2]);
21
        $doy=($j_m<7)?(($j_m-1)*31)+$j_d-1:(($j_m-7)*30)+$j_d+185;
22
        $kab=(((($j_y%33)%4)-1)==((int)(($j_y%33)*0.05)))?1:0;
23
        $sl=strlen($format);
24
        $out='';
25
        for($i=0; $i<$sl; $i++){
26
            $sub=substr($format,$i,1);
27
            if($sub=='\\'){
28
                $out.=substr($format,++$i,1);
29
                continue;
30
            }
31
            switch($sub){
32
33
                case'E':case'R':case'x':case'X':
34
                $out.='http://jdf.scr.ir';
35
                break;
36
37
                case'B':case'e':case'g':
38
                case'G':case'h':case'I':
39
                case'T':case'u':case'Z':
40
                $out.=date($sub,$ts);
41
                break;
42
43
                case'a':
44
                    $out.=($date[0]<12)?'ق.ظ':'ب.ظ';
45
                    break;
46
47
                case'A':
48
                    $out.=($date[0]<12)?'قبل از ظهر':'بعد از ظهر';
49
                    break;
50
51
                case'b':
52
                    $out.=(int)($j_m/3.1)+1;
53
                    break;
54
55
                case'c':
56
                    $out.=$j_y.'/'.$j_m.'/'.$j_d.' ،'.$date[0].':'.$date[1].':'.$date[6].' '.$date[5];
57
                    break;
58
59
                case'C':
60
                    $out.=(int)(($j_y+99)/100);
61
                    break;
62
63
                case'd':
64
                    $out.=($j_d<10)?'0'.$j_d:$j_d;
65
                    break;
66
67
                case'D':
68
                    $out.=$this->jdate_words(array('kh'=>$date[7]),' ');
69
                    break;
70
71
                case'f':
72
                    $out.=$this->jdate_words(array('ff'=>$j_m),' ');
73
                    break;
74
75
                case'F':
76
                    $out.=$this->jdate_words(array('mm'=>$j_m),' ');
77
                    break;
78
79
                case'H':
80
                    $out.=$date[0];
81
                    break;
82
83
                case'i':
84
                    $out.=$date[1];
85
                    break;
86
87
                case'j':
88
                    $out.=$j_d;
89
                    break;
90
91
                case'J':
92
                    $out.=$this->jdate_words(array('rr'=>$j_d),' ');
93
                    break;
94
95 View Code Duplication
                case'k';
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
96
                    $out.=$this->tr_num(100-(int)($doy/($kab+365)*1000)/10,$tr_num);
97
                    break;
98
99 View Code Duplication
                case'K':
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
100
                    $out.=$this->tr_num((int)($doy/($kab+365)*1000)/10,$tr_num);
101
                    break;
102
103
                case'l':
104
                    $out.=$this->jdate_words(array('rh'=>$date[7]),' ');
105
                    break;
106
107
                case'L':
108
                    $out.=$kab;
109
                    break;
110
111
                case'm':
112
                    $out.=($j_m>9)?$j_m:'0'.$j_m;
113
                    break;
114
115
                case'M':
116
                    $out.=$this->jdate_words(array('km'=>$j_m),' ');
117
                    break;
118
119
                case'n':
120
                    $out.=$j_m;
121
                    break;
122
123
                case'N':
124
                    $out.=$date[7]+1;
125
                    break;
126
127
                case'o':
128
                    $jdw=($date[7]==6)?0:$date[7]+1;
129
                    $dny=364+$kab-$doy;
130
                    $out.=($jdw>($doy+3) and $doy<3)?$j_y-1:(((3-$dny)>$jdw and $dny<3)?$j_y+1:$j_y);
131
                    break;
132
133
                case'O':
134
                    $out.=$date[4];
135
                    break;
136
137
                case'p':
138
                    $out.=$this->jdate_words(array('mb'=>$j_m),' ');
139
                    break;
140
141
                case'P':
142
                    $out.=$date[5];
143
                    break;
144
145
                case'q':
146
                    $out.=$this->jdate_words(array('sh'=>$j_y),' ');
147
                    break;
148
149
                case'Q':
150
                    $out.=$kab+364-$doy;
151
                    break;
152
153 View Code Duplication
                case'r':
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
154
                    $key=$this->jdate_words(array('rh'=>$date[7],'mm'=>$j_m));
155
                    $out.=$date[0].':'.$date[1].':'.$date[6].' '.$date[4].' '.$key['rh'].'، '.$j_d.' '.$key['mm'].' '.$j_y;
156
                    break;
157
158
                case's':
159
                    $out.=$date[6];
160
                    break;
161
162
                case'S':
163
                    $out.='ام';
164
                    break;
165
166
                case't':
167
                    $out.=($j_m!=12)?(31-(int)($j_m/6.5)):($kab+29);
168
                    break;
169
170
                case'U':
171
                    $out.=$ts;
172
                    break;
173
174
                case'v':
175
                    $out.=$this->jdate_words(array('ss'=>($j_y%100)),' ');
176
                    break;
177
178
                case'V':
179
                    $out.=$this->jdate_words(array('ss'=>$j_y),' ');
180
                    break;
181
182 View Code Duplication
                case'w':
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
183
                    $out.=($date[7]==6)?0:$date[7]+1;
184
                    break;
185
186 View Code Duplication
                case'W':
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
187
                    $avs=(($date[7]==6)?0:$date[7]+1)-($doy%7);
188
                    if($avs<0)$avs+=7;
189
                    $num=(int)(($doy+$avs)/7);
190
                    if($avs<4){
191
                        $num++;
192
                    }elseif($num<1){
193
                        $num=($avs==4 or $avs==((((($j_y%33)%4)-2)==((int)(($j_y%33)*0.05)))?5:4))?53:52;
194
                    }
195
                    $aks=$avs+$kab;
196
                    if($aks==7)$aks=0;
197
                    $out.=(($kab+363-$doy)<$aks and $aks<3)?'01':(($num<10)?'0'.$num:$num);
198
                    break;
199
200
                case'y':
201
                    $out.=substr($j_y,2,2);
202
                    break;
203
204
                case'Y':
205
                    $out.=$j_y;
206
                    break;
207
208
                case'z':
209
                    $out.=$doy;
210
                    break;
211
212
                default:$out.=$sub;
213
            }
214
        }
215
        return($tr_num!='en')?$this->tr_num($out,'fa','.'):$out;
216
    }
217
218
    /*	F	*/
219
    public function jstrftime($format,$timestamp='',$none='',$time_zone='Asia/Tehran',$tr_num='fa'){
0 ignored issues
show
Unused Code introduced by
The parameter $none is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

219
    public function jstrftime($format,$timestamp='',/** @scrutinizer ignore-unused */ $none='',$time_zone='Asia/Tehran',$tr_num='fa'){

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
220
221
        $T_sec=0;/* <= رفع خطاي زمان سرور ، با اعداد '+' و '-' بر حسب ثانيه */
222
223
        if($time_zone!='local')date_default_timezone_set(($time_zone==='')?'Asia/Tehran':$time_zone);
224
        $ts=$T_sec+(($timestamp==='')?time():$this->tr_num($timestamp));
225
        $date=explode('_',date('h_H_i_j_n_s_w_Y',$ts));
226
        list($j_y,$j_m,$j_d)=$this->gregorian_to_jalali($date[7],$date[4],$date[3]);
227
        $doy=($j_m<7)?(($j_m-1)*31)+$j_d-1:(($j_m-7)*30)+$j_d+185;
228
        $kab=(((($j_y%33)%4)-1)==((int)(($j_y%33)*0.05)))?1:0;
229
        $sl=strlen($format);
230
        $out='';
231
        for($i=0; $i<$sl; $i++){
232
            $sub=substr($format,$i,1);
233
            if($sub=='%'){
234
                $sub=substr($format,++$i,1);
235
            }else{
236
                $out.=$sub;
237
                continue;
238
            }
239
            switch($sub){
240
241
                /* Day */
242
                case'a':
243
                    $out.=$this->jdate_words(array('kh'=>$date[6]),' ');
244
                    break;
245
246
                case'A':
247
                    $out.=$this->jdate_words(array('rh'=>$date[6]),' ');
248
                    break;
249
250
                case'd':
251
                    $out.=($j_d<10)?'0'.$j_d:$j_d;
252
                    break;
253
254
                case'e':
255
                    $out.=($j_d<10)?' '.$j_d:$j_d;
256
                    break;
257
258
                case'j':
259
                    $out.=str_pad($doy+1,3,0,STR_PAD_LEFT);
260
                    break;
261
262
                case'u':
263
                    $out.=$date[6]+1;
264
                    break;
265
266 View Code Duplication
                case'w':
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
267
                    $out.=($date[6]==6)?0:$date[6]+1;
268
                    break;
269
270
                /* Week */
271
                case'U':
272
                    $avs=(($date[6]<5)?$date[6]+2:$date[6]-5)-($doy%7);
273
                    if($avs<0)$avs+=7;
274
                    $num=(int)(($doy+$avs)/7)+1;
275
                    if($avs>3 or $avs==1)$num--;
276
                    $out.=($num<10)?'0'.$num:$num;
277
                    break;
278
279 View Code Duplication
                case'V':
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
280
                    $avs=(($date[6]==6)?0:$date[6]+1)-($doy%7);
281
                    if($avs<0)$avs+=7;
282
                    $num=(int)(($doy+$avs)/7);
283
                    if($avs<4){
284
                        $num++;
285
                    }elseif($num<1){
286
                        $num=($avs==4 or $avs==((((($j_y%33)%4)-2)==((int)(($j_y%33)*0.05)))?5:4))?53:52;
287
                    }
288
                    $aks=$avs+$kab;
289
                    if($aks==7)$aks=0;
290
                    $out.=(($kab+363-$doy)<$aks and $aks<3)?'01':(($num<10)?'0'.$num:$num);
291
                    break;
292
293
                case'W':
294
                    $avs=(($date[6]==6)?0:$date[6]+1)-($doy%7);
295
                    if($avs<0)$avs+=7;
296
                    $num=(int)(($doy+$avs)/7)+1;
297
                    if($avs>3)$num--;
298
                    $out.=($num<10)?'0'.$num:$num;
299
                    break;
300
301
                /* Month */
302
                case'b':
303
                case'h':
304
                    $out.=$this->jdate_words(array('km'=>$j_m),' ');
305
                    break;
306
307
                case'B':
308
                    $out.=$this->jdate_words(array('mm'=>$j_m),' ');
309
                    break;
310
311
                case'm':
312
                    $out.=($j_m>9)?$j_m:'0'.$j_m;
313
                    break;
314
315
                /* Year */
316
                case'C':
317
                    $tmp=(int)($j_y/100);
318
                    $out.=($tmp>9)?$tmp:'0'.$tmp;
319
                    break;
320
321 View Code Duplication
                case'g':
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
322
                    $jdw=($date[6]==6)?0:$date[6]+1;
323
                    $dny=364+$kab-$doy;
324
                    $out.=substr(($jdw>($doy+3) and $doy<3)?$j_y-1:(((3-$dny)>$jdw and $dny<3)?$j_y+1:$j_y),2,2);
325
                    break;
326
327 View Code Duplication
                case'G':
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
328
                    $jdw=($date[6]==6)?0:$date[6]+1;
329
                    $dny=364+$kab-$doy;
330
                    $out.=($jdw>($doy+3) and $doy<3)?$j_y-1:(((3-$dny)>$jdw and $dny<3)?$j_y+1:$j_y);
331
                    break;
332
333
                case'y':
334
                    $out.=substr($j_y,2,2);
335
                    break;
336
337
                case'Y':
338
                    $out.=$j_y;
339
                    break;
340
341
                /* Time */
342
                case'H':
343
                    $out.=$date[1];
344
                    break;
345
346
                case'I':
347
                    $out.=$date[0];
348
                    break;
349
350
                case'l':
351
                    $out.=($date[0]>9)?$date[0]:' '.(int)$date[0];
352
                    break;
353
354
                case'M':
355
                    $out.=$date[2];
356
                    break;
357
358
                case'p':
359
                    $out.=($date[1]<12)?'قبل از ظهر':'بعد از ظهر';
360
                    break;
361
362
                case'P':
363
                    $out.=($date[1]<12)?'ق.ظ':'ب.ظ';
364
                    break;
365
366
                case'r':
367
                    $out.=$date[0].':'.$date[2].':'.$date[5].' '.(($date[1]<12)?'قبل از ظهر':'بعد از ظهر');
368
                    break;
369
370
                case'R':
371
                    $out.=$date[1].':'.$date[2];
372
                    break;
373
374
                case'S':
375
                    $out.=$date[5];
376
                    break;
377
378
                case'T':
379
                    $out.=$date[1].':'.$date[2].':'.$date[5];
380
                    break;
381
382
                case'X':
383
                    $out.=$date[0].':'.$date[2].':'.$date[5];
384
                    break;
385
386
                case'z':
387
                    $out.=date('O',$ts);
388
                    break;
389
390
                case'Z':
391
                    $out.=date('T',$ts);
392
                    break;
393
394
                /* Time and Date Stamps */
395 View Code Duplication
                case'c':
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
396
                    $key=$this->jdate_words(array('rh'=>$date[6],'mm'=>$j_m));
397
                    $out.=$date[1].':'.$date[2].':'.$date[5].' '.date('P',$ts).' '.$key['rh'].'، '.$j_d.' '.$key['mm'].' '.$j_y;
398
                    break;
399
400 View Code Duplication
                case'D':
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
401
                    $out.=substr($j_y,2,2).'/'.(($j_m>9)?$j_m:'0'.$j_m).'/'.(($j_d<10)?'0'.$j_d:$j_d);
402
                    break;
403
404
                case'F':
405
                    $out.=$j_y.'-'.(($j_m>9)?$j_m:'0'.$j_m).'-'.(($j_d<10)?'0'.$j_d:$j_d);
406
                    break;
407
408
                case's':
409
                    $out.=$ts;
410
                    break;
411
412 View Code Duplication
                case'x':
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
413
                    $out.=substr($j_y,2,2).'/'.(($j_m>9)?$j_m:'0'.$j_m).'/'.(($j_d<10)?'0'.$j_d:$j_d);
414
                    break;
415
416
                /* Miscellaneous */
417
                case'n':
418
                    $out.="\n";
419
                    break;
420
421
                case't':
422
                    $out.="\t";
423
                    break;
424
425
                case'%':
426
                    $out.='%';
427
                    break;
428
429
                default:$out.=$sub;
430
            }
431
        }
432
        return($tr_num!='en')?$this->tr_num($out,'fa','.'):$out;
433
    }
434
435
    /*	F	*/
436
    public function jmktime($h='',$m='',$s='',$jm='',$jd='',$jy='',$none='',$timezone='Asia/Tehran'){
0 ignored issues
show
Unused Code introduced by
The parameter $none is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

436
    public function jmktime($h='',$m='',$s='',$jm='',$jd='',$jy='',/** @scrutinizer ignore-unused */ $none='',$timezone='Asia/Tehran'){

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
437
        if($timezone!='local')date_default_timezone_set($timezone);
438
        if($h===''){
439
            return time();
440
        }else{
441
            list($h,$m,$s,$jm,$jd,$jy)=explode('_',$this->tr_num($h.'_'.$m.'_'.$s.'_'.$jm.'_'.$jd.'_'.$jy));
442
            if($m===''){
443
                return mktime($h);
444
            }else{
445
                if($s===''){
446
                    return mktime($h,$m);
447
                }else{
448
                    if($jm===''){
449
                        return mktime($h,$m,$s);
450
                    }else{
451
                        $jdate=explode('_',jdate('Y_j','','',$timezone,'en'));
0 ignored issues
show
Bug introduced by
The function jdate was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

451
                        $jdate=explode('_',/** @scrutinizer ignore-call */ jdate('Y_j','','',$timezone,'en'));
Loading history...
452
                        if($jd===''){
453
                            list($gy,$gm,$gd)=$this->jalali_to_gregorian($jdate[0],$jm,$jdate[1]);
454
                            return mktime($h,$m,$s,$gm);
455
                        }else{
456
                            if($jy===''){
457
                                list($gy,$gm,$gd)=$this->jalali_to_gregorian($jdate[0],$jm,$jd);
458
                                return mktime($h,$m,$s,$gm,$gd);
459
                            }else{
460
                                list($gy,$gm,$gd)=$this->jalali_to_gregorian($jy,$jm,$jd);
461
                                return mktime($h,$m,$s,$gm,$gd,$gy);
462
                            }
463
                        }
464
                    }
465
                }
466
            }
467
        }
468
    }
469
470
    /*	F	*/
471
    public function jgetdate($timestamp='',$none='',$timezone='Asia/Tehran',$tn='en'){
0 ignored issues
show
Unused Code introduced by
The parameter $none is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

471
    public function jgetdate($timestamp='',/** @scrutinizer ignore-unused */ $none='',$timezone='Asia/Tehran',$tn='en'){

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
472
        $ts=($timestamp==='')?time():$this->tr_num($timestamp);
473
        $jdate=explode('_',jdate('F_G_i_j_l_n_s_w_Y_z',$ts,'',$timezone,$tn));
0 ignored issues
show
Bug introduced by
The function jdate was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

473
        $jdate=explode('_',/** @scrutinizer ignore-call */ jdate('F_G_i_j_l_n_s_w_Y_z',$ts,'',$timezone,$tn));
Loading history...
474
        return array(
475
            'seconds'=>$this->tr_num((int)$this->tr_num($jdate[6]),$tn),
476
            'minutes'=>$this->tr_num((int)$this->tr_num($jdate[2]),$tn),
477
            'hours'=>$jdate[1],
478
            'mday'=>$jdate[3],
479
            'wday'=>$jdate[7],
480
            'mon'=>$jdate[5],
481
            'year'=>$jdate[8],
482
            'yday'=>$jdate[9],
483
            'weekday'=>$jdate[4],
484
            'month'=>$jdate[0],
485
            0=>$this->tr_num($ts,$tn)
486
        );
487
    }
488
489
    /*	F	*/
490
    public function jcheckdate($jm,$jd,$jy){
491
        list($jm,$jd,$jy)=explode('_',$this->tr_num($jm.'_'.$jd.'_'.$jy));
492
        $l_d=($jm==12)?((((($jy%33)%4)-1)==((int)(($jy%33)*0.05)))?30:29):31-(int)($jm/6.5);
493
        return($jm>12 or $jd>$l_d or $jm<1 or $jd<1 or $jy<1)?false:true;
494
    }
495
496
    /*	F	*/
497
    private function tr_num($str,$mod='en',$mf='٫'){
498
        $num_a=array('0','1','2','3','4','5','6','7','8','9','.');
499
        $key_a=array('۰','۱','۲','۳','۴','۵','۶','۷','۸','۹',$mf);
500
        return($mod=='fa')?str_replace($num_a,$key_a,$str):str_replace($key_a,$num_a,$str);
501
    }
502
503
    /*	F	*/
504
    private function jdate_words($array,$mod=''){
505
        foreach($array as $type=>$num){
506
            $num=(int)$this->tr_num($num);
507
            switch($type){
508
509
                case'ss':
510
                    $sl=strlen($num);
511
                    $xy3=substr($num,2-$sl,1);
512
                    $h3=$h34=$h4='';
513
                    if($xy3==1){
514
                        $p34='';
515
                        $k34=array('ده','یازده','دوازده','سیزده','چهارده','پانزده','شانزده','هفده','هجده','نوزده');
516
                        $h34=$k34[substr($num,2-$sl,2)-10];
517
                    }else{
518
                        $xy4=substr($num,3-$sl,1);
519
                        $p34=($xy3==0 or $xy4==0)?'':' و ';
520
                        $k3=array('','','بیست','سی','چهل','پنجاه','شصت','هفتاد','هشتاد','نود');
521
                        $h3=$k3[$xy3];
522
                        $k4=array('','یک','دو','سه','چهار','پنج','شش','هفت','هشت','نه');
523
                        $h4=$k4[$xy4];
524
                    }
525
                    $array[$type]=(($num>99)?str_replace(array('12','13','14','19','20')
526
                                ,array('هزار و دویست','هزار و سیصد','هزار و چهارصد','هزار و نهصد','دوهزار')
527
                                ,substr($num,0,2)).((substr($num,2,2)=='00')?'':' و '):'').$h3.$p34.$h34.$h4;
528
                    break;
529
530 View Code Duplication
                case'mm':
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
531
                    $key=array('فروردین','اردیبهشت','خرداد','تیر','مرداد','شهریور','مهر','آبان','آذر','دی','بهمن','اسفند');
532
                    $array[$type]=$key[$num-1];
533
                    break;
534
535
                case'rr':
536
                    $key=array('یک','دو','سه','چهار','پنج','شش','هفت','هشت','نه','ده','یازده','دوازده','سیزده'
537
                    ,'چهارده','پانزده','شانزده','هفده','هجده','نوزده','بیست','بیست و یک','بیست و دو','بیست و سه'
538
                    ,'بیست و چهار','بیست و پنج','بیست و شش','بیست و هفت','بیست و هشت','بیست و نه','سی','سی و یک');
539
                    $array[$type]=$key[$num-1];
540
                    break;
541
542
                case'rh':
543
                    $key=array('یکشنبه','دوشنبه','سه شنبه','چهارشنبه','پنجشنبه','جمعه','شنبه');
544
                    $array[$type]=$key[$num];
545
                    break;
546
547 View Code Duplication
                case'sh':
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
548
                    $key=array('مار','اسب','گوسفند','میمون','مرغ','سگ','خوک','موش','گاو','پلنگ','خرگوش','نهنگ');
549
                    $array[$type]=$key[$num%12];
550
                    break;
551
552 View Code Duplication
                case'mb':
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
553
                    $key=array('حمل','ثور','جوزا','سرطان','اسد','سنبله','میزان','عقرب','قوس','جدی','دلو','حوت');
554
                    $array[$type]=$key[$num-1];
555
                    break;
556
557
                case'ff':
558
                    $key=array('بهار','تابستان','پاییز','زمستان');
559
                    $array[$type]=$key[(int)($num/3.1)];
560
                    break;
561
562 View Code Duplication
                case'km':
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
563
                    $key=array('فر','ار','خر','تی‍','مر','شه‍','مه‍','آب‍','آذ','دی','به‍','اس‍');
564
                    $array[$type]=$key[$num-1];
565
                    break;
566
567
                case'kh':
568
                    $key=array('ی','د','س','چ','پ','ج','ش');
569
                    $array[$type]=$key[$num];
570
                    break;
571
572
                default:$array[$type]=$num;
573
            }
574
        }
575
        return($mod==='')?$array:implode($mod,$array);
576
    }
577
578
579
    /** Gregorian & Jalali (Hijri_Shamsi,Solar) date converter Functions
580
    Author: JDF.SCR.IR =>> Download Full Version : http://jdf.scr.ir/jdf
581
    License: GNU/LGPL _ Open Source & Free _ Version: 2.70 : [2017=1395]
582
    --------------------------------------------------------------------
583
    1461 = 365*4 + 4/4   &  146097 = 365*400 + 400/4 - 400/100 + 400/400
584
    12053 = 365*33 + 32/4    &    36524 = 365*100 + 100/4 - 100/100   */
585
586
    /*	F	*/
587
   public  function gregorian_to_jalali($gy,$gm,$gd,$mod=''){
588
        list($gy,$gm,$gd)=explode('_',$this->tr_num($gy.'_'.$gm.'_'.$gd));/* <= Extra :اين سطر ، جزء تابع اصلي نيست */
589
        $g_d_m=array(0,31,59,90,120,151,181,212,243,273,304,334);
590
        if($gy > 1600){
591
            $jy=979;
592
            $gy-=1600;
593
        }else{
594
            $jy=0;
595
            $gy-=621;
596
        }
597
        $gy2=($gm > 2)?($gy+1):$gy;
598
        $days=(365*$gy) +((int)(($gy2+3)/4)) -((int)(($gy2+99)/100)) +((int)(($gy2+399)/400)) -80 +$gd +$g_d_m[$gm-1];
599
        $jy+=33*((int)($days/12053));
600
        $days%=12053;
601
        $jy+=4*((int)($days/1461));
602
        $days%=1461;
603
        $jy+=(int)(($days-1)/365);
604
        if($days > 365)$days=($days-1)%365;
605
        if($days < 186){
606
            $jm=1+(int)($days/31);
607
            $jd=1+($days%31);
608
        }else{
609
            $jm=7+(int)(($days-186)/30);
610
            $jd=1+(($days-186)%30);
611
        }
612
        return($mod==='')?array($jy,$jm,$jd):$jy .$mod .$jm .$mod .$jd;
613
    }
614
615
    /*	F	*/
616
   public function jalali_to_gregorian($jy,$jm,$jd,$mod=''){
617
        list($jy,$jm,$jd)=explode('_',$this->tr_num($jy.'_'.$jm.'_'.$jd));/* <= Extra :اين سطر ، جزء تابع اصلي نيست */
618
        if($jy > 979){
619
            $gy=1600;
620
            $jy-=979;
621
        }else{
622
            $gy=621;
623
        }
624
        $days=(365*$jy) +(((int)($jy/33))*8) +((int)((($jy%33)+3)/4)) +78 +$jd +(($jm<7)?($jm-1)*31:(($jm-7)*30)+186);
625
        $gy+=400*((int)($days/146097));
626
        $days%=146097;
627
        if($days > 36524){
628
            $gy+=100*((int)(--$days/36524));
629
            $days%=36524;
630
            if($days >= 365)$days++;
631
        }
632
        $gy+=4*((int)(($days)/1461));
633
        $days%=1461;
634
        $gy+=(int)(($days-1)/365);
635
        if($days > 365)$days=($days-1)%365;
636
        $gd=$days+1;
637
        foreach(array(0,31,((($gy%4==0) and ($gy%100!=0)) or ($gy%400==0))?29:28 ,31,30,31,30,31,31,30,31,30,31) as $gm=>$v){
638
            if($gd <= $v)break;
639
            $gd-=$v;
640
        }
641
        return($mod==='')?array($gy,$gm,$gd):$gy .$mod .$gm .$mod .$gd;
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $gm seems to be defined by a foreach iteration on line 637. Are you sure the iterator is never empty, otherwise this variable is not defined?
Loading history...
642
    }
643
644
645
   public  function g_t_j($date,$separator='-'){
646
        $query_date = date('Y-m-d',strtotime($date));
647
        $query_date = explode('-',$query_date);
648
649
        $gDate = $this->gregorian_to_jalali($query_date[0],$query_date[1],$query_date[2]);
650
        return $gDate[0].$separator.$gDate[1].$separator.$gDate[2];
651
    }
652
653
}
654
655