You are here

function cmfcCalendarV1Iranian::fromGregorian in Calendar Systems 7.3

Same name and namespace in other branches
  1. 8 calendar/v1/calendarSystems/iranian.class.inc.php \cmfcCalendarV1Iranian::fromGregorian()
  2. 8.2 calendar/v1/calendarSystems/iranian.class.inc.php \cmfcCalendarV1Iranian::fromGregorian()
  3. 5 calendar/v1/calendarSystems/iranian.class.inc.php \cmfcCalendarV1Iranian::fromGregorian()
  4. 6.3 calendar/v1/calendarSystems/iranian.class.inc.php \cmfcCalendarV1Iranian::fromGregorian()
  5. 6 calendar/v1/calendarSystems/iranian.class.inc.php \cmfcCalendarV1Iranian::fromGregorian()
  6. 7 calendar/v1/calendarSystems/iranian.class.inc.php \cmfcCalendarV1Iranian::fromGregorian()
  7. 7.2 calendar/v1/calendarSystems/iranian.class.inc.php \cmfcCalendarV1Iranian::fromGregorian()
4 calls to cmfcCalendarV1Iranian::fromGregorian()
cmfcCalendarV1Iranian::date in calendar/v1/calendarSystems/iranian.class.inc.php
Implementation of PHP date function This is the simplified versino by Sina Salek
cmfcCalendarV1Iranian::monthStartDay in calendar/v1/calendarSystems/iranian.class.inc.php
Find num of Day Begining Of Month ( 0 for Sat & 6 for Sun)
cmfcCalendarV1Iranian::monthTotalDays in calendar/v1/calendarSystems/iranian.class.inc.php
* @author * Find Number Of Days In This Month
cmfcCalendarV1Iranian::timestampToInfoArray in calendar/v1/calendarSystems/iranian.class.inc.php

File

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

Class

cmfcCalendarV1Iranian

Code

function fromGregorian($g_y, $g_m, $g_d) {
  if ($g_y < 1300 or $g_m < 1 or $g_d < 1) {
    return array(
      '',
      '',
      '',
    );
  }
  $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,
  );
  $gy = $g_y - 1600;
  $gm = $g_m - 1;
  $gd = $g_d - 1;
  $g_day_no = 365 * $gy + div($gy + 3, 4) - div($gy + 99, 100) + div($gy + 399, 400);
  for ($i = 0; $i < $gm; ++$i) {
    $g_day_no += $g_days_in_month[$i];
  }
  if ($gm > 1 && ($gy % 4 == 0 && $gy % 100 != 0 || $gy % 400 == 0)) {

    /* leap and after Feb */
    $g_day_no++;
  }
  $g_day_no += $gd;
  $j_day_no = $g_day_no - 79;
  $j_np = div($j_day_no, 12053);

  /* 12053 = 365*33 + 32/4 */
  $j_day_no = $j_day_no % 12053;
  $jy = 979 + 33 * $j_np + 4 * div($j_day_no, 1461);

  /* 1461 = 365*4 + 4/4 */
  $j_day_no %= 1461;
  if ($j_day_no >= 366) {
    $jy += div($j_day_no - 1, 365);
    $j_day_no = ($j_day_no - 1) % 365;
  }
  for ($i = 0; $i < 11 && $j_day_no >= $j_days_in_month[$i]; ++$i) {
    $j_day_no -= $j_days_in_month[$i];
  }
  $jm = $i + 1;
  $jd = $j_day_no + 1;
  return array(
    $jy,
    $jm,
    $jd,
  );
}