You are here

function cmfcCalendarV1Iranian::toGregorian in Calendar Systems 8.2

Same name and namespace in other branches
  1. 8 calendar/v1/calendarSystems/iranian.class.inc.php \cmfcCalendarV1Iranian::toGregorian()
  2. 5 calendar/v1/calendarSystems/iranian.class.inc.php \cmfcCalendarV1Iranian::toGregorian()
  3. 6.3 calendar/v1/calendarSystems/iranian.class.inc.php \cmfcCalendarV1Iranian::toGregorian()
  4. 6 calendar/v1/calendarSystems/iranian.class.inc.php \cmfcCalendarV1Iranian::toGregorian()
  5. 7.3 calendar/v1/calendarSystems/iranian.class.inc.php \cmfcCalendarV1Iranian::toGregorian()
  6. 7 calendar/v1/calendarSystems/iranian.class.inc.php \cmfcCalendarV1Iranian::toGregorian()
  7. 7.2 calendar/v1/calendarSystems/iranian.class.inc.php \cmfcCalendarV1Iranian::toGregorian()

Overrides cmfcCalendarV1Plugin::toGregorian

6 calls to cmfcCalendarV1Iranian::toGregorian()
cmfcCalendarV1Iranian::date in calendar/v1/calendarSystems/iranian.class.inc.php
Implementation of PHP date function This is the simplified versino by Sina Salek
cmfcCalendarV1Iranian::infoArrayToTimestamp in calendar/v1/calendarSystems/iranian.class.inc.php
cmfcCalendarV1Iranian::makeTime in calendar/v1/calendarSystems/iranian.class.inc.php
cmfcCalendarV1Iranian::monthStartDay in calendar/v1/calendarSystems/iranian.class.inc.php
Find num of Day Begining Of Month ( 0 for Sat & 6 for Sun)
cmfcCalendarV1Iranian::valueToTimeStamp in calendar/v1/calendarSystems/iranian.class.inc.php

... See full list

File

calendar/v1/calendarSystems/iranian.class.inc.php, line 416

Class

cmfcCalendarV1Iranian

Code

function toGregorian($j_y, $j_m, $j_d) {
  $j_d = (int) $j_d;
  $j_m = (int) $j_m;
  $j_y = (int) $j_y;
  $g_days_in_month = array(
    31,
    28,
    31,
    30,
    31,
    30,
    31,
    31,
    30,
    31,
    30,
    31,
  );
  $j_days_in_month = array(
    31,
    31,
    31,
    31,
    31,
    31,
    30,
    30,
    30,
    30,
    30,
    29,
  );

  #--(Begin)-->By Sina
  if ($j_m > 12) {
    $j_y = $j_y + floor($j_m / 12);
    $j_m = $j_m % 12;
  }

  #--(End)-->By Sina
  if ($j_d < 1) {
    $j_d = 1;
  }

  //elseif ($j_d > $j_days_in_month[ $j_m - 1 ])

  //  $j_d = $j_days_in_month[ $j_m - 1 ];
  $jy = $j_y - 979;
  $jm = $j_m - 1;
  $jd = 0;
  $jd = $j_d - 1;
  $j_day_no = 365 * $jy + div($jy, 33) * 8 + div($jy % 33 + 3, 4);
  for ($i = 0; $i < $jm; ++$i) {
    $j_day_no += $j_days_in_month[$i];
  }
  $j_day_no += $jd;
  $g_day_no = $j_day_no + 79;
  $gy = 1600 + 400 * div($g_day_no, 146097);

  /* 146097 = 365*400 + 400/4 - 400/100 + 400/400 */
  $g_day_no = $g_day_no % 146097;
  $leap = true;
  if ($g_day_no >= 36525) {

    /* 36525 = 365*100 + 100/4 */
    $g_day_no--;
    $gy += 100 * div($g_day_no, 36524);

    /* 36524 = 365*100 + 100/4 - 100/100 */
    $g_day_no = $g_day_no % 36524;
    if ($g_day_no >= 365) {
      $g_day_no++;
    }
    else {
      $leap = false;
    }
  }
  $gy += 4 * div($g_day_no, 1461);

  /* 1461 = 365*4 + 4/4 */
  $g_day_no %= 1461;
  if ($g_day_no >= 366) {
    $leap = false;
    $g_day_no--;
    $gy += div($g_day_no, 365);
    $g_day_no = $g_day_no % 365;
  }
  for ($i = 0; $g_day_no >= $g_days_in_month[$i] + ($i == 1 && $leap); $i++) {
    $g_day_no -= $g_days_in_month[$i] + ($i == 1 && $leap);
  }
  $gm = $i + 1;
  $gd = $g_day_no + 1;
  return array(
    $gy,
    $gm,
    $gd,
  );
}