You are here

function calendar_jalali_convert_reverse in Calendar Systems 6.2

Jalali calendar reverse date converter callback.

Converts Jalali to Gregorian.

Parameters

$year: Jalali year.

$month: Jalali month.

$day: Jalali day.

Return value

An array of Gregorian date elements.

  • year: Gregorian year.
  • month: Gregorian month.
  • day: Gregorian day.
1 string reference to 'calendar_jalali_convert_reverse'
calendar_jalali_calendar_info in calendars/calendar_jalali/calendar_jalali.module
Implements hook_calendar_info().

File

calendars/calendar_jalali/calendar_jalali.module, line 185
Implements necessary hooks & helpers to support Jalali Calendar.

Code

function calendar_jalali_convert_reverse($year, $month, $day) {
  $day = $day - 1;
  $month = $month - 1;
  $year = $year - 979;
  $jmonth_days = calendar_jalali_month_days();
  $gmonth_days = calendar_gregorian_month_days();
  $jday_no = 365 * $year + (int) ($year / 33) * 8 + (int) (($year % 33 + 3) / 4);
  for ($i = 0; $i < $month; ++$i) {
    $jday_no += $jmonth_days[$i];
  }
  $jday_no += $day;
  $gday_no = $jday_no + 79;
  $gyear = 1600 + 400 * (int) ($gday_no / 146097);
  $gday_no = $gday_no % 146097;
  $leap = TRUE;
  if ($gday_no >= 36525) {
    $gday_no--;
    $gyear += 100 * (int) ($gday_no / 36524);
    $gday_no = $gday_no % 36524;
    if ($gday_no >= 365) {
      $gday_no++;
    }
    else {
      $leap = FALSE;
    }
  }
  $gyear += 4 * (int) ($gday_no / 1461);
  $gday_no %= 1461;
  if ($gday_no >= 366) {
    $leap = FALSE;
    $gday_no--;
    $gyear += (int) ($gday_no / 365);
    $gday_no = $gday_no % 365;
  }
  for ($i = 0; $gday_no >= $gmonth_days[$i] + ($i == 1 && $leap); $i++) {
    $gday_no -= $gmonth_days[$i] + ($i == 1 && $leap);
  }
  return array(
    $gyear,
    $i + 1,
    $gday_no + 1,
  );
}