Ejemplo n.º 1
0
 /**
  * returns a string formatted according to the given format string using the given
  * integer timestamp or the current time if no timestamp is given. In other words, timestamp 
  * is optional and defaults to the value of time(). 
  * 
  * @param $format String date format (see http://php.net/manual/en/function.date.php)
  * @param $timestamp Integer time measured in the number of seconds since the Unix Epoch (January 1 1970 00:00:00 GMT)
  * 
  * @return String Returns the Hijri date according to format and timestamp in Arabic/English
  *
  */
 public static function date($format, $timestamp = 0)
 {
     if ($timestamp === 0) {
         $timestamp = time();
     }
     list($d, $D, $j, $l, $S, $F, $m, $M, $n, $t, $L, $o, $Y, $y, $w, $a, $A, $H, $i, $s, $O) = explode("/", date("d/D/j/l/S/F/m/M/n/t/L/o/Y/y/w/a/A/H/i/s/O", $timestamp));
     extract(Hijri::toHijri($d, $m, $Y));
     $j = $day;
     $t = $ml;
     $L = $ln;
     $d = sprintf("%02d", $day);
     $m = sprintf("%02d", $month);
     $n = $month;
     $Y = $year;
     $y = substr($year, 2);
     $S = substr($j, -1) == 1 ? "st" : (substr($j, -1) == 2 ? "nd" : (substr($j, -1) == 3 ? "rd" : "th"));
     $F = Hijri::getMonthName($n);
     $M = Hijri::getMonthName($n, true);
     $D = Hijri::getDayName($w, true);
     $l = Hijri::getDayName($w);
     $S = "";
     $a = Hijri::getTimeOfDay($a, true);
     $A = Hijri::getTimeOfDay($A);
     $r = "{$D}, {$j} {$M} {$Y} {$H}:{$i}:{$s} {$O}";
     $davars = array("d", "D", "j", "l", "S", "F", "m", "M", "n", "t", "L", "o", "Y", "y", "a", "A", "r");
     $myvars = array($d, "¢", $j, "£", "ç", "¥", $m, "©", $n, $t, $L, $Y, $Y, $y, "ï", "â", "®");
     $format = str_replace($davars, $myvars, $format);
     $date = date($format, $timestamp);
     $date = str_replace(array("¢", "£", "ç", "¥", "©", "ï", "â", "®"), array($D, $l, $S, $F, $M, $a, $A, $r), $date);
     return $date;
 }