khmer date in php code example
Example: region desktop khmer date
function get_bodithey($year) {
$ahk = get_aharkun($year);
$avml = floor((11 * $ahk + 25) / 692);
$m = $avml + $ahk + 29;
return ($m % 30);
}
function get_avoman($year) {
$ahk = get_aharkun($year);
$avm = (11 * $ahk + 25) % 692;
return $avm;
}
function get_aharkun($ad_year) {
$beyear = get_be_year($ad_year);
$t = $beyear * 292207 + 499;
$ahk = floor($t / 800) + 4;
return $ahk;
}
function kromthupul($be_year) {
$akh = get_akhakun_mod($be_year);
$krom = 800 - $akh;
return $krom;
}
function is_khmer_solar_leap($year) {
$be_year = get_be_year($year);
$krom = kromthupul($be_year);
if ($krom <= 207) return 1;
else return 0;
}
function get_akhakun_mod($be_year) {
$t = $be_year * 292207 + 499;
$ahkmod = $t % 800;
return $ahkmod;
}
function get_bodithey_leap($ad_year) {
$result = 0;
$a = get_avoman($ad_year);
$b = get_bodithey($ad_year);
$bodithey_leap = 0;
if ($b >= 25 || $b <= 5) {
$bodithey_leap = 1;
}
$avoman_leap = 0;
if (is_khmer_solar_leap($ad_year)) {
if ($a <= 126) $avoman_leap = 1;
} else {
if ($a <=137) {
if (get_avoman($ad_year + 1) == 0) {
$avoman_leap = 0;
} else $avoman_leap = 1;
}
}
if ($b == 25) {
$next_b = get_bodithey($ad_year + 1);
if ($next_b == 5) $bodithey_leap = 0;
}
if ($b == 24) {
$next_b = get_bodithey($ad_year + 1);
if ($next_b == 6) $bodithey_leap = 1;
}
if ($bodithey_leap == 1 && $avoman_leap == 1) {
$result = 3;
} else if ($bodithey_leap == 1) {
$result = 1;
} else if ($avoman_leap == 1) {
$result = 2;
} else $result = 0;
return $result;
}
function get_protetin_leap($adyear) {
$b = get_bodithey_leap($adyear);
if ($b == 3) {
return 1;
}
if ($b == 2 || $b == 1) {
return $b;
}
if (get_bodithey_leap($adyear - 1) == 3) {
return 2;
}
return 0;
}