You are here

public static function DatexJalali::convert in Datex 7.2

Converts a Gregorian date to Jalali.

Overrides DatexCalendarIterface::convert

1 call to DatexJalali::convert()
DatexJalali::toGregorian in datex_api/DatexJalali.inc
Converts a Jalali date to Gregorian.

File

datex_api/DatexJalali.inc, line 335
Jalali calendar for datex.

Class

DatexJalali
Jalali calendar for datex.

Code

public static function convert($timestamp, $offset = 0) {
  $timestamp = $timestamp + $offset;

  // DateTime will handle time.
  $ts = floor($timestamp % 60);
  $tm = floor($timestamp % 3600 / 60);
  $th = floor($timestamp % 86400 / 3600);
  $d = floor($timestamp / 86400) + 287;
  $y = floor($d / self::$khayamYear - $d * self::$khayamYearCorrection);
  $day_of_year = $d - round($y * self::$khayamYear, 0);
  if ($day_of_year == 0) {
    $day_of_year = 366;
  }
  $y += 1348;
  $m = 0;
  while ($m < 12 && $day_of_year > self::$mCounter[$m]) {
    $m++;
  }
  $d = $day_of_year - self::$mCounter[$m - 1];
  $day_of_week = self::dayOfWeek($y, $day_of_year);
  return array(
    $y,
    $m,
    $d,
    $th,
    $tm,
    $ts,
    $day_of_year,
    $day_of_week,
  );
}