Source for file modifier.date_format.php

Documentation is available at modifier.date_format.php

  1. <?php
  2. /**
  3.  * Plugin from smarty project and adapted for jtpl
  4.  * @package    jelix
  5.  * @subpackage jtpl_plugin
  6.  * @author        Smarty team
  7.  * @contributor   Yannick Le Guédart <yannick at over-blog dot com>
  8.  * @copyright  2001-2003 ispi of Lincoln, Inc., Yannick Le Guédart
  9.  * @link http://smarty.php.net/
  10.  * @link http://jelix.org/
  11.  * @licence    GNU Lesser General Public Licence see LICENCE file or http://www.gnu.org/licenses/lgpl.html
  12.  */
  13.  
  14. /**
  15.  * modifier plugin : format a date
  16.  * <pre>
  17.  *  {$mydate|date_format:"%b %e, %Y"}
  18.  * </pre>
  19.  * @param string $string input date string
  20.  * @param string $format strftime format for output
  21.  * @param string $default_date default date if $string is empty
  22.  * @return string|void
  23.  */
  24. function jtpl_modifier_common_date_format( $string, $format="%b %e, %Y",
  25.                                     $default_date=null) {
  26.  
  27.     if (substr(PHP_OS,0,3) == 'WIN') {
  28.         $_win_from = array ('%e',  '%T',       '%D');
  29.         $_win_to   = array ('%#d', '%H:%M:%S', '%m/%d/%y');
  30.         $format    = str_replace($_win_from, $_win_to, $format);
  31.     }
  32.  
  33.     if($string != '') {
  34.         if (is_int($string))
  35.             return strftime($format, $string);
  36.         else
  37.             return strftime($format, strtotime($string));
  38.  
  39.     } elseif (isset($default_date) && $default_date != '') {
  40.  
  41.         return strftime($format, strtotime($default_date));
  42.  
  43.     } else {
  44.  
  45.         return '';
  46.     }
  47. }

Documentation generated on Thu, 22 Mar 2012 22:17:48 +0100 by phpDocumentor 1.4.3