public static function jDateTime::jalaliCal in Persian Date for Drupal 8 8.4
This function determines if the Jalaali (Persian) year is leap (366-day long) or is the common year (365 days), and finds the day in March (Gregorian calendar) of the first day of the Jalaali year (jy).
@see: http://www.astro.uni.torun.pl/~kb/Papers/EMP/PersianC-EMP.htm @see: http://www.fourmilab.ch/documents/calendar/
Parameters
int $jy Jalaali calendar year (-61 to 3177):
Return value
array leap: number of years since the last leap year (0 to 4) gy: Gregorian year of the beginning of Jalaali year march: the March day of Farvardin the 1st (1st day of jy)
2 calls to jDateTime::jalaliCal()
- jDateTime::d2j in src/
Library/ Jalali/ jDateTime.php - Converts the Julian Day number to a date in the Jalaali calendar.
- jDateTime::j2d in src/
Library/ Jalali/ jDateTime.php - Converts a date of the Jalaali calendar to the Julian Day number.
File
- src/
Library/ Jalali/ jDateTime.php, line 143
Class
- jDateTime
- Class jDateTime @package Morilog\Jalali
Namespace
Drupal\persian_date\Library\JalaliCode
public static function jalaliCal($jy) {
$breaks = [
-61,
9,
38,
199,
426,
686,
756,
818,
1111,
1181,
1210,
1635,
2060,
2097,
2192,
2262,
2324,
2394,
2456,
3178,
];
$breaksCount = count($breaks);
$gy = $jy + 621;
$leapJ = -14;
$jp = $breaks[0];
if ($jy < $jp || $jy >= $breaks[$breaksCount - 1]) {
throw new \InvalidArgumentException('Invalid Jalali year : ' . $jy);
}
$jump = 0;
for ($i = 1; $i < $breaksCount; $i += 1) {
$jm = $breaks[$i];
$jump = $jm - $jp;
if ($jy < $jm) {
break;
}
$leapJ = $leapJ + self::div($jump, 33) * 8 + self::div(self::mod($jump, 33), 4);
$jp = $jm;
}
$n = $jy - $jp;
$leapJ = $leapJ + self::div($n, 33) * 8 + self::div(self::mod($n, 33) + 3, 4);
if (self::mod($jump, 33) === 4 && $jump - $n === 4) {
$leapJ += 1;
}
$leapG = self::div($gy, 4) - self::div((self::div($gy, 100) + 1) * 3, 4) - 150;
$march = 20 + $leapJ - $leapG;
if ($jump - $n < 6) {
$n = $n - $jump + self::div($jump + 4, 33) * 33;
}
$leap = self::mod(self::mod($n + 1, 33) - 1, 4);
if ($leap === -1) {
$leap = 4;
}
return [
'leap' => $leap,
'gy' => $gy,
'march' => $march,
];
}