[ PHPXref.com ] [ Generated: Sun Jul 20 20:29:46 2008 ] [ Swat 0.1.8 ]
[ Index ]     [ Variables ]     [ Functions ]     [ Classes ]     [ Constants ]     [ Statistics ]

title

Body

[close]

/Swat/ -> SwatDate.php (source)

   1  <?php
   2  
   3  require_once 'Date.php';
   4  
   5  /**
   6   * Date Tools
   7   *
   8   * @package   Swat
   9   * @copyright 2005 silverorange
  10   * @license   http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
  11   */
  12  class SwatDate extends Date
  13  {
  14      /**
  15       * 07/02/02
  16       */
  17      const DF_MDY                    = 1;
  18  
  19      /**
  20       * 070202
  21       */
  22      const DF_MDY_SHORT              = 2;
  23  
  24      /**
  25       * July 2, 2002
  26       */
  27      const DF_DATE                   = 3;
  28  
  29      /**
  30       * Tuesday, July 2, 2002
  31       */
  32      const DF_DATE_LONG              = 4;
  33  
  34      /**
  35       * July 2, 2002 10:09 AM
  36       */
  37      const DF_DATE_TIME              = 5;
  38  
  39      /**
  40       * Tuesday, July 2, 2002 10:09 AM
  41       */
  42      const DF_DATE_TIME_LONG         = 6;
  43  
  44      /**
  45       * 10:09 AM
  46       */
  47      const DF_TIME                   = 7;
  48  
  49      /**
  50       * Aug 5, 2002
  51       */
  52      const DF_DATE_SHORT             = 8;
  53  
  54      /**
  55       * Aug 5
  56       */
  57      const DF_DATE_SHORT_NOYEAR      = 9;
  58  
  59      /**
  60       * Aug 5, 2002 10:09 AM
  61       */
  62      const DF_DATE_TIME_SHORT        = 10;
  63  
  64      /**
  65       * Aug 5, 10:09 AM
  66       */
  67      const DF_DATE_TIME_SHORT_NOYEAR = 11;
  68  
  69      /**
  70       * August 2002
  71       */
  72      const DF_MY                     = 12;
  73  
  74  	public function __construct($date)
  75      {
  76          parent::Date($date);
  77      }
  78  
  79      /**
  80       * Formats this date given either a format string of a format id
  81       *
  82       * @param mixed $format either a format string or an integer format id.
  83       *
  84       * @return string the formatted date.
  85       */
  86  	public function format($format)
  87      {
  88          if (is_int($format))
  89              $format = self::getFormatById($format);
  90  
  91          return parent::format($format);
  92      }
  93  
  94      /**
  95       * Gets a date format string by id
  96       *
  97       * @param integer $id the id of the format string to retrieve.
  98       *
  99       * @return string the formatting string that was requested.
 100       *
 101       * @throws SwatException
 102       */
 103  	static function getFormatById($id)
 104      {
 105          switch ($id) {
 106          case self::DF_MDY:
 107              return Swat::_('%D');
 108          case self::DF_MDY_SHORT:
 109              return Swat::_('%m%d%y');
 110          case self::DF_DATE:
 111              return Swat::_('%B %e, %Y');
 112          case self::DF_DATE_LONG:
 113              return Swat::_('%A, %B %e, %Y');
 114          case self::DF_DATE_TIME:
 115              return Swat::_('%B %e, %Y %i:%M %p');
 116          case self::DF_DATE_TIME_LONG:
 117              return Swat::_('%A, %B %e, %Y %i:%M %p');
 118          case self::DF_TIME:
 119              return Swat::_('%i:%M %p');
 120          case self::DF_DATE_SHORT:
 121              return Swat::_('%b %e, %Y');
 122          case self::DF_DATE_SHORT_NOYEAR:
 123              return Swat::_('%b %e');
 124          case self::DF_DATE_TIME_SHORT:
 125              return Swat::_('%b %e, %Y %i:%M %p');
 126          case self::DF_DATE_TIME_SHORT_NOYEAR:
 127              return Swat::_('%b %e, %i:%M %p');
 128          case self::DF_MY:
 129              return Swat::_('%B %Y');
 130          default:
 131              throw new Exception("Unknown date format id '$id'.");
 132          }
 133      }
 134  }
 135  
 136  ?>


[ Powered by PHPXref - Served by Debian GNU/Linux ]