Code Duplication    Length = 54-54 lines in 2 locations

src/Convert.php 2 locations

@@ 257-310 (lines=54) @@
254
   * @since  Oct, 17 2015
255
   * @return object
256
   */
257
    public function hijriToJalali($date_time)
258
    {
259
260
          $this->date_time = $date_time;
261
262
          $this->year = $this->date_time->format('Y');
263
264
          $this->month = $this->date_time->format('m');
265
266
          $this->day = $this->date_time->format('d');
267
268
          $days_of_year = 0;
269
270
          $this->config = include __DIR__.'/Hijri.php';
271
272
        foreach ($this->config[ 'month_days_number' ] as $month => $value) {
273
            if ($this->month > $month) {
274
                $days_of_year += $value;
275
            }
276
        }
277
278
          $days_of_year += $this->day;
279
280
          $days_of_leap_years =  intval(( ( $this->year - 1 ) / 3 ));
281
282
          $days_of_hijri_years = ( ( ( $this->year - 1 ) * 354 ) + $days_of_year + $days_of_leap_years );
283
284
          $days_of_jalali_years = $days_of_hijri_years + 179;
285
286
          $days_of_jalali_years = $days_of_jalali_years - intval(( ( $this->year - 43 ) / 4 ));
287
288
          $jalali_month = ( $days_of_jalali_years % 365 );
289
290
          $jalali_year = intval($days_of_jalali_years / 365) + 1;
291
292
          $this->config = include __DIR__.'/Jalali.php';
293
294
        foreach ($this->config[ 'month_days_number' ] as $month => $value) {
295
            if ($jalali_month < $value) {
296
                break;
297
            }
298
299
              $jalali_month -= $value;
300
        }
301
302
          $jalali_day = $jalali_month;
303
304
          $jalali_month = $month;
305
306
          $this->date_time->setDate($jalali_year, $jalali_month, $jalali_day);
307
308
         return $this->date_time;
309
310
    }
311
312
    /**
313
    * convert hijri year to gregorian year
@@ 318-371 (lines=54) @@
315
    * @since  Oct, 17 2015
316
    * @return object
317
    */
318
    public function hijriToGregorian($date_time)
319
    {
320
321
        $this->date_time = $date_time;
322
323
        $this->year = $this->date_time->format('Y');
324
325
        $this->month = $this->date_time->format('m');
326
327
        $this->day = $this->date_time->format('d');
328
329
        $days_of_year = 0;
330
331
        $this->config = include __DIR__.'/Hijri.php';
332
333
        foreach ($this->config[ 'month_days_number' ] as $month => $value) {
334
            if ($this->month > $month) {
335
                $days_of_year += $value;
336
            }
337
        }
338
339
        $days_of_year += $this->day;
340
341
        $days_of_leap_years =  intval(( ( $this->year - 1 ) / 3 ));
342
343
        $days_of_hijri_years = ( ( ( $this->year - 1 ) * 354 ) + $days_of_year + $days_of_leap_years );
344
345
        $days_of_gregorain_years = $days_of_hijri_years + 227078;
346
347
        $days_of_gregorain_years = $days_of_gregorain_years - intval(( ( $this->year + 578 ) / 4 ));
348
349
        $gregorian_month = ( $days_of_gregorain_years % 365 );
350
351
        $gregorian_year = intval($days_of_gregorain_years / 365) + 1;
352
353
        $this->config = include __DIR__.'/Gregorian.php';
354
355
        foreach ($this->config[ 'month_days_number' ] as $month => $value) {
356
            if ($gregorian_month < $value) {
357
                break;
358
            }
359
360
            $gregorian_month -= $value;
361
        }
362
363
        $gregorian_day = $gregorian_month;
364
365
        $gregorian_month = $month;
366
367
        $this->date_time->setDate($gregorian_year, $gregorian_month, $gregorian_day);
368
369
         return $this->date_time;
370
371
    }
372
}
373