<?php
final class HijriBirthday {
public function convertSolarToLunar($year, $month, $date) {
return HijriConverter::gregorianToHijri($year, $month, $date);
}
}
class HijriConverter {
public static function intPart($float) {
if ($float < -0.0000001) {
return ceil($float - 0.0000001);
}
return floor($float + 0.0000001);
}
public static function gregorianToHijri($y, $m, $d) {
if ($y > 1700) {
if (($y > 1582) || (($y == 1582) && ($m > 10)) ||
(($y == 1582) && ($m == 10) && ($d > 14))) {
$jd = self::intPart(
(1461 * ($y + 4800 + self::intPart(($m - 14) / 12))) / 4
) + self::intPart(
(367 * ($m - 2 - 12 * (self::intPart(($m - 14) / 12)))) / 12
) - self::intPart((3 * (
self::intPart(($y + 4900 + self::intPart(($m - 14) / 12)) / 100)
)) / 4) + $d - 32075;
} else {
$jd = 367 * $y - self::intPart(
(7 * ($y + 5001 + self::intPart(($m - 9) / 7))) / 4
) + self::intPart((275 * $m) / 9) + $d + 1729777;
}
$l = $jd - 1948440 + 10632;
$n = self::intPart(($l - 1) / 10631);
$l = $l - 10631 * $n + 354;
$j = (self::intPart((10985 - $l) / 5316)) *
(self::intPart(( 50 * $l) / 17719)) +
(self::intPart($l / 5670)) * (self::intPart((43 * $l) / 15238));
$l = $l - (self::intPart((30 - $j) / 15)) *
(self::intPart((17719 * $j) / 50)) -
(self::intPart($j / 16)) * (self::intPart((15238 * $j) / 43)) + 29;
$m = self::intPart((24 * $l) / 709);
$d = $l - self::intPart((709 * $m) / 24);
$y = 30 * $n + $j - 30;
if ($d < 10)
$d = "0".$d;
if ($m < 10)
$m = "0".$m;
return array($y, $m, $d);
}
return array();
}
}
function main() {
var_dump((new HijriBirthday)->convertSolarToLunar(1983, (double)31, 7));
var_dump((new HijriBirthday)->convertSolarToLunar(1983, (double)31, 7));
var_dump((new HijriBirthday)->convertSolarToLunar(1983, (double)31, 7));
}
main();
echo "done\n";
- Output for 5.4.0 - 5.4.45, 5.5.24 - 5.5.35, 5.6.8 - 5.6.28, 7.0.0 - 7.0.20, 7.1.0 - 7.1.20, 7.2.0 - 7.2.33, 7.3.16 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
- array(3) {
[0]=>
float(1405)
[1]=>
float(10)
[2]=>
float(20)
}
array(3) {
[0]=>
float(1405)
[1]=>
float(10)
[2]=>
float(20)
}
array(3) {
[0]=>
float(1405)
[1]=>
float(10)
[2]=>
float(20)
}
done
- Output for 5.1.0 - 5.1.6, 5.2.0 - 5.2.17, 5.3.0 - 5.3.29
- Parse error: syntax error, unexpected T_OBJECT_OPERATOR in /in/ospES on line 61
Process exited with code 255. - Output for 5.0.0 - 5.0.5
- Parse error: parse error, unexpected T_OBJECT_OPERATOR in /in/ospES on line 61
Process exited with code 255. - Output for 4.4.2 - 4.4.9
- Parse error: syntax error, unexpected T_CLASS in /in/ospES on line 3
Process exited with code 255. - Output for 4.3.0 - 4.3.1, 4.3.5 - 4.3.11, 4.4.0 - 4.4.1
- Parse error: parse error, unexpected T_CLASS in /in/ospES on line 3
Process exited with code 255. - Output for 4.3.2 - 4.3.4
- Parse error: parse error in /in/ospES on line 3
Process exited with code 255.
preferences:
245.43 ms | 401 KiB | 312 Q