You are here

function hijri_shamsi_calc in Hijri 7

Calculate Hijri Shamsi (Jalali-Iranian) date From the given Gregorian by converting through Julian day. For more checkout these links: http://php.net/manual/en/ref.calendar.php#54234 https://github.com/mohamadnorouzi20/JalaliGregorianConverter.

1 call to hijri_shamsi_calc()
hijri in ./hijri.module
Retrive Hijri date from given format and timestamp.

File

./hijri.module, line 597
This module convert to Hijri date in nodes,comments and a block.

Code

function hijri_shamsi_calc($y, $m, $d) {
  $g_d_m = [
    0,
    31,
    59,
    90,
    120,
    151,
    181,
    212,
    243,
    273,
    304,
    334,
  ];
  $j_year = $y <= 1600 ? 0 : 979;
  $y -= $y <= 1600 ? 621 : 1600;
  $gy2 = $m > 2 ? $y + 1 : $y;
  $days = 365 * $y + (int) (($gy2 + 3) / 4) - (int) (($gy2 + 99) / 100) + (int) (($gy2 + 399) / 400) - 80 + $d + $g_d_m[$m - 1];
  $j_year += 33 * (int) ($days / 12053);
  $days %= 12053;
  $j_year += 4 * (int) ($days / 1461);
  $days %= 1461;
  $j_year += (int) (($days - 1) / 365);
  if ($days > 365) {
    $days = ($days - 1) % 365;
  }
  $j_month = $days < 186 ? 1 + (int) ($days / 31) : 7 + (int) (($days - 186) / 30);
  $j_day = 1 + ($days < 186 ? $days % 31 : ($days - 186) % 30);
  return array(
    $j_year,
    $j_month,
    $j_day,
  );
}