DB_Table
[ class tree: DB_Table ] [ index: DB_Table ] [ all elements ]

Source for file Date.php

Documentation is available at Date.php

  1. <?php
  2. /* vim: set expandtab tabstop=4 shiftwidth=4: */
  3. // +----------------------------------------------------------------------+
  4. // | PHP Version 4                                                        |
  5. // +----------------------------------------------------------------------+
  6. // | Copyright (c) 1997-2003 The PHP Group                                |
  7. // +----------------------------------------------------------------------+
  8. // | This source file is subject to version 2.02 of the PHP license,      |
  9. // | that is bundled with this package in the file LICENSE, and is        |
  10. // | available at through the world-wide-web at                           |
  11. // | http://www.php.net/license/2_02.txt.                                 |
  12. // | If you did not receive a copy of the PHP license and are unable to   |
  13. // | obtain it through the world-wide-web, please send a note to          |
  14. // | license@php.net so we can mail you a copy immediately.               |
  15. // +----------------------------------------------------------------------+
  16. // | Authors: Baba Buehler <baba@babaz.com>                               |
  17. // |          Pierre-Alain Joye <pajoye@php.net>                          |
  18. // |                                                                      |
  19. // | Stripped down to two essential methods specially for DB_Table        |
  20. // | under PHP 5.1 by Paul M. Jones <pmjones@php.net>                     |
  21. // +----------------------------------------------------------------------+
  22. //
  23. // $Id: Date.php,v 1.2 2007/03/23 10:41:13 morse Exp $
  24.  
  25. /**
  26.  * Generic date handling class for DB_Table.
  27.  *
  28.  * @category Database
  29.  * @package DB_Table
  30.  * @author Baba Buehler <baba@babaz.com>
  31.  * @access public
  32.  */
  33. class DB_Table_Date {
  34.     
  35.     /**
  36.      * the year
  37.      * @var int 
  38.      */
  39.     var $year;
  40.     /**
  41.      * the month
  42.      * @var int 
  43.      */
  44.     var $month;
  45.     /**
  46.      * the day
  47.      * @var int 
  48.      */
  49.     var $day;
  50.     /**
  51.      * the hour
  52.      * @var int 
  53.      */
  54.     var $hour;
  55.     /**
  56.      * the minute
  57.      * @var int 
  58.      */
  59.     var $minute;
  60.     /**
  61.      * the second
  62.      * @var int 
  63.      */
  64.     var $second;
  65.     /**
  66.      * the parts of a second
  67.      * @var float 
  68.      */
  69.     var $partsecond;
  70.     
  71.     /**
  72.      * Constructor
  73.      *
  74.      * Creates a new DB_Table_Date Object. The date should be near to
  75.      * ISO 8601 format.
  76.      *
  77.      * @access public
  78.      * @param string $date A date in ISO 8601 format.
  79.      */
  80.     function DB_Table_Date($date)
  81.     {
  82.         // This regex is very loose and accepts almost any butchered
  83.         // format you could throw at it.  e.g. 2003-10-07 19:45:15 and
  84.         // 2003-10071945:15 are the same thing in the eyes of this
  85.         // regex, even though the latter is not a valid ISO 8601 date.
  86.         preg_match('/^(\d{4})-?(\d{2})-?(\d{2})([T\s]?(\d{2}):?(\d{2}):?(\d{2})(\.\d+)?(Z|[\+\-]\d{2}:?\d{2})?)?$/i'$date$regs);
  87.         $this->year       = $regs[1];
  88.         $this->month      = $regs[2];
  89.         $this->day        = $regs[3];
  90.         $this->hour       = isset($regs[5])?$regs[5]:0;
  91.         $this->minute     = isset($regs[6])?$regs[6]:0;
  92.         $this->second     = isset($regs[7])?$regs[7]:0;
  93.         $this->partsecond = isset($regs[8])?(float)$regs[8]:(float)0;
  94.  
  95.         // if an offset is defined, convert time to UTC
  96.         // Date currently can't set a timezone only by offset,
  97.         // so it has to store it as UTC
  98.         if (isset($regs[9])) {
  99.             $this->toUTCbyOffset($regs[9]);
  100.         }
  101.     }
  102.     
  103.     
  104.     /**
  105.      *  Date pretty printing, similar to strftime()
  106.      *
  107.      *  Formats the date in the given format, much like
  108.      *  strftime().  Most strftime() options are supported.<br><br>
  109.      *
  110.      *  formatting options:<br><br>
  111.      *
  112.      *  <code>%Y  </code>  year as decimal including century (range 0000 to 9999) <br>
  113.      *  <code>%m  </code>  month as decimal number (range 01 to 12) <br>
  114.      *  <code>%d  </code>  day of month (range 00 to 31) <br>
  115.      *  <code>%H  </code>  hour as decimal number (00 to 23) <br>
  116.      *  <code>%M  </code>  minute as a decimal number (00 to 59) <br>
  117.      *  <code>%S  </code>  seconds as a decimal number (00 to 59) <br>
  118.      *  <code>%%  </code>  literal '%' <br>
  119.      * <br>
  120.      *
  121.      * @access public
  122.      * @param string format the format string for returned date/time
  123.      * @return string date/time in given format
  124.      */
  125.     function format($format)
  126.     {
  127.         $output "";
  128.  
  129.         for($strpos = 0; $strpos strlen($format)$strpos++{
  130.             $char substr($format,$strpos,1);
  131.             if ($char == "%"{
  132.                 $nextchar substr($format,$strpos + 1,1);
  133.                 switch ($nextchar{
  134.                 case "Y":
  135.                     $output .= $this->year;
  136.                     break;
  137.                 case "m":
  138.                     $output .= sprintf("%02d",$this->month);
  139.                     break;
  140.                 case "d":
  141.                     $output .= sprintf("%02d",$this->day);
  142.                     break;
  143.                 case "H":
  144.                     $output .= sprintf("%02d"$this->hour);
  145.                     break;
  146.                 case "M":
  147.                     $output .= sprintf("%02d",$this->minute);
  148.                     break;
  149.                 case "S":
  150.                     $output .= sprintf("%02d"$this->second);
  151.                     break;
  152.                 default:
  153.                     $output .= $char.$nextchar;
  154.                 }
  155.                 $strpos++;
  156.             else {
  157.                 $output .= $char;
  158.             }
  159.         }
  160.         return $output;
  161.  
  162.     }
  163. }
  164.  
  165. ?>

Documentation generated on Mon, 11 Mar 2019 15:06:20 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.