Location: PHPKode > scripts > Gedar Template Engine > gedar-template-engine/gPlugins/gPlugin.fdate.inc.php
<?php
  /**
   * Gedar Template Engine plugin
   * @package Gedar
   * @subpackage plugins
   */

  /**
   * Gedar {fdate} function
   *
   * Type:             function
   * Name:             persian Date
   * Purpose:          change date format from georgen to jalali
   * Syntax            {fdate(date="yyyy-mm-dd" , separator="sep")}
   * Special Thanks:   from farsi project and masoud alinaqian
   *
   * @param array  $params
   * @param object $gedar
   * @return       date in jalali format
   */
function gedar_fdate_excute($params,&$gedar)
{
  $date=$gedar->_getParamValue($params,"date");
  $separator=$gedar->_getParamValue($params,"separator")?
    $gedar->_getParamValue($params,"separator"):
    " / ";
  $return=$gedar->_makeVariable("<?php echo gedar_fdate_do($date,$separator); ?>");
  return $return;
}

function _g_div($a, $b)
{
  return (int) ($a / $b);
} 


function gedar_fdate_do($gregorianDate,$separator)
{
  if (is_array($gregorianDate))
    {
      list($g_y,$g_m,$g_d)=$gregorianDate;
    }
  else
    {
      @list($g_y,$g_m,$g_d)=split('\s|\/|\-',$gregorianDate);
    }
  
  
  $g_days_in_month=array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
  $j_days_in_month=array(31, 31, 31, 31, 31, 31, 30, 30, 30, 30, 30, 29);
  
  $gy = $g_y-1600;
  $gm = $g_m-1;
  $gd = $g_d-1;
  

  $g_day_no = 365*$gy+_g_div($gy+3,4)-_g_div($gy+99,100)+_g_div($gy+399,400);
  
  for ($i=0; $i < $gm; ++$i)
    {
      $g_day_no += $g_days_in_month[$i];
    }
  
  if ($gm>1 && (($gy%4==0 && $gy%100!=0) || ($gy%400==0)))
    {
      /* leap and after Feb */
      ++$g_day_no;
    }
  
  $g_day_no += $gd;
  
  $j_day_no = $g_day_no-79;
  
  $j_np = _g_div($j_day_no, 12053);
  $j_day_no %= 12053;
  
  $jy = 979+33*$j_np+4*_g_div($j_day_no,1461);
  
  $j_day_no %= 1461;
  
  if ($j_day_no >= 366)
    {
      $jy += _g_div($j_day_no-1, 365);
      $j_day_no = ($j_day_no-1)%365;
    }
  
  for ($i = 0; $i < 11 && $j_day_no >= $j_days_in_month[$i]; ++$i)
    {
      $j_day_no -= $j_days_in_month[$i];
    }
  
  $jm = $i+1;
  $jd = $j_day_no+1;
  
  if ($jm<10)
    {
      $jm='0'.$jm;
    }
  
  if ($jd<10)
    {
      $jd='0'.$jd;
    }
  
  return  "$jy".$separator."$jm".$separator."$jd";
  
}
?>
Return current item: Gedar Template Engine