static function PersianDateConverter::jalali_to_gregorian in Persian Date for Drupal 8 8.4
Same name and namespace in other branches
- 8 src/Converter/PersianDateConverter.php \Drupal\persian_date\Converter\PersianDateConverter::jalali_to_gregorian()
Convert Persian date parameters to Gregorian.
Parameters
int $year Persian year:
int $month Persian month:
int $day Persian day:
string $mod:
Return value
array|string
2 calls to PersianDateConverter::jalali_to_gregorian()
- PersianDate::setDate in src/
Converter/ PersianDate.php - @inheritDoc
- PersianDateFactory::buildFromExactDate in src/
Converter/ PersianDateFactory.php - Build PersianDateTime instance from given parameters.
File
- src/
Converter/ PersianDateConverter.php, line 62
Class
- PersianDateConverter
- This class converts Gregorian datetime to Persian datetime and reverse.
Namespace
Drupal\persian_date\ConverterCode
static function jalali_to_gregorian($year, $month, $day, $mod = '') {
$gy = $year <= 979 ? 621 : 1600;
$year -= $year <= 979 ? 0 : 979;
$days = 365 * $year + (int) ($year / 33) * 8 + (int) (($year % 33 + 3) / 4) + 78 + (int) $day + ((int) $month < 7 ? ((int) $month - 1) * 31 : ((int) $month - 7) * 30 + 186);
$gy += 400 * (int) ($days / 146097);
$days %= 146097;
if ($days > 36524) {
$gy += 100 * (int) (--$days / 36524);
$days %= 36524;
if ($days >= 365) {
$days++;
}
}
$gy += 4 * (int) ($days / 1461);
$days %= 1461;
$gy += (int) (($days - 1) / 365);
if ($days > 365) {
$days = ($days - 1) % 365;
}
$gd = $days + 1;
foreach (array(
0,
31,
($gy % 4 == 0 and $gy % 100 != 0 or $gy % 400 == 0) ? 29 : 28,
31,
30,
31,
30,
31,
31,
30,
31,
30,
31,
) as $gm => $v) {
if ($gd <= $v) {
break;
}
$gd -= $v;
}
return $mod == '' ? array(
$gy,
$gm,
$gd,
) : $gy . $mod . $gm . $mod . $gd;
}