[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

/lib/horde/framework/Horde/Imap/Client/ -> DateTime.php (source)

   1  <?php
   2  /**
   3   * Copyright 2012-2014 Horde LLC (http://www.horde.org/)
   4   *
   5   * See the enclosed file COPYING for license information (LGPL). If you
   6   * did not receive this file, see http://www.horde.org/licenses/lgpl21.
   7   *
   8   * @category  Horde
   9   * @copyright 2012-2014 Horde LLC
  10   * @license   http://www.horde.org/licenses/lgpl21 LGPL 2.1
  11   * @package   Imap_Client
  12   */
  13  
  14  /**
  15   * A wrapper around PHP's native DateTime class that handles improperly
  16   * formatted dates and adds a few features missing from the base object
  17   * (string representation; doesn't fail on bad date input).
  18   *
  19   * @author    Michael Slusarz <slusarz@horde.org>
  20   * @category  Horde
  21   * @copyright 2012-2014 Horde LLC
  22   * @license   http://www.horde.org/licenses/lgpl21 LGPL 2.1
  23   * @package   Imap_Client
  24   */
  25  class Horde_Imap_Client_DateTime extends DateTime
  26  {
  27      /**
  28       */
  29      public function __construct($time = null)
  30      {
  31          $tz = new DateTimeZone('UTC');
  32  
  33          try {
  34              parent::__construct($time, $tz);
  35              return;
  36          } catch (Exception $e) {}
  37  
  38          /* Bug #5717 - Check for UT vs. UTC. */
  39          if (substr(rtrim($time), -3) === ' UT') {
  40              try {
  41                  parent::__construct($time . 'C', $tz);
  42                  return;
  43              } catch (Exception $e) {}
  44          }
  45  
  46          /* Bug #9847 - Catch paranthesized timezone information at end of date
  47           * string. */
  48          $date = preg_replace("/\s*\([^\)]+\)\s*$/", '', $time, -1, $i);
  49          if ($i) {
  50              try {
  51                  parent::__construct($date, $tz);
  52                  return;
  53              } catch (Exception $e) {}
  54          }
  55  
  56          parent::__construct('@-1', $tz);
  57      }
  58  
  59      /**
  60       * String representation: UNIX timestamp.
  61       */
  62      public function __toString()
  63      {
  64          return $this->error()
  65              ? '0'
  66              : $this->format('U');
  67      }
  68  
  69      /**
  70       * Was this an unparseable date?
  71       *
  72       * @return boolean  True if unparseable.
  73       */
  74      public function error()
  75      {
  76          return (intval($this->format('U')) === -1);
  77      }
  78  
  79  }


Generated: Thu Aug 11 10:00:09 2016 Cross-referenced by PHPXref 0.7.1