Completed
Push — master ( 01907b...5981e6 )
by mehdi
03:03
created

src/CalendarSettings/Hijri.php (1 issue)

Severity

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
use OpenCafe\Datium as Datium;
4
use OpenCafe\Tools\Leap as Leap;
5
6
 return array (
7
8
 /************************************************************
9
  *                        Convert to
10
  ************************************************************
11
  *
12
  * Convert algorith to convert Gregorian to Jalali calerndar
13
  *
14
  *\_________________________________________________________/
15
  */
16
   'convert_to' => function ( $date_time ) {
17
18
     $config = include 'Jalali.php';
19
20
     $date_time = Datium::create($date_time)->to('jalali')->object();
0 ignored issues
show
'jalali' is of type string, but the function expects a object.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
21
22
     $year = $date_time->format('Y');
23
24
     $month = $date_time->format('n');
25
26
     $day = $date_time->format('d');
27
28
     $temp_day = 0 ;
29
30
    for ( $i = 1 ; $i < $month ; $i++ ) {
31
32
        $temp_day += $config[ 'month_days_number' ][ $i ];
33
34
    }
35
36
      $temp_day += $day;
37
38
      $leap = new Leap($year);
39
40
    if($leap->get() && $month > 11 ) { $temp_day++; 
41
    }
42
43
     $_year = ( ( ( ( ( $year - 1 ) * 365.2422 ) + $temp_day ) - 119) / 354.3670 ) + 1;
44
45
     $_year = explode('.', $_year);
46
47
     $year = $_year[0];
48
49
     $_month = $_year[1];
50
51
      $var_temp = '0.0';
52
53
    for ( $i = strlen($_month); $i > 2; $i-- ) {
54
55
        $var_temp .= '0';
56
57
    }
58
59
      $var_temp .= '1';
60
61
     $_month = $_month * $var_temp ;
62
63
     $_month = ( $_month * 12 ) + 1;
64
65
     $_month = explode('.', $_month);
66
67
     $month = $_month[0];
68
69
     $_day = $_month[1];
70
71
     $var_temp = '0.0';
72
73
    for ( $i = strlen($_day);  $i > 2;  $i-- ) {
74
75
        $var_temp .= '0' ;
76
77
    }
78
79
     $var_temp .= '1';
80
81
     $_day = $_day * $var_temp;
82
83
     $_day = ( $_day * 29.530 );
84
85
     $_day = explode('.', $_day);
86
87
     $day = $_day[0];
88
89
    $date_time->setDate($year, $month, $day);
90
91
    return $date_time;
92
93
   },
94
95
    /************************************************************
96
    *                        Convert From
97
    ************************************************************
98
    *
99
    * Convert algorith to convert Jalali to Gregorian calerndar
100
    *
101
    *\_________________________________________________________/
102
    */
103
    'convert_from' => function ( $date_time ) {
104
105
        $config = include 'Hijri.php';
106
107
        $year = $date_time->format('Y');
108
109
        $month = $date_time->format('m');
110
111
        $day = $date_time->format('d');
112
113
        $days_of_year = 0;
114
115
        foreach ( $config['month_days_number'] as $month => $value ) {
116
117
            if($month > $month ) { $days_of_year += $value; 
118
            }
119
120
        }
121
122
        $days_of_year += $day;
123
124
        $days_of_leap_years =  intval(( ( $year - 1 ) / 3 ));
125
126
        $days_of_ghamari_years = ( ( ( $year - 1 ) * 354 ) + $days_of_year + $days_of_leap_years );
127
128
        $days_of_gregorain_years = $days_of_ghamari_years + 227078;
129
130
        $days_of_gregorain_years = $days_of_gregorain_years - intval(( ( $year + 578 ) / 4 ));
131
132
        $gregorian_month = ( $days_of_gregorain_years % 365 );
133
134
        $gregorian_year = intval($days_of_gregorain_years / 365) + 1;
135
136
        $config = include 'Gregorian.php';
137
138
        foreach ($config [ 'month_days_number' ] as $month => $value) {
139
140
            if ($gregorian_month < $value ) {
141
142
                break;
143
            }
144
145
            $gregorian_month -= $value;
146
        }
147
148
        $gregorian_day = $gregorian_month;
149
150
        $gregorian_month = $month;
151
152
        $date_time->setDate($gregorian_year, $gregorian_month, $gregorian_day);
153
154
        return $date_time;
155
156
157
    },
158
159
    /************************************************************
160
    *               Shorthand for jalali calendar
161
    ************************************************************
162
    *
163
    * Jalali calendar shorthand
164
    *
165
    *\_________________________________________________________/
166
    */
167
    'shorthand' => 'sh',
168
169
    /************************************************************
170
    *                        Month's name
171
    ************************************************************
172
    *
173
    * Jalali month name
174
    *
175
    *\_________________________________________________________/
176
    */
177
    'month' => array (
178
179
        'Muharram',
180
181
        'Safar',
182
183
        'Rabi I',
184
185
        'Rabi II',
186
187
        'Jumada I',
188
189
        'Jumada II',
190
191
        'Rajab',
192
193
        'Shaban',
194
195
        'Ramadan',
196
197
        'Shawwal',
198
199
        'Dhu al_Qadah',
200
201
        'Dhu al_Hijjah'
202
203
     ),
204
205
    /************************************************************
206
    *                        Days of Week
207
    ************************************************************
208
    *
209
    * Here is week days on jalali calendar, offset 0 is first
210
    * day of week and offset 6 is the last one.
211
    *
212
    *\_________________________________________________________/
213
    */
214
    'days_of_week' => array (
215
         'al-Aḥad',
216
         'al-Ithnayn',
217
         'ath-Thulatha\'',
218
         'al-Arbi\'a',
219
         'al-Khamees',
220
         'al-Jumu\'ah',
221
         'as-Sabt',
222
223
    ),
224
225
    'numbers' => array( '0', '1', '2', '3', '4', '5', '6', '7', '8', '9'),
226
227
    'am_time' => 'AM',
228
229
    'pm_time' => 'PM',
230
231
    'end_of_days' => array( 'th', 'st', 'nd', 'rd' ),
232
233
234
235
236
    'month_days_number' => array(     1 => 30,
237
                                     2 => 29,
238
                                     3 => 30,
239
                                     4 => 30,
240
                                     5 => 29,
241
                                     6 => 29,
242
                                     7 => 30,
243
                                     8 => 29,
244
                                     9 => 30,
245
                                     10 => 29,
246
                                     11 => 30,
247
                                     12 => 30 ),
248
    /************************************************************
249
    *                      Day of year
250
    ************************************************************
251
    *
252
    *  Return days of year on ghamari cleander
253
    *
254
    *\_________________________________________________________/
255
    */
256 View Code Duplication
     'day_of_year' => function ( $date_time ) {
257
258
        $result = null;
259
260
        $config = include 'Hijri.php';
261
262
        $month = $date_time->format('n');
263
264
        $day = $date_time->format('d');
265
266
        foreach( $config['month_days_number'] as $_month => $value ) {
267
268
            if ($_month < $month ) {
269
270
                $result += $value;
271
272
            }
273
274
        }
275
276
        $result += $day;
277
278
        return $result;
279
280
     },
281
282
     /************************************************************
283
      *                      Day of week
284
      ************************************************************
285
      *
286
      *  Return day of week on ghamari cleander
287
      *  example : al-Aḥad = result is 1
288
      *\_________________________________________________________/
289
      */
290
     'day_of_week' => function ( $date_time ) {
291
292
        $configGhamari = include 'Hijri.php';
293
294
        $configGregorian = include 'Gregorian.php';
295
296
        $day = $date_time->format('l');
297
298
        $day = str_replace($configGregorian['days_of_week'], $configGhamari['days_of_week'], $day);
299
300
        foreach ( $configGhamari['days_of_week'] as $key => $value ) {
301
302
            if($value == $day ) {
303
304
                return $key += 1;
305
306
            }
307
308
        }
309
310
     },
311
312
     /************************************************************
313
      *                       Leap year
314
      ************************************************************
315
      *
316
      * Leap Year formula on ghamari calendar
317
      *
318
      *\_________________________________________________________/
319
      */
320
     'leap_year' => null,
321
322
    /************************************************************
323
    *                        Weekend
324
    ************************************************************
325
    *
326
    * weekend in arabic countries and some islamic countries
327
    *
328
    *\_________________________________________________________/
329
    */
330
    'weekend' => array( 'friday', 'saturday' ),
331
332
  );
333