Skip to content

Instantly share code, notes, and snippets.

@sercanarga
Last active November 10, 2018 19:41
Show Gist options
  • Save sercanarga/9b5e7441cde1583347185341a0353201 to your computer and use it in GitHub Desktop.
Save sercanarga/9b5e7441cde1583347185341a0353201 to your computer and use it in GitHub Desktop.
Miladi Tarihi Hicri Tarihe Çevirme Sınıfı
<?php
class Hicri {
private $hicri;
public function __construct($tarih = false) {
if(!$tarih) $tarih = time();
$this->hicri = $this->donustur($tarih);
}
public function hici_aylar($i) {
static $ay = array("Muharrem", "Safer", "Rebiü’l-Evvel", "Rebiü’l-Ahir", "Cemaziye’l-Evvel", "Cemaziye’l-Ahir", "Recep", "Şaban", "Ramazan", "Sevval", "Zi’l-ka’de", "Zi’l-Hicce");
return $ay[$i-1];
}
private function donustur($tarih = null) {
if ($tarih === null) $tarih = time();
$m = date('m', $tarih);
$d = date('d', $tarih);
$y = date('Y', $tarih);
return $this->hesapla(cal_to_jd(CAL_GREGORIAN, $m, $d, $y));
}
private function hesapla($jd) {
$jd = $jd - 1948440 + 10632;
$n = (int)(($jd - 1) / 10631);
$jd = $jd - 10631 * $n + 354;
$j = ((int)((10985 - $jd) / 5316)) * ((int)(50 * $jd / 17719)) + ((int)($jd / 5670)) * ((int)(43 * $jd / 15238));
$jd = $jd - ((int)((30 - $j) / 15)) * ((int)((17719 * $j) / 50)) - ((int)($j / 16)) * ((int)((15238 * $j) / 43)) + 29;
$m = (int)(24 * $jd / 709);
$d = $jd - (int)(709 * $m / 24);
$y = 30*$n + $j - 30;
return array($m, $d, $y);
}
public function hicri_tarih() {
return $this->hicri[1] . ' ' . $this->hici_aylar($this->hicri[0]) . ' ' . $this->hicri[2];
}
}
$hicri = new Hicri(strtotime(date('d-m-Y')));
echo $hicri->hicri_tarih();
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment