Source for file date_format.php

Documentation is available at date_format.php

  1. <?php
  2.  
  3. /**
  4.  * Formats a date
  5.  * <pre>
  6.  *  * value : the date, as a unix timestamp, mysql datetime or whatever strtotime() can parse
  7.  *  * format : output format, see {@link http://php.net/strftime} for details
  8.  *  * default : a default timestamp value, if the first one is empty
  9.  * </pre>
  10.  * This software is provided 'as-is', without any express or implied warranty.
  11.  * In no event will the authors be held liable for any damages arising from the use of this software.
  12.  *
  13.  * This file is released under the LGPL
  14.  * "GNU Lesser General Public License"
  15.  * More information can be found here:
  16.  * {@link http://www.gnu.org/copyleft/lesser.html}
  17.  *
  18.  * @author     Jordi Boggiano <j.boggiano@seld.be>
  19.  * @copyright  Copyright (c) 2008, Jordi Boggiano
  20.  * @license    http://www.gnu.org/copyleft/lesser.html  GNU Lesser General Public License
  21.  * @link       http://dwoo.org/
  22.  * @version    0.9.1
  23.  * @date       2008-05-30
  24.  * @package    Dwoo
  25.  */
  26. function Dwoo_Plugin_date_format(Dwoo $dwoo$value$format='%b %e, %Y'$default=null)
  27. {
  28.     if (!empty($value)) {
  29.         // convert if it's not a valid unix timestamp
  30.         if (preg_match('#^\d{10}$#'$value)===0{
  31.             $value strtotime($value);
  32.         }
  33.     elseif (!empty($default)) {
  34.         // convert if it's not a valid unix timestamp
  35.         if (preg_match('#^\d{10}$#'$default)===0{
  36.             $value strtotime($default);
  37.         else {
  38.             $value $default;
  39.         }
  40.     else {
  41.         return '';
  42.     }
  43.  
  44.     // Credits for that windows compat block to Monte Ohrt who made smarty's date_format plugin
  45.     if (DIRECTORY_SEPARATOR == '\\'{
  46.         $_win_from array('%D',       '%h''%n''%r',          '%R',    '%t''%T');
  47.         $_win_to   array('%m/%d/%y''%b'"\n"'%I:%M:%S %p''%H:%M'"\t"'%H:%M:%S');
  48.         if (strpos($format'%e'!== false{
  49.             $_win_from['%e';
  50.             $_win_to[]   sprintf('%\' 2d'date('j'$value));
  51.         }
  52.         if (strpos($format'%l'!== false{
  53.             $_win_from['%l';
  54.             $_win_to[]   sprintf('%\' 2d'date('h'$value));
  55.         }
  56.         $format str_replace($_win_from$_win_to$format);
  57.     }
  58.     return strftime($format$value);
  59. }

Documentation generated on Sat, 28 Jun 2008 01:38:16 +0200 by phpDocumentor 1.4.0