Completed
Push — master ( 2b83b7...dd6000 )
by
unknown
02:21
created

src/CalendarSettings/Shamsi.php (4 issues)

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 Datium\Datium as Datium;
4
use Datium\Tools\Leap as Leap;
5
6
return array (
7
8
  'timezone' => 'Asia/Tehran',
9
10
  'language' =>  'fa',
11
12
  'events' => array(),
13
14
  'numbers' => array( '0', '1', '2', '3', '4', '5', '6', '7', '8', '9'),
15
16
  'day_to_nigh' => 'AM',
17
18
  'night_to_day' => 'PM',
19
20
  'end_of_days_number' => 'th',
21
22
23
24
/************************************************************
25
 *                        Convert to
26
 ************************************************************
27
 *
28
 * Convert algorith to convert Gregorian to Jalali calerndar
29
 *
30
 *\_________________________________________________________/
31
 */
32
  'convert_to' => function( $date_time ) {
33
34
        $config = include( 'Gregorian.php' );
35
36
        $year = $date_time->format( 'Y' );
37
38
        $month = $date_time->format( 'm' );
39
40
        $day = $date_time->format( 'd' );
41
42
        $temp_day = 0;
43
44 View Code Duplication
         for ( $i = 1 ; $i < $month ; $i++ ) {
0 ignored issues
show
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...
45
46
           $temp_day += $config['month_days_number'][$i];
47
48
         }
49
50
         $temp_day += $day;
51
52
         $leap = new Leap( $year );
53
54
         if( $leap->get() && $month > 2 ) $temp_day++;
55
56
         if ( $temp_day <= 79 ) {
57
58
          if( ( $year - 1 ) % 4 == 0 )
59
60
            $temp_day = $temp_day + 11;
61
62
          else
63
64
            $temp_day = $temp_day + 10;
65
66
          $year = $year - 622;
67
68 View Code Duplication
          if($temp_day % 30 == 0) {
0 ignored issues
show
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...
69
70
            $month = ( $temp_day / 30 ) + 9;
71
72
            $day = 30;
73
74
          }
75
76
          else {
77
78
            $month = ( $temp_day / 30 ) + 10;
79
80
            $day = $temp_day % 30;
81
82
          }
83
84
         }
85
86
         else {
87
88
          $year = $year - 621;
89
90
          $temp_day = $temp_day - 79;
91
92
          if( $temp_day <= 186 ) {
93
94 View Code Duplication
            if( $temp_day % 31 == 0 ) {
0 ignored issues
show
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...
95
96
              $month = ( $temp_day / 31 );
97
98
              $day = 31;
99
            }
100
101
          else {
102
103
            $month = ( $temp_day / 31 ) + 1;
104
105
            $day = ( $temp_day % 31 );
106
          }
107
108
          }
109
110 View Code Duplication
          else {
0 ignored issues
show
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...
111
112
            $temp_day = $temp_day - 186;
113
114
            if( $temp_day % 30 == 0 ) {
115
116
            $month = ( $temp_day / 30 ) + 6;
117
118
            $day = 30;
119
120
            }
121
122
            else {
123
124
            $month = ( $temp_day / 30 ) + 7;
125
126
            $day = $temp_day % 30;
127
128
            }
129
130
          }
131
132
         }
133
134
         $date_time->setDate( $year, $month, $day );
135
136
         return $date_time;
137
138
  },
139
140
  /************************************************************
141
   *                        Convert From
142
   ************************************************************
143
   *
144
   * Convert algorith to convert Jalali to Gregorian calerndar
145
   *
146
   *\_________________________________________________________/
147
   */
148
  'convert_from' => function( $date_time ) {
149
150
    $config = include( 'Shamsi.php' );
151
152
    $year = $date_time->format('Y');
153
154
    $month = $date_time->format('m');
155
156
    $day = $date_time->format('d');
157
158
    $days_of_year = 0;
159
160
    foreach ( $config['month_days_number'] as $mon => $value ) {
161
162
      if( $month > $mon ) $days_of_year += $value;
163
164
    }
165
166
    $days_of_year += $day;
167
168
    $days_of_leap_years =  intval( ( ( $year - 1 ) / 4 )  );
169
170
    $days_of_shamsi_years = ( ( ( $year - 1 ) * 365 ) + $days_of_year + $days_of_leap_years );
171
172
    $days_of_gregorain_years = $days_of_shamsi_years + 226899;
173
174
    if ( $month < 10 )  {
175
176
    $days_of_gregorain_years = $days_of_gregorain_years - intval( ( ( $year + 621 ) / 4 ) );
177
178
    }
179
180
    elseif ( ( ( 10 == $month ) && ( $day > 10 ) ) || ( $month > 10 ) ) {
181
182
    $days_of_gregorain_years = $days_of_gregorain_years - intval( ( ( $year + 622 ) / 4 ) );
183
184
    }
185
186
    $gregorian_month = ( $days_of_gregorain_years % 365 );
187
188
    $gregorian_year = intval( $days_of_gregorain_years / 365 ) + 1;
189
190
    $config = include( 'Gregorian.php' );
191
192
    foreach ( $config['month_days_number'] as $month => $value ) {
193
194
      if ( $gregorian_month < $value ) break;
195
196
        $gregorian_month -= $value;
197
    }
198
199
      $gregorian_day = $gregorian_month;
200
201
      $gregorian_month = $month;
202
203
      $date_time->setDate( $gregorian_year, $gregorian_month, $gregorian_day );
204
205
206
     return $date_time;
207
208
  },
209
210
  /************************************************************
211
   *               Shorthand for jalali calendar
212
   ************************************************************
213
   *
214
   * Jalali calendar shorthand
215
   *
216
   *\_________________________________________________________/
217
   */
218
  'shorthand' => 'sh',
219
220
  /************************************************************
221
   *                        Month's name
222
   ************************************************************
223
   *
224
   * Jalali month name
225
   *
226
   *\_________________________________________________________/
227
   */
228
  'month' => array (
229
230
    'Farvardin',
231
232
    'Ordibehesht',
233
234
    'Khordad',
235
236
    'Tir',
237
238
    'Mordad',
239
240
    'Shahrivar',
241
242
    'Mehr',
243
244
    'Aban',
245
246
    'Azar',
247
248
    'Dey',
249
250
    'Bahman',
251
252
    'Esfand'
253
254
    ),
255
256
  /************************************************************
257
   *                        Days of Week
258
   ************************************************************
259
   *
260
   * Here is week days on jalali calendar, offset 0 is first
261
   * day of week and offset 6 is the last one.
262
   *
263
   *\_________________________________________________________/
264
   */
265
  'days_of_week' => array (
266
267
     'Yekshanbe',
268
     'Doshanbe',
269
     'Seshanbe',
270
     'Chaharshanbe',
271
     'Panjshanbe',
272
     'Jome',
273
     'Shanbe',
274
275
  ),
276
277
  'start_day_of_week' => 'Shanbe',
278
279
  'month_days_number' => array(      1 => 31,
280
                                     2 => 31,
281
                                     3 => 31,
282
                                     4 => 31,
283
                                     5 => 31,
284
                                     6 => 31,
285
                                     7 => 30,
286
                                     8 => 30,
287
                                     9 => 30,
288
                                     10 => 30,
289
                                     11 => 30,
290
                                     12 => 29 ),
291
292
293 View Code Duplication
  'day_of_year' => function( $date_time ) {
294
295
    $result = null;
296
297
    $config = include( 'Shamsi.php' );
298
299
    $month = $date_time->format('n');
300
301
    $day = $date_time->format('d');
302
303
    foreach( $config['month_days_number'] as $_month => $value ) {
304
305
      if ( $_month < $month ) $result += $value;
306
307
    }
308
309
    $result += $day;
310
311
    return $result + 1;
312
313
  },
314
315 View Code Duplication
  'day_of_week' => function( $date_time ) {
316
317
        $configShamsi = include(  'Shamsi.php' );
318
319
        $configGregorian = include( 'Gregorian.php' );
320
321
        $day = $date_time->format('l');
322
323
        $day = str_replace( $configGregorian['days_of_week'], $configShamsi['days_of_week'], $day );
324
325
        foreach ( $configShamsi['days_of_week'] as $key => $value ) {
326
327
          if( $value == $day ) {
328
329
              return $key += 1;
330
331
          }
332
333
        }
334
335
  },
336
337
  /************************************************************
338
   *                       Leap year
339
   ************************************************************
340
   *
341
   * Leap Year formula on jalali calendar
342
   *
343
   *\_________________________________________________________/
344
   */
345
  'leap_year' => '',
346
347
  /************************************************************
348
   *                        Weekend
349
   ************************************************************
350
   *
351
   * Jalali weekend
352
   *
353
   *\_________________________________________________________/
354
   */
355
  'weekend' => array( 'friday' )
356
357
 );
358