PageRenderTime 389ms CodeModel.GetById 141ms app.highlight 142ms RepoModel.GetById 59ms app.codeStats 2ms

/lib/Zend/Date.php

https://bitbucket.org/andrewjleavitt/magestudy
PHP | 4954 lines | 3070 code | 503 blank | 1381 comment | 643 complexity | a6bbf535dc9ebfd369af332198cdd233 MD5 | raw file

Large files files are truncated, but you can click here to view the full file

   1<?php
   2/**
   3 * Zend Framework
   4 *
   5 * LICENSE
   6 *
   7 * This source file is subject to the new BSD license that is bundled
   8 * with this package in the file LICENSE.txt.
   9 * It is also available through the world-wide-web at this URL:
  10 * http://framework.zend.com/license/new-bsd
  11 * If you did not receive a copy of the license and are unable to
  12 * obtain it through the world-wide-web, please send an email
  13 * to license@zend.com so we can send you a copy immediately.
  14 *
  15 * @category  Zend
  16 * @package   Zend_Date
  17 * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
  18 * @license   http://framework.zend.com/license/new-bsd     New BSD License
  19 * @version   $Id: Date.php 22713 2010-07-29 11:41:56Z thomas $
  20 */
  21
  22/**
  23 * Include needed Date classes
  24 */
  25#require_once 'Zend/Date/DateObject.php';
  26#require_once 'Zend/Locale.php';
  27#require_once 'Zend/Locale/Format.php';
  28#require_once 'Zend/Locale/Math.php';
  29
  30/**
  31 * @category  Zend
  32 * @package   Zend_Date
  33 * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
  34 * @license   http://framework.zend.com/license/new-bsd     New BSD License
  35 */
  36class Zend_Date extends Zend_Date_DateObject
  37{
  38    private $_locale  = null;
  39
  40    // Fractional second variables
  41    private $_fractional = 0;
  42    private $_precision  = 3;
  43
  44    private static $_options = array(
  45        'format_type'  => 'iso',      // format for date strings 'iso' or 'php'
  46        'fix_dst'      => true,       // fix dst on summer/winter time change
  47        'extend_month' => false,      // false - addMonth like SQL, true like excel
  48        'cache'        => null,       // cache to set
  49        'timesync'     => null        // timesync server to set
  50    );
  51
  52    // Class wide Date Constants
  53    const DAY               = 'dd';
  54    const DAY_SHORT         = 'd';
  55    const DAY_SUFFIX        = 'SS';
  56    const DAY_OF_YEAR       = 'D';
  57    const WEEKDAY           = 'EEEE';
  58    const WEEKDAY_SHORT     = 'EEE';
  59    const WEEKDAY_NARROW    = 'E';
  60    const WEEKDAY_NAME      = 'EE';
  61    const WEEKDAY_8601      = 'eee';
  62    const WEEKDAY_DIGIT     = 'e';
  63    const WEEK              = 'ww';
  64    const MONTH             = 'MM';
  65    const MONTH_SHORT       = 'M';
  66    const MONTH_DAYS        = 'ddd';
  67    const MONTH_NAME        = 'MMMM';
  68    const MONTH_NAME_SHORT  = 'MMM';
  69    const MONTH_NAME_NARROW = 'MMMMM';
  70    const YEAR              = 'y';
  71    const YEAR_SHORT        = 'yy';
  72    const YEAR_8601         = 'Y';
  73    const YEAR_SHORT_8601   = 'YY';
  74    const LEAPYEAR          = 'l';
  75    const MERIDIEM          = 'a';
  76    const SWATCH            = 'B';
  77    const HOUR              = 'HH';
  78    const HOUR_SHORT        = 'H';
  79    const HOUR_AM           = 'hh';
  80    const HOUR_SHORT_AM     = 'h';
  81    const MINUTE            = 'mm';
  82    const MINUTE_SHORT      = 'm';
  83    const SECOND            = 'ss';
  84    const SECOND_SHORT      = 's';
  85    const MILLISECOND       = 'S';
  86    const TIMEZONE_NAME     = 'zzzz';
  87    const DAYLIGHT          = 'I';
  88    const GMT_DIFF          = 'Z';
  89    const GMT_DIFF_SEP      = 'ZZZZ';
  90    const TIMEZONE          = 'z';
  91    const TIMEZONE_SECS     = 'X';
  92    const ISO_8601          = 'c';
  93    const RFC_2822          = 'r';
  94    const TIMESTAMP         = 'U';
  95    const ERA               = 'G';
  96    const ERA_NAME          = 'GGGG';
  97    const ERA_NARROW        = 'GGGGG';
  98    const DATES             = 'F';
  99    const DATE_FULL         = 'FFFFF';
 100    const DATE_LONG         = 'FFFF';
 101    const DATE_MEDIUM       = 'FFF';
 102    const DATE_SHORT        = 'FF';
 103    const TIMES             = 'WW';
 104    const TIME_FULL         = 'TTTTT';
 105    const TIME_LONG         = 'TTTT';
 106    const TIME_MEDIUM       = 'TTT';
 107    const TIME_SHORT        = 'TT';
 108    const DATETIME          = 'K';
 109    const DATETIME_FULL     = 'KKKKK';
 110    const DATETIME_LONG     = 'KKKK';
 111    const DATETIME_MEDIUM   = 'KKK';
 112    const DATETIME_SHORT    = 'KK';
 113    const ATOM              = 'OOO';
 114    const COOKIE            = 'CCC';
 115    const RFC_822           = 'R';
 116    const RFC_850           = 'RR';
 117    const RFC_1036          = 'RRR';
 118    const RFC_1123          = 'RRRR';
 119    const RFC_3339          = 'RRRRR';
 120    const RSS               = 'SSS';
 121    const W3C               = 'WWW';
 122
 123    /**
 124     * Generates the standard date object, could be a unix timestamp, localized date,
 125     * string, integer, array and so on. Also parts of dates or time are supported
 126     * Always set the default timezone: http://php.net/date_default_timezone_set
 127     * For example, in your bootstrap: date_default_timezone_set('America/Los_Angeles');
 128     * For detailed instructions please look in the docu.
 129     *
 130     * @param  string|integer|Zend_Date|array  $date    OPTIONAL Date value or value of date part to set
 131     *                                                 ,depending on $part. If null the actual time is set
 132     * @param  string                          $part    OPTIONAL Defines the input format of $date
 133     * @param  string|Zend_Locale              $locale  OPTIONAL Locale for parsing input
 134     * @return Zend_Date
 135     * @throws Zend_Date_Exception
 136     */
 137    public function __construct($date = null, $part = null, $locale = null)
 138    {
 139        if (is_object($date) and !($date instanceof Zend_TimeSync_Protocol) and
 140            !($date instanceof Zend_Date)) {
 141            if ($locale instanceof Zend_Locale) {
 142                $locale = $date;
 143                $date   = null;
 144                $part   = null;
 145            } else {
 146                $date = (string) $date;
 147            }
 148        }
 149
 150        if (($date !== null) and !is_array($date) and !($date instanceof Zend_TimeSync_Protocol) and
 151            !($date instanceof Zend_Date) and !defined($date) and Zend_Locale::isLocale($date, true, false)) {
 152            $locale = $date;
 153            $date   = null;
 154            $part   = null;
 155        } else if (($part !== null) and !defined($part) and Zend_Locale::isLocale($part, true, false)) {
 156            $locale = $part;
 157            $part   = null;
 158        }
 159
 160        $this->setLocale($locale);
 161        if (is_string($date) && ($part === null) && (strlen($date) <= 5)) {
 162            $part = $date;
 163            $date = null;
 164        }
 165
 166        if ($date === null) {
 167            if ($part === null) {
 168                $date = time();
 169            } else if ($part !== self::TIMESTAMP) {
 170                $date = self::now($locale);
 171                $date = $date->get($part);
 172            }
 173        }
 174
 175        if ($date instanceof Zend_TimeSync_Protocol) {
 176            $date = $date->getInfo();
 177            $date = $this->_getTime($date['offset']);
 178            $part = null;
 179        } else if (parent::$_defaultOffset != 0) {
 180            $date = $this->_getTime(parent::$_defaultOffset);
 181        }
 182
 183        // set the timezone and offset for $this
 184        $zone = @date_default_timezone_get();
 185        $this->setTimezone($zone);
 186
 187        // try to get timezone from date-string
 188        if (!is_int($date)) {
 189            $zone = $this->getTimezoneFromString($date);
 190            $this->setTimezone($zone);
 191        }
 192
 193        // set datepart
 194        if (($part !== null && $part !== self::TIMESTAMP) or (!is_numeric($date))) {
 195            // switch off dst handling for value setting
 196            $this->setUnixTimestamp($this->getGmtOffset());
 197            $this->set($date, $part, $this->_locale);
 198
 199            // DST fix
 200            if (is_array($date) === true) {
 201                if (!isset($date['hour'])) {
 202                    $date['hour'] = 0;
 203                }
 204
 205                $hour = $this->toString('H', 'iso', true);
 206                $hour = $date['hour'] - $hour;
 207                switch ($hour) {
 208                    case 1 :
 209                    case -23 :
 210                        $this->addTimestamp(3600);
 211                        break;
 212                    case -1 :
 213                    case 23 :
 214                        $this->subTimestamp(3600);
 215                        break;
 216                    case 2 :
 217                    case -22 :
 218                        $this->addTimestamp(7200);
 219                        break;
 220                    case -2 :
 221                    case 22 :
 222                        $this->subTimestamp(7200);
 223                        break;
 224                }
 225            }
 226        } else {
 227            $this->setUnixTimestamp($date);
 228        }
 229    }
 230
 231    /**
 232     * Sets class wide options, if no option was given, the actual set options will be returned
 233     *
 234     * @param  array  $options  Options to set
 235     * @throws Zend_Date_Exception
 236     * @return Options array if no option was given
 237     */
 238    public static function setOptions(array $options = array())
 239    {
 240        if (empty($options)) {
 241            return self::$_options;
 242        }
 243
 244        foreach ($options as $name => $value) {
 245            $name  = strtolower($name);
 246
 247            if (array_key_exists($name, self::$_options)) {
 248                switch($name) {
 249                    case 'format_type' :
 250                        if ((strtolower($value) != 'php') && (strtolower($value) != 'iso')) {
 251                            #require_once 'Zend/Date/Exception.php';
 252                            throw new Zend_Date_Exception("Unknown format type ($value) for dates, only 'iso' and 'php' supported", 0, null, $value);
 253                        }
 254                        break;
 255                    case 'fix_dst' :
 256                        if (!is_bool($value)) {
 257                            #require_once 'Zend/Date/Exception.php';
 258                            throw new Zend_Date_Exception("'fix_dst' has to be boolean", 0, null, $value);
 259                        }
 260                        break;
 261                    case 'extend_month' :
 262                        if (!is_bool($value)) {
 263                            #require_once 'Zend/Date/Exception.php';
 264                            throw new Zend_Date_Exception("'extend_month' has to be boolean", 0, null, $value);
 265                        }
 266                        break;
 267                    case 'cache' :
 268                        if ($value === null) {
 269                            parent::$_cache = null;
 270                        } else {
 271                            if (!$value instanceof Zend_Cache_Core) {
 272                                #require_once 'Zend/Date/Exception.php';
 273                                throw new Zend_Date_Exception("Instance of Zend_Cache expected");
 274                            }
 275
 276                            parent::$_cache = $value;
 277                            parent::$_cacheTags = Zend_Date_DateObject::_getTagSupportForCache();
 278                            Zend_Locale_Data::setCache($value);
 279                        }
 280                        break;
 281                    case 'timesync' :
 282                        if ($value === null) {
 283                            parent::$_defaultOffset = 0;
 284                        } else {
 285                            if (!$value instanceof Zend_TimeSync_Protocol) {
 286                                #require_once 'Zend/Date/Exception.php';
 287                                throw new Zend_Date_Exception("Instance of Zend_TimeSync expected");
 288                            }
 289
 290                            $date = $value->getInfo();
 291                            parent::$_defaultOffset = $date['offset'];
 292                        }
 293                        break;
 294                }
 295                self::$_options[$name] = $value;
 296            }
 297            else {
 298                #require_once 'Zend/Date/Exception.php';
 299                throw new Zend_Date_Exception("Unknown option: $name = $value");
 300            }
 301        }
 302    }
 303
 304    /**
 305     * Returns this object's internal UNIX timestamp (equivalent to Zend_Date::TIMESTAMP).
 306     * If the timestamp is too large for integers, then the return value will be a string.
 307     * This function does not return the timestamp as an object.
 308     * Use clone() or copyPart() instead.
 309     *
 310     * @return integer|string  UNIX timestamp
 311     */
 312    public function getTimestamp()
 313    {
 314        return $this->getUnixTimestamp();
 315    }
 316
 317    /**
 318     * Returns the calculated timestamp
 319     * HINT: timestamps are always GMT
 320     *
 321     * @param  string                          $calc    Type of calculation to make
 322     * @param  string|integer|array|Zend_Date  $stamp   Timestamp to calculate, when null the actual timestamp is calculated
 323     * @return Zend_Date|integer
 324     * @throws Zend_Date_Exception
 325     */
 326    private function _timestamp($calc, $stamp)
 327    {
 328        if ($stamp instanceof Zend_Date) {
 329            // extract timestamp from object
 330            $stamp = $stamp->getTimestamp();
 331        }
 332
 333        if (is_array($stamp)) {
 334            if (isset($stamp['timestamp']) === true) {
 335                $stamp = $stamp['timestamp'];
 336            } else {
 337                #require_once 'Zend/Date/Exception.php';
 338                throw new Zend_Date_Exception('no timestamp given in array');
 339            }
 340        }
 341
 342        if ($calc === 'set') {
 343            $return = $this->setUnixTimestamp($stamp);
 344        } else {
 345            $return = $this->_calcdetail($calc, $stamp, self::TIMESTAMP, null);
 346        }
 347        if ($calc != 'cmp') {
 348            return $this;
 349        }
 350        return $return;
 351    }
 352
 353    /**
 354     * Sets a new timestamp
 355     *
 356     * @param  integer|string|array|Zend_Date  $timestamp  Timestamp to set
 357     * @return Zend_Date Provides fluid interface
 358     * @throws Zend_Date_Exception
 359     */
 360    public function setTimestamp($timestamp)
 361    {
 362        return $this->_timestamp('set', $timestamp);
 363    }
 364
 365    /**
 366     * Adds a timestamp
 367     *
 368     * @param  integer|string|array|Zend_Date  $timestamp  Timestamp to add
 369     * @return Zend_Date Provides fluid interface
 370     * @throws Zend_Date_Exception
 371     */
 372    public function addTimestamp($timestamp)
 373    {
 374        return $this->_timestamp('add', $timestamp);
 375    }
 376
 377    /**
 378     * Subtracts a timestamp
 379     *
 380     * @param  integer|string|array|Zend_Date  $timestamp  Timestamp to sub
 381     * @return Zend_Date Provides fluid interface
 382     * @throws Zend_Date_Exception
 383     */
 384    public function subTimestamp($timestamp)
 385    {
 386        return $this->_timestamp('sub', $timestamp);
 387    }
 388
 389    /**
 390     * Compares two timestamps, returning the difference as integer
 391     *
 392     * @param  integer|string|array|Zend_Date  $timestamp  Timestamp to compare
 393     * @return integer  0 = equal, 1 = later, -1 = earlier
 394     * @throws Zend_Date_Exception
 395     */
 396    public function compareTimestamp($timestamp)
 397    {
 398        return $this->_timestamp('cmp', $timestamp);
 399    }
 400
 401    /**
 402     * Returns a string representation of the object
 403     * Supported format tokens are:
 404     * G - era, y - year, Y - ISO year, M - month, w - week of year, D - day of year, d - day of month
 405     * E - day of week, e - number of weekday (1-7), h - hour 1-12, H - hour 0-23, m - minute, s - second
 406     * A - milliseconds of day, z - timezone, Z - timezone offset, S - fractional second, a - period of day
 407     *
 408     * Additionally format tokens but non ISO conform are:
 409     * SS - day suffix, eee - php number of weekday(0-6), ddd - number of days per month
 410     * l - Leap year, B - swatch internet time, I - daylight saving time, X - timezone offset in seconds
 411     * r - RFC2822 format, U - unix timestamp
 412     *
 413     * Not supported ISO tokens are
 414     * u - extended year, Q - quarter, q - quarter, L - stand alone month, W - week of month
 415     * F - day of week of month, g - modified julian, c - stand alone weekday, k - hour 0-11, K - hour 1-24
 416     * v - wall zone
 417     *
 418     * @param  string              $format  OPTIONAL Rule for formatting output. If null the default date format is used
 419     * @param  string              $type    OPTIONAL Type for the format string which overrides the standard setting
 420     * @param  string|Zend_Locale  $locale  OPTIONAL Locale for parsing input
 421     * @return string
 422     */
 423    public function toString($format = null, $type = null, $locale = null)
 424    {
 425        if (is_object($format)) {
 426            if ($format instanceof Zend_Locale) {
 427                $locale = $format;
 428                $format = null;
 429            } else {
 430                $format = (string) $format;
 431            }
 432        }
 433
 434        if (is_object($type)) {
 435            if ($type instanceof Zend_Locale) {
 436                $locale = $type;
 437                $type   = null;
 438            } else {
 439                $type = (string) $type;
 440            }
 441        }
 442
 443        if (($format !== null) && !defined($format)
 444            && ($format != 'ee') && ($format != 'ss') && ($format != 'GG') && ($format != 'MM') && ($format != 'EE') && ($format != 'TT')
 445            && Zend_Locale::isLocale($format, null, false)) {
 446            $locale = $format;
 447            $format = null;
 448        }
 449
 450        if (($type !== null) and ($type != 'php') and ($type != 'iso') and
 451            Zend_Locale::isLocale($type, null, false)) {
 452            $locale = $type;
 453            $type = null;
 454        }
 455
 456        if ($locale === null) {
 457            $locale = $this->getLocale();
 458        }
 459
 460        if ($format === null) {
 461            $format = Zend_Locale_Format::getDateFormat($locale) . ' ' . Zend_Locale_Format::getTimeFormat($locale);
 462        } else if (((self::$_options['format_type'] == 'php') && ($type === null)) or ($type == 'php')) {
 463            $format = Zend_Locale_Format::convertPhpToIsoFormat($format);
 464        }
 465
 466        return $this->date($this->_toToken($format, $locale), $this->getUnixTimestamp(), false);
 467    }
 468
 469    /**
 470     * Returns a string representation of the date which is equal with the timestamp
 471     *
 472     * @return string
 473     */
 474    public function __toString()
 475    {
 476        return $this->toString(null, $this->_locale);
 477    }
 478
 479    /**
 480     * Returns a integer representation of the object
 481     * But returns false when the given part is no value f.e. Month-Name
 482     *
 483     * @param  string|integer|Zend_Date  $part  OPTIONAL Defines the date or datepart to return as integer
 484     * @return integer|false
 485     */
 486    public function toValue($part = null)
 487    {
 488        $result = $this->get($part);
 489        if (is_numeric($result)) {
 490          return intval("$result");
 491        } else {
 492          return false;
 493        }
 494    }
 495
 496    /**
 497     * Returns an array representation of the object
 498     *
 499     * @return array
 500     */
 501    public function toArray()
 502    {
 503        return array('day'       => $this->toString(self::DAY_SHORT, 'iso'),
 504                     'month'     => $this->toString(self::MONTH_SHORT, 'iso'),
 505                     'year'      => $this->toString(self::YEAR, 'iso'),
 506                     'hour'      => $this->toString(self::HOUR_SHORT, 'iso'),
 507                     'minute'    => $this->toString(self::MINUTE_SHORT, 'iso'),
 508                     'second'    => $this->toString(self::SECOND_SHORT, 'iso'),
 509                     'timezone'  => $this->toString(self::TIMEZONE, 'iso'),
 510                     'timestamp' => $this->toString(self::TIMESTAMP, 'iso'),
 511                     'weekday'   => $this->toString(self::WEEKDAY_8601, 'iso'),
 512                     'dayofyear' => $this->toString(self::DAY_OF_YEAR, 'iso'),
 513                     'week'      => $this->toString(self::WEEK, 'iso'),
 514                     'gmtsecs'   => $this->toString(self::TIMEZONE_SECS, 'iso'));
 515    }
 516
 517    /**
 518     * Returns a representation of a date or datepart
 519     * This could be for example a localized monthname, the time without date,
 520     * the era or only the fractional seconds. There are about 50 different supported date parts.
 521     * For a complete list of supported datepart values look into the docu
 522     *
 523     * @param  string              $part    OPTIONAL Part of the date to return, if null the timestamp is returned
 524     * @param  string|Zend_Locale  $locale  OPTIONAL Locale for parsing input
 525     * @return string  date or datepart
 526     */
 527    public function get($part = null, $locale = null)
 528    {
 529        if ($locale === null) {
 530            $locale = $this->getLocale();
 531        }
 532
 533        if (($part !== null) && !defined($part)
 534            && ($part != 'ee') && ($part != 'ss') && ($part != 'GG') && ($part != 'MM') && ($part != 'EE') && ($part != 'TT')
 535            && Zend_Locale::isLocale($part, null, false)) {
 536            $locale = $part;
 537            $part = null;
 538        }
 539
 540        if ($part === null) {
 541            $part = self::TIMESTAMP;
 542        } else if (self::$_options['format_type'] == 'php') {
 543            $part = Zend_Locale_Format::convertPhpToIsoFormat($part);
 544        }
 545
 546        return $this->date($this->_toToken($part, $locale), $this->getUnixTimestamp(), false);
 547    }
 548
 549    /**
 550     * Internal method to apply tokens
 551     *
 552     * @param string $part
 553     * @param string $locale
 554     * @return string
 555     */
 556    private function _toToken($part, $locale) {
 557        // get format tokens
 558        $comment = false;
 559        $format  = '';
 560        $orig    = '';
 561        for ($i = 0; isset($part[$i]); ++$i) {
 562            if ($part[$i] == "'") {
 563                $comment = $comment ? false : true;
 564                if (isset($part[$i+1]) && ($part[$i+1] == "'")) {
 565                    $comment = $comment ? false : true;
 566                    $format .= "\\'";
 567                    ++$i;
 568                }
 569
 570                $orig = '';
 571                continue;
 572            }
 573
 574            if ($comment) {
 575                $format .= '\\' . $part[$i];
 576                $orig = '';
 577            } else {
 578                $orig .= $part[$i];
 579                if (!isset($part[$i+1]) || (isset($orig[0]) && ($orig[0] != $part[$i+1]))) {
 580                    $format .= $this->_parseIsoToDate($orig, $locale);
 581                    $orig  = '';
 582                }
 583            }
 584        }
 585
 586        return $format;
 587    }
 588
 589    /**
 590     * Internal parsing method
 591     *
 592     * @param string $token
 593     * @param string $locale
 594     * @return string
 595     */
 596    private function _parseIsoToDate($token, $locale) {
 597        switch($token) {
 598            case self::DAY :
 599                return 'd';
 600                break;
 601
 602            case self::WEEKDAY_SHORT :
 603                $weekday = strtolower($this->date('D', $this->getUnixTimestamp(), false));
 604                $day     = Zend_Locale_Data::getContent($locale, 'day', array('gregorian', 'format', 'wide', $weekday));
 605                return $this->_toComment(iconv_substr($day, 0, 3, 'UTF-8'));
 606                break;
 607
 608            case self::DAY_SHORT :
 609                return 'j';
 610                break;
 611
 612            case self::WEEKDAY :
 613                $weekday = strtolower($this->date('D', $this->getUnixTimestamp(), false));
 614                return $this->_toComment(Zend_Locale_Data::getContent($locale, 'day', array('gregorian', 'format', 'wide', $weekday)));
 615                break;
 616
 617            case self::WEEKDAY_8601 :
 618                return 'N';
 619                break;
 620
 621            case 'ee' :
 622                return $this->_toComment(str_pad($this->date('N', $this->getUnixTimestamp(), false), 2, '0', STR_PAD_LEFT));
 623                break;
 624
 625            case self::DAY_SUFFIX :
 626                return 'S';
 627                break;
 628
 629            case self::WEEKDAY_DIGIT :
 630                return 'w';
 631                break;
 632
 633            case self::DAY_OF_YEAR :
 634                return 'z';
 635                break;
 636
 637            case 'DDD' :
 638                return $this->_toComment(str_pad($this->date('z', $this->getUnixTimestamp(), false), 3, '0', STR_PAD_LEFT));
 639                break;
 640
 641            case 'DD' :
 642                return $this->_toComment(str_pad($this->date('z', $this->getUnixTimestamp(), false), 2, '0', STR_PAD_LEFT));
 643                break;
 644
 645            case self::WEEKDAY_NARROW :
 646            case 'EEEEE' :
 647                $weekday = strtolower($this->date('D', $this->getUnixTimestamp(), false));
 648                $day = Zend_Locale_Data::getContent($locale, 'day', array('gregorian', 'format', 'abbreviated', $weekday));
 649                return $this->_toComment(iconv_substr($day, 0, 1, 'UTF-8'));
 650                break;
 651
 652            case self::WEEKDAY_NAME :
 653                $weekday = strtolower($this->date('D', $this->getUnixTimestamp(), false));
 654                return $this->_toComment(Zend_Locale_Data::getContent($locale, 'day', array('gregorian', 'format', 'abbreviated', $weekday)));
 655                break;
 656
 657            case 'w' :
 658                $week = $this->date('W', $this->getUnixTimestamp(), false);
 659                return $this->_toComment(($week[0] == '0') ? $week[1] : $week);
 660                break;
 661
 662            case self::WEEK :
 663                return 'W';
 664                break;
 665
 666            case self::MONTH_NAME :
 667                $month = $this->date('n', $this->getUnixTimestamp(), false);
 668                return $this->_toComment(Zend_Locale_Data::getContent($locale, 'month', array('gregorian', 'format', 'wide', $month)));
 669                break;
 670
 671            case self::MONTH :
 672                return 'm';
 673                break;
 674
 675            case self::MONTH_NAME_SHORT :
 676                $month = $this->date('n', $this->getUnixTimestamp(), false);
 677                return $this->_toComment(Zend_Locale_Data::getContent($locale, 'month', array('gregorian', 'format', 'abbreviated', $month)));
 678                break;
 679
 680            case self::MONTH_SHORT :
 681                return 'n';
 682                break;
 683
 684            case self::MONTH_DAYS :
 685                return 't';
 686                break;
 687
 688            case self::MONTH_NAME_NARROW :
 689                $month = $this->date('n', $this->getUnixTimestamp(), false);
 690                $mon = Zend_Locale_Data::getContent($locale, 'month', array('gregorian', 'format', 'abbreviated', $month));
 691                return $this->_toComment(iconv_substr($mon, 0, 1, 'UTF-8'));
 692                break;
 693
 694            case self::LEAPYEAR :
 695                return 'L';
 696                break;
 697
 698            case self::YEAR_8601 :
 699                return 'o';
 700                break;
 701
 702            case self::YEAR :
 703                return 'Y';
 704                break;
 705
 706            case self::YEAR_SHORT :
 707                return 'y';
 708                break;
 709
 710            case self::YEAR_SHORT_8601 :
 711                return $this->_toComment(substr($this->date('o', $this->getUnixTimestamp(), false), -2, 2));
 712                break;
 713
 714            case self::MERIDIEM :
 715                $am = $this->date('a', $this->getUnixTimestamp(), false);
 716                if ($am == 'am') {
 717                    return $this->_toComment(Zend_Locale_Data::getContent($locale, 'am'));
 718                }
 719
 720                return $this->_toComment(Zend_Locale_Data::getContent($locale, 'pm'));
 721                break;
 722
 723            case self::SWATCH :
 724                return 'B';
 725                break;
 726
 727            case self::HOUR_SHORT_AM :
 728                return 'g';
 729                break;
 730
 731            case self::HOUR_SHORT :
 732                return 'G';
 733                break;
 734
 735            case self::HOUR_AM :
 736                return 'h';
 737                break;
 738
 739            case self::HOUR :
 740                return 'H';
 741                break;
 742
 743            case self::MINUTE :
 744                return $this->_toComment(str_pad($this->date('i', $this->getUnixTimestamp(), false), 2, '0', STR_PAD_LEFT));
 745                break;
 746
 747            case self::SECOND :
 748                return $this->_toComment(str_pad($this->date('s', $this->getUnixTimestamp(), false), 2, '0', STR_PAD_LEFT));
 749                break;
 750
 751            case self::MINUTE_SHORT :
 752                return 'i';
 753                break;
 754
 755            case self::SECOND_SHORT :
 756                return 's';
 757                break;
 758
 759            case self::MILLISECOND :
 760                return $this->_toComment($this->getMilliSecond());
 761                break;
 762
 763            case self::TIMEZONE_NAME :
 764            case 'vvvv' :
 765                return 'e';
 766                break;
 767
 768            case self::DAYLIGHT :
 769                return 'I';
 770                break;
 771
 772            case self::GMT_DIFF :
 773            case 'ZZ' :
 774            case 'ZZZ' :
 775                return 'O';
 776                break;
 777
 778            case self::GMT_DIFF_SEP :
 779                return 'P';
 780                break;
 781
 782            case self::TIMEZONE :
 783            case 'v' :
 784            case 'zz' :
 785            case 'zzz' :
 786                return 'T';
 787                break;
 788
 789            case self::TIMEZONE_SECS :
 790                return 'Z';
 791                break;
 792
 793            case self::ISO_8601 :
 794                return 'c';
 795                break;
 796
 797            case self::RFC_2822 :
 798                return 'r';
 799                break;
 800
 801            case self::TIMESTAMP :
 802                return 'U';
 803                break;
 804
 805            case self::ERA :
 806            case 'GG' :
 807            case 'GGG' :
 808                $year = $this->date('Y', $this->getUnixTimestamp(), false);
 809                if ($year < 0) {
 810                    return $this->_toComment(Zend_Locale_Data::getContent($locale, 'era', array('gregorian', 'Abbr', '0')));
 811                }
 812
 813                return $this->_toComment(Zend_Locale_Data::getContent($locale, 'era', array('gregorian', 'Abbr', '1')));
 814                break;
 815
 816            case self::ERA_NARROW :
 817                $year = $this->date('Y', $this->getUnixTimestamp(), false);
 818                if ($year < 0) {
 819                    return $this->_toComment(iconv_substr(Zend_Locale_Data::getContent($locale, 'era', array('gregorian', 'Abbr', '0')), 0, 1, 'UTF-8')) . '.';
 820                }
 821
 822                return $this->_toComment(iconv_substr(Zend_Locale_Data::getContent($locale, 'era', array('gregorian', 'Abbr', '1')), 0, 1, 'UTF-8')) . '.';
 823                break;
 824
 825            case self::ERA_NAME :
 826                $year = $this->date('Y', $this->getUnixTimestamp(), false);
 827                if ($year < 0) {
 828                    return $this->_toComment(Zend_Locale_Data::getContent($locale, 'era', array('gregorian', 'Names', '0')));
 829                }
 830
 831                return $this->_toComment(Zend_Locale_Data::getContent($locale, 'era', array('gregorian', 'Names', '1')));
 832                break;
 833
 834            case self::DATES :
 835                return $this->_toToken(Zend_Locale_Format::getDateFormat($locale), $locale);
 836                break;
 837
 838            case self::DATE_FULL :
 839                return $this->_toToken(Zend_Locale_Data::getContent($locale, 'date', array('gregorian', 'full')), $locale);
 840                break;
 841
 842            case self::DATE_LONG :
 843                return $this->_toToken(Zend_Locale_Data::getContent($locale, 'date', array('gregorian', 'long')), $locale);
 844                break;
 845
 846            case self::DATE_MEDIUM :
 847                return $this->_toToken(Zend_Locale_Data::getContent($locale, 'date', array('gregorian', 'medium')), $locale);
 848                break;
 849
 850            case self::DATE_SHORT :
 851                return $this->_toToken(Zend_Locale_Data::getContent($locale, 'date', array('gregorian', 'short')), $locale);
 852                break;
 853
 854            case self::TIMES :
 855                return $this->_toToken(Zend_Locale_Format::getTimeFormat($locale), $locale);
 856                break;
 857
 858            case self::TIME_FULL :
 859                return $this->_toToken(Zend_Locale_Data::getContent($locale, 'time', 'full'), $locale);
 860                break;
 861
 862            case self::TIME_LONG :
 863                return $this->_toToken(Zend_Locale_Data::getContent($locale, 'time', 'long'), $locale);
 864                break;
 865
 866            case self::TIME_MEDIUM :
 867                return $this->_toToken(Zend_Locale_Data::getContent($locale, 'time', 'medium'), $locale);
 868                break;
 869
 870            case self::TIME_SHORT :
 871                return $this->_toToken(Zend_Locale_Data::getContent($locale, 'time', 'short'), $locale);
 872                break;
 873
 874            case self::DATETIME :
 875                return $this->_toToken(Zend_Locale_Format::getDateTimeFormat($locale), $locale);
 876                break;
 877
 878            case self::DATETIME_FULL :
 879                return $this->_toToken(Zend_Locale_Data::getContent($locale, 'datetime', array('gregorian', 'full')), $locale);
 880                break;
 881
 882            case self::DATETIME_LONG :
 883                return $this->_toToken(Zend_Locale_Data::getContent($locale, 'datetime', array('gregorian', 'long')), $locale);
 884                break;
 885
 886            case self::DATETIME_MEDIUM :
 887                return $this->_toToken(Zend_Locale_Data::getContent($locale, 'datetime', array('gregorian', 'medium')), $locale);
 888                break;
 889
 890            case self::DATETIME_SHORT :
 891                return $this->_toToken(Zend_Locale_Data::getContent($locale, 'datetime', array('gregorian', 'short')), $locale);
 892                break;
 893
 894            case self::ATOM :
 895                return 'Y\-m\-d\TH\:i\:sP';
 896                break;
 897
 898            case self::COOKIE :
 899                return 'l\, d\-M\-y H\:i\:s e';
 900                break;
 901
 902            case self::RFC_822 :
 903                return 'D\, d M y H\:i\:s O';
 904                break;
 905
 906            case self::RFC_850 :
 907                return 'l\, d\-M\-y H\:i\:s e';
 908                break;
 909
 910            case self::RFC_1036 :
 911                return 'D\, d M y H\:i\:s O';
 912                break;
 913
 914            case self::RFC_1123 :
 915                return 'D\, d M Y H\:i\:s O';
 916                break;
 917
 918            case self::RFC_3339 :
 919                return 'Y\-m\-d\TH\:i\:sP';
 920                break;
 921
 922            case self::RSS :
 923                return 'D\, d M Y H\:i\:s O';
 924                break;
 925
 926            case self::W3C :
 927                return 'Y\-m\-d\TH\:i\:sP';
 928                break;
 929        }
 930
 931        if ($token == '') {
 932            return '';
 933        }
 934
 935        switch ($token[0]) {
 936            case 'y' :
 937                if ((strlen($token) == 4) && (abs($this->getUnixTimestamp()) <= 0x7FFFFFFF)) {
 938                    return 'Y';
 939                }
 940
 941                $length = iconv_strlen($token, 'UTF-8');
 942                return $this->_toComment(str_pad($this->date('Y', $this->getUnixTimestamp(), false), $length, '0', STR_PAD_LEFT));
 943                break;
 944
 945            case 'Y' :
 946                if ((strlen($token) == 4) && (abs($this->getUnixTimestamp()) <= 0x7FFFFFFF)) {
 947                    return 'o';
 948                }
 949
 950                $length = iconv_strlen($token, 'UTF-8');
 951                return $this->_toComment(str_pad($this->date('o', $this->getUnixTimestamp(), false), $length, '0', STR_PAD_LEFT));
 952                break;
 953
 954            case 'A' :
 955                $length  = iconv_strlen($token, 'UTF-8');
 956                $result  = substr($this->getMilliSecond(), 0, 3);
 957                $result += $this->date('s', $this->getUnixTimestamp(), false) * 1000;
 958                $result += $this->date('i', $this->getUnixTimestamp(), false) * 60000;
 959                $result += $this->date('H', $this->getUnixTimestamp(), false) * 3600000;
 960
 961                return $this->_toComment(str_pad($result, $length, '0', STR_PAD_LEFT));
 962                break;
 963        }
 964
 965        return $this->_toComment($token);
 966    }
 967
 968    /**
 969     * Private function to make a comment of a token
 970     *
 971     * @param string $token
 972     * @return string
 973     */
 974    private function _toComment($token)
 975    {
 976        $token = str_split($token);
 977        $result = '';
 978        foreach ($token as $tok) {
 979            $result .= '\\' . $tok;
 980        }
 981
 982        return $result;
 983    }
 984
 985    /**
 986     * Return digit from standard names (english)
 987     * Faster implementation than locale aware searching
 988     *
 989     * @param  string  $name
 990     * @return integer  Number of this month
 991     * @throws Zend_Date_Exception
 992     */
 993    private function _getDigitFromName($name)
 994    {
 995        switch($name) {
 996            case "Jan":
 997                return 1;
 998
 999            case "Feb":
1000                return 2;
1001
1002            case "Mar":
1003                return 3;
1004
1005            case "Apr":
1006                return 4;
1007
1008            case "May":
1009                return 5;
1010
1011            case "Jun":
1012                return 6;
1013
1014            case "Jul":
1015                return 7;
1016
1017            case "Aug":
1018                return 8;
1019
1020            case "Sep":
1021                return 9;
1022
1023            case "Oct":
1024                return 10;
1025
1026            case "Nov":
1027                return 11;
1028
1029            case "Dec":
1030                return 12;
1031
1032            default:
1033                #require_once 'Zend/Date/Exception.php';
1034                throw new Zend_Date_Exception('Month ($name) is not a known month');
1035        }
1036    }
1037
1038    /**
1039     * Counts the exact year number
1040     * < 70 - 2000 added, >70 < 100 - 1900, others just returned
1041     *
1042     * @param  integer  $value year number
1043     * @return integer  Number of year
1044     */
1045    public static function getFullYear($value)
1046    {
1047        if ($value >= 0) {
1048            if ($value < 70) {
1049                $value += 2000;
1050            } else if ($value < 100) {
1051                $value += 1900;
1052            }
1053        }
1054        return $value;
1055    }
1056
1057    /**
1058     * Sets the given date as new date or a given datepart as new datepart returning the new datepart
1059     * This could be for example a localized dayname, the date without time,
1060     * the month or only the seconds. There are about 50 different supported date parts.
1061     * For a complete list of supported datepart values look into the docu
1062     *
1063     * @param  string|integer|array|Zend_Date  $date    Date or datepart to set
1064     * @param  string                          $part    OPTIONAL Part of the date to set, if null the timestamp is set
1065     * @param  string|Zend_Locale              $locale  OPTIONAL Locale for parsing input
1066     * @return Zend_Date Provides fluid interface
1067     * @throws Zend_Date_Exception
1068     */
1069    public function set($date, $part = null, $locale = null)
1070    {
1071        if (self::$_options['format_type'] == 'php') {
1072            $part = Zend_Locale_Format::convertPhpToIsoFormat($part);
1073        }
1074
1075        $zone = $this->getTimezoneFromString($date);
1076        $this->setTimezone($zone);
1077
1078        $this->_calculate('set', $date, $part, $locale);
1079        return $this;
1080    }
1081
1082    /**
1083     * Adds a date or datepart to the existing date, by extracting $part from $date,
1084     * and modifying this object by adding that part.  The $part is then extracted from
1085     * this object and returned as an integer or numeric string (for large values, or $part's
1086     * corresponding to pre-defined formatted date strings).
1087     * This could be for example a ISO 8601 date, the hour the monthname or only the minute.
1088     * There are about 50 different supported date parts.
1089     * For a complete list of supported datepart values look into the docu.
1090     *
1091     * @param  string|integer|array|Zend_Date  $date    Date or datepart to add
1092     * @param  string                          $part    OPTIONAL Part of the date to add, if null the timestamp is added
1093     * @param  string|Zend_Locale              $locale  OPTIONAL Locale for parsing input
1094     * @return Zend_Date Provides fluid interface
1095     * @throws Zend_Date_Exception
1096     */
1097    public function add($date, $part = self::TIMESTAMP, $locale = null)
1098    {
1099        if (self::$_options['format_type'] == 'php') {
1100            $part = Zend_Locale_Format::convertPhpToIsoFormat($part);
1101        }
1102
1103        $this->_calculate('add', $date, $part, $locale);
1104        return $this;
1105    }
1106
1107    /**
1108     * Subtracts a date from another date.
1109     * This could be for example a RFC2822 date, the time,
1110     * the year or only the timestamp. There are about 50 different supported date parts.
1111     * For a complete list of supported datepart values look into the docu
1112     * Be aware: Adding -2 Months is not equal to Subtracting 2 Months !!!
1113     *
1114     * @param  string|integer|array|Zend_Date  $date    Date or datepart to subtract
1115     * @param  string                          $part    OPTIONAL Part of the date to sub, if null the timestamp is subtracted
1116     * @param  string|Zend_Locale              $locale  OPTIONAL Locale for parsing input
1117     * @return Zend_Date Provides fluid interface
1118     * @throws Zend_Date_Exception
1119     */
1120    public function sub($date, $part = self::TIMESTAMP, $locale = null)
1121    {
1122        if (self::$_options['format_type'] == 'php') {
1123            $part = Zend_Locale_Format::convertPhpToIsoFormat($part);
1124        }
1125
1126        $this->_calculate('sub', $date, $part, $locale);
1127        return $this;
1128    }
1129
1130    /**
1131     * Compares a date or datepart with the existing one.
1132     * Returns -1 if earlier, 0 if equal and 1 if later.
1133     *
1134     * @param  string|integer|array|Zend_Date  $date    Date or datepart to compare with the date object
1135     * @param  string                          $part    OPTIONAL Part of the date to compare, if null the timestamp is subtracted
1136     * @param  string|Zend_Locale              $locale  OPTIONAL Locale for parsing input
1137     * @return integer  0 = equal, 1 = later, -1 = earlier
1138     * @throws Zend_Date_Exception
1139     */
1140    public function compare($date, $part = self::TIMESTAMP, $locale = null)
1141    {
1142        if (self::$_options['format_type'] == 'php') {
1143            $part = Zend_Locale_Format::convertPhpToIsoFormat($part);
1144        }
1145
1146        $compare = $this->_calculate('cmp', $date, $part, $locale);
1147
1148        if ($compare > 0) {
1149            return 1;
1150        } else if ($compare < 0) {
1151            return -1;
1152        }
1153        return 0;
1154    }
1155
1156    /**
1157     * Returns a new instance of Zend_Date with the selected part copied.
1158     * To make an exact copy, use PHP's clone keyword.
1159     * For a complete list of supported date part values look into the docu.
1160     * If a date part is copied, all other date parts are set to standard values.
1161     * For example: If only YEAR is copied, the returned date object is equal to
1162     * 01-01-YEAR 00:00:00 (01-01-1970 00:00:00 is equal to timestamp 0)
1163     * If only HOUR is copied, the returned date object is equal to
1164     * 01-01-1970 HOUR:00:00 (so $this contains a timestamp equal to a timestamp of 0 plus HOUR).
1165     *
1166     * @param  string              $part    Part of the date to compare, if null the timestamp is subtracted
1167     * @param  string|Zend_Locale  $locale  OPTIONAL New object's locale.  No adjustments to timezone are made.
1168     * @return Zend_Date New clone with requested part
1169     */
1170    public function copyPart($part, $locale = null)
1171    {
1172        $clone = clone $this;           // copy all instance variables
1173        $clone->setUnixTimestamp(0);    // except the timestamp
1174        if ($locale != null) {
1175            $clone->setLocale($locale); // set an other locale if selected
1176        }
1177        $clone->set($this, $part);
1178        return $clone;
1179    }
1180
1181    /**
1182     * Internal function, returns the offset of a given timezone
1183     *
1184     * @param string $zone
1185     * @return integer
1186     */
1187    public function getTimezoneFromString($zone)
1188    {
1189        if (is_array($zone)) {
1190            return $this->getTimezone();
1191        }
1192
1193        if ($zone instanceof Zend_Date) {
1194            return $zone->getTimezone();
1195        }
1196
1197        $match = array();
1198        preg_match('/\dZ$/', $zone, $match);
1199        if (!empty($match)) {
1200            return "Etc/UTC";
1201        }
1202
1203        preg_match('/([+-]\d{2}):{0,1}\d{2}/', $zone, $match);
1204        if (!empty($match) and ($match[count($match) - 1] <= 12) and ($match[count($match) - 1] >= -12)) {
1205            $zone = "Etc/GMT";
1206            $zone .= ($match[count($match) - 1] < 0) ? "+" : "-";
1207            $zone .= (int) abs($match[count($match) - 1]);
1208            return $zone;
1209        }
1210
1211        preg_match('/([[:alpha:]\/]{3,30})(?!.*([[:alpha:]\/]{3,30}))/', $zone, $match);
1212        try {
1213            if (!empty($match) and (!is_int($match[count($match) - 1]))) {
1214                $oldzone = $this->getTimezone();
1215                $this->setTimezone($match[count($match) - 1]);
1216                $result = $this->getTimezone();
1217                $this->setTimezone($oldzone);
1218                if ($result !== $oldzone) {
1219                    return $match[count($match) - 1];
1220                }
1221            }
1222        } catch (Exception $e) {
1223            // fall through
1224        }
1225
1226        return $this->getTimezone();
1227    }
1228
1229    /**
1230     * Calculates the date or object
1231     *
1232     * @param  string                    $calc  Calculation to make
1233     * @param  string|integer            $date  Date for calculation
1234     * @param  string|integer            $comp  Second date for calculation
1235     * @param  boolean|integer           $dst   Use dst correction if option is set
1236     * @return integer|string|Zend_Date  new timestamp or Zend_Date depending on calculation
1237     */
1238    private function _assign($calc, $date, $comp = 0, $dst = false)
1239    {
1240        switch ($calc) {
1241            case 'set' :
1242                if (!empty($comp)) {
1243                    $this->setUnixTimestamp(call_user_func(Zend_Locale_Math::$sub, $this->getUnixTimestamp(), $comp));
1244                }
1245                $this->setUnixTimestamp(call_user_func(Zend_Locale_Math::$add, $this->getUnixTimestamp(), $date));
1246                $value = $this->getUnixTimestamp();
1247                break;
1248            case 'add' :
1249                $this->setUnixTimestamp(call_user_func(Zend_Locale_Math::$add, $this->getUnixTimestamp(), $date));
1250                $value = $this->getUnixTimestamp();
1251                break;
1252            case 'sub' :
1253                $this->setUnixTimestamp(call_user_func(Zend_Locale_Math::$sub, $this->getUnixTimestamp(), $date));
1254                $value = $this->getUnixTimestamp();
1255                break;
1256            default :
1257                // cmp - compare
1258                return call_user_func(Zend_Locale_Math::$comp, $comp, $date);
1259                break;
1260        }
1261
1262        // dst-correction if 'fix_dst' = true and dst !== false but only for non UTC and non GMT
1263        if ((self::$_options['fix_dst'] === true) and ($dst !== false) and ($this->_dst === true)) {
1264            $hour = $this->toString(self::HOUR, 'iso');
1265            if ($hour != $dst) {
1266                if (($dst == ($hour + 1)) or ($dst == ($hour - 23))) {
1267                    $value += 3600;
1268                } else if (($dst == ($hour - 1)) or ($dst == ($hour + 23))) {
1269                    $value -= 3600;
1270                }
1271                $this->setUnixTimestamp($value);
1272            }
1273        }
1274        return $this->getUnixTimestamp();
1275    }
1276
1277
1278    /**
1279     * Calculates the date or object
1280     *
1281     * @param  string                          $calc    Calculation to make, one of: 'add'|'sub'|'cmp'|'copy'|'set'
1282     * @param  string|integer|array|Zend_Date  $date    Date or datepart to calculate with
1283     * @param  string                          $part    Part of the date to calculate, if null the timestamp is used
1284     * @param  string|Zend_Locale              $locale  Locale for parsing input
1285     * @return integer|string|Zend_Date        new timestamp
1286     * @throws Zend_Date_Exception
1287     */
1288    private function _calculate($calc, $date, $part, $locale)
1289    {
1290        if ($date === null) {
1291            #require_once 'Zend/Date/Exception.php';
1292            throw new Zend_Date_Exception('parameter $date must be set, null is not allowed');
1293        }
1294
1295        if (($part !== null) && (strlen($part) !== 2) && (Zend_Locale::isLocale($part, null, false))) {
1296            $locale = $part;
1297            $part   = null;
1298        }
1299
1300        if ($locale === null) {
1301            $locale = $this->getLocale();
1302        }
1303
1304        $locale = (string) $locale;
1305
1306        // Create date parts
1307        $year   = $this->toString(self::YEAR, 'iso');
1308        $month  = $this->toString(self::MONTH_SHORT, 'iso');
1309        $day    = $this->toString(self::DAY_SHORT, 'iso');
1310        $hour   = $this->toString(self::HOUR_SHORT, 'iso');
1311        $minute = $this->toString(self::MINUTE_SHORT, 'iso');
1312        $second = $this->toString(self::SECOND_SHORT, 'iso');
1313        // If object extract value
1314        if ($date instanceof Zend_Date) {
1315            $date = $date->toString($part, 'iso', $locale);
1316        }
1317
1318        if (is_array($date) === true) {
1319            if (empty($part) === false) {
1320                switch($part) {
1321                    // Fall through
1322                    case self::DAY:
1323                    case self::DAY_SHORT:
1324                        if (isset($date['day']) === true) {
1325                            $date = $date['day'];
1326                        }
1327                        break;
1328                    // Fall through
1329                    case self::WEEKDAY_SHORT:
1330                    case self::WEEKDAY:
1331                    case self::WEEKDAY_8601:
1332                    case self::WEEKDAY_DIGIT:
1333                    case self::WEEKDAY_NARROW:
1334                    case self::WEEKDAY_NAME:
1335                        if (isset($date['weekday']) === true) {
1336                            $date = $date['weekday'];
1337                            $part = self::WEEKDAY_DIGIT;
1338                        }
1339                        break;
1340                    case self::DAY_OF_YEAR:
1341                        if (isset($date['day_of_year']) === true) {
1342                            $date = $date['day_of_year'];
1343                        }
1344                        break;
1345                    // Fall through
1346                    case self::MONTH:
1347                    case self::MONTH_SHORT:
1348                    case self::MONTH_NAME:
1349                    case self::MONTH_NAME_SHORT:
1350                    case self::MONTH_NAME_NARROW:
1351                        if (isset($date['month']) === true) {
1352                            $date = $date['month'];
1353                        }
1354                        break;
1355                    // Fall through
1356                    case self::YEAR:
1357                    case self::YEAR_SHORT:
1358                    case self::YEAR_8601:
1359                    case self::YEAR_SHORT_8601:
1360                        if (isset($date['year']) === true) {
1361                            $date = $date['year'];
1362          

Large files files are truncated, but you can click here to view the full file