function calendar_jalali_convert in Calendar Systems 6.2
Jalali calendar date converter callback.
Converts Gregorian to Jalali.
Parameters
$year: Gregorian year.
$month: Gregorian month.
$day: Gregorian day.
Return value
An array of Jalali date elements.
- year: Jalali year.
- month: Jalali month.
- day: Jalali day.
1 call to calendar_jalali_convert()
- calendar_jalali_formatter in calendars/
calendar_jalali/ calendar_jalali.module - Jalali calendar date formatter callback.
1 string reference to 'calendar_jalali_convert'
- calendar_jalali_calendar_info in calendars/
calendar_jalali/ calendar_jalali.module - Implements hook_calendar_info().
File
- calendars/
calendar_jalali/ calendar_jalali.module, line 125 - Implements necessary hooks & helpers to support Jalali Calendar.
Code
function calendar_jalali_convert($year, $month, $day) {
$day = $day - 1;
$month = $month - 1;
$year = $year - 1600;
$jmonth_days = calendar_jalali_month_days();
$gmonth_days = calendar_gregorian_month_days();
$gday_no = 365 * $year + (int) (($year + 3) / 4) - (int) (($year + 99) / 100) + (int) (($year + 399) / 400);
for ($i = 0; $i < $month; ++$i) {
$gday_no += $gmonth_days[$i];
}
// Leap year / After february.
if ($month > 1 && ($year % 4 == 0 && $year % 100 != 0 || $year % 400 == 0)) {
++$gday_no;
}
$gday_no += $day;
$jday_no = $gday_no - 79;
$j_np = (int) ($jday_no / 12053);
$jday_no %= 12053;
$jyear = 979 + 33 * $j_np + 4 * (int) ($jday_no / 1461);
$jday_no %= 1461;
if ($jday_no >= 366) {
$jyear += (int) (($jday_no - 1) / 365);
$jday_no = ($jday_no - 1) % 365;
}
for ($i = 0; $i < 11 && $jday_no >= $jmonth_days[$i]; ++$i) {
$jday_no -= $jmonth_days[$i];
}
return array(
$jyear,
$i + 1,
$jday_no + 1,
);
}