Overview

Packages

  • currencysymbol
  • MAbout
  • Mage
    • Admin
    • Adminhtml
    • AdminNotification
    • Api
    • Api2
    • Authorizenet
    • Backup
    • Bundle
    • Captcha
    • Catalog
    • CatalogIndex
    • CatalogInventory
    • CatalogRule
    • CatalogSearch
    • Centinel
    • Checkout
    • Cms
    • Compiler
    • Connect
    • Contacts
    • Core
    • Cron
    • CurrencySymbol
    • Customer
    • Dataflow
    • Directory
    • DirtectPost
    • Downloadable
    • Eav
    • GiftMessage
    • GoogleAnalytics
    • GoogleBase
    • GoogleCheckout
    • ImportExport
    • Index
    • Install
    • Log
    • Media
    • Newsletter
    • Oauth
    • Page
    • PageCache
    • Paygate
    • Payment
    • Paypal
    • PaypalUk
    • Persistent
    • Poll
    • ProductAlert
    • Rating
    • Reports
    • Review
    • Rss
    • Rule
    • Sales
    • SalesRule
    • Sedfriend
    • Sendfriend
    • Shipping
    • Sitemap
    • Tag
    • Tax
    • Usa
    • Weee
    • Widget
    • Wishlist
    • XmlConnect
  • None
  • Phoenix
    • Moneybookers
  • PHP
  • Zend
    • Date
    • Mime
    • XmlRpc

Classes

  • Zend_Date
  • Overview
  • Package
  • Class
  • Tree
   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:  * This class replaces default Zend_Date because of problem described in Jira ticket MAGE-4872
  32:  * The only difference between current class and original one is overwritten implementation of mktime method
  33:  *
  34:  * @category  Zend
  35:  * @package   Zend_Date
  36:  * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
  37:  * @license   http://framework.zend.com/license/new-bsd     New BSD License
  38:  */
  39: class Zend_Date extends Zend_Date_DateObject
  40: {
  41:     private $_locale  = null;
  42: 
  43:     // Fractional second variables
  44:     private $_fractional = 0;
  45:     private $_precision  = 3;
  46: 
  47:     private static $_options = array(
  48:         'format_type'  => 'iso',      // format for date strings 'iso' or 'php'
  49:         'fix_dst'      => true,       // fix dst on summer/winter time change
  50:         'extend_month' => false,      // false - addMonth like SQL, true like excel
  51:         'cache'        => null,       // cache to set
  52:         'timesync'     => null        // timesync server to set
  53:     );
  54: 
  55:     // Class wide Date Constants
  56:     const DAY               = 'dd';
  57:     const DAY_SHORT         = 'd';
  58:     const DAY_SUFFIX        = 'SS';
  59:     const DAY_OF_YEAR       = 'D';
  60:     const WEEKDAY           = 'EEEE';
  61:     const WEEKDAY_SHORT     = 'EEE';
  62:     const WEEKDAY_NARROW    = 'E';
  63:     const WEEKDAY_NAME      = 'EE';
  64:     const WEEKDAY_8601      = 'eee';
  65:     const WEEKDAY_DIGIT     = 'e';
  66:     const WEEK              = 'ww';
  67:     const MONTH             = 'MM';
  68:     const MONTH_SHORT       = 'M';
  69:     const MONTH_DAYS        = 'ddd';
  70:     const MONTH_NAME        = 'MMMM';
  71:     const MONTH_NAME_SHORT  = 'MMM';
  72:     const MONTH_NAME_NARROW = 'MMMMM';
  73:     const YEAR              = 'y';
  74:     const YEAR_SHORT        = 'yy';
  75:     const YEAR_8601         = 'Y';
  76:     const YEAR_SHORT_8601   = 'YY';
  77:     const LEAPYEAR          = 'l';
  78:     const MERIDIEM          = 'a';
  79:     const SWATCH            = 'B';
  80:     const HOUR              = 'HH';
  81:     const HOUR_SHORT        = 'H';
  82:     const HOUR_AM           = 'hh';
  83:     const HOUR_SHORT_AM     = 'h';
  84:     const MINUTE            = 'mm';
  85:     const MINUTE_SHORT      = 'm';
  86:     const SECOND            = 'ss';
  87:     const SECOND_SHORT      = 's';
  88:     const MILLISECOND       = 'S';
  89:     const TIMEZONE_NAME     = 'zzzz';
  90:     const DAYLIGHT          = 'I';
  91:     const GMT_DIFF          = 'Z';
  92:     const GMT_DIFF_SEP      = 'ZZZZ';
  93:     const TIMEZONE          = 'z';
  94:     const TIMEZONE_SECS     = 'X';
  95:     const ISO_8601          = 'c';
  96:     const RFC_2822          = 'r';
  97:     const TIMESTAMP         = 'U';
  98:     const ERA               = 'G';
  99:     const ERA_NAME          = 'GGGG';
 100:     const ERA_NARROW        = 'GGGGG';
 101:     const DATES             = 'F';
 102:     const DATE_FULL         = 'FFFFF';
 103:     const DATE_LONG         = 'FFFF';
 104:     const DATE_MEDIUM       = 'FFF';
 105:     const DATE_SHORT        = 'FF';
 106:     const TIMES             = 'WW';
 107:     const TIME_FULL         = 'TTTTT';
 108:     const TIME_LONG         = 'TTTT';
 109:     const TIME_MEDIUM       = 'TTT';
 110:     const TIME_SHORT        = 'TT';
 111:     const DATETIME          = 'K';
 112:     const DATETIME_FULL     = 'KKKKK';
 113:     const DATETIME_LONG     = 'KKKK';
 114:     const DATETIME_MEDIUM   = 'KKK';
 115:     const DATETIME_SHORT    = 'KK';
 116:     const ATOM              = 'OOO';
 117:     const COOKIE            = 'CCC';
 118:     const RFC_822           = 'R';
 119:     const RFC_850           = 'RR';
 120:     const RFC_1036          = 'RRR';
 121:     const RFC_1123          = 'RRRR';
 122:     const RFC_3339          = 'RRRRR';
 123:     const RSS               = 'SSS';
 124:     const W3C               = 'WWW';
 125: 
 126:     /**
 127:      * Minimum allowed year value
 128:      */
 129:     const YEAR_MIN_VALUE = -10000;
 130: 
 131:     /**
 132:      * Maximum allowed year value
 133:      */
 134:     const YEAR_MAX_VALUE = 10000;
 135: 
 136:     /**
 137:      * Generates the standard date object, could be a unix timestamp, localized date,
 138:      * string, integer, array and so on. Also parts of dates or time are supported
 139:      * Always set the default timezone: http://php.net/date_default_timezone_set
 140:      * For example, in your bootstrap: date_default_timezone_set('America/Los_Angeles');
 141:      * For detailed instructions please look in the docu.
 142:      *
 143:      * @param  string|integer|Zend_Date|array  $date    OPTIONAL Date value or value of date part to set
 144:      *                                                 ,depending on $part. If null the actual time is set
 145:      * @param  string                          $part    OPTIONAL Defines the input format of $date
 146:      * @param  string|Zend_Locale              $locale  OPTIONAL Locale for parsing input
 147:      * @return Zend_Date
 148:      * @throws Zend_Date_Exception
 149:      */
 150:     public function __construct($date = null, $part = null, $locale = null)
 151:     {
 152:         if (is_object($date) and !($date instanceof Zend_TimeSync_Protocol) and
 153:             !($date instanceof Zend_Date)) {
 154:             if ($locale instanceof Zend_Locale) {
 155:                 $locale = $date;
 156:                 $date   = null;
 157:                 $part   = null;
 158:             } else {
 159:                 $date = (string) $date;
 160:             }
 161:         }
 162: 
 163:         if (($date !== null) and !is_array($date) and !($date instanceof Zend_TimeSync_Protocol) and
 164:             !($date instanceof Zend_Date) and !defined($date) and Zend_Locale::isLocale($date, true, false)) {
 165:             $locale = $date;
 166:             $date   = null;
 167:             $part   = null;
 168:         } else if (($part !== null) and !defined($part) and Zend_Locale::isLocale($part, true, false)) {
 169:             $locale = $part;
 170:             $part   = null;
 171:         }
 172: 
 173:         $this->setLocale($locale);
 174:         if (is_string($date) && ($part === null) && (strlen($date) <= 5)) {
 175:             $part = $date;
 176:             $date = null;
 177:         }
 178: 
 179:         if ($date === null) {
 180:             if ($part === null) {
 181:                 $date = time();
 182:             } else if ($part !== self::TIMESTAMP) {
 183:                 $date = self::now($locale);
 184:                 $date = $date->get($part);
 185:             }
 186:         }
 187: 
 188:         if ($date instanceof Zend_TimeSync_Protocol) {
 189:             $date = $date->getInfo();
 190:             $date = $this->_getTime($date['offset']);
 191:             $part = null;
 192:         } else if (parent::$_defaultOffset != 0) {
 193:             $date = $this->_getTime(parent::$_defaultOffset);
 194:         }
 195: 
 196:         // set the timezone and offset for $this
 197:         $zone = @date_default_timezone_get();
 198:         $this->setTimezone($zone);
 199: 
 200:         // try to get timezone from date-string
 201:         if (!is_int($date)) {
 202:             $zone = $this->getTimezoneFromString($date);
 203:             $this->setTimezone($zone);
 204:         }
 205: 
 206:         // set datepart
 207:         if (($part !== null && $part !== self::TIMESTAMP) or (!is_numeric($date))) {
 208:             // switch off dst handling for value setting
 209:             $this->setUnixTimestamp($this->getGmtOffset());
 210:             $this->set($date, $part, $this->_locale);
 211: 
 212:             // DST fix
 213:             if (is_array($date) === true) {
 214:                 if (!isset($date['hour'])) {
 215:                     $date['hour'] = 0;
 216:                 }
 217: 
 218:                 $hour = $this->toString('H', 'iso', true);
 219:                 $hour = $date['hour'] - $hour;
 220:                 switch ($hour) {
 221:                     case 1 :
 222:                     case -23 :
 223:                         $this->addTimestamp(3600);
 224:                         break;
 225:                     case -1 :
 226:                     case 23 :
 227:                         $this->subTimestamp(3600);
 228:                         break;
 229:                     case 2 :
 230:                     case -22 :
 231:                         $this->addTimestamp(7200);
 232:                         break;
 233:                     case -2 :
 234:                     case 22 :
 235:                         $this->subTimestamp(7200);
 236:                         break;
 237:                 }
 238:             }
 239:         } else {
 240:             $this->setUnixTimestamp($date);
 241:         }
 242:     }
 243: 
 244:     /**
 245:      * Sets class wide options, if no option was given, the actual set options will be returned
 246:      *
 247:      * @param  array  $options  Options to set
 248:      * @throws Zend_Date_Exception
 249:      * @return Options array if no option was given
 250:      */
 251:     public static function setOptions(array $options = array())
 252:     {
 253:         if (empty($options)) {
 254:             return self::$_options;
 255:         }
 256: 
 257:         foreach ($options as $name => $value) {
 258:             $name  = strtolower($name);
 259: 
 260:             if (array_key_exists($name, self::$_options)) {
 261:                 switch($name) {
 262:                     case 'format_type' :
 263:                         if ((strtolower($value) != 'php') && (strtolower($value) != 'iso')) {
 264:                             #require_once 'Zend/Date/Exception.php';
 265:                             throw new Zend_Date_Exception("Unknown format type ($value) for dates, only 'iso' and 'php' supported", 0, null, $value);
 266:                         }
 267:                         break;
 268:                     case 'fix_dst' :
 269:                         if (!is_bool($value)) {
 270:                             #require_once 'Zend/Date/Exception.php';
 271:                             throw new Zend_Date_Exception("'fix_dst' has to be boolean", 0, null, $value);
 272:                         }
 273:                         break;
 274:                     case 'extend_month' :
 275:                         if (!is_bool($value)) {
 276:                             #require_once 'Zend/Date/Exception.php';
 277:                             throw new Zend_Date_Exception("'extend_month' has to be boolean", 0, null, $value);
 278:                         }
 279:                         break;
 280:                     case 'cache' :
 281:                         if ($value === null) {
 282:                             parent::$_cache = null;
 283:                         } else {
 284:                             if (!$value instanceof Zend_Cache_Core) {
 285:                                 #require_once 'Zend/Date/Exception.php';
 286:                                 throw new Zend_Date_Exception("Instance of Zend_Cache expected");
 287:                             }
 288: 
 289:                             parent::$_cache = $value;
 290:                             parent::$_cacheTags = Zend_Date_DateObject::_getTagSupportForCache();
 291:                             Zend_Locale_Data::setCache($value);
 292:                         }
 293:                         break;
 294:                     case 'timesync' :
 295:                         if ($value === null) {
 296:                             parent::$_defaultOffset = 0;
 297:                         } else {
 298:                             if (!$value instanceof Zend_TimeSync_Protocol) {
 299:                                 #require_once 'Zend/Date/Exception.php';
 300:                                 throw new Zend_Date_Exception("Instance of Zend_TimeSync expected");
 301:                             }
 302: 
 303:                             $date = $value->getInfo();
 304:                             parent::$_defaultOffset = $date['offset'];
 305:                         }
 306:                         break;
 307:                 }
 308:                 self::$_options[$name] = $value;
 309:             }
 310:             else {
 311:                 #require_once 'Zend/Date/Exception.php';
 312:                 throw new Zend_Date_Exception("Unknown option: $name = $value");
 313:             }
 314:         }
 315:     }
 316: 
 317:     /**
 318:      * Returns this object's internal UNIX timestamp (equivalent to Zend_Date::TIMESTAMP).
 319:      * If the timestamp is too large for integers, then the return value will be a string.
 320:      * This function does not return the timestamp as an object.
 321:      * Use clone() or copyPart() instead.
 322:      *
 323:      * @return integer|string  UNIX timestamp
 324:      */
 325:     public function getTimestamp()
 326:     {
 327:         return $this->getUnixTimestamp();
 328:     }
 329: 
 330:     /**
 331:      * Returns the calculated timestamp
 332:      * HINT: timestamps are always GMT
 333:      *
 334:      * @param  string                          $calc    Type of calculation to make
 335:      * @param  string|integer|array|Zend_Date  $stamp   Timestamp to calculate, when null the actual timestamp is calculated
 336:      * @return Zend_Date|integer
 337:      * @throws Zend_Date_Exception
 338:      */
 339:     private function _timestamp($calc, $stamp)
 340:     {
 341:         if ($stamp instanceof Zend_Date) {
 342:             // extract timestamp from object
 343:             $stamp = $stamp->getTimestamp();
 344:         }
 345: 
 346:         if (is_array($stamp)) {
 347:             if (isset($stamp['timestamp']) === true) {
 348:                 $stamp = $stamp['timestamp'];
 349:             } else {
 350:                 #require_once 'Zend/Date/Exception.php';
 351:                 throw new Zend_Date_Exception('no timestamp given in array');
 352:             }
 353:         }
 354: 
 355:         if ($calc === 'set') {
 356:             $return = $this->setUnixTimestamp($stamp);
 357:         } else {
 358:             $return = $this->_calcdetail($calc, $stamp, self::TIMESTAMP, null);
 359:         }
 360:         if ($calc != 'cmp') {
 361:             return $this;
 362:         }
 363:         return $return;
 364:     }
 365: 
 366:     /**
 367:      * Sets a new timestamp
 368:      *
 369:      * @param  integer|string|array|Zend_Date  $timestamp  Timestamp to set
 370:      * @return Zend_Date Provides fluid interface
 371:      * @throws Zend_Date_Exception
 372:      */
 373:     public function setTimestamp($timestamp)
 374:     {
 375:         return $this->_timestamp('set', $timestamp);
 376:     }
 377: 
 378:     /**
 379:      * Adds a timestamp
 380:      *
 381:      * @param  integer|string|array|Zend_Date  $timestamp  Timestamp to add
 382:      * @return Zend_Date Provides fluid interface
 383:      * @throws Zend_Date_Exception
 384:      */
 385:     public function addTimestamp($timestamp)
 386:     {
 387:         return $this->_timestamp('add', $timestamp);
 388:     }
 389: 
 390:     /**
 391:      * Subtracts a timestamp
 392:      *
 393:      * @param  integer|string|array|Zend_Date  $timestamp  Timestamp to sub
 394:      * @return Zend_Date Provides fluid interface
 395:      * @throws Zend_Date_Exception
 396:      */
 397:     public function subTimestamp($timestamp)
 398:     {
 399:         return $this->_timestamp('sub', $timestamp);
 400:     }
 401: 
 402:     /**
 403:      * Compares two timestamps, returning the difference as integer
 404:      *
 405:      * @param  integer|string|array|Zend_Date  $timestamp  Timestamp to compare
 406:      * @return integer  0 = equal, 1 = later, -1 = earlier
 407:      * @throws Zend_Date_Exception
 408:      */
 409:     public function compareTimestamp($timestamp)
 410:     {
 411:         return $this->_timestamp('cmp', $timestamp);
 412:     }
 413: 
 414:     /**
 415:      * Returns a string representation of the object
 416:      * Supported format tokens are:
 417:      * G - era, y - year, Y - ISO year, M - month, w - week of year, D - day of year, d - day of month
 418:      * E - day of week, e - number of weekday (1-7), h - hour 1-12, H - hour 0-23, m - minute, s - second
 419:      * A - milliseconds of day, z - timezone, Z - timezone offset, S - fractional second, a - period of day
 420:      *
 421:      * Additionally format tokens but non ISO conform are:
 422:      * SS - day suffix, eee - php number of weekday(0-6), ddd - number of days per month
 423:      * l - Leap year, B - swatch internet time, I - daylight saving time, X - timezone offset in seconds
 424:      * r - RFC2822 format, U - unix timestamp
 425:      *
 426:      * Not supported ISO tokens are
 427:      * u - extended year, Q - quarter, q - quarter, L - stand alone month, W - week of month
 428:      * F - day of week of month, g - modified julian, c - stand alone weekday, k - hour 0-11, K - hour 1-24
 429:      * v - wall zone
 430:      *
 431:      * @param  string              $format  OPTIONAL Rule for formatting output. If null the default date format is used
 432:      * @param  string              $type    OPTIONAL Type for the format string which overrides the standard setting
 433:      * @param  string|Zend_Locale  $locale  OPTIONAL Locale for parsing input
 434:      * @return string
 435:      */
 436:     public function toString($format = null, $type = null, $locale = null)
 437:     {
 438:         if (is_object($format)) {
 439:             if ($format instanceof Zend_Locale) {
 440:                 $locale = $format;
 441:                 $format = null;
 442:             } else {
 443:                 $format = (string) $format;
 444:             }
 445:         }
 446: 
 447:         if (is_object($type)) {
 448:             if ($type instanceof Zend_Locale) {
 449:                 $locale = $type;
 450:                 $type   = null;
 451:             } else {
 452:                 $type = (string) $type;
 453:             }
 454:         }
 455: 
 456:         if (($format !== null) && !defined($format)
 457:             && ($format != 'ee') && ($format != 'ss') && ($format != 'GG') && ($format != 'MM') && ($format != 'EE') && ($format != 'TT')
 458:             && Zend_Locale::isLocale($format, null, false)) {
 459:             $locale = $format;
 460:             $format = null;
 461:         }
 462: 
 463:         if (($type !== null) and ($type != 'php') and ($type != 'iso') and
 464:             Zend_Locale::isLocale($type, null, false)) {
 465:             $locale = $type;
 466:             $type = null;
 467:         }
 468: 
 469:         if ($locale === null) {
 470:             $locale = $this->getLocale();
 471:         }
 472: 
 473:         if ($format === null) {
 474:             $format = Zend_Locale_Format::getDateFormat($locale) . ' ' . Zend_Locale_Format::getTimeFormat($locale);
 475:         } else if (((self::$_options['format_type'] == 'php') && ($type === null)) or ($type == 'php')) {
 476:             $format = Zend_Locale_Format::convertPhpToIsoFormat($format);
 477:         }
 478: 
 479:         return $this->date($this->_toToken($format, $locale), $this->getUnixTimestamp(), false);
 480:     }
 481: 
 482:     /**
 483:      * Returns a string representation of the date which is equal with the timestamp
 484:      *
 485:      * @return string
 486:      */
 487:     public function __toString()
 488:     {
 489:         return $this->toString(null, $this->_locale);
 490:     }
 491: 
 492:     /**
 493:      * Returns a integer representation of the object
 494:      * But returns false when the given part is no value f.e. Month-Name
 495:      *
 496:      * @param  string|integer|Zend_Date  $part  OPTIONAL Defines the date or datepart to return as integer
 497:      * @return integer|false
 498:      */
 499:     public function toValue($part = null)
 500:     {
 501:         $result = $this->get($part);
 502:         if (is_numeric($result)) {
 503:           return intval("$result");
 504:         } else {
 505:           return false;
 506:         }
 507:     }
 508: 
 509:     /**
 510:      * Returns an array representation of the object
 511:      *
 512:      * @return array
 513:      */
 514:     public function toArray()
 515:     {
 516:         return array('day'       => $this->toString(self::DAY_SHORT, 'iso'),
 517:                      'month'     => $this->toString(self::MONTH_SHORT, 'iso'),
 518:                      'year'      => $this->toString(self::YEAR, 'iso'),
 519:                      'hour'      => $this->toString(self::HOUR_SHORT, 'iso'),
 520:                      'minute'    => $this->toString(self::MINUTE_SHORT, 'iso'),
 521:                      'second'    => $this->toString(self::SECOND_SHORT, 'iso'),
 522:                      'timezone'  => $this->toString(self::TIMEZONE, 'iso'),
 523:                      'timestamp' => $this->toString(self::TIMESTAMP, 'iso'),
 524:                      'weekday'   => $this->toString(self::WEEKDAY_8601, 'iso'),
 525:                      'dayofyear' => $this->toString(self::DAY_OF_YEAR, 'iso'),
 526:                      'week'      => $this->toString(self::WEEK, 'iso'),
 527:                      'gmtsecs'   => $this->toString(self::TIMEZONE_SECS, 'iso'));
 528:     }
 529: 
 530:     /**
 531:      * Returns a representation of a date or datepart
 532:      * This could be for example a localized monthname, the time without date,
 533:      * the era or only the fractional seconds. There are about 50 different supported date parts.
 534:      * For a complete list of supported datepart values look into the docu
 535:      *
 536:      * @param  string              $part    OPTIONAL Part of the date to return, if null the timestamp is returned
 537:      * @param  string|Zend_Locale  $locale  OPTIONAL Locale for parsing input
 538:      * @return string  date or datepart
 539:      */
 540:     public function get($part = null, $locale = null)
 541:     {
 542:         if ($locale === null) {
 543:             $locale = $this->getLocale();
 544:         }
 545: 
 546:         if (($part !== null) && !defined($part)
 547:             && ($part != 'ee') && ($part != 'ss') && ($part != 'GG') && ($part != 'MM') && ($part != 'EE') && ($part != 'TT')
 548:             && Zend_Locale::isLocale($part, null, false)) {
 549:             $locale = $part;
 550:             $part = null;
 551:         }
 552: 
 553:         if ($part === null) {
 554:             $part = self::TIMESTAMP;
 555:         } else if (self::$_options['format_type'] == 'php') {
 556:             $part = Zend_Locale_Format::convertPhpToIsoFormat($part);
 557:         }
 558: 
 559:         return $this->date($this->_toToken($part, $locale), $this->getUnixTimestamp(), false);
 560:     }
 561: 
 562:     /**
 563:      * Internal method to apply tokens
 564:      *
 565:      * @param string $part
 566:      * @param string $locale
 567:      * @return string
 568:      */
 569:     private function _toToken($part, $locale) {
 570:         // get format tokens
 571:         $comment = false;
 572:         $format  = '';
 573:         $orig    = '';
 574:         for ($i = 0; isset($part[$i]); ++$i) {
 575:             if ($part[$i] == "'") {
 576:                 $comment = $comment ? false : true;
 577:                 if (isset($part[$i+1]) && ($part[$i+1] == "'")) {
 578:                     $comment = $comment ? false : true;
 579:                     $format .= "\\'";
 580:                     ++$i;
 581:                 }
 582: 
 583:                 $orig = '';
 584:                 continue;
 585:             }
 586: 
 587:             if ($comment) {
 588:                 $format .= '\\' . $part[$i];
 589:                 $orig = '';
 590:             } else {
 591:                 $orig .= $part[$i];
 592:                 if (!isset($part[$i+1]) || (isset($orig[0]) && ($orig[0] != $part[$i+1]))) {
 593:                     $format .= $this->_parseIsoToDate($orig, $locale);
 594:                     $orig  = '';
 595:                 }
 596:             }
 597:         }
 598: 
 599:         return $format;
 600:     }
 601: 
 602:     /**
 603:      * Internal parsing method
 604:      *
 605:      * @param string $token
 606:      * @param string $locale
 607:      * @return string
 608:      */
 609:     private function _parseIsoToDate($token, $locale) {
 610:         switch($token) {
 611:             case self::DAY :
 612:                 return 'd';
 613:                 break;
 614: 
 615:             case self::WEEKDAY_SHORT :
 616:                 $weekday = strtolower($this->date('D', $this->getUnixTimestamp(), false));
 617:                 $day     = Zend_Locale_Data::getContent($locale, 'day', array('gregorian', 'format', 'wide', $weekday));
 618:                 return $this->_toComment(iconv_substr($day, 0, 3, 'UTF-8'));
 619:                 break;
 620: 
 621:             case self::DAY_SHORT :
 622:                 return 'j';
 623:                 break;
 624: 
 625:             case self::WEEKDAY :
 626:                 $weekday = strtolower($this->date('D', $this->getUnixTimestamp(), false));
 627:                 return $this->_toComment(Zend_Locale_Data::getContent($locale, 'day', array('gregorian', 'format', 'wide', $weekday)));
 628:                 break;
 629: 
 630:             case self::WEEKDAY_8601 :
 631:                 return 'N';
 632:                 break;
 633: 
 634:             case 'ee' :
 635:                 return $this->_toComment(str_pad($this->date('N', $this->getUnixTimestamp(), false), 2, '0', STR_PAD_LEFT));
 636:                 break;
 637: 
 638:             case self::DAY_SUFFIX :
 639:                 return 'S';
 640:                 break;
 641: 
 642:             case self::WEEKDAY_DIGIT :
 643:                 return 'w';
 644:                 break;
 645: 
 646:             case self::DAY_OF_YEAR :
 647:                 return 'z';
 648:                 break;
 649: 
 650:             case 'DDD' :
 651:                 return $this->_toComment(str_pad($this->date('z', $this->getUnixTimestamp(), false), 3, '0', STR_PAD_LEFT));
 652:                 break;
 653: 
 654:             case 'DD' :
 655:                 return $this->_toComment(str_pad($this->date('z', $this->getUnixTimestamp(), false), 2, '0', STR_PAD_LEFT));
 656:                 break;
 657: 
 658:             case self::WEEKDAY_NARROW :
 659:             case 'EEEEE' :
 660:                 $weekday = strtolower($this->date('D', $this->getUnixTimestamp(), false));
 661:                 $day = Zend_Locale_Data::getContent($locale, 'day', array('gregorian', 'format', 'abbreviated', $weekday));
 662:                 return $this->_toComment(iconv_substr($day, 0, 1, 'UTF-8'));
 663:                 break;
 664: 
 665:             case self::WEEKDAY_NAME :
 666:                 $weekday = strtolower($this->date('D', $this->getUnixTimestamp(), false));
 667:                 return $this->_toComment(Zend_Locale_Data::getContent($locale, 'day', array('gregorian', 'format', 'abbreviated', $weekday)));
 668:                 break;
 669: 
 670:             case 'w' :
 671:                 $week = $this->date('W', $this->getUnixTimestamp(), false);
 672:                 return $this->_toComment(($week[0] == '0') ? $week[1] : $week);
 673:                 break;
 674: 
 675:             case self::WEEK :
 676:                 return 'W';
 677:                 break;
 678: 
 679:             case self::MONTH_NAME :
 680:                 $month = $this->date('n', $this->getUnixTimestamp(), false);
 681:                 return $this->_toComment(Zend_Locale_Data::getContent($locale, 'month', array('gregorian', 'format', 'wide', $month)));
 682:                 break;
 683: 
 684:             case self::MONTH :
 685:                 return 'm';
 686:                 break;
 687: 
 688:             case self::MONTH_NAME_SHORT :
 689:                 $month = $this->date('n', $this->getUnixTimestamp(), false);
 690:                 return $this->_toComment(Zend_Locale_Data::getContent($locale, 'month', array('gregorian', 'format', 'abbreviated', $month)));
 691:                 break;
 692: 
 693:             case self::MONTH_SHORT :
 694:                 return 'n';
 695:                 break;
 696: 
 697:             case self::MONTH_DAYS :
 698:                 return 't';
 699:                 break;
 700: 
 701:             case self::MONTH_NAME_NARROW :
 702:                 $month = $this->date('n', $this->getUnixTimestamp(), false);
 703:                 $mon = Zend_Locale_Data::getContent($locale, 'month', array('gregorian', 'format', 'abbreviated', $month));
 704:                 return $this->_toComment(iconv_substr($mon, 0, 1, 'UTF-8'));
 705:                 break;
 706: 
 707:             case self::LEAPYEAR :
 708:                 return 'L';
 709:                 break;
 710: 
 711:             case self::YEAR_8601 :
 712:                 return 'o';
 713:                 break;
 714: 
 715:             case self::YEAR :
 716:                 return 'Y';
 717:                 break;
 718: 
 719:             case self::YEAR_SHORT :
 720:                 return 'y';
 721:                 break;
 722: 
 723:             case self::YEAR_SHORT_8601 :
 724:                 return $this->_toComment(substr($this->date('o', $this->getUnixTimestamp(), false), -2, 2));
 725:                 break;
 726: 
 727:             case self::MERIDIEM :
 728:                 $am = $this->date('a', $this->getUnixTimestamp(), false);
 729:                 if ($am == 'am') {
 730:                     return $this->_toComment(Zend_Locale_Data::getContent($locale, 'am'));
 731:                 }
 732: 
 733:                 return $this->_toComment(Zend_Locale_Data::getContent($locale, 'pm'));
 734:                 break;
 735: 
 736:             case self::SWATCH :
 737:                 return 'B';
 738:                 break;
 739: 
 740:             case self::HOUR_SHORT_AM :
 741:                 return 'g';
 742:                 break;
 743: 
 744:             case self::HOUR_SHORT :
 745:                 return 'G';
 746:                 break;
 747: 
 748:             case self::HOUR_AM :
 749:                 return 'h';
 750:                 break;
 751: 
 752:             case self::HOUR :
 753:                 return 'H';
 754:                 break;
 755: 
 756:             case self::MINUTE :
 757:                 return $this->_toComment(str_pad($this->date('i', $this->getUnixTimestamp(), false), 2, '0', STR_PAD_LEFT));
 758:                 break;
 759: 
 760:             case self::SECOND :
 761:                 return $this->_toComment(str_pad($this->date('s', $this->getUnixTimestamp(), false), 2, '0', STR_PAD_LEFT));
 762:                 break;
 763: 
 764:             case self::MINUTE_SHORT :
 765:                 return 'i';
 766:                 break;
 767: 
 768:             case self::SECOND_SHORT :
 769:                 return 's';
 770:                 break;
 771: 
 772:             case self::MILLISECOND :
 773:                 return $this->_toComment($this->getMilliSecond());
 774:                 break;
 775: 
 776:             case self::TIMEZONE_NAME :
 777:             case 'vvvv' :
 778:                 return 'e';
 779:                 break;
 780: 
 781:             case self::DAYLIGHT :
 782:                 return 'I';
 783:                 break;
 784: 
 785:             case self::GMT_DIFF :
 786:             case 'ZZ' :
 787:             case 'ZZZ' :
 788:                 return 'O';
 789:                 break;
 790: 
 791:             case self::GMT_DIFF_SEP :
 792:                 return 'P';
 793:                 break;
 794: 
 795:             case self::TIMEZONE :
 796:             case 'v' :
 797:             case 'zz' :
 798:             case 'zzz' :
 799:                 return 'T';
 800:                 break;
 801: 
 802:             case self::TIMEZONE_SECS :
 803:                 return 'Z';
 804:                 break;
 805: 
 806:             case self::ISO_8601 :
 807:                 return 'c';
 808:                 break;
 809: 
 810:             case self::RFC_2822 :
 811:                 return 'r';
 812:                 break;
 813: 
 814:             case self::TIMESTAMP :
 815:                 return 'U';
 816:                 break;
 817: 
 818:             case self::ERA :
 819:             case 'GG' :
 820:             case 'GGG' :
 821:                 $year = $this->date('Y', $this->getUnixTimestamp(), false);
 822:                 if ($year < 0) {
 823:                     return $this->_toComment(Zend_Locale_Data::getContent($locale, 'era', array('gregorian', 'Abbr', '0')));
 824:                 }
 825: 
 826:                 return $this->_toComment(Zend_Locale_Data::getContent($locale, 'era', array('gregorian', 'Abbr', '1')));
 827:                 break;
 828: 
 829:             case self::ERA_NARROW :
 830:                 $year = $this->date('Y', $this->getUnixTimestamp(), false);
 831:                 if ($year < 0) {
 832:                     return $this->_toComment(iconv_substr(Zend_Locale_Data::getContent($locale, 'era', array('gregorian', 'Abbr', '0')), 0, 1, 'UTF-8')) . '.';
 833:                 }
 834: 
 835:                 return $this->_toComment(iconv_substr(Zend_Locale_Data::getContent($locale, 'era', array('gregorian', 'Abbr', '1')), 0, 1, 'UTF-8')) . '.';
 836:                 break;
 837: 
 838:             case self::ERA_NAME :
 839:                 $year = $this->date('Y', $this->getUnixTimestamp(), false);
 840:                 if ($year < 0) {
 841:                     return $this->_toComment(Zend_Locale_Data::getContent($locale, 'era', array('gregorian', 'Names', '0')));
 842:                 }
 843: 
 844:                 return $this->_toComment(Zend_Locale_Data::getContent($locale, 'era', array('gregorian', 'Names', '1')));
 845:                 break;
 846: 
 847:             case self::DATES :
 848:                 return $this->_toToken(Zend_Locale_Format::getDateFormat($locale), $locale);
 849:                 break;
 850: 
 851:             case self::DATE_FULL :
 852:                 return $this->_toToken(Zend_Locale_Data::getContent($locale, 'date', array('gregorian', 'full')), $locale);
 853:                 break;
 854: 
 855:             case self::DATE_LONG :
 856:                 return $this->_toToken(Zend_Locale_Data::getContent($locale, 'date', array('gregorian', 'long')), $locale);
 857:                 break;
 858: 
 859:             case self::DATE_MEDIUM :
 860:                 return $this->_toToken(Zend_Locale_Data::getContent($locale, 'date', array('gregorian', 'medium')), $locale);
 861:                 break;
 862: 
 863:             case self::DATE_SHORT :
 864:                 return $this->_toToken(Zend_Locale_Data::getContent($locale, 'date', array('gregorian', 'short')), $locale);
 865:                 break;
 866: 
 867:             case self::TIMES :
 868:                 return $this->_toToken(Zend_Locale_Format::getTimeFormat($locale), $locale);
 869:                 break;
 870: 
 871:             case self::TIME_FULL :
 872:                 return $this->_toToken(Zend_Locale_Data::getContent($locale, 'time', 'full'), $locale);
 873:                 break;
 874: 
 875:             case self::TIME_LONG :
 876:                 return $this->_toToken(Zend_Locale_Data::getContent($locale, 'time', 'long'), $locale);
 877:                 break;
 878: 
 879:             case self::TIME_MEDIUM :
 880:                 return $this->_toToken(Zend_Locale_Data::getContent($locale, 'time', 'medium'), $locale);
 881:                 break;
 882: 
 883:             case self::TIME_SHORT :
 884:                 return $this->_toToken(Zend_Locale_Data::getContent($locale, 'time', 'short'), $locale);
 885:                 break;
 886: 
 887:             case self::DATETIME :
 888:                 return $this->_toToken(Zend_Locale_Format::getDateTimeFormat($locale), $locale);
 889:                 break;
 890: 
 891:             case self::DATETIME_FULL :
 892:                 return $this->_toToken(Zend_Locale_Data::getContent($locale, 'datetime', array('gregorian', 'full')), $locale);
 893:                 break;
 894: 
 895:             case self::DATETIME_LONG :
 896:                 return $this->_toToken(Zend_Locale_Data::getContent($locale, 'datetime', array('gregorian', 'long')), $locale);
 897:                 break;
 898: 
 899:             case self::DATETIME_MEDIUM :
 900:                 return $this->_toToken(Zend_Locale_Data::getContent($locale, 'datetime', array('gregorian', 'medium')), $locale);
 901:                 break;
 902: 
 903:             case self::DATETIME_SHORT :
 904:                 return $this->_toToken(Zend_Locale_Data::getContent($locale, 'datetime', array('gregorian', 'short')), $locale);
 905:                 break;
 906: 
 907:             case self::ATOM :
 908:                 return 'Y\-m\-d\TH\:i\:sP';
 909:                 break;
 910: 
 911:             case self::COOKIE :
 912:                 return 'l\, d\-M\-y H\:i\:s e';
 913:                 break;
 914: 
 915:             case self::RFC_822 :
 916:                 return 'D\, d M y H\:i\:s O';
 917:                 break;
 918: 
 919:             case self::RFC_850 :
 920:                 return 'l\, d\-M\-y H\:i\:s e';
 921:                 break;
 922: 
 923:             case self::RFC_1036 :
 924:                 return 'D\, d M y H\:i\:s O';
 925:                 break;
 926: 
 927:             case self::RFC_1123 :
 928:                 return 'D\, d M Y H\:i\:s O';
 929:                 break;
 930: 
 931:             case self::RFC_3339 :
 932:                 return 'Y\-m\-d\TH\:i\:sP';
 933:                 break;
 934: 
 935:             case self::RSS :
 936:                 return 'D\, d M Y H\:i\:s O';
 937:                 break;
 938: 
 939:             case self::W3C :
 940:                 return 'Y\-m\-d\TH\:i\:sP';
 941:                 break;
 942:         }
 943: 
 944:         if ($token == '') {
 945:             return '';
 946:         }
 947: 
 948:         switch ($token[0]) {
 949:             case 'y' :
 950:                 if ((strlen($token) == 4) && (abs($this->getUnixTimestamp()) <= 0x7FFFFFFF)) {
 951:                     return 'Y';
 952:                 }
 953: 
 954:                 $length = iconv_strlen($token, 'UTF-8');
 955:                 return $this->_toComment(str_pad($this->date('Y', $this->getUnixTimestamp(), false), $length, '0', STR_PAD_LEFT));
 956:                 break;
 957: 
 958:             case 'Y' :
 959:                 if ((strlen($token) == 4) && (abs($this->getUnixTimestamp()) <= 0x7FFFFFFF)) {
 960:                     return 'o';
 961:                 }
 962: 
 963:                 $length = iconv_strlen($token, 'UTF-8');
 964:                 return $this->_toComment(str_pad($this->date('o', $this->getUnixTimestamp(), false), $length, '0', STR_PAD_LEFT));
 965:                 break;
 966: 
 967:             case 'A' :
 968:                 $length  = iconv_strlen($token, 'UTF-8');
 969:                 $result  = substr($this->getMilliSecond(), 0, 3);
 970:                 $result += $this->date('s', $this->getUnixTimestamp(), false) * 1000;
 971:                 $result += $this->date('i', $this->getUnixTimestamp(), false) * 60000;
 972:                 $result += $this->date('H', $this->getUnixTimestamp(), false) * 3600000;
 973: 
 974:                 return $this->_toComment(str_pad($result, $length, '0', STR_PAD_LEFT));
 975:                 break;
 976:         }
 977: 
 978:         return $this->_toComment($token);
 979:     }
 980: 
 981:     /**
 982:      * Private function to make a comment of a token
 983:      *
 984:      * @param string $token
 985:      * @return string
 986:      */
 987:     private function _toComment($token)
 988:     {
 989:         $token = str_split($token);
 990:         $result = '';
 991:         foreach ($token as $tok) {
 992:             $result .= '\\' . $tok;
 993:         }
 994: 
 995:         return $result;
 996:     }
 997: 
 998:     /**
 999:      * Return digit from standard names (english)
1000:      * Faster implementation than locale aware searching
1001:      *
1002:      * @param  string  $name
1003:      * @return integer  Number of this month
1004:      * @throws Zend_Date_Exception
1005:      */
1006:     private function _getDigitFromName($name)
1007:     {
1008:         switch($name) {
1009:             case "Jan":
1010:                 return 1;
1011: 
1012:             case "Feb":
1013:                 return 2;
1014: 
1015:             case "Mar":
1016:                 return 3;
1017: 
1018:             case "Apr":
1019:                 return 4;
1020: 
1021:             case "May":
1022:                 return 5;
1023: 
1024:             case "Jun":
1025:                 return 6;
1026: 
1027:             case "Jul":
1028:                 return 7;
1029: 
1030:             case "Aug":
1031:                 return 8;
1032: 
1033:             case "Sep":
1034:                 return 9;
1035: 
1036:             case "Oct":
1037:                 return 10;
1038: 
1039:             case "Nov":
1040:                 return 11;
1041: 
1042:             case "Dec":
1043:                 return 12;
1044: 
1045:             default:
1046:                 #require_once 'Zend/Date/Exception.php';
1047:                 throw new Zend_Date_Exception('Month ($name) is not a known month');
1048:         }
1049:     }
1050: 
1051:     /**
1052:      * Counts the exact year number
1053:      * < 70 - 2000 added, >70 < 100 - 1900, others just returned
1054:      *
1055:      * @param  integer  $value year number
1056:      * @return integer  Number of year
1057:      */
1058:     public static function getFullYear($value)
1059:     {
1060:         if ($value >= 0) {
1061:             if ($value < 70) {
1062:                 $value += 2000;
1063:             } else if ($value < 100) {
1064:                 $value += 1900;
1065:             }
1066:         }
1067:         return $value;
1068:     }
1069: 
1070:     /**
1071:      * Sets the given date as new date or a given datepart as new datepart returning the new datepart
1072:      * This could be for example a localized dayname, the date without time,
1073:      * the month or only the seconds. There are about 50 different supported date parts.
1074:      * For a complete list of supported datepart values look into the docu
1075:      *
1076:      * @param  string|integer|array|Zend_Date  $date    Date or datepart to set
1077:      * @param  string                          $part    OPTIONAL Part of the date to set, if null the timestamp is set
1078:      * @param  string|Zend_Locale              $locale  OPTIONAL Locale for parsing input
1079:      * @return Zend_Date Provides fluid interface
1080:      * @throws Zend_Date_Exception
1081:      */
1082:     public function set($date, $part = null, $locale = null)
1083:     {
1084:         if (self::$_options['format_type'] == 'php') {
1085:             $part = Zend_Locale_Format::convertPhpToIsoFormat($part);
1086:         }
1087: 
1088:         $zone = $this->getTimezoneFromString($date);
1089:         $this->setTimezone($zone);
1090: 
1091:         $this->_calculate('set', $date, $part, $locale);
1092:         return $this;
1093:     }
1094: 
1095:     /**
1096:      * Adds a date or datepart to the existing date, by extracting $part from $date,
1097:      * and modifying this object by adding that part.  The $part is then extracted from
1098:      * this object and returned as an integer or numeric string (for large values, or $part's
1099:      * corresponding to pre-defined formatted date strings).
1100:      * This could be for example a ISO 8601 date, the hour the monthname or only the minute.
1101:      * There are about 50 different supported date parts.
1102:      * For a complete list of supported datepart values look into the docu.
1103:      *
1104:      * @param  string|integer|array|Zend_Date  $date    Date or datepart to add
1105:      * @param  string                          $part    OPTIONAL Part of the date to add, if null the timestamp is added
1106:      * @param  string|Zend_Locale              $locale  OPTIONAL Locale for parsing input
1107:      * @return Zend_Date Provides fluid interface
1108:      * @throws Zend_Date_Exception
1109:      */
1110:     public function add($date, $part = self::TIMESTAMP, $locale = null)
1111:     {
1112:         if (self::$_options['format_type'] == 'php') {
1113:             $part = Zend_Locale_Format::convertPhpToIsoFormat($part);
1114:         }
1115: 
1116:         $this->_calculate('add', $date, $part, $locale);
1117:         return $this;
1118:     }
1119: 
1120:     /**
1121:      * Subtracts a date from another date.
1122:      * This could be for example a RFC2822 date, the time,
1123:      * the year or only the timestamp. There are about 50 different supported date parts.
1124:      * For a complete list of supported datepart values look into the docu
1125:      * Be aware: Adding -2 Months is not equal to Subtracting 2 Months !!!
1126:      *
1127:      * @param  string|integer|array|Zend_Date  $date    Date or datepart to subtract
1128:      * @param  string                          $part    OPTIONAL Part of the date to sub, if null the timestamp is subtracted
1129:      * @param  string|Zend_Locale              $locale  OPTIONAL Locale for parsing input
1130:      * @return Zend_Date Provides fluid interface
1131:      * @throws Zend_Date_Exception
1132:      */
1133:     public function sub($date, $part = self::TIMESTAMP, $locale = null)
1134:     {
1135:         if (self::$_options['format_type'] == 'php') {
1136:             $part = Zend_Locale_Format::convertPhpToIsoFormat($part);
1137:         }
1138: 
1139:         $this->_calculate('sub', $date, $part, $locale);
1140:         return $this;
1141:     }
1142: 
1143:     /**
1144:      * Compares a date or datepart with the existing one.
1145:      * Returns -1 if earlier, 0 if equal and 1 if later.
1146:      *
1147:      * @param  string|integer|array|Zend_Date  $date    Date or datepart to compare with the date object
1148:      * @param  string                          $part    OPTIONAL Part of the date to compare, if null the timestamp is subtracted
1149:      * @param  string|Zend_Locale              $locale  OPTIONAL Locale for parsing input
1150:      * @return integer  0 = equal, 1 = later, -1 = earlier
1151:      * @throws Zend_Date_Exception
1152:      */
1153:     public function compare($date, $part = self::TIMESTAMP, $locale = null)
1154:     {
1155:         if (self::$_options['format_type'] == 'php') {
1156:             $part = Zend_Locale_Format::convertPhpToIsoFormat($part);
1157:         }
1158: 
1159:         $compare = $this->_calculate('cmp', $date, $part, $locale);
1160: 
1161:         if ($compare > 0) {
1162:             return 1;
1163:         } else if ($compare < 0) {
1164:             return -1;
1165:         }
1166:         return 0;
1167:     }
1168: 
1169:     /**
1170:      * Returns a new instance of Zend_Date with the selected part copied.
1171:      * To make an exact copy, use PHP's clone keyword.
1172:      * For a complete list of supported date part values look into the docu.
1173:      * If a date part is copied, all other date parts are set to standard values.
1174:      * For example: If only YEAR is copied, the returned date object is equal to
1175:      * 01-01-YEAR 00:00:00 (01-01-1970 00:00:00 is equal to timestamp 0)
1176:      * If only HOUR is copied, the returned date object is equal to
1177:      * 01-01-1970 HOUR:00:00 (so $this contains a timestamp equal to a timestamp of 0 plus HOUR).
1178:      *
1179:      * @param  string              $part    Part of the date to compare, if null the timestamp is subtracted
1180:      * @param  string|Zend_Locale  $locale  OPTIONAL New object's locale.  No adjustments to timezone are made.
1181:      * @return Zend_Date New clone with requested part
1182:      */
1183:     public function copyPart($part, $locale = null)
1184:     {
1185:         $clone = clone $this;           // copy all instance variables
1186:         $clone->setUnixTimestamp(0);    // except the timestamp
1187:         if ($locale != null) {
1188:             $clone->setLocale($locale); // set an other locale if selected
1189:         }
1190:         $clone->set($this, $part);
1191:         return $clone;
1192:     }
1193: 
1194:     /**
1195:      * Internal function, returns the offset of a given timezone
1196:      *
1197:      * @param string $zone
1198:      * @return integer
1199:      */
1200:     public function getTimezoneFromString($zone)
1201:     {
1202:         if (is_array($zone)) {
1203:             return $this->getTimezone();
1204:         }
1205: 
1206:         if ($zone instanceof Zend_Date) {
1207:             return $zone->getTimezone();
1208:         }
1209: 
1210:         $match = array();
1211:         preg_match('/\dZ$/', $zone, $match);
1212:         if (!empty($match)) {
1213:             return "Etc/UTC";
1214:         }
1215: 
1216:         preg_match('/([+-]\d{2}):{0,1}\d{2}/', $zone, $match);
1217:         if (!empty($match) and ($match[count($match) - 1] <= 12) and ($match[count($match) - 1] >= -12)) {
1218:             $zone = "Etc/GMT";
1219:             $zone .= ($match[count($match) - 1] < 0) ? "+" : "-";
1220:             $zone .= (int) abs($match[count($match) - 1]);
1221:             return $zone;
1222:         }
1223: 
1224:         preg_match('/([[:alpha:]\/]{3,30})(?!.*([[:alpha:]\/]{3,30}))/', $zone, $match);
1225:         try {
1226:             if (!empty($match) and (!is_int($match[count($match) - 1]))) {
1227:                 $oldzone = $this->getTimezone();
1228:                 $this->setTimezone($match[count($match) - 1]);
1229:                 $result = $this->getTimezone();
1230:                 $this->setTimezone($oldzone);
1231:                 if ($result !== $oldzone) {
1232:                     return $match[count($match) - 1];
1233:                 }
1234:             }
1235:         } catch (Exception $e) {
1236:             // fall through
1237:         }
1238: 
1239:         return $this->getTimezone();
1240:     }
1241: 
1242:     /**
1243:      * Calculates the date or object
1244:      *
1245:      * @param  string                    $calc  Calculation to make
1246:      * @param  string|integer            $date  Date for calculation
1247:      * @param  string|integer            $comp  Second date for calculation
1248:      * @param  boolean|integer           $dst   Use dst correction if option is set
1249:      * @return integer|string|Zend_Date  new timestamp or Zend_Date depending on calculation
1250:      */
1251:     private function _assign($calc, $date, $comp = 0, $dst = false)
1252:     {
1253:         switch ($calc) {
1254:             case 'set' :
1255:                 if (!empty($comp)) {
1256:                     $this->setUnixTimestamp(call_user_func(Zend_Locale_Math::$sub, $this->getUnixTimestamp(), $comp));
1257:                 }
1258:                 $this->setUnixTimestamp(call_user_func(Zend_Locale_Math::$add, $this->getUnixTimestamp(), $date));
1259:                 $value = $this->getUnixTimestamp();
1260:                 break;
1261:             case 'add' :
1262:                 $this->setUnixTimestamp(call_user_func(Zend_Locale_Math::$add, $this->getUnixTimestamp(), $date));
1263:                 $value = $this->getUnixTimestamp();
1264:                 break;
1265:             case 'sub' :
1266:                 $this->setUnixTimestamp(call_user_func(Zend_Locale_Math::$sub, $this->getUnixTimestamp(), $date));
1267:                 $value = $this->getUnixTimestamp();
1268:                 break;
1269:             default :
1270:                 // cmp - compare
1271:                 return call_user_func(Zend_Locale_Math::$comp, $comp, $date);
1272:                 break;
1273:         }
1274: 
1275:         // dst-correction if 'fix_dst' = true and dst !== false but only for non UTC and non GMT
1276:         if ((self::$_options['fix_dst'] === true) and ($dst !== false) and ($this->_dst === true)) {
1277:             $hour = $this->toString(self::HOUR, 'iso');
1278:             if ($hour != $dst) {
1279:                 if (($dst == ($hour + 1)) or ($dst == ($hour - 23))) {
1280:                     $value += 3600;
1281:                 } else if (($dst == ($hour - 1)) or ($dst == ($hour + 23))) {
1282:                     $value -= 3600;
1283:                 }
1284:                 $this->setUnixTimestamp($value);
1285:             }
1286:         }
1287:         return $this->getUnixTimestamp();
1288:     }
1289: 
1290: 
1291:     /**
1292:      * Calculates the date or object
1293:      *
1294:      * @param  string                          $calc    Calculation to make, one of: 'add'|'sub'|'cmp'|'copy'|'set'
1295:      * @param  string|integer|array|Zend_Date  $date    Date or datepart to calculate with
1296:      * @param  string                          $part    Part of the date to calculate, if null the timestamp is used
1297:      * @param  string|Zend_Locale              $locale  Locale for parsing input
1298:      * @return integer|string|Zend_Date        new timestamp
1299:      * @throws Zend_Date_Exception
1300:      */
1301:     private function _calculate($calc, $date, $part, $locale)
1302:     {
1303:         if ($date === null) {
1304:             #require_once 'Zend/Date/Exception.php';
1305:             throw new Zend_Date_Exception('parameter $date must be set, null is not allowed');
1306:         }
1307: 
1308:         if (($part !== null) && (strlen($part) !== 2) && (Zend_Locale::isLocale($part, null, false))) {
1309:             $locale = $part;
1310:             $part   = null;
1311:         }
1312: 
1313:         if ($locale === null) {
1314:             $locale = $this->getLocale();
1315:         }
1316: 
1317:         $locale = (string) $locale;
1318: 
1319:         // Create date parts
1320:         $year   = $this->toString(self::YEAR, 'iso');
1321:         $month  = $this->toString(self::MONTH_SHORT, 'iso');
1322:         $day    = $this->toString(self::DAY_SHORT, 'iso');
1323:         $hour   = $this->toString(self::HOUR_SHORT, 'iso');
1324:         $minute = $this->toString(self::MINUTE_SHORT, 'iso');
1325:         $second = $this->toString(self::SECOND_SHORT, 'iso');
1326:         // If object extract value
1327:         if ($date instanceof Zend_Date) {
1328:             $date = $date->toString($part, 'iso', $locale);
1329:         }
1330: 
1331:         if (is_array($date) === true) {
1332:             if (empty($part) === false) {
1333:                 switch($part) {
1334:                     // Fall through
1335:                     case self::DAY:
1336:                     case self::DAY_SHORT:
1337:                         if (isset($date['day']) === true) {
1338:                             $date = $date['day'];
1339:                         }
1340:                         break;
1341:                     // Fall through
1342:                     case self::WEEKDAY_SHORT:
1343:                     case self::WEEKDAY:
1344:                     case self::WEEKDAY_8601:
1345:                     case self::WEEKDAY_DIGIT:
1346:                     case self::WEEKDAY_NARROW:
1347:                     case self::WEEKDAY_NAME:
1348:                         if (isset($date['weekday']) === true) {
1349:                             $date = $date['weekday'];
1350:                             $part = self::WEEKDAY_DIGIT;
1351:                         }
1352:                         break;
1353:                     case self::DAY_OF_YEAR:
1354:                         if (isset($date['day_of_year']) === true) {
1355:                             $date = $date['day_of_year'];
1356:                         }
1357:                         break;
1358:                     // Fall through
1359:                     case self::MONTH:
1360:                     case self::MONTH_SHORT:
1361:                     case self::MONTH_NAME:
1362:                     case self::MONTH_NAME_SHORT:
1363:                     case self::MONTH_NAME_NARROW:
1364:                         if (isset($date['month']) === true) {
1365:                             $date = $date['month'];
1366:                         }
1367:                         break;
1368:                     // Fall through
1369:                     case self::YEAR:
1370:                     case self::YEAR_SHORT:
1371:                     case self::YEAR_8601:
1372:                     case self::YEAR_SHORT_8601:
1373:                         if (isset($date['year']) === true) {
1374:                             $date = $date['year'];
1375:                         }
1376:                         break;
1377:                     // Fall through
1378:                     case self::HOUR:
1379:                     case self::HOUR_AM:
1380:                     case self::HOUR_SHORT:
1381:                     case self::HOUR_SHORT_AM:
1382:                         if (isset($date['hour']) === true) {
1383:                             $date = $date['hour'];
1384:                         }
1385:                         break;
1386:                     // Fall through
1387:                     case self::MINUTE:
1388:                     case self::MINUTE_SHORT:
1389:                         if (isset($date['minute']) === true) {
1390:                             $date = $date['minute'];
1391:                         }
1392:                         break;
1393:                     // Fall through
1394:                     case self::SECOND:
1395:                     case self::SECOND_SHORT:
1396:                         if (isset($date['second']) === true) {
1397:                             $date = $date['second'];
1398:                         }
1399:                         break;
1400:                     // Fall through
1401:                     case self::TIMEZONE:
1402:                     case self::TIMEZONE_NAME:
1403:                         if (isset($date['timezone']) === true) {
1404:                             $date = $date['timezone'];
1405:                         }
1406:                         break;
1407:                     case self::TIMESTAMP:
1408:                         if (isset($date['timestamp']) === true) {
1409:                             $date = $date['timestamp'];
1410:                         }
1411:                         break;
1412:                     case self::WEEK:
1413:                         if (isset($date['week']) === true) {
1414:                             $date = $date['week'];
1415:                         }
1416:                         break;
1417:                     case self::TIMEZONE_SECS:
1418:                         if (isset($date['gmtsecs']) === true) {
1419:                             $date = $date['gmtsecs'];
1420:                         }
1421:                         break;
1422:                     default:
1423:                         #require_once 'Zend/Date/Exception.php';
1424:                         throw new Zend_Date_Exception("datepart for part ($part) not found in array");
1425:                         break;
1426:                 }
1427:             } else {
1428:                 $hours = 0;
1429:                 if (isset($date['hour']) === true) {
1430:                     $hours = $date['hour'];
1431:                 }
1432:                 $minutes = 0;
1433:                 if (isset($date['minute']) === true) {
1434:                     $minutes = $date['minute'];
1435:                 }
1436:                 $seconds = 0;
1437:                 if (isset($date['second']) === true) {
1438:                     $seconds = $date['second'];
1439:                 }
1440:                 $months = 0;
1441:                 if (isset($date['month']) === true) {
1442:                     $months = $date['month'];
1443:                 }
1444:                 $days = 0;
1445:                 if (isset($date['day']) === true) {
1446:                     $days = $date['day'];
1447:                 }
1448:                 $years = 0;
1449:                 if (isset($date['year']) === true) {
1450:                     $years = $date['year'];
1451:                 }
1452:                 return $this->_assign($calc, $this->mktime($hours, $minutes, $seconds, $months, $days, $years, true),
1453:                                              $this->mktime($hour, $minute, $second, $month, $day, $year, true), $hour);
1454:             }
1455:         }
1456: 
1457:         // $date as object, part of foreign date as own date
1458:         switch($part) {
1459: 
1460:             // day formats
1461:             case self::DAY:
1462:                 if (is_numeric($date)) {
1463:                     return $this->_assign($calc, $this->mktime(0, 0, 0, 1, 1 + intval($date), 1970, true),
1464:                                                  $this->mktime(0, 0, 0, 1, 1 + intval($day), 1970, true), $hour);
1465:                 }
1466: 
1467:                 #require_once 'Zend/Date/Exception.php';
1468:                 throw new Zend_Date_Exception("invalid date ($date) operand, day expected", 0, null, $date);
1469:                 break;
1470: 
1471:             case self::WEEKDAY_SHORT:
1472:                 $daylist = Zend_Locale_Data::getList($locale, 'day');
1473:                 $weekday = (int) $this->toString(self::WEEKDAY_DIGIT, 'iso', $locale);
1474:                 $cnt = 0;
1475: 
1476:                 foreach ($daylist as $key => $value) {
1477:                     if (strtoupper(iconv_substr($value, 0, 3, 'UTF-8')) == strtoupper($date)) {
1478:                          $found = $cnt;
1479:                         break;
1480:                     }
1481:                     ++$cnt;
1482:                 }
1483: 
1484:                 // Weekday found
1485:                 if ($cnt < 7) {
1486:                     return $this->_assign($calc, $this->mktime(0, 0, 0, 1, 1 + $found, 1970, true),
1487:                                                  $this->mktime(0, 0, 0, 1, 1 + $weekday, 1970, true), $hour);
1488:                 }
1489: 
1490:                 // Weekday not found
1491:                 #require_once 'Zend/Date/Exception.php';
1492:                 throw new Zend_Date_Exception("invalid date ($date) operand, weekday expected", 0, null, $date);
1493:                 break;
1494: 
1495:             case self::DAY_SHORT:
1496:                 if (is_numeric($date)) {
1497:                     return $this->_assign($calc, $this->mktime(0, 0, 0, 1, 1 + intval($date), 1970, true),
1498:                                                  $this->mktime(0, 0, 0, 1, 1 + intval($day), 1970, true), $hour);
1499:                 }
1500: 
1501:                 #require_once 'Zend/Date/Exception.php';
1502:                 throw new Zend_Date_Exception("invalid date ($date) operand, day expected", 0, null, $date);
1503:                 break;
1504: 
1505:             case self::WEEKDAY:
1506:                 $daylist = Zend_Locale_Data::getList($locale, 'day');
1507:                 $weekday = (int) $this->toString(self::WEEKDAY_DIGIT, 'iso', $locale);
1508:                 $cnt = 0;
1509: 
1510:                 foreach ($daylist as $key => $value) {
1511:                     if (strtoupper($value) == strtoupper($date)) {
1512:                         $found = $cnt;
1513:                         break;
1514:                     }
1515:                     ++$cnt;
1516:                 }
1517: 
1518:                 // Weekday found
1519:                 if ($cnt < 7) {
1520:                     return $this->_assign($calc, $this->mktime(0, 0, 0, 1, 1 + $found, 1970, true),
1521:                                                  $this->mktime(0, 0, 0, 1, 1 + $weekday, 1970, true), $hour);
1522:                 }
1523: 
1524:                 // Weekday not found
1525:                 #require_once 'Zend/Date/Exception.php';
1526:                 throw new Zend_Date_Exception("invalid date ($date) operand, weekday expected", 0, null, $date);
1527:                 break;
1528: 
1529:             case self::WEEKDAY_8601:
1530:                 $weekday = (int) $this->toString(self::WEEKDAY_8601, 'iso', $locale);
1531:                 if ((intval($date) > 0) and (intval($date) < 8)) {
1532:                     return $this->_assign($calc, $this->mktime(0, 0, 0, 1, 1 + intval($date), 1970, true),
1533:                                                  $this->mktime(0, 0, 0, 1, 1 + $weekday, 1970, true), $hour);
1534:                 }
1535: 
1536:                 // Weekday not found
1537:                 #require_once 'Zend/Date/Exception.php';
1538:                 throw new Zend_Date_Exception("invalid date ($date) operand, weekday expected", 0, null, $date);
1539:                 break;
1540: 
1541:             case self::DAY_SUFFIX:
1542:                 #require_once 'Zend/Date/Exception.php';
1543:                 throw new Zend_Date_Exception('day suffix not supported', 0, null, $date);
1544:                 break;
1545: 
1546:             case self::WEEKDAY_DIGIT:
1547:                 $weekday = (int) $this->toString(self::WEEKDAY_DIGIT, 'iso', $locale);
1548:                 if (is_numeric($date) and (intval($date) >= 0) and (intval($date) < 7)) {
1549:                     return $this->_assign($calc, $this->mktime(0, 0, 0, 1, 1 + $date, 1970, true),
1550:                                                  $this->mktime(0, 0, 0, 1, 1 + $weekday, 1970, true), $hour);
1551:                 }
1552: 
1553:                 // Weekday not found
1554:                 #require_once 'Zend/Date/Exception.php';
1555:                 throw new Zend_Date_Exception("invalid date ($date) operand, weekday expected", 0, null, $date);
1556:                 break;
1557: 
1558:             case self::DAY_OF_YEAR:
1559:                 if (is_numeric($date)) {
1560:                     if (($calc == 'add') || ($calc == 'sub')) {
1561:                         $year = 1970;
1562:                         ++$date;
1563:                         ++$day;
1564:                     }
1565: 
1566:                     return $this->_assign($calc, $this->mktime(0, 0, 0, 1, $date, $year, true),
1567:                                                  $this->mktime(0, 0, 0, $month, $day, $year, true), $hour);
1568:                 }
1569: 
1570:                 #require_once 'Zend/Date/Exception.php';
1571:                 throw new Zend_Date_Exception("invalid date ($date) operand, day expected", 0, null, $date);
1572:                 break;
1573: 
1574:             case self::WEEKDAY_NARROW:
1575:                 $daylist = Zend_Locale_Data::getList($locale, 'day', array('gregorian', 'format', 'abbreviated'));
1576:                 $weekday = (int) $this->toString(self::WEEKDAY_DIGIT, 'iso', $locale);
1577:                 $cnt = 0;
1578:                 foreach ($daylist as $key => $value) {
1579:                     if (strtoupper(iconv_substr($value, 0, 1, 'UTF-8')) == strtoupper($date)) {
1580:                         $found = $cnt;
1581:                         break;
1582:                     }
1583:                     ++$cnt;
1584:                 }
1585: 
1586:                 // Weekday found
1587:                 if ($cnt < 7) {
1588:                     return $this->_assign($calc, $this->mktime(0, 0, 0, 1, 1 + $found, 1970, true),
1589:                                                  $this->mktime(0, 0, 0, 1, 1 + $weekday, 1970, true), $hour);
1590:                 }
1591: 
1592:                 // Weekday not found
1593:                 #require_once 'Zend/Date/Exception.php';
1594:                 throw new Zend_Date_Exception("invalid date ($date) operand, weekday expected", 0, null, $date);
1595:                 break;
1596: 
1597:             case self::WEEKDAY_NAME:
1598:                 $daylist = Zend_Locale_Data::getList($locale, 'day', array('gregorian', 'format', 'abbreviated'));
1599:                 $weekday = (int) $this->toString(self::WEEKDAY_DIGIT, 'iso', $locale);
1600:                 $cnt = 0;
1601:                 foreach ($daylist as $key => $value) {
1602:                     if (strtoupper($value) == strtoupper($date)) {
1603:                         $found = $cnt;
1604:                         break;
1605:                     }
1606:                     ++$cnt;
1607:                 }
1608: 
1609:                 // Weekday found
1610:                 if ($cnt < 7) {
1611:                     return $this->_assign($calc, $this->mktime(0, 0, 0, 1, 1 + $found, 1970, true),
1612:                                                  $this->mktime(0, 0, 0, 1, 1 + $weekday, 1970, true), $hour);
1613:                 }
1614: 
1615:                 // Weekday not found
1616:                 #require_once 'Zend/Date/Exception.php';
1617:                 throw new Zend_Date_Exception("invalid date ($date) operand, weekday expected", 0, null, $date);
1618:                 break;
1619: 
1620:             // week formats
1621:             case self::WEEK:
1622:                 if (is_numeric($date)) {
1623:                     $week = (int) $this->toString(self::WEEK, 'iso', $locale);
1624:                     return $this->_assign($calc, parent::mktime(0, 0, 0, 1, 1 + ($date * 7), 1970, true),
1625:                                                  parent::mktime(0, 0, 0, 1, 1 + ($week * 7), 1970, true), $hour);
1626:                 }
1627: 
1628:                 #require_once 'Zend/Date/Exception.php';
1629:                 throw new Zend_Date_Exception("invalid date ($date) operand, week expected", 0, null, $date);
1630:                 break;
1631: 
1632:             // month formats
1633:             case self::MONTH_NAME:
1634:                 $monthlist = Zend_Locale_Data::getList($locale, 'month');
1635:                 $cnt = 0;
1636:                 foreach ($monthlist as $key => $value) {
1637:                     if (strtoupper($value) == strtoupper($date)) {
1638:                         $found = $key;
1639:                         break;
1640:                     }
1641:                     ++$cnt;
1642:                 }
1643:                 $date = array_search($date, $monthlist);
1644: 
1645:                 // Monthname found
1646:                 if ($cnt < 12) {
1647:                     $fixday = 0;
1648:                     if ($calc == 'add') {
1649:                         $date += $found;
1650:                         $calc = 'set';
1651:                         if (self::$_options['extend_month'] == false) {
1652:                             $parts = $this->getDateParts($this->mktime($hour, $minute, $second, $date, $day, $year, false));
1653:                             if ($parts['mday'] != $day) {
1654:                                 $fixday = ($parts['mday'] < $day) ? -$parts['mday'] : ($parts['mday'] - $day);
1655:                             }
1656:                         }
1657:                     } else if ($calc == 'sub') {
1658:                         $date = $month - $found;
1659:                         $calc = 'set';
1660:                         if (self::$_options['extend_month'] == false) {
1661:                             $parts = $this->getDateParts($this->mktime($hour, $minute, $second, $date, $day, $year, false));
1662:                             if ($parts['mday'] != $day) {
1663:                                 $fixday = ($parts['mday'] < $day) ? -$parts['mday'] : ($parts['mday'] - $day);
1664:                             }
1665:                         }
1666:                     }
1667:                     return $this->_assign($calc, $this->mktime(0, 0, 0, $date,  $day + $fixday, $year, true),
1668:                                                  $this->mktime(0, 0, 0, $month, $day, $year, true), $hour);
1669:                 }
1670: 
1671:                 // Monthname not found
1672:                 #require_once 'Zend/Date/Exception.php';
1673:                 throw new Zend_Date_Exception("invalid date ($date) operand, month expected", 0, null, $date);
1674:                 break;
1675: 
1676:             case self::MONTH:
1677:                 if (is_numeric($date)) {
1678:                     $fixday = 0;
1679:                     if ($calc == 'add') {
1680:                         $date += $month;
1681:                         $calc = 'set';
1682:                         if (self::$_options['extend_month'] == false) {
1683:                             $parts = $this->getDateParts($this->mktime($hour, $minute, $second, $date, $day, $year, false));
1684:                             if ($parts['mday'] != $day) {
1685:                                 $fixday = ($parts['mday'] < $day) ? -$parts['mday'] : ($parts['mday'] - $day);
1686:                             }
1687:                         }
1688:                     } else if ($calc == 'sub') {
1689:                         $date = $month - $date;
1690:                         $calc = 'set';
1691:                         if (self::$_options['extend_month'] == false) {
1692:                             $parts = $this->getDateParts($this->mktime($hour, $minute, $second, $date, $day, $year, false));
1693:                             if ($parts['mday'] != $day) {
1694:                                 $fixday = ($parts['mday'] < $day) ? -$parts['mday'] : ($parts['mday'] - $day);
1695:                             }
1696:                         }
1697:                     }
1698:                     return $this->_assign($calc, $this->mktime(0, 0, 0, $date, $day + $fixday, $year, true),
1699:                                                  $this->mktime(0, 0, 0, $month, $day, $year, true), $hour);
1700:                 }
1701: 
1702:                 #require_once 'Zend/Date/Exception.php';
1703:                 throw new Zend_Date_Exception("invalid date ($date) operand, month expected", 0, null, $date);
1704:                 break;
1705: 
1706:             case self::MONTH_NAME_SHORT:
1707:                 $monthlist = Zend_Locale_Data::getList($locale, 'month', array('gregorian', 'format', 'abbreviated'));
1708:                 $cnt = 0;
1709:                 foreach ($monthlist as $key => $value) {
1710:                     if (strtoupper($value) == strtoupper($date)) {
1711:                         $found = $key;
1712:                         break;
1713:                     }
1714:                     ++$cnt;
1715:                 }
1716:                 $date = array_search($date, $monthlist);
1717: 
1718:                 // Monthname found
1719:                 if ($cnt < 12) {
1720:                     $fixday = 0;
1721:                     if ($calc == 'add') {
1722:                         $date += $found;
1723:                         $calc = 'set';
1724:                         if (self::$_options['extend_month'] === false) {
1725:                             $parts = $this->getDateParts($this->mktime($hour, $minute, $second, $date, $day, $year, false));
1726:                             if ($parts['mday'] != $day) {
1727:                                 $fixday = ($parts['mday'] < $day) ? -$parts['mday'] : ($parts['mday'] - $day);
1728:                             }
1729:                         }
1730:                     } else if ($calc == 'sub') {
1731:                         $date = $month - $found;
1732:                         $calc = 'set';
1733:                         if (self::$_options['extend_month'] === false) {
1734:                             $parts = $this->getDateParts($this->mktime($hour, $minute, $second, $date, $day, $year, false));
1735:                             if ($parts['mday'] != $day) {
1736:                                 $fixday = ($parts['mday'] < $day) ? -$parts['mday'] : ($parts['mday'] - $day);
1737:                             }
1738:                         }
1739:                     }
1740:                     return $this->_assign($calc, $this->mktime(0, 0, 0, $date, $day + $fixday, $year, true),
1741:                                                  $this->mktime(0, 0, 0, $month, $day, $year, true), $hour);
1742:                 }
1743: 
1744:                 // Monthname not found
1745:                 #require_once 'Zend/Date/Exception.php';
1746:                 throw new Zend_Date_Exception("invalid date ($date) operand, month expected", 0, null, $date);
1747:                 break;
1748: 
1749:             case self::MONTH_SHORT:
1750:                 if (is_numeric($date) === true) {
1751:                     $fixday = 0;
1752:                     if ($calc === 'add') {
1753:                         $date += $month;
1754:                         $calc  = 'set';
1755:                         if (self::$_options['extend_month'] === false) {
1756:                             $parts = $this->getDateParts($this->mktime($hour, $minute, $second, $date, $day, $year, false));
1757:                             if ($parts['mday'] != $day) {
1758:                                 $fixday = ($parts['mday'] < $day) ? -$parts['mday'] : ($parts['mday'] - $day);
1759:                             }
1760:                         }
1761:                     } else if ($calc === 'sub') {
1762:                         $date = $month - $date;
1763:                         $calc = 'set';
1764:                         if (self::$_options['extend_month'] === false) {
1765:                             $parts = $this->getDateParts($this->mktime($hour, $minute, $second, $date, $day, $year, false));
1766:                             if ($parts['mday'] != $day) {
1767:                                 $fixday = ($parts['mday'] < $day) ? -$parts['mday'] : ($parts['mday'] - $day);
1768:                             }
1769:                         }
1770:                     }
1771: 
1772:                     return $this->_assign($calc, $this->mktime(0, 0, 0, $date,  $day + $fixday, $year, true),
1773:                                                  $this->mktime(0, 0, 0, $month, $day,           $year, true), $hour);
1774:                 }
1775: 
1776:                 #require_once 'Zend/Date/Exception.php';
1777:                 throw new Zend_Date_Exception("invalid date ($date) operand, month expected", 0, null, $date);
1778:                 break;
1779: 
1780:             case self::MONTH_DAYS:
1781:                 #require_once 'Zend/Date/Exception.php';
1782:                 throw new Zend_Date_Exception('month days not supported', 0, null, $date);
1783:                 break;
1784: 
1785:             case self::MONTH_NAME_NARROW:
1786:                 $monthlist = Zend_Locale_Data::getList($locale, 'month', array('gregorian', 'stand-alone', 'narrow'));
1787:                 $cnt       = 0;
1788:                 foreach ($monthlist as $key => $value) {
1789:                     if (strtoupper($value) === strtoupper($date)) {
1790:                         $found = $key;
1791:                         break;
1792:                     }
1793:                     ++$cnt;
1794:                 }
1795:                 $date = array_search($date, $monthlist);
1796: 
1797:                 // Monthname found
1798:                 if ($cnt < 12) {
1799:                     $fixday = 0;
1800:                     if ($calc === 'add') {
1801:                         $date += $found;
1802:                         $calc  = 'set';
1803:                         if (self::$_options['extend_month'] === false) {
1804:                             $parts = $this->getDateParts($this->mktime($hour, $minute, $second, $date, $day, $year, false));
1805:                             if ($parts['mday'] != $day) {
1806:                                 $fixday = ($parts['mday'] < $day) ? -$parts['mday'] : ($parts['mday'] - $day);
1807:                             }
1808:                         }
1809:                     } else if ($calc === 'sub') {
1810:                         $date = $month - $found;
1811:                         $calc = 'set';
1812:                         if (self::$_options['extend_month'] === false) {
1813:                             $parts = $this->getDateParts($this->mktime($hour, $minute, $second, $date, $day, $year, false));
1814:                             if ($parts['mday'] != $day) {
1815:                                 $fixday = ($parts['mday'] < $day) ? -$parts['mday'] : ($parts['mday'] - $day);
1816:                             }
1817:                         }
1818:                     }
1819:                     return $this->_assign($calc, $this->mktime(0, 0, 0, $date,  $day + $fixday, $year, true),
1820:                                                  $this->mktime(0, 0, 0, $month, $day,           $year, true), $hour);
1821:                 }
1822: 
1823:                 // Monthname not found
1824:                 #require_once 'Zend/Date/Exception.php';
1825:                 throw new Zend_Date_Exception("invalid date ($date) operand, month expected", 0, null, $date);
1826:                 break;
1827: 
1828:             // year formats
1829:             case self::LEAPYEAR:
1830:                 #require_once 'Zend/Date/Exception.php';
1831:                 throw new Zend_Date_Exception('leap year not supported', 0, null, $date);
1832:                 break;
1833: 
1834:             case self::YEAR_8601:
1835:                 if (is_numeric($date)) {
1836:                     if ($calc === 'add') {
1837:                         $date += $year;
1838:                         $calc  = 'set';
1839:                     } else if ($calc === 'sub') {
1840:                         $date = $year - $date;
1841:                         $calc = 'set';
1842:                     }
1843: 
1844:                     return $this->_assign($calc, $this->mktime(0, 0, 0, $month, $day, intval($date), true),
1845:                                                  $this->mktime(0, 0, 0, $month, $day, $year,         true), false);
1846:                 }
1847: 
1848:                 #require_once 'Zend/Date/Exception.php';
1849:                 throw new Zend_Date_Exception("invalid date ($date) operand, year expected", 0, null, $date);
1850:                 break;
1851: 
1852:             case self::YEAR:
1853:                 if (is_numeric($date)) {
1854:                     if ($calc === 'add') {
1855:                         $date += $year;
1856:                         $calc  = 'set';
1857:                     } else if ($calc === 'sub') {
1858:                         $date = $year - $date;
1859:                         $calc = 'set';
1860:                     }
1861: 
1862:                     return $this->_assign($calc, $this->mktime(0, 0, 0, $month, $day, intval($date), true),
1863:                                                  $this->mktime(0, 0, 0, $month, $day, $year,         true), false);
1864:                 }
1865: 
1866:                 #require_once 'Zend/Date/Exception.php';
1867:                 throw new Zend_Date_Exception("invalid date ($date) operand, year expected", 0, null, $date);
1868:                 break;
1869: 
1870:             case self::YEAR_SHORT:
1871:                 if (is_numeric($date)) {
1872:                     $date = intval($date);
1873:                     if (($calc == 'set') || ($calc == 'cmp')) {
1874:                         $date = self::getFullYear($date);
1875:                     }
1876:                     if ($calc === 'add') {
1877:                         $date += $year;
1878:                         $calc  = 'set';
1879:                     } else if ($calc === 'sub') {
1880:                         $date = $year - $date;
1881:                         $calc = 'set';
1882:                     }
1883: 
1884:                     return $this->_assign($calc, $this->mktime(0, 0, 0, $month, $day, $date, true),
1885:                                                  $this->mktime(0, 0, 0, $month, $day, $year, true), false);
1886:                 }
1887: 
1888:                 #require_once 'Zend/Date/Exception.php';
1889:                 throw new Zend_Date_Exception("invalid date ($date) operand, year expected", 0, null, $date);
1890:                 break;
1891: 
1892:             case self::YEAR_SHORT_8601:
1893:                 if (is_numeric($date)) {
1894:                     $date = intval($date);
1895:                     if (($calc === 'set') || ($calc === 'cmp')) {
1896:                         $date = self::getFullYear($date);
1897:                     }
1898:                     if ($calc === 'add') {
1899:                         $date += $year;
1900:                         $calc  = 'set';
1901:                     } else if ($calc === 'sub') {
1902:                         $date = $year - $date;
1903:                         $calc = 'set';
1904:                     }
1905: 
1906:                     return $this->_assign($calc, $this->mktime(0, 0, 0, $month, $day, $date, true),
1907:                                                  $this->mktime(0, 0, 0, $month, $day, $year, true), false);
1908:                 }
1909: 
1910:                 #require_once 'Zend/Date/Exception.php';
1911:                 throw new Zend_Date_Exception("invalid date ($date) operand, year expected", 0, null, $date);
1912:                 break;
1913: 
1914:             // time formats
1915:             case self::MERIDIEM:
1916:                 #require_once 'Zend/Date/Exception.php';
1917:                 throw new Zend_Date_Exception('meridiem not supported', 0, null, $date);
1918:                 break;
1919: 
1920:             case self::SWATCH:
1921:                 if (is_numeric($date)) {
1922:                     $rest    = intval($date);
1923:                     $hours   = floor($rest * 24 / 1000);
1924:                     $rest    = $rest - ($hours * 1000 / 24);
1925:                     $minutes = floor($rest * 1440 / 1000);
1926:                     $rest    = $rest - ($minutes * 1000 / 1440);
1927:                     $seconds = floor($rest * 86400 / 1000);
1928:                     return $this->_assign($calc, $this->mktime($hours, $minutes, $seconds, 1, 1, 1970, true),
1929:                                                  $this->mktime($hour,  $minute,  $second,  1, 1, 1970, true), false);
1930:                 }
1931: 
1932:                 #require_once 'Zend/Date/Exception.php';
1933:                 throw new Zend_Date_Exception("invalid date ($date) operand, swatchstamp expected", 0, null, $date);
1934:                 break;
1935: 
1936:             case self::HOUR_SHORT_AM:
1937:                 if (is_numeric($date)) {
1938:                     return $this->_assign($calc, $this->mktime(intval($date), 0, 0, 1, 1, 1970, true),
1939:                                                  $this->mktime($hour,         0, 0, 1, 1, 1970, true), false);
1940:                 }
1941: 
1942:                 #require_once 'Zend/Date/Exception.php';
1943:                 throw new Zend_Date_Exception("invalid date ($date) operand, hour expected", 0, null, $date);
1944:                 break;
1945: 
1946:             case self::HOUR_SHORT:
1947:                 if (is_numeric($date)) {
1948:                     return $this->_assign($calc, $this->mktime(intval($date), 0, 0, 1, 1, 1970, true),
1949:                                                  $this->mktime($hour,         0, 0, 1, 1, 1970, true), false);
1950:                 }
1951: 
1952:                 #require_once 'Zend/Date/Exception.php';
1953:                 throw new Zend_Date_Exception("invalid date ($date) operand, hour expected", 0, null, $date);
1954:                 break;
1955: 
1956:             case self::HOUR_AM:
1957:                 if (is_numeric($date)) {
1958:                     return $this->_assign($calc, $this->mktime(intval($date), 0, 0, 1, 1, 1970, true),
1959:                                                  $this->mktime($hour,         0, 0, 1, 1, 1970, true), false);
1960:                 }
1961: 
1962:                 #require_once 'Zend/Date/Exception.php';
1963:                 throw new Zend_Date_Exception("invalid date ($date) operand, hour expected", 0, null, $date);
1964:                 break;
1965: 
1966:             case self::HOUR:
1967:                 if (is_numeric($date)) {
1968:                     return $this->_assign($calc, $this->mktime(intval($date), 0, 0, 1, 1, 1970, true),
1969:                                                  $this->mktime($hour,         0, 0, 1, 1, 1970, true), false);
1970:                 }
1971: 
1972:                 #require_once 'Zend/Date/Exception.php';
1973:                 throw new Zend_Date_Exception("invalid date ($date) operand, hour expected", 0, null, $date);
1974:                 break;
1975: 
1976:             case self::MINUTE:
1977:                 if (is_numeric($date)) {
1978:                     return $this->_assign($calc, $this->mktime(0, intval($date), 0, 1, 1, 1970, true),
1979:                                                  $this->mktime(0, $minute,       0, 1, 1, 1970, true), false);
1980:                 }
1981: 
1982:                 #require_once 'Zend/Date/Exception.php';
1983:                 throw new Zend_Date_Exception("invalid date ($date) operand, minute expected", 0, null, $date);
1984:                 break;
1985: 
1986:             case self::SECOND:
1987:                 if (is_numeric($date)) {
1988:                     return $this->_assign($calc, $this->mktime(0, 0, intval($date), 1, 1, 1970, true),
1989:                                                  $this->mktime(0, 0, $second,       1, 1, 1970, true), false);
1990:                 }
1991: 
1992:                 #require_once 'Zend/Date/Exception.php';
1993:                 throw new Zend_Date_Exception("invalid date ($date) operand, second expected", 0, null, $date);
1994:                 break;
1995: 
1996:             case self::MILLISECOND:
1997:                 if (is_numeric($date)) {
1998:                     switch($calc) {
1999:                         case 'set' :
2000:                             return $this->setMillisecond($date);
2001:                             break;
2002:                         case 'add' :
2003:                             return $this->addMillisecond($date);
2004:                             break;
2005:                         case 'sub' :
2006:                             return $this->subMillisecond($date);
2007:                             break;
2008:                     }
2009: 
2010:                     return $this->compareMillisecond($date);
2011:                 }
2012: 
2013:                 #require_once 'Zend/Date/Exception.php';
2014:                 throw new Zend_Date_Exception("invalid date ($date) operand, milliseconds expected", 0, null, $date);
2015:                 break;
2016: 
2017:             case self::MINUTE_SHORT:
2018:                 if (is_numeric($date)) {
2019:                     return $this->_assign($calc, $this->mktime(0, intval($date), 0, 1, 1, 1970, true),
2020:                                                  $this->mktime(0, $minute,       0, 1, 1, 1970, true), false);
2021:                 }
2022: 
2023:                 #require_once 'Zend/Date/Exception.php';
2024:                 throw new Zend_Date_Exception("invalid date ($date) operand, minute expected", 0, null, $date);
2025:                 break;
2026: 
2027:             case self::SECOND_SHORT:
2028:                 if (is_numeric($date)) {
2029:                     return $this->_assign($calc, $this->mktime(0, 0, intval($date), 1, 1, 1970, true),
2030:                                                  $this->mktime(0, 0, $second,       1, 1, 1970, true), false);
2031:                 }
2032: 
2033:                 #require_once 'Zend/Date/Exception.php';
2034:                 throw new Zend_Date_Exception("invalid date ($date) operand, second expected", 0, null, $date);
2035:                 break;
2036: 
2037:             // timezone formats
2038:             // break intentionally omitted
2039:             case self::TIMEZONE_NAME:
2040:             case self::TIMEZONE:
2041:             case self::TIMEZONE_SECS:
2042:                 #require_once 'Zend/Date/Exception.php';
2043:                 throw new Zend_Date_Exception('timezone not supported', 0, null, $date);
2044:                 break;
2045: 
2046:             case self::DAYLIGHT:
2047:                 #require_once 'Zend/Date/Exception.php';
2048:                 throw new Zend_Date_Exception('daylight not supported', 0, null, $date);
2049:                 break;
2050: 
2051:             case self::GMT_DIFF:
2052:             case self::GMT_DIFF_SEP:
2053:                 #require_once 'Zend/Date/Exception.php';
2054:                 throw new Zend_Date_Exception('gmtdiff not supported', 0, null, $date);
2055:                 break;
2056: 
2057:             // date strings
2058:             case self::ISO_8601:
2059:                 // (-)YYYY-MM-dd
2060:                 preg_match('/^(-{0,1}\d{4})-(\d{2})-(\d{2})/', $date, $datematch);
2061:                 // (-)YY-MM-dd
2062:                 if (empty($datematch)) {
2063:                     preg_match('/^(-{0,1}\d{2})-(\d{2})-(\d{2})/', $date, $datematch);
2064:                 }
2065:                 // (-)YYYYMMdd
2066:                 if (empty($datematch)) {
2067:                     preg_match('/^(-{0,1}\d{4})(\d{2})(\d{2})/', $date, $datematch);
2068:                 }
2069:                 // (-)YYMMdd
2070:                 if (empty($datematch)) {
2071:                     preg_match('/^(-{0,1}\d{2})(\d{2})(\d{2})/', $date, $datematch);
2072:                 }
2073:                 $tmpdate = $date;
2074:                 if (!empty($datematch)) {
2075:                     $dateMatchCharCount = iconv_strlen($datematch[0], 'UTF-8');
2076:                     $tmpdate = iconv_substr($date,
2077:                                             $dateMatchCharCount,
2078:                                             iconv_strlen($date, 'UTF-8') - $dateMatchCharCount,
2079:                                             'UTF-8');
2080:                 }
2081:                 // (T)hh:mm:ss
2082:                 preg_match('/[T,\s]{0,1}(\d{2}):(\d{2}):(\d{2})/', $tmpdate, $timematch);
2083:                 if (empty($timematch)) {
2084:                     preg_match('/[T,\s]{0,1}(\d{2})(\d{2})(\d{2})/', $tmpdate, $timematch);
2085:                 }
2086:                 if (empty($datematch) and empty($timematch)) {
2087:                     #require_once 'Zend/Date/Exception.php';
2088:                     throw new Zend_Date_Exception("unsupported ISO8601 format ($date)", 0, null, $date);
2089:                 }
2090:                 if (!empty($timematch)) {
2091:                     $timeMatchCharCount = iconv_strlen($timematch[0], 'UTF-8');
2092:                     $tmpdate = iconv_substr($tmpdate,
2093:                                             $timeMatchCharCount,
2094:                                             iconv_strlen($tmpdate, 'UTF-8') - $timeMatchCharCount,
2095:                                             'UTF-8');
2096:                 }
2097:                 if (empty($datematch)) {
2098:                     $datematch[1] = 1970;
2099:                     $datematch[2] = 1;
2100:                     $datematch[3] = 1;
2101:                 } else if (iconv_strlen($datematch[1], 'UTF-8') == 2) {
2102:                     $datematch[1] = self::getFullYear($datematch[1]);
2103:                 }
2104:                 if (empty($timematch)) {
2105:                     $timematch[1] = 0;
2106:                     $timematch[2] = 0;
2107:                     $timematch[3] = 0;
2108:                 }
2109: 
2110:                 if (($calc == 'set') || ($calc == 'cmp')) {
2111:                     --$datematch[2];
2112:                     --$month;
2113:                     --$datematch[3];
2114:                     --$day;
2115:                     $datematch[1] -= 1970;
2116:                     $year         -= 1970;
2117:                 }
2118:                 return $this->_assign($calc, $this->mktime($timematch[1], $timematch[2], $timematch[3], 1 + $datematch[2], 1 + $datematch[3], 1970 + $datematch[1], false),
2119:                                              $this->mktime($hour,         $minute,       $second,       1 + $month,        1 + $day,          1970 + $year,         false), false);
2120:                 break;
2121: 
2122:             case self::RFC_2822:
2123:                 $result = preg_match('/^\w{3},\s(\d{1,2})\s(\w{3})\s(\d{4})\s(\d{2}):(\d{2}):{0,1}(\d{0,2})\s([+-]{1}\d{4})$/', $date, $match);
2124:                 if (!$result) {
2125:                     #require_once 'Zend/Date/Exception.php';
2126:                     throw new Zend_Date_Exception("no RFC 2822 format ($date)", 0, null, $date);
2127:                 }
2128: 
2129:                 $months  = $this->_getDigitFromName($match[2]);
2130: 
2131:                 if (($calc == 'set') || ($calc == 'cmp')) {
2132:                     --$months;
2133:                     --$month;
2134:                     --$match[1];
2135:                     --$day;
2136:                     $match[3] -= 1970;
2137:                     $year     -= 1970;
2138:                 }
2139:                 return $this->_assign($calc, $this->mktime($match[4], $match[5], $match[6], 1 + $months, 1 + $match[1], 1970 + $match[3], false),
2140:                                              $this->mktime($hour,     $minute,   $second,   1 + $month,  1 + $day,      1970 + $year,     false), false);
2141:                 break;
2142: 
2143:             case self::TIMESTAMP:
2144:                 if (is_numeric($date)) {
2145:                     return $this->_assign($calc, $date, $this->getUnixTimestamp());
2146:                 }
2147: 
2148:                 #require_once 'Zend/Date/Exception.php';
2149:                 throw new Zend_Date_Exception("invalid date ($date) operand, timestamp expected", 0, null, $date);
2150:                 break;
2151: 
2152:             // additional formats
2153:             // break intentionally omitted
2154:             case self::ERA:
2155:             case self::ERA_NAME:
2156:                 #require_once 'Zend/Date/Exception.php';
2157:                 throw new Zend_Date_Exception('era not supported', 0, null, $date);
2158:                 break;
2159: 
2160:             case self::DATES:
2161:                 try {
2162:                     $parsed = Zend_Locale_Format::getDate($date, array('locale' => $locale, 'format_type' => 'iso', 'fix_date' => true));
2163: 
2164:                     if (($calc == 'set') || ($calc == 'cmp')) {
2165:                         --$parsed['month'];
2166:                         --$month;
2167:                         --$parsed['day'];
2168:                         --$day;
2169:                         $parsed['year'] -= 1970;
2170:                         $year  -= 1970;
2171:                     }
2172: 
2173:                     return $this->_assign($calc, $this->mktime(0, 0, 0, 1 + $parsed['month'], 1 + $parsed['day'], 1970 + $parsed['year'], true),
2174:                                                  $this->mktime(0, 0, 0, 1 + $month,           1 + $day,           1970 + $year,           true), $hour);
2175:                 } catch (Zend_Locale_Exception $e) {
2176:                     #require_once 'Zend/Date/Exception.php';
2177:                     throw new Zend_Date_Exception($e->getMessage(), 0, $e, $date);
2178:                 }
2179:                 break;
2180: 
2181:             case self::DATE_FULL:
2182:                 try {
2183:                     $format = Zend_Locale_Data::getContent($locale, 'date', array('gregorian', 'full'));
2184:                     $parsed = Zend_Locale_Format::getDate($date, array('date_format' => $format, 'format_type' => 'iso', 'locale' => $locale));
2185: 
2186:                     if (($calc == 'set') || ($calc == 'cmp')) {
2187:                         --$parsed['month'];
2188:                         --$month;
2189:                         --$parsed['day'];
2190:                         --$day;
2191:                         $parsed['year'] -= 1970;
2192:                         $year  -= 1970;
2193:                     }
2194:                     return $this->_assign($calc, $this->mktime(0, 0, 0, 1 + $parsed['month'], 1 + $parsed['day'], 1970 + $parsed['year'], true),
2195:                                                  $this->mktime(0, 0, 0, 1 + $month,           1 + $day,           1970 + $year,           true), $hour);
2196:                 } catch (Zend_Locale_Exception $e) {
2197:                     #require_once 'Zend/Date/Exception.php';
2198:                     throw new Zend_Date_Exception($e->getMessage(), 0, $e, $date);
2199:                 }
2200:                 break;
2201: 
2202:             case self::DATE_LONG:
2203:                 try {
2204:                     $format = Zend_Locale_Data::getContent($locale, 'date', array('gregorian', 'long'));
2205:                     $parsed = Zend_Locale_Format::getDate($date, array('date_format' => $format, 'format_type' => 'iso', 'locale' => $locale));
2206: 
2207:                     if (($calc == 'set') || ($calc == 'cmp')){
2208:                         --$parsed['month'];
2209:                         --$month;
2210:                         --$parsed['day'];
2211:                         --$day;
2212:                         $parsed['year'] -= 1970;
2213:                         $year  -= 1970;
2214:                     }
2215:                     return $this->_assign($calc, $this->mktime(0, 0, 0, 1 + $parsed['month'], 1 + $parsed['day'], 1970 + $parsed['year'], true),
2216:                                                  $this->mktime(0, 0, 0, 1 + $month,           1 + $day,           1970 + $year,           true), $hour);
2217:                 } catch (Zend_Locale_Exception $e) {
2218:                     #require_once 'Zend/Date/Exception.php';
2219:                     throw new Zend_Date_Exception($e->getMessage(), 0, $e, $date);
2220:                 }
2221:                 break;
2222: 
2223:             case self::DATE_MEDIUM:
2224:                 try {
2225:                     $format = Zend_Locale_Data::getContent($locale, 'date', array('gregorian', 'medium'));
2226:                     $parsed = Zend_Locale_Format::getDate($date, array('date_format' => $format, 'format_type' => 'iso', 'locale' => $locale));
2227: 
2228:                     if (($calc == 'set') || ($calc == 'cmp')) {
2229:                         --$parsed['month'];
2230:                         --$month;
2231:                         --$parsed['day'];
2232:                         --$day;
2233:                         $parsed['year'] -= 1970;
2234:                         $year  -= 1970;
2235:                     }
2236:                     return $this->_assign($calc, $this->mktime(0, 0, 0, 1 + $parsed['month'], 1 + $parsed['day'], 1970 + $parsed['year'], true),
2237:                                                  $this->mktime(0, 0, 0, 1 + $month,           1 + $day,           1970 + $year,           true), $hour);
2238:                 } catch (Zend_Locale_Exception $e) {
2239:                     #require_once 'Zend/Date/Exception.php';
2240:                     throw new Zend_Date_Exception($e->getMessage(), 0, $e, $date);
2241:                 }
2242:                 break;
2243: 
2244:             case self::DATE_SHORT:
2245:                 try {
2246:                     $format = Zend_Locale_Data::getContent($locale, 'date', array('gregorian', 'short'));
2247:                     $parsed = Zend_Locale_Format::getDate($date, array('date_format' => $format, 'format_type' => 'iso', 'locale' => $locale));
2248: 
2249:                     $parsed['year'] = self::getFullYear($parsed['year']);
2250: 
2251:                     if (($calc == 'set') || ($calc == 'cmp')) {
2252:                         --$parsed['month'];
2253:                         --$month;
2254:                         --$parsed['day'];
2255:                         --$day;
2256:                         $parsed['year'] -= 1970;
2257:                         $year  -= 1970;
2258:                     }
2259:                     return $this->_assign($calc, $this->mktime(0, 0, 0, 1 + $parsed['month'], 1 + $parsed['day'], 1970 + $parsed['year'], true),
2260:                                                  $this->mktime(0, 0, 0, 1 + $month,           1 + $day,           1970 + $year,           true), $hour);
2261:                 } catch (Zend_Locale_Exception $e) {
2262:                     #require_once 'Zend/Date/Exception.php';
2263:                     throw new Zend_Date_Exception($e->getMessage(), 0, $e, $date);
2264:                 }
2265:                 break;
2266: 
2267:             case self::TIMES:
2268:                 try {
2269:                     if ($calc != 'set') {
2270:                         $month = 1;
2271:                         $day   = 1;
2272:                         $year  = 1970;
2273:                     }
2274:                     $parsed = Zend_Locale_Format::getTime($date, array('locale' => $locale, 'format_type' => 'iso', 'fix_date' => true));
2275:                     return $this->_assign($calc, $this->mktime($parsed['hour'], $parsed['minute'], $parsed['second'], $month, $day, $year, true),
2276:                                                  $this->mktime($hour,           $minute,           $second,           $month, $day, $year, true), false);
2277:                 } catch (Zend_Locale_Exception $e) {
2278:                     #require_once 'Zend/Date/Exception.php';
2279:                     throw new Zend_Date_Exception($e->getMessage(), 0, $e, $date);
2280:                 }
2281:                 break;
2282: 
2283:             case self::TIME_FULL:
2284:                 try {
2285:                     $format = Zend_Locale_Data::getContent($locale, 'time', array('gregorian', 'full'));
2286:                     $parsed = Zend_Locale_Format::getTime($date, array('date_format' => $format, 'format_type' => 'iso', 'locale' => $locale));
2287:                     if ($calc != 'set') {
2288:                         $month = 1;
2289:                         $day   = 1;
2290:                         $year  = 1970;
2291:                     }
2292: 
2293:                     if (!isset($parsed['second'])) {
2294:                         $parsed['second'] = 0;
2295:                     }
2296: 
2297:                     return $this->_assign($calc, $this->mktime($parsed['hour'], $parsed['minute'], $parsed['second'], $month, $day, $year, true),
2298:                                                  $this->mktime($hour,           $minute,           $second,           $month, $day, $year, true), false);
2299:                 } catch (Zend_Locale_Exception $e) {
2300:                     #require_once 'Zend/Date/Exception.php';
2301:                     throw new Zend_Date_Exception($e->getMessage(), 0, $e, $date);
2302:                 }
2303:                 break;
2304: 
2305:             case self::TIME_LONG:
2306:                 try {
2307:                     $format = Zend_Locale_Data::getContent($locale, 'time', array('gregorian', 'long'));
2308:                     $parsed = Zend_Locale_Format::getTime($date, array('date_format' => $format, 'format_type' => 'iso', 'locale' => $locale));
2309:                     if ($calc != 'set') {
2310:                         $month = 1;
2311:                         $day   = 1;
2312:                         $year  = 1970;
2313:                     }
2314:                     return $this->_assign($calc, $this->mktime($parsed['hour'], $parsed['minute'], $parsed['second'], $month, $day, $year, true),
2315:                                                  $this->mktime($hour,           $minute,           $second,           $month, $day, $year, true), false);
2316:                 } catch (Zend_Locale_Exception $e) {
2317:                     #require_once 'Zend/Date/Exception.php';
2318:                     throw new Zend_Date_Exception($e->getMessage(), 0, $e, $date);
2319:                 }
2320:                 break;
2321: 
2322:             case self::TIME_MEDIUM:
2323:                 try {
2324:                     $format = Zend_Locale_Data::getContent($locale, 'time', array('gregorian', 'medium'));
2325:                     $parsed = Zend_Locale_Format::getTime($date, array('date_format' => $format, 'format_type' => 'iso', 'locale' => $locale));
2326:                     if ($calc != 'set') {
2327:                         $month = 1;
2328:                         $day   = 1;
2329:                         $year  = 1970;
2330:                     }
2331:                     return $this->_assign($calc, $this->mktime($parsed['hour'], $parsed['minute'], $parsed['second'], $month, $day, $year, true),
2332:                                                  $this->mktime($hour,           $minute,           $second,           $month, $day, $year, true), false);
2333:                 } catch (Zend_Locale_Exception $e) {
2334:                     #require_once 'Zend/Date/Exception.php';
2335:                     throw new Zend_Date_Exception($e->getMessage(), 0, $e, $date);
2336:                 }
2337:                 break;
2338: 
2339:             case self::TIME_SHORT:
2340:                 try {
2341:                     $format = Zend_Locale_Data::getContent($locale, 'time', array('gregorian', 'short'));
2342:                     $parsed = Zend_Locale_Format::getTime($date, array('date_format' => $format, 'format_type' => 'iso', 'locale' => $locale));
2343:                     if ($calc != 'set') {
2344:                         $month = 1;
2345:                         $day   = 1;
2346:                         $year  = 1970;
2347:                     }
2348: 
2349:                     if (!isset($parsed['second'])) {
2350:                         $parsed['second'] = 0;
2351:                     }
2352: 
2353:                     return $this->_assign($calc, $this->mktime($parsed['hour'], $parsed['minute'], $parsed['second'], $month, $day, $year, true),
2354:                                                  $this->mktime($hour,           $minute,           $second,           $month, $day, $year, true), false);
2355:                 } catch (Zend_Locale_Exception $e) {
2356:                     #require_once 'Zend/Date/Exception.php';
2357:                     throw new Zend_Date_Exception($e->getMessage(), 0, $e, $date);
2358:                 }
2359:                 break;
2360: 
2361:             case self::DATETIME:
2362:                 try {
2363:                     $parsed = Zend_Locale_Format::getDateTime($date, array('locale' => $locale, 'format_type' => 'iso', 'fix_date' => true));
2364:                     if (($calc == 'set') || ($calc == 'cmp')) {
2365:                         --$parsed['month'];
2366:                         --$month;
2367:                         --$parsed['day'];
2368:                         --$day;
2369:                         $parsed['year'] -= 1970;
2370:                         $year  -= 1970;
2371:                     }
2372:                     return $this->_assign($calc, $this->mktime($parsed['hour'], $parsed['minute'], $parsed['second'], 1 + $parsed['month'], 1 + $parsed['day'], 1970 + $parsed['year'], true),
2373:                                                  $this->mktime($hour,           $minute,           $second,           1 + $month,           1 + $day,           1970 + $year,           true), $hour);
2374:                 } catch (Zend_Locale_Exception $e) {
2375:                     #require_once 'Zend/Date/Exception.php';
2376:                     throw new Zend_Date_Exception($e->getMessage(), 0, $e, $date);
2377:                 }
2378:                 break;
2379: 
2380:             case self::DATETIME_FULL:
2381:                 try {
2382:                     $format = Zend_Locale_Data::getContent($locale, 'datetime', array('gregorian', 'full'));
2383:                     $parsed = Zend_Locale_Format::getDateTime($date, array('date_format' => $format, 'format_type' => 'iso', 'locale' => $locale));
2384: 
2385:                     if (($calc == 'set') || ($calc == 'cmp')) {
2386:                         --$parsed['month'];
2387:                         --$month;
2388:                         --$parsed['day'];
2389:                         --$day;
2390:                         $parsed['year'] -= 1970;
2391:                         $year  -= 1970;
2392:                     }
2393: 
2394:                     if (!isset($parsed['second'])) {
2395:                         $parsed['second'] = 0;
2396:                     }
2397: 
2398:                     return $this->_assign($calc, $this->mktime($parsed['hour'], $parsed['minute'], $parsed['second'], 1 + $parsed['month'], 1 + $parsed['day'], 1970 + $parsed['year'], true),
2399:                                                  $this->mktime($hour,           $minute,           $second,           1 + $month,           1 + $day,           1970 + $year,           true), $hour);
2400:                 } catch (Zend_Locale_Exception $e) {
2401:                     #require_once 'Zend/Date/Exception.php';
2402:                     throw new Zend_Date_Exception($e->getMessage(), 0, $e, $date);
2403:                 }
2404:                 break;
2405: 
2406:             case self::DATETIME_LONG:
2407:                 try {
2408:                     $format = Zend_Locale_Data::getContent($locale, 'datetime', array('gregorian', 'long'));
2409:                     $parsed = Zend_Locale_Format::getDateTime($date, array('date_format' => $format, 'format_type' => 'iso', 'locale' => $locale));
2410: 
2411:                     if (($calc == 'set') || ($calc == 'cmp')){
2412:                         --$parsed['month'];
2413:                         --$month;
2414:                         --$parsed['day'];
2415:                         --$day;
2416:                         $parsed['year'] -= 1970;
2417:                         $year  -= 1970;
2418:                     }
2419:                     return $this->_assign($calc, $this->mktime($parsed['hour'], $parsed['minute'], $parsed['second'], 1 + $parsed['month'], 1 + $parsed['day'], 1970 + $parsed['year'], true),
2420:                                                  $this->mktime($hour,           $minute,           $second,           1 + $month,           1 + $day,           1970 + $year,           true), $hour);
2421:                 } catch (Zend_Locale_Exception $e) {
2422:                     #require_once 'Zend/Date/Exception.php';
2423:                     throw new Zend_Date_Exception($e->getMessage(), 0, $e, $date);
2424:                 }
2425:                 break;
2426: 
2427:             case self::DATETIME_MEDIUM:
2428:                 try {
2429:                     $format = Zend_Locale_Data::getContent($locale, 'datetime', array('gregorian', 'medium'));
2430:                     $parsed = Zend_Locale_Format::getDateTime($date, array('date_format' => $format, 'format_type' => 'iso', 'locale' => $locale));
2431:                     if (($calc == 'set') || ($calc == 'cmp')) {
2432:                         --$parsed['month'];
2433:                         --$month;
2434:                         --$parsed['day'];
2435:                         --$day;
2436:                         $parsed['year'] -= 1970;
2437:                         $year  -= 1970;
2438:                     }
2439:                     return $this->_assign($calc, $this->mktime($parsed['hour'], $parsed['minute'], $parsed['second'], 1 + $parsed['month'], 1 + $parsed['day'], 1970 + $parsed['year'], true),
2440:                                                  $this->mktime($hour,           $minute,           $second,           1 + $month,           1 + $day,           1970 + $year,           true), $hour);
2441:                 } catch (Zend_Locale_Exception $e) {
2442:                     #require_once 'Zend/Date/Exception.php';
2443:                     throw new Zend_Date_Exception($e->getMessage(), 0, $e, $date);
2444:                 }
2445:                 break;
2446: 
2447:             case self::DATETIME_SHORT:
2448:                 try {
2449:                     $format = Zend_Locale_Data::getContent($locale, 'datetime', array('gregorian', 'short'));
2450:                     $parsed = Zend_Locale_Format::getDateTime($date, array('date_format' => $format, 'format_type' => 'iso', 'locale' => $locale));
2451: 
2452:                     $parsed['year'] = self::getFullYear($parsed['year']);
2453: 
2454:                     if (($calc == 'set') || ($calc == 'cmp')) {
2455:                         --$parsed['month'];
2456:                         --$month;
2457:                         --$parsed['day'];
2458:                         --$day;
2459:                         $parsed['year'] -= 1970;
2460:                         $year  -= 1970;
2461:                     }
2462: 
2463:                     if (!isset($parsed['second'])) {
2464:                         $parsed['second'] = 0;
2465:                     }
2466: 
2467:                     return $this->_assign($calc, $this->mktime($parsed['hour'], $parsed['minute'], $parsed['second'], 1 + $parsed['month'], 1 + $parsed['day'], 1970 + $parsed['year'], true),
2468:                                                  $this->mktime($hour,           $minute,           $second,           1 + $month,           1 + $day,           1970 + $year,           true), $hour);
2469:                 } catch (Zend_Locale_Exception $e) {
2470:                     #require_once 'Zend/Date/Exception.php';
2471:                     throw new Zend_Date_Exception($e->getMessage(), 0, $e, $date);
2472:                 }
2473:                 break;
2474: 
2475:             // ATOM and RFC_3339 are identical
2476:             case self::ATOM:
2477:             case self::RFC_3339:
2478:                 $result = preg_match('/^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})\d{0,4}([+-]{1}\d{2}:\d{2}|Z)$/', $date, $match);
2479:                 if (!$result) {
2480:                     #require_once 'Zend/Date/Exception.php';
2481:                     throw new Zend_Date_Exception("invalid date ($date) operand, ATOM format expected", 0, null, $date);
2482:                 }
2483: 
2484:                 if (($calc == 'set') || ($calc == 'cmp')) {
2485:                     --$match[2];
2486:                     --$month;
2487:                     --$match[3];
2488:                     --$day;
2489:                     $match[1] -= 1970;
2490:                     $year     -= 1970;
2491:                 }
2492:                 return $this->_assign($calc, $this->mktime($match[4], $match[5], $match[6], 1 + $match[2], 1 + $match[3], 1970 + $match[1], true),
2493:                                              $this->mktime($hour,     $minute,   $second,   1 + $month,    1 + $day,      1970 + $year,     true), false);
2494:                 break;
2495: 
2496:             case self::COOKIE:
2497:                 $result = preg_match("/^\w{6,9},\s(\d{2})-(\w{3})-(\d{2})\s(\d{2}):(\d{2}):(\d{2})\s.{3,20}$/", $date, $match);
2498:                 if (!$result) {
2499:                     #require_once 'Zend/Date/Exception.php';
2500:                     throw new Zend_Date_Exception("invalid date ($date) operand, COOKIE format expected", 0, null, $date);
2501:                 }
2502:                 $matchStartPos = iconv_strpos($match[0], ' ', 0, 'UTF-8') + 1;
2503:                 $match[0] = iconv_substr($match[0],
2504:                                          $matchStartPos,
2505:                                          iconv_strlen($match[0], 'UTF-8') - $matchStartPos,
2506:                                          'UTF-8');
2507: 
2508:                 $months    = $this->_getDigitFromName($match[2]);
2509:                 $match[3] = self::getFullYear($match[3]);
2510: 
2511:                 if (($calc == 'set') || ($calc == 'cmp')) {
2512:                     --$months;
2513:                     --$month;
2514:                     --$match[1];
2515:                     --$day;
2516:                     $match[3] -= 1970;
2517:                     $year     -= 1970;
2518:                 }
2519:                 return $this->_assign($calc, $this->mktime($match[4], $match[5], $match[6], 1 + $months, 1 + $match[1], 1970 + $match[3], true),
2520:                                              $this->mktime($hour,     $minute,   $second,   1 + $month,  1 + $day,      1970 + $year,     true), false);
2521:                 break;
2522: 
2523:             case self::RFC_822:
2524:             case self::RFC_1036:
2525:                 // new RFC 822 format, identical to RFC 1036 standard
2526:                 $result = preg_match('/^\w{0,3},{0,1}\s{0,1}(\d{1,2})\s(\w{3})\s(\d{2})\s(\d{2}):(\d{2}):{0,1}(\d{0,2})\s([+-]{1}\d{4}|\w{1,20})$/', $date, $match);
2527:                 if (!$result) {
2528:                     #require_once 'Zend/Date/Exception.php';
2529:                     throw new Zend_Date_Exception("invalid date ($date) operand, RFC 822 date format expected", 0, null, $date);
2530:                 }
2531: 
2532:                 $months    = $this->_getDigitFromName($match[2]);
2533:                 $match[3] = self::getFullYear($match[3]);
2534: 
2535:                 if (($calc == 'set') || ($calc == 'cmp')) {
2536:                     --$months;
2537:                     --$month;
2538:                     --$match[1];
2539:                     --$day;
2540:                     $match[3] -= 1970;
2541:                     $year     -= 1970;
2542:                 }
2543:                 return $this->_assign($calc, $this->mktime($match[4], $match[5], $match[6], 1 + $months, 1 + $match[1], 1970 + $match[3], false),
2544:                                              $this->mktime($hour,     $minute,   $second,   1 + $month,  1 + $day,      1970 + $year,     false), false);
2545:                 break;
2546: 
2547:             case self::RFC_850:
2548:                 $result = preg_match('/^\w{6,9},\s(\d{2})-(\w{3})-(\d{2})\s(\d{2}):(\d{2}):(\d{2})\s.{3,21}$/', $date, $match);
2549:                 if (!$result) {
2550:                     #require_once 'Zend/Date/Exception.php';
2551:                     throw new Zend_Date_Exception("invalid date ($date) operand, RFC 850 date format expected", 0, null, $date);
2552:                 }
2553: 
2554:                 $months    = $this->_getDigitFromName($match[2]);
2555:                 $match[3] = self::getFullYear($match[3]);
2556: 
2557:                 if (($calc == 'set') || ($calc == 'cmp')) {
2558:                     --$months;
2559:                     --$month;
2560:                     --$match[1];
2561:                     --$day;
2562:                     $match[3] -= 1970;
2563:                     $year     -= 1970;
2564:                 }
2565:                 return $this->_assign($calc, $this->mktime($match[4], $match[5], $match[6], 1 + $months, 1 + $match[1], 1970 + $match[3], true),
2566:                                              $this->mktime($hour,     $minute,   $second,   1 + $month,  1 + $day,      1970 + $year,     true), false);
2567:                 break;
2568: 
2569:             case self::RFC_1123:
2570:                 $result = preg_match('/^\w{0,3},{0,1}\s{0,1}(\d{1,2})\s(\w{3})\s(\d{2,4})\s(\d{2}):(\d{2}):{0,1}(\d{0,2})\s([+-]{1}\d{4}|\w{1,20})$/', $date, $match);
2571:                 if (!$result) {
2572:                     #require_once 'Zend/Date/Exception.php';
2573:                     throw new Zend_Date_Exception("invalid date ($date) operand, RFC 1123 date format expected", 0, null, $date);
2574:                 }
2575: 
2576:                 $months  = $this->_getDigitFromName($match[2]);
2577: 
2578:                 if (($calc == 'set') || ($calc == 'cmp')) {
2579:                     --$months;
2580:                     --$month;
2581:                     --$match[1];
2582:                     --$day;
2583:                     $match[3] -= 1970;
2584:                     $year     -= 1970;
2585:                 }
2586:                 return $this->_assign($calc, $this->mktime($match[4], $match[5], $match[6], 1 + $months, 1 + $match[1], 1970 + $match[3], true),
2587:                                              $this->mktime($hour,     $minute,   $second,   1 + $month,  1 + $day,      1970 + $year,     true), false);
2588:                 break;
2589: 
2590:             case self::RSS:
2591:                 $result = preg_match('/^\w{3},\s(\d{2})\s(\w{3})\s(\d{2,4})\s(\d{1,2}):(\d{2}):(\d{2})\s.{1,21}$/', $date, $match);
2592:                 if (!$result) {
2593:                     #require_once 'Zend/Date/Exception.php';
2594:                     throw new Zend_Date_Exception("invalid date ($date) operand, RSS date format expected", 0, null, $date);
2595:                 }
2596: 
2597:                 $months  = $this->_getDigitFromName($match[2]);
2598:                 $match[3] = self::getFullYear($match[3]);
2599: 
2600:                 if (($calc == 'set') || ($calc == 'cmp')) {
2601:                     --$months;
2602:                     --$month;
2603:                     --$match[1];
2604:                     --$day;
2605:                     $match[3] -= 1970;
2606:                     $year  -= 1970;
2607:                 }
2608:                 return $this->_assign($calc, $this->mktime($match[4], $match[5], $match[6], 1 + $months, 1 + $match[1], 1970 + $match[3], true),
2609:                                              $this->mktime($hour,     $minute,   $second,   1 + $month,  1 + $day,      1970 + $year,     true), false);
2610:                 break;
2611: 
2612:             case self::W3C:
2613:                 $result = preg_match('/^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})[+-]{1}\d{2}:\d{2}$/', $date, $match);
2614:                 if (!$result) {
2615:                     #require_once 'Zend/Date/Exception.php';
2616:                     throw new Zend_Date_Exception("invalid date ($date) operand, W3C date format expected", 0, null, $date);
2617:                 }
2618: 
2619:                 if (($calc == 'set') || ($calc == 'cmp')) {
2620:                     --$match[2];
2621:                     --$month;
2622:                     --$match[3];
2623:                     --$day;
2624:                     $match[1] -= 1970;
2625:                     $year     -= 1970;
2626:                 }
2627:                 return $this->_assign($calc, $this->mktime($match[4], $match[5], $match[6], 1 + $match[2], 1 + $match[3], 1970 + $match[1], true),
2628:                                              $this->mktime($hour,     $minute,   $second,   1 + $month,    1 + $day,      1970 + $year,     true), false);
2629:                 break;
2630: 
2631:             default:
2632:                 if (!is_numeric($date) || !empty($part)) {
2633:                     try {
2634:                         if (empty($part)) {
2635:                             $part  = Zend_Locale_Format::getDateFormat($locale) . " ";
2636:                             $part .= Zend_Locale_Format::getTimeFormat($locale);
2637:                         }
2638: 
2639:                         $parsed = Zend_Locale_Format::getDate($date, array('date_format' => $part, 'locale' => $locale, 'fix_date' => true, 'format_type' => 'iso'));
2640:                         if ((strpos(strtoupper($part), 'YY') !== false) and (strpos(strtoupper($part), 'YYYY') === false)) {
2641:                             $parsed['year'] = self::getFullYear($parsed['year']);
2642:                         }
2643: 
2644:                         if (($calc == 'set') || ($calc == 'cmp')) {
2645:                             if (isset($parsed['month'])) {
2646:                                 --$parsed['month'];
2647:                             } else {
2648:                                 $parsed['month'] = 0;
2649:                             }
2650: 
2651:                             if (isset($parsed['day'])) {
2652:                                 --$parsed['day'];
2653:                             } else {
2654:                                 $parsed['day'] = 0;
2655:                             }
2656: 
2657:                             if (isset($parsed['year'])) {
2658:                                 $parsed['year'] -= 1970;
2659:                             } else {
2660:                                 $parsed['year'] = 0;
2661:                             }
2662:                         }
2663: 
2664:                         return $this->_assign($calc, $this->mktime(
2665:                             isset($parsed['hour']) ? $parsed['hour'] : 0,
2666:                             isset($parsed['minute']) ? $parsed['minute'] : 0,
2667:                             isset($parsed['second']) ? $parsed['second'] : 0,
2668:                             isset($parsed['month']) ? (1 + $parsed['month']) : 1,
2669:                             isset($parsed['day']) ? (1 + $parsed['day']) : 1,
2670:                             isset($parsed['year']) ? (1970 + $parsed['year']) : 1970,
2671:                             false), $this->getUnixTimestamp(), false);
2672:                     } catch (Zend_Locale_Exception $e) {
2673:                         if (!is_numeric($date)) {
2674:                             #require_once 'Zend/Date/Exception.php';
2675:                             throw new Zend_Date_Exception($e->getMessage(), 0, $e, $date);
2676:                         }
2677:                     }
2678:                 }
2679: 
2680:                 return $this->_assign($calc, $date, $this->getUnixTimestamp(), false);
2681:                 break;
2682:         }
2683:     }
2684: 
2685:     /**
2686:      * Returns true when both date objects or date parts are equal.
2687:      * For example:
2688:      * 15.May.2000 <-> 15.June.2000 Equals only for Day or Year... all other will return false
2689:      *
2690:      * @param  string|integer|array|Zend_Date  $date    Date or datepart to equal with
2691:      * @param  string                          $part    OPTIONAL Part of the date to compare, if null the timestamp is used
2692:      * @param  string|Zend_Locale              $locale  OPTIONAL Locale for parsing input
2693:      * @return boolean
2694:      * @throws Zend_Date_Exception
2695:      */
2696:     public function equals($date, $part = self::TIMESTAMP, $locale = null)
2697:     {
2698:         $result = $this->compare($date, $part, $locale);
2699: 
2700:         if ($result == 0) {
2701:             return true;
2702:         }
2703: 
2704:         return false;
2705:     }
2706: 
2707:     /**
2708:      * Returns if the given date or datepart is earlier
2709:      * For example:
2710:      * 15.May.2000 <-> 13.June.1999 will return true for day, year and date, but not for month
2711:      *
2712:      * @param  string|integer|array|Zend_Date  $date    Date or datepart to compare with
2713:      * @param  string                          $part    OPTIONAL Part of the date to compare, if null the timestamp is used
2714:      * @param  string|Zend_Locale              $locale  OPTIONAL Locale for parsing input
2715:      * @return boolean
2716:      * @throws Zend_Date_Exception
2717:      */
2718:     public function isEarlier($date, $part = null, $locale = null)
2719:     {
2720:         $result = $this->compare($date, $part, $locale);
2721: 
2722:         if ($result == -1) {
2723:             return true;
2724:         }
2725: 
2726:         return false;
2727:     }
2728: 
2729:     /**
2730:      * Returns if the given date or datepart is later
2731:      * For example:
2732:      * 15.May.2000 <-> 13.June.1999 will return true for month but false for day, year and date
2733:      * Returns if the given date is later
2734:      *
2735:      * @param  string|integer|array|Zend_Date  $date    Date or datepart to compare with
2736:      * @param  string                          $part    OPTIONAL Part of the date to compare, if null the timestamp is used
2737:      * @param  string|Zend_Locale              $locale  OPTIONAL Locale for parsing input
2738:      * @return boolean
2739:      * @throws Zend_Date_Exception
2740:      */
2741:     public function isLater($date, $part = null, $locale = null)
2742:     {
2743:         $result = $this->compare($date, $part, $locale);
2744: 
2745:         if ($result == 1) {
2746:             return true;
2747:         }
2748: 
2749:         return false;
2750:     }
2751: 
2752:     /**
2753:      * Returns only the time of the date as new Zend_Date object
2754:      * For example:
2755:      * 15.May.2000 10:11:23 will return a dateobject equal to 01.Jan.1970 10:11:23
2756:      *
2757:      * @param  string|Zend_Locale  $locale  OPTIONAL Locale for parsing input
2758:      * @return Zend_Date
2759:      */
2760:     public function getTime($locale = null)
2761:     {
2762:         if (self::$_options['format_type'] == 'php') {
2763:             $format = 'H:i:s';
2764:         } else {
2765:             $format = self::TIME_MEDIUM;
2766:         }
2767: 
2768:         return $this->copyPart($format, $locale);
2769:     }
2770: 
2771:     /**
2772:      * Returns the calculated time
2773:      *
2774:      * @param  string                    $calc    Calculation to make
2775:      * @param  string|integer|array|Zend_Date  $time    Time to calculate with, if null the actual time is taken
2776:      * @param  string                          $format  Timeformat for parsing input
2777:      * @param  string|Zend_Locale              $locale  Locale for parsing input
2778:      * @return integer|Zend_Date  new time
2779:      * @throws Zend_Date_Exception
2780:      */
2781:     private function _time($calc, $time, $format, $locale)
2782:     {
2783:         if ($time === null) {
2784:             #require_once 'Zend/Date/Exception.php';
2785:             throw new Zend_Date_Exception('parameter $time must be set, null is not allowed');
2786:         }
2787: 
2788:         if ($time instanceof Zend_Date) {
2789:             // extract time from object
2790:             $time = $time->toString('HH:mm:ss', 'iso');
2791:         } else {
2792:             if (is_array($time)) {
2793:                 if ((isset($time['hour']) === true) or (isset($time['minute']) === true) or
2794:                     (isset($time['second']) === true)) {
2795:                     $parsed = $time;
2796:                 } else {
2797:                     #require_once 'Zend/Date/Exception.php';
2798:                     throw new Zend_Date_Exception("no hour, minute or second given in array");
2799:                 }
2800:             } else {
2801:                 if (self::$_options['format_type'] == 'php') {
2802:                     $format = Zend_Locale_Format::convertPhpToIsoFormat($format);
2803:                 }
2804:                 try {
2805:                     if ($locale === null) {
2806:                         $locale = $this->getLocale();
2807:                     }
2808: 
2809:                     $parsed = Zend_Locale_Format::getTime($time, array('date_format' => $format, 'locale' => $locale, 'format_type' => 'iso'));
2810:                 } catch (Zend_Locale_Exception $e) {
2811:                     #require_once 'Zend/Date/Exception.php';
2812:                     throw new Zend_Date_Exception($e->getMessage(), 0, $e);
2813:                 }
2814:             }
2815: 
2816:             if (!array_key_exists('hour', $parsed)) {
2817:                 $parsed['hour'] = 0;
2818:             }
2819: 
2820:             if (!array_key_exists('minute', $parsed)) {
2821:                 $parsed['minute'] = 0;
2822:             }
2823: 
2824:             if (!array_key_exists('second', $parsed)) {
2825:                 $parsed['second'] = 0;
2826:             }
2827: 
2828:             $time  = str_pad($parsed['hour'], 2, '0', STR_PAD_LEFT) . ":";
2829:             $time .= str_pad($parsed['minute'], 2, '0', STR_PAD_LEFT) . ":";
2830:             $time .= str_pad($parsed['second'], 2, '0', STR_PAD_LEFT);
2831:         }
2832: 
2833:         $return = $this->_calcdetail($calc, $time, self::TIMES, 'de');
2834:         if ($calc != 'cmp') {
2835:             return $this;
2836:         }
2837: 
2838:         return $return;
2839:     }
2840: 
2841: 
2842:     /**
2843:      * Sets a new time for the date object. Format defines how to parse the time string.
2844:      * Also a complete date can be given, but only the time is used for setting.
2845:      * For example: dd.MMMM.yyTHH:mm' and 'ss sec'-> 10.May.07T25:11 and 44 sec => 1h11min44sec + 1 day
2846:      * Returned is the new date object and the existing date is left as it was before
2847:      *
2848:      * @param  string|integer|array|Zend_Date  $time    Time to set
2849:      * @param  string                          $format  OPTIONAL Timeformat for parsing input
2850:      * @param  string|Zend_Locale              $locale  OPTIONAL Locale for parsing input
2851:      * @return Zend_Date Provides fluid interface
2852:      * @throws Zend_Date_Exception
2853:      */
2854:     public function setTime($time, $format = null, $locale = null)
2855:     {
2856:         return $this->_time('set', $time, $format, $locale);
2857:     }
2858: 
2859: 
2860:     /**
2861:      * Adds a time to the existing date. Format defines how to parse the time string.
2862:      * If only parts are given the other parts are set to 0.
2863:      * If no format is given, the standardformat of this locale is used.
2864:      * For example: HH:mm:ss -> 10 -> +10 hours
2865:      *
2866:      * @param  string|integer|array|Zend_Date  $time    Time to add
2867:      * @param  string                          $format  OPTIONAL Timeformat for parsing input
2868:      * @param  string|Zend_Locale              $locale  OPTIONAL Locale for parsing input
2869:      * @return Zend_Date Provides fluid interface
2870:      * @throws Zend_Date_Exception
2871:      */
2872:     public function addTime($time, $format = null, $locale = null)
2873:     {
2874:         return $this->_time('add', $time, $format, $locale);
2875:     }
2876: 
2877: 
2878:     /**
2879:      * Subtracts a time from the existing date. Format defines how to parse the time string.
2880:      * If only parts are given the other parts are set to 0.
2881:      * If no format is given, the standardformat of this locale is used.
2882:      * For example: HH:mm:ss -> 10 -> -10 hours
2883:      *
2884:      * @param  string|integer|array|Zend_Date  $time    Time to sub
2885:      * @param  string                          $format  OPTIONAL Timeformat for parsing input
2886:      * @param  string|Zend_Locale              $locale  OPTIONAL Locale for parsing input
2887:      * @return Zend_Date Provides fluid inteface
2888:      * @throws Zend_Date_Exception
2889:      */
2890:     public function subTime($time, $format = null, $locale = null)
2891:     {
2892:         return $this->_time('sub', $time, $format, $locale);
2893:     }
2894: 
2895: 
2896:     /**
2897:      * Compares the time from the existing date. Format defines how to parse the time string.
2898:      * If only parts are given the other parts are set to default.
2899:      * If no format us given, the standardformat of this locale is used.
2900:      * For example: HH:mm:ss -> 10 -> 10 hours
2901:      *
2902:      * @param  string|integer|array|Zend_Date  $time    Time to compare
2903:      * @param  string                          $format  OPTIONAL Timeformat for parsing input
2904:      * @param  string|Zend_Locale              $locale  OPTIONAL Locale for parsing input
2905:      * @return integer  0 = equal, 1 = later, -1 = earlier
2906:      * @throws Zend_Date_Exception
2907:      */
2908:     public function compareTime($time, $format = null, $locale = null)
2909:     {
2910:         return $this->_time('cmp', $time, $format, $locale);
2911:     }
2912: 
2913:     /**
2914:      * Returns a clone of $this, with the time part set to 00:00:00.
2915:      *
2916:      * @param  string|Zend_Locale  $locale  OPTIONAL Locale for parsing input
2917:      * @return Zend_Date
2918:      */
2919:     public function getDate($locale = null)
2920:     {
2921:         $orig = self::$_options['format_type'];
2922:         if (self::$_options['format_type'] == 'php') {
2923:             self::$_options['format_type'] = 'iso';
2924:         }
2925: 
2926:         $date = $this->copyPart(self::DATE_MEDIUM, $locale);
2927:         $date->addTimestamp($this->getGmtOffset());
2928:         self::$_options['format_type'] = $orig;
2929: 
2930:         return $date;
2931:     }
2932: 
2933:     /**
2934:      * Returns the calculated date
2935:      *
2936:      * @param  string                          $calc    Calculation to make
2937:      * @param  string|integer|array|Zend_Date  $date    Date to calculate with, if null the actual date is taken
2938:      * @param  string                          $format  Date format for parsing
2939:      * @param  string|Zend_Locale              $locale  Locale for parsing input
2940:      * @return integer|Zend_Date  new date
2941:      * @throws Zend_Date_Exception
2942:      */
2943:     private function _date($calc, $date, $format, $locale)
2944:     {
2945:         if ($date === null) {
2946:             #require_once 'Zend/Date/Exception.php';
2947:             throw new Zend_Date_Exception('parameter $date must be set, null is not allowed');
2948:         }
2949: 
2950:         if ($date instanceof Zend_Date) {
2951:             // extract date from object
2952:             $date = $date->toString('d.M.y', 'iso');
2953:         } else {
2954:             if (is_array($date)) {
2955:                 if ((isset($date['year']) === true) or (isset($date['month']) === true) or
2956:                     (isset($date['day']) === true)) {
2957:                     $parsed = $date;
2958:                 } else {
2959:                     #require_once 'Zend/Date/Exception.php';
2960:                     throw new Zend_Date_Exception("no day,month or year given in array");
2961:                 }
2962:             } else {
2963:                 if ((self::$_options['format_type'] == 'php') && !defined($format)) {
2964:                     $format = Zend_Locale_Format::convertPhpToIsoFormat($format);
2965:                 }
2966:                 try {
2967:                     if ($locale === null) {
2968:                         $locale = $this->getLocale();
2969:                     }
2970: 
2971:                     $parsed = Zend_Locale_Format::getDate($date, array('date_format' => $format, 'locale' => $locale, 'format_type' => 'iso'));
2972:                     if ((strpos(strtoupper($format), 'YY') !== false) and (strpos(strtoupper($format), 'YYYY') === false)) {
2973:                         $parsed['year'] = self::getFullYear($parsed['year']);
2974:                     }
2975:                 } catch (Zend_Locale_Exception $e) {
2976:                     #require_once 'Zend/Date/Exception.php';
2977:                     throw new Zend_Date_Exception($e->getMessage(), 0, $e);
2978:                 }
2979:             }
2980: 
2981:             if (!array_key_exists('day', $parsed)) {
2982:                 $parsed['day'] = 1;
2983:             }
2984: 
2985:             if (!array_key_exists('month', $parsed)) {
2986:                 $parsed['month'] = 1;
2987:             }
2988: 
2989:             if (!array_key_exists('year', $parsed)) {
2990:                 $parsed['year'] = 0;
2991:             }
2992: 
2993:             $date  = $parsed['day'] . "." . $parsed['month'] . "." . $parsed['year'];
2994:         }
2995: 
2996:         $return = $this->_calcdetail($calc, $date, self::DATE_MEDIUM, 'de');
2997:         if ($calc != 'cmp') {
2998:             return $this;
2999:         }
3000:         return $return;
3001:     }
3002: 
3003: 
3004:     /**
3005:      * Sets a new date for the date object. Format defines how to parse the date string.
3006:      * Also a complete date with time can be given, but only the date is used for setting.
3007:      * For example: MMMM.yy HH:mm-> May.07 22:11 => 01.May.07 00:00
3008:      * Returned is the new date object and the existing time is left as it was before
3009:      *
3010:      * @param  string|integer|array|Zend_Date  $date    Date to set
3011:      * @param  string                          $format  OPTIONAL Date format for parsing
3012:      * @param  string|Zend_Locale              $locale  OPTIONAL Locale for parsing input
3013:      * @return Zend_Date Provides fluid interface
3014:      * @throws Zend_Date_Exception
3015:      */
3016:     public function setDate($date, $format = null, $locale = null)
3017:     {
3018:         return $this->_date('set', $date, $format, $locale);
3019:     }
3020: 
3021: 
3022:     /**
3023:      * Adds a date to the existing date object. Format defines how to parse the date string.
3024:      * If only parts are given the other parts are set to 0.
3025:      * If no format is given, the standardformat of this locale is used.
3026:      * For example: MM.dd.YYYY -> 10 -> +10 months
3027:      *
3028:      * @param  string|integer|array|Zend_Date  $date    Date to add
3029:      * @param  string                          $format  OPTIONAL Date format for parsing input
3030:      * @param  string|Zend_Locale              $locale  OPTIONAL Locale for parsing input
3031:      * @return Zend_Date Provides fluid interface
3032:      * @throws Zend_Date_Exception
3033:      */
3034:     public function addDate($date, $format = null, $locale = null)
3035:     {
3036:         return $this->_date('add', $date, $format, $locale);
3037:     }
3038: 
3039: 
3040:     /**
3041:      * Subtracts a date from the existing date object. Format defines how to parse the date string.
3042:      * If only parts are given the other parts are set to 0.
3043:      * If no format is given, the standardformat of this locale is used.
3044:      * For example: MM.dd.YYYY -> 10 -> -10 months
3045:      * Be aware: Subtracting 2 months is not equal to Adding -2 months !!!
3046:      *
3047:      * @param  string|integer|array|Zend_Date  $date    Date to sub
3048:      * @param  string                          $format  OPTIONAL Date format for parsing input
3049:      * @param  string|Zend_Locale              $locale  OPTIONAL Locale for parsing input
3050:      * @return Zend_Date Provides fluid interface
3051:      * @throws Zend_Date_Exception
3052:      */
3053:     public function subDate($date, $format = null, $locale = null)
3054:     {
3055:         return $this->_date('sub', $date, $format, $locale);
3056:     }
3057: 
3058: 
3059:     /**
3060:      * Compares the date from the existing date object, ignoring the time.
3061:      * Format defines how to parse the date string.
3062:      * If only parts are given the other parts are set to 0.
3063:      * If no format is given, the standardformat of this locale is used.
3064:      * For example: 10.01.2000 => 10.02.1999 -> false
3065:      *
3066:      * @param  string|integer|array|Zend_Date  $date    Date to compare
3067:      * @param  string                          $format  OPTIONAL Date format for parsing input
3068:      * @param  string|Zend_Locale              $locale  OPTIONAL Locale for parsing input
3069:      * @return integer  0 = equal, 1 = later, -1 = earlier
3070:      * @throws Zend_Date_Exception
3071:      */
3072:     public function compareDate($date, $format = null, $locale = null)
3073:     {
3074:         return $this->_date('cmp', $date, $format, $locale);
3075:     }
3076: 
3077: 
3078:     /**
3079:      * Returns the full ISO 8601 date from the date object.
3080:      * Always the complete ISO 8601 specifiction is used. If an other ISO date is needed
3081:      * (ISO 8601 defines several formats) use toString() instead.
3082:      * This function does not return the ISO date as object. Use copy() instead.
3083:      *
3084:      * @param  string|Zend_Locale  $locale  OPTIONAL Locale for parsing input
3085:      * @return string
3086:      */
3087:     public function getIso($locale = null)
3088:     {
3089:         return $this->toString(self::ISO_8601, 'iso', $locale);
3090:     }
3091: 
3092: 
3093:     /**
3094:      * Sets a new date for the date object. Not given parts are set to default.
3095:      * Only supported ISO 8601 formats are accepted.
3096:      * For example: 050901 -> 01.Sept.2005 00:00:00, 20050201T10:00:30 -> 01.Feb.2005 10h00m30s
3097:      * Returned is the new date object
3098:      *
3099:      * @param  string|integer|Zend_Date  $date    ISO Date to set
3100:      * @param  string|Zend_Locale        $locale  OPTIONAL Locale for parsing input
3101:      * @return Zend_Date Provides fluid interface
3102:      * @throws Zend_Date_Exception
3103:      */
3104:     public function setIso($date, $locale = null)
3105:     {
3106:         return $this->_calcvalue('set', $date, 'iso', self::ISO_8601, $locale);
3107:     }
3108: 
3109: 
3110:     /**
3111:      * Adds a ISO date to the date object. Not given parts are set to default.
3112:      * Only supported ISO 8601 formats are accepted.
3113:      * For example: 050901 -> + 01.Sept.2005 00:00:00, 10:00:00 -> +10h
3114:      * Returned is the new date object
3115:      *
3116:      * @param  string|integer|Zend_Date  $date    ISO Date to add
3117:      * @param  string|Zend_Locale        $locale  OPTIONAL Locale for parsing input
3118:      * @return Zend_Date Provides fluid interface
3119:      * @throws Zend_Date_Exception
3120:      */
3121:     public function addIso($date, $locale = null)
3122:     {
3123:         return $this->_calcvalue('add', $date, 'iso', self::ISO_8601, $locale);
3124:     }
3125: 
3126: 
3127:     /**
3128:      * Subtracts a ISO date from the date object. Not given parts are set to default.
3129:      * Only supported ISO 8601 formats are accepted.
3130:      * For example: 050901 -> - 01.Sept.2005 00:00:00, 10:00:00 -> -10h
3131:      * Returned is the new date object
3132:      *
3133:      * @param  string|integer|Zend_Date  $date    ISO Date to sub
3134:      * @param  string|Zend_Locale        $locale  OPTIONAL Locale for parsing input
3135:      * @return Zend_Date Provides fluid interface
3136:      * @throws Zend_Date_Exception
3137:      */
3138:     public function subIso($date, $locale = null)
3139:     {
3140:         return $this->_calcvalue('sub', $date, 'iso', self::ISO_8601, $locale);
3141:     }
3142: 
3143: 
3144:     /**
3145:      * Compares a ISO date with the date object. Not given parts are set to default.
3146:      * Only supported ISO 8601 formats are accepted.
3147:      * For example: 050901 -> - 01.Sept.2005 00:00:00, 10:00:00 -> -10h
3148:      * Returns if equal, earlier or later
3149:      *
3150:      * @param  string|integer|Zend_Date  $date    ISO Date to sub
3151:      * @param  string|Zend_Locale        $locale  OPTIONAL Locale for parsing input
3152:      * @return integer  0 = equal, 1 = later, -1 = earlier
3153:      * @throws Zend_Date_Exception
3154:      */
3155:     public function compareIso($date, $locale = null)
3156:     {
3157:         return $this->_calcvalue('cmp', $date, 'iso', self::ISO_8601, $locale);
3158:     }
3159: 
3160: 
3161:     /**
3162:      * Returns a RFC 822 compilant datestring from the date object.
3163:      * This function does not return the RFC date as object. Use copy() instead.
3164:      *
3165:      * @param  string|Zend_Locale  $locale  OPTIONAL Locale for parsing input
3166:      * @return string
3167:      */
3168:     public function getArpa($locale = null)
3169:     {
3170:         if (self::$_options['format_type'] == 'php') {
3171:             $format = 'D\, d M y H\:i\:s O';
3172:         } else {
3173:             $format = self::RFC_822;
3174:         }
3175: 
3176:         return $this->toString($format, 'iso', $locale);
3177:     }
3178: 
3179: 
3180:     /**
3181:      * Sets a RFC 822 date as new date for the date object.
3182:      * Only RFC 822 compilant date strings are accepted.
3183:      * For example: Sat, 14 Feb 09 00:31:30 +0100
3184:      * Returned is the new date object
3185:      *
3186:      * @param  string|integer|Zend_Date  $date    RFC 822 to set
3187:      * @param  string|Zend_Locale        $locale  OPTIONAL Locale for parsing input
3188:      * @return Zend_Date Provides fluid interface
3189:      * @throws Zend_Date_Exception
3190:      */
3191:     public function setArpa($date, $locale = null)
3192:     {
3193:         return $this->_calcvalue('set', $date, 'arpa', self::RFC_822, $locale);
3194:     }
3195: 
3196: 
3197:     /**
3198:      * Adds a RFC 822 date to the date object.
3199:      * ARPA messages are used in emails or HTTP Headers.
3200:      * Only RFC 822 compilant date strings are accepted.
3201:      * For example: Sat, 14 Feb 09 00:31:30 +0100
3202:      * Returned is the new date object
3203:      *
3204:      * @param  string|integer|Zend_Date  $date    RFC 822 Date to add
3205:      * @param  string|Zend_Locale        $locale  OPTIONAL Locale for parsing input
3206:      * @return Zend_Date Provides fluid interface
3207:      * @throws Zend_Date_Exception
3208:      */
3209:     public function addArpa($date, $locale = null)
3210:     {
3211:         return $this->_calcvalue('add', $date, 'arpa', self::RFC_822, $locale);
3212:     }
3213: 
3214: 
3215:     /**
3216:      * Subtracts a RFC 822 date from the date object.
3217:      * ARPA messages are used in emails or HTTP Headers.
3218:      * Only RFC 822 compilant date strings are accepted.
3219:      * For example: Sat, 14 Feb 09 00:31:30 +0100
3220:      * Returned is the new date object
3221:      *
3222:      * @param  string|integer|Zend_Date  $date    RFC 822 Date to sub
3223:      * @param  string|Zend_Locale        $locale  OPTIONAL Locale for parsing input
3224:      * @return Zend_Date Provides fluid interface
3225:      * @throws Zend_Date_Exception
3226:      */
3227:     public function subArpa($date, $locale = null)
3228:     {
3229:         return $this->_calcvalue('sub', $date, 'arpa', self::RFC_822, $locale);
3230:     }
3231: 
3232: 
3233:     /**
3234:      * Compares a RFC 822 compilant date with the date object.
3235:      * ARPA messages are used in emails or HTTP Headers.
3236:      * Only RFC 822 compilant date strings are accepted.
3237:      * For example: Sat, 14 Feb 09 00:31:30 +0100
3238:      * Returns if equal, earlier or later
3239:      *
3240:      * @param  string|integer|Zend_Date  $date    RFC 822 Date to sub
3241:      * @param  string|Zend_Locale        $locale  OPTIONAL Locale for parsing input
3242:      * @return integer  0 = equal, 1 = later, -1 = earlier
3243:      * @throws Zend_Date_Exception
3244:      */
3245:     public function compareArpa($date, $locale = null)
3246:     {
3247:         return $this->_calcvalue('cmp', $date, 'arpa', self::RFC_822, $locale);
3248:     }
3249: 
3250: 
3251:     /**
3252:      * Check if location is supported
3253:      *
3254:      * @param $location array - locations array
3255:      * @return $horizon float
3256:      */
3257:     private function _checkLocation($location)
3258:     {
3259:         if (!isset($location['longitude']) or !isset($location['latitude'])) {
3260:             #require_once 'Zend/Date/Exception.php';
3261:             throw new Zend_Date_Exception('Location must include \'longitude\' and \'latitude\'', 0, null, $location);
3262:         }
3263:         if (($location['longitude'] > 180) or ($location['longitude'] < -180)) {
3264:             #require_once 'Zend/Date/Exception.php';
3265:             throw new Zend_Date_Exception('Longitude must be between -180 and 180', 0, null, $location);
3266:         }
3267:         if (($location['latitude'] > 90) or ($location['latitude'] < -90)) {
3268:             #require_once 'Zend/Date/Exception.php';
3269:             throw new Zend_Date_Exception('Latitude must be between -90 and 90', 0, null, $location);
3270:         }
3271: 
3272:         if (!isset($location['horizon'])){
3273:             $location['horizon'] = 'effective';
3274:         }
3275: 
3276:         switch ($location['horizon']) {
3277:             case 'civil' :
3278:                 return -0.104528;
3279:                 break;
3280:             case 'nautic' :
3281:                 return -0.207912;
3282:                 break;
3283:             case 'astronomic' :
3284:                 return -0.309017;
3285:                 break;
3286:             default :
3287:                 return -0.0145439;
3288:                 break;
3289:         }
3290:     }
3291: 
3292: 
3293:     /**
3294:      * Returns the time of sunrise for this date and a given location as new date object
3295:      * For a list of cities and correct locations use the class Zend_Date_Cities
3296:      *
3297:      * @param  $location array - location of sunrise
3298:      *                   ['horizon']   -> civil, nautic, astronomical, effective (default)
3299:      *                   ['longitude'] -> longitude of location
3300:      *                   ['latitude']  -> latitude of location
3301:      * @return Zend_Date
3302:      * @throws Zend_Date_Exception
3303:      */
3304:     public function getSunrise($location)
3305:     {
3306:         $horizon = $this->_checkLocation($location);
3307:         $result = clone $this;
3308:         $result->set($this->calcSun($location, $horizon, true), self::TIMESTAMP);
3309:         return $result;
3310:     }
3311: 
3312: 
3313:     /**
3314:      * Returns the time of sunset for this date and a given location as new date object
3315:      * For a list of cities and correct locations use the class Zend_Date_Cities
3316:      *
3317:      * @param  $location array - location of sunset
3318:      *                   ['horizon']   -> civil, nautic, astronomical, effective (default)
3319:      *                   ['longitude'] -> longitude of location
3320:      *                   ['latitude']  -> latitude of location
3321:      * @return Zend_Date
3322:      * @throws Zend_Date_Exception
3323:      */
3324:     public function getSunset($location)
3325:     {
3326:         $horizon = $this->_checkLocation($location);
3327:         $result = clone $this;
3328:         $result->set($this->calcSun($location, $horizon, false), self::TIMESTAMP);
3329:         return $result;
3330:     }
3331: 
3332: 
3333:     /**
3334:      * Returns an array with the sunset and sunrise dates for all horizon types
3335:      * For a list of cities and correct locations use the class Zend_Date_Cities
3336:      *
3337:      * @param  $location array - location of suninfo
3338:      *                   ['horizon']   -> civil, nautic, astronomical, effective (default)
3339:      *                   ['longitude'] -> longitude of location
3340:      *                   ['latitude']  -> latitude of location
3341:      * @return array - [sunset|sunrise][effective|civil|nautic|astronomic]
3342:      * @throws Zend_Date_Exception
3343:      */
3344:     public function getSunInfo($location)
3345:     {
3346:         $suninfo = array();
3347:         for ($i = 0; $i < 4; ++$i) {
3348:             switch ($i) {
3349:                 case 0 :
3350:                     $location['horizon'] = 'effective';
3351:                     break;
3352:                 case 1 :
3353:                     $location['horizon'] = 'civil';
3354:                     break;
3355:                 case 2 :
3356:                     $location['horizon'] = 'nautic';
3357:                     break;
3358:                 case 3 :
3359:                     $location['horizon'] = 'astronomic';
3360:                     break;
3361:             }
3362:             $horizon = $this->_checkLocation($location);
3363:             $result = clone $this;
3364:             $result->set($this->calcSun($location, $horizon, true), self::TIMESTAMP);
3365:             $suninfo['sunrise'][$location['horizon']] = $result;
3366:             $result = clone $this;
3367:             $result->set($this->calcSun($location, $horizon, false), self::TIMESTAMP);
3368:             $suninfo['sunset'][$location['horizon']]  = $result;
3369:         }
3370:         return $suninfo;
3371:     }
3372: 
3373: 
3374:     /**
3375:      * Check a given year for leap year.
3376:      *
3377:      * @param  integer|array|Zend_Date  $year  Year to check
3378:      * @return boolean
3379:      */
3380:     public static function checkLeapYear($year)
3381:     {
3382:         if ($year instanceof Zend_Date) {
3383:             $year = (int) $year->toString(self::YEAR, 'iso');
3384:         }
3385: 
3386:         if (is_array($year)) {
3387:             if (isset($year['year']) === true) {
3388:                 $year = $year['year'];
3389:             } else {
3390:                 #require_once 'Zend/Date/Exception.php';
3391:                 throw new Zend_Date_Exception("no year given in array");
3392:             }
3393:         }
3394: 
3395:         if (!is_numeric($year)) {
3396:             #require_once 'Zend/Date/Exception.php';
3397:             throw new Zend_Date_Exception("year ($year) has to be integer for checkLeapYear()", 0, null, $year);
3398:         }
3399: 
3400:         return (bool) parent::isYearLeapYear($year);
3401:     }
3402: 
3403: 
3404:     /**
3405:      * Returns true, if the year is a leap year.
3406:      *
3407:      * @return boolean
3408:      */
3409:     public function isLeapYear()
3410:     {
3411:         return self::checkLeapYear($this);
3412:     }
3413: 
3414: 
3415:     /**
3416:      * Returns if the set date is todays date
3417:      *
3418:      * @return boolean
3419:      */
3420:     public function isToday()
3421:     {
3422:         $today = $this->date('Ymd', $this->_getTime());
3423:         $day   = $this->date('Ymd', $this->getUnixTimestamp());
3424:         return ($today == $day);
3425:     }
3426: 
3427: 
3428:     /**
3429:      * Returns if the set date is yesterdays date
3430:      *
3431:      * @return boolean
3432:      */
3433:     public function isYesterday()
3434:     {
3435:         list($year, $month, $day) = explode('-', $this->date('Y-m-d', $this->_getTime()));
3436:         // adjusts for leap days and DST changes that are timezone specific
3437:         $yesterday = $this->date('Ymd', $this->mktime(0, 0, 0, $month, $day -1, $year));
3438:         $day   = $this->date('Ymd', $this->getUnixTimestamp());
3439:         return $day == $yesterday;
3440:     }
3441: 
3442: 
3443:     /**
3444:      * Returns if the set date is tomorrows date
3445:      *
3446:      * @return boolean
3447:      */
3448:     public function isTomorrow()
3449:     {
3450:         list($year, $month, $day) = explode('-', $this->date('Y-m-d', $this->_getTime()));
3451:         // adjusts for leap days and DST changes that are timezone specific
3452:         $tomorrow = $this->date('Ymd', $this->mktime(0, 0, 0, $month, $day +1, $year));
3453:         $day   = $this->date('Ymd', $this->getUnixTimestamp());
3454:         return $day == $tomorrow;
3455:     }
3456: 
3457:     /**
3458:      * Returns the actual date as new date object
3459:      *
3460:      * @param  string|Zend_Locale        $locale  OPTIONAL Locale for parsing input
3461:      * @return Zend_Date
3462:      */
3463:     public static function now($locale = null)
3464:     {
3465:         return new Zend_Date(time(), self::TIMESTAMP, $locale);
3466:     }
3467: 
3468:     /**
3469:      * Calculate date details
3470:      *
3471:      * @param  string                          $calc    Calculation to make
3472:      * @param  string|integer|array|Zend_Date  $date    Date or Part to calculate
3473:      * @param  string                          $part    Datepart for Calculation
3474:      * @param  string|Zend_Locale              $locale  Locale for parsing input
3475:      * @return integer|string  new date
3476:      * @throws Zend_Date_Exception
3477:      */
3478:     private function _calcdetail($calc, $date, $type, $locale)
3479:     {
3480:         $old = false;
3481:         if (self::$_options['format_type'] == 'php') {
3482:             self::$_options['format_type'] = 'iso';
3483:             $old = true;
3484:         }
3485: 
3486:         switch($calc) {
3487:             case 'set' :
3488:                 $return = $this->set($date, $type, $locale);
3489:                 break;
3490:             case 'add' :
3491:                 $return = $this->add($date, $type, $locale);
3492:                 break;
3493:             case 'sub' :
3494:                 $return = $this->sub($date, $type, $locale);
3495:                 break;
3496:             default :
3497:                 $return = $this->compare($date, $type, $locale);
3498:                 break;
3499:         }
3500: 
3501:         if ($old) {
3502:             self::$_options['format_type'] = 'php';
3503:         }
3504: 
3505:         return $return;
3506:     }
3507: 
3508:     /**
3509:      * Internal calculation, returns the requested date type
3510:      *
3511:      * @param  string                    $calc    Calculation to make
3512:      * @param  string|integer|Zend_Date  $value   Datevalue to calculate with, if null the actual value is taken
3513:      * @param  string|Zend_Locale        $locale  Locale for parsing input
3514:      * @return integer|Zend_Date  new date
3515:      * @throws Zend_Date_Exception
3516:      */
3517:     private function _calcvalue($calc, $value, $type, $parameter, $locale)
3518:     {
3519:         if ($value === null) {
3520:             #require_once 'Zend/Date/Exception.php';
3521:             throw new Zend_Date_Exception("parameter $type must be set, null is not allowed");
3522:         }
3523: 
3524:         if ($locale === null) {
3525:             $locale = $this->getLocale();
3526:         }
3527: 
3528:         if ($value instanceof Zend_Date) {
3529:             // extract value from object
3530:             $value = $value->toString($parameter, 'iso', $locale);
3531:         } else if (!is_array($value) && !is_numeric($value) && ($type != 'iso') && ($type != 'arpa')) {
3532:             #require_once 'Zend/Date/Exception.php';
3533:             throw new Zend_Date_Exception("invalid $type ($value) operand", 0, null, $value);
3534:         }
3535: 
3536:         $return = $this->_calcdetail($calc, $value, $parameter, $locale);
3537:         if ($calc != 'cmp') {
3538:             return $this;
3539:         }
3540:         return $return;
3541:     }
3542: 
3543: 
3544:     /**
3545:      * Returns only the year from the date object as new object.
3546:      * For example: 10.May.2000 10:30:00 -> 01.Jan.2000 00:00:00
3547:      *
3548:      * @param  string|Zend_Locale  $locale  OPTIONAL Locale for parsing input
3549:      * @return Zend_Date
3550:      */
3551:     public function getYear($locale = null)
3552:     {
3553:         if (self::$_options['format_type'] == 'php') {
3554:             $format = 'Y';
3555:         } else {
3556:             $format = self::YEAR;
3557:         }
3558: 
3559:         return $this->copyPart($format, $locale);
3560:     }
3561: 
3562: 
3563:     /**
3564:      * Sets a new year
3565:      * If the year is between 0 and 69, 2000 will be set (2000-2069)
3566:      * If the year if between 70 and 99, 1999 will be set (1970-1999)
3567:      * 3 or 4 digit years are set as expected. If you need to set year 0-99
3568:      * use set() instead.
3569:      * Returned is the new date object
3570:      *
3571:      * @param  string|integer|array|Zend_Date  $date    Year to set
3572:      * @param  string|Zend_Locale              $locale  OPTIONAL Locale for parsing input
3573:      * @return Zend_Date Provides fluid interface
3574:      * @throws Zend_Date_Exception
3575:      */
3576:     public function setYear($year, $locale = null)
3577:     {
3578:         return $this->_calcvalue('set', $year, 'year', self::YEAR, $locale);
3579:     }
3580: 
3581: 
3582:     /**
3583:      * Adds the year to the existing date object
3584:      * If the year is between 0 and 69, 2000 will be added (2000-2069)
3585:      * If the year if between 70 and 99, 1999 will be added (1970-1999)
3586:      * 3 or 4 digit years are added as expected. If you need to add years from 0-99
3587:      * use add() instead.
3588:      * Returned is the new date object
3589:      *
3590:      * @param  string|integer|array|Zend_Date  $date    Year to add
3591:      * @param  string|Zend_Locale              $locale  OPTIONAL Locale for parsing input
3592:      * @return Zend_Date Provides fluid interface
3593:      * @throws Zend_Date_Exception
3594:      */
3595:     public function addYear($year, $locale = null)
3596:     {
3597:         return $this->_calcvalue('add', $year, 'year', self::YEAR, $locale);
3598:     }
3599: 
3600: 
3601:     /**
3602:      * Subs the year from the existing date object
3603:      * If the year is between 0 and 69, 2000 will be subtracted (2000-2069)
3604:      * If the year if between 70 and 99, 1999 will be subtracted (1970-1999)
3605:      * 3 or 4 digit years are subtracted as expected. If you need to subtract years from 0-99
3606:      * use sub() instead.
3607:      * Returned is the new date object
3608:      *
3609:      * @param  string|integer|array|Zend_Date  $date    Year to sub
3610:      * @param  string|Zend_Locale              $locale  OPTIONAL Locale for parsing input
3611:      * @return Zend_Date Provides fluid interface
3612:      * @throws Zend_Date_Exception
3613:      */
3614:     public function subYear($year, $locale = null)
3615:     {
3616:         return $this->_calcvalue('sub', $year, 'year', self::YEAR, $locale);
3617:     }
3618: 
3619: 
3620:     /**
3621:      * Compares the year with the existing date object, ignoring other date parts.
3622:      * For example: 10.03.2000 -> 15.02.2000 -> true
3623:      * Returns if equal, earlier or later
3624:      *
3625:      * @param  string|integer|array|Zend_Date  $year    Year to compare
3626:      * @param  string|Zend_Locale              $locale  OPTIONAL Locale for parsing input
3627:      * @return integer  0 = equal, 1 = later, -1 = earlier
3628:      * @throws Zend_Date_Exception
3629:      */
3630:     public function compareYear($year, $locale = null)
3631:     {
3632:         return $this->_calcvalue('cmp', $year, 'year', self::YEAR, $locale);
3633:     }
3634: 
3635: 
3636:     /**
3637:      * Returns only the month from the date object as new object.
3638:      * For example: 10.May.2000 10:30:00 -> 01.May.1970 00:00:00
3639:      *
3640:      * @param  string|Zend_Locale  $locale  OPTIONAL Locale for parsing input
3641:      * @return Zend_Date
3642:      */
3643:     public function getMonth($locale = null)
3644:     {
3645:         if (self::$_options['format_type'] == 'php') {
3646:             $format = 'm';
3647:         } else {
3648:             $format = self::MONTH;
3649:         }
3650: 
3651:         return $this->copyPart($format, $locale);
3652:     }
3653: 
3654: 
3655:     /**
3656:      * Returns the calculated month
3657:      *
3658:      * @param  string                          $calc    Calculation to make
3659:      * @param  string|integer|array|Zend_Date  $month   Month to calculate with, if null the actual month is taken
3660:      * @param  string|Zend_Locale              $locale  Locale for parsing input
3661:      * @return integer|Zend_Date  new time
3662:      * @throws Zend_Date_Exception
3663:      */
3664:     private function _month($calc, $month, $locale)
3665:     {
3666:         if ($month === null) {
3667:             #require_once 'Zend/Date/Exception.php';
3668:             throw new Zend_Date_Exception('parameter $month must be set, null is not allowed');
3669:         }
3670: 
3671:         if ($locale === null) {
3672:             $locale = $this->getLocale();
3673:         }
3674: 
3675:         if ($month instanceof Zend_Date) {
3676:             // extract month from object
3677:             $found = $month->toString(self::MONTH_SHORT, 'iso', $locale);
3678:         } else {
3679:             if (is_numeric($month)) {
3680:                 $found = $month;
3681:             } else if (is_array($month)) {
3682:                 if (isset($month['month']) === true) {
3683:                     $month = $month['month'];
3684:                 } else {
3685:                     #require_once 'Zend/Date/Exception.php';
3686:                     throw new Zend_Date_Exception("no month given in array");
3687:                 }
3688:             } else {
3689:                 $monthlist  = Zend_Locale_Data::getList($locale, 'month');
3690:                 $monthlist2 = Zend_Locale_Data::getList($locale, 'month', array('gregorian', 'format', 'abbreviated'));
3691: 
3692:                 $monthlist = array_merge($monthlist, $monthlist2);
3693:                 $found = 0;
3694:                 $cnt = 0;
3695:                 foreach ($monthlist as $key => $value) {
3696:                     if (strtoupper($value) == strtoupper($month)) {
3697:                         $found = ($key % 12) + 1;
3698:                         break;
3699:                     }
3700:                     ++$cnt;
3701:                 }
3702:                 if ($found == 0) {
3703:                     foreach ($monthlist2 as $key => $value) {
3704:                         if (strtoupper(iconv_substr($value, 0, 1, 'UTF-8')) == strtoupper($month)) {
3705:                             $found = $key + 1;
3706:                             break;
3707:                         }
3708:                         ++$cnt;
3709:                     }
3710:                 }
3711:                 if ($found == 0) {
3712:                     #require_once 'Zend/Date/Exception.php';
3713:                     throw new Zend_Date_Exception("unknown month name ($month)", 0, null, $month);
3714:                 }
3715:             }
3716:         }
3717:         $return = $this->_calcdetail($calc, $found, self::MONTH_SHORT, $locale);
3718:         if ($calc != 'cmp') {
3719:             return $this;
3720:         }
3721:         return $return;
3722:     }
3723: 
3724: 
3725:     /**
3726:      * Sets a new month
3727:      * The month can be a number or a string. Setting months lower then 0 and greater then 12
3728:      * will result in adding or subtracting the relevant year. (12 months equal one year)
3729:      * If a localized monthname is given it will be parsed with the default locale or the optional
3730:      * set locale.
3731:      * Returned is the new date object
3732:      *
3733:      * @param  string|integer|array|Zend_Date  $month   Month to set
3734:      * @param  string|Zend_Locale              $locale  OPTIONAL Locale for parsing input
3735:      * @return Zend_Date Provides fluid interface
3736:      * @throws Zend_Date_Exception
3737:      */
3738:     public function setMonth($month, $locale = null)
3739:     {
3740:         return $this->_month('set', $month, $locale);
3741:     }
3742: 
3743: 
3744:     /**
3745:      * Adds months to the existing date object.
3746:      * The month can be a number or a string. Adding months lower then 0 and greater then 12
3747:      * will result in adding or subtracting the relevant year. (12 months equal one year)
3748:      * If a localized monthname is given it will be parsed with the default locale or the optional
3749:      * set locale.
3750:      * Returned is the new date object
3751:      *
3752:      * @param  string|integer|array|Zend_Date  $month   Month to add
3753:      * @param  string|Zend_Locale              $locale  OPTIONAL Locale for parsing input
3754:      * @return Zend_Date Provides fluid interface
3755:      * @throws Zend_Date_Exception
3756:      */
3757:     public function addMonth($month, $locale = null)
3758:     {
3759:         return $this->_month('add', $month, $locale);
3760:     }
3761: 
3762: 
3763:     /**
3764:      * Subtracts months from the existing date object.
3765:      * The month can be a number or a string. Subtracting months lower then 0 and greater then 12
3766:      * will result in adding or subtracting the relevant year. (12 months equal one year)
3767:      * If a localized monthname is given it will be parsed with the default locale or the optional
3768:      * set locale.
3769:      * Returned is the new date object
3770:      *
3771:      * @param  string|integer|array|Zend_Date  $month   Month to sub
3772:      * @param  string|Zend_Locale              $locale  OPTIONAL Locale for parsing input
3773:      * @return Zend_Date Provides fluid interface
3774:      * @throws Zend_Date_Exception
3775:      */
3776:     public function subMonth($month, $locale = null)
3777:     {
3778:         return $this->_month('sub', $month, $locale);
3779:     }
3780: 
3781: 
3782:     /**
3783:      * Compares the month with the existing date object, ignoring other date parts.
3784:      * For example: 10.03.2000 -> 15.03.1950 -> true
3785:      * Returns if equal, earlier or later
3786:      *
3787:      * @param  string|integer|array|Zend_Date  $month   Month to compare
3788:      * @param  string|Zend_Locale              $locale  OPTIONAL Locale for parsing input
3789:      * @return integer  0 = equal, 1 = later, -1 = earlier
3790:      * @throws Zend_Date_Exception
3791:      */
3792:     public function compareMonth($month, $locale = null)
3793:     {
3794:         return $this->_month('cmp', $month, $locale);
3795:     }
3796: 
3797: 
3798:     /**
3799:      * Returns the day as new date object
3800:      * Example: 20.May.1986 -> 20.Jan.1970 00:00:00
3801:      *
3802:      * @param $locale  string|Zend_Locale  OPTIONAL Locale for parsing input
3803:      * @return Zend_Date
3804:      */
3805:     public function getDay($locale = null)
3806:     {
3807:         return $this->copyPart(self::DAY_SHORT, $locale);
3808:     }
3809: 
3810: 
3811:     /**
3812:      * Returns the calculated day
3813:      *
3814:      * @param $calc    string                    Type of calculation to make
3815:      * @param $day     string|integer|Zend_Date  Day to calculate, when null the actual day is calculated
3816:      * @param $locale  string|Zend_Locale        Locale for parsing input
3817:      * @return Zend_Date|integer
3818:      */
3819:     private function _day($calc, $day, $locale)
3820:     {
3821:         if ($day === null) {
3822:             #require_once 'Zend/Date/Exception.php';
3823:             throw new Zend_Date_Exception('parameter $day must be set, null is not allowed');
3824:         }
3825: 
3826:         if ($locale === null) {
3827:             $locale = $this->getLocale();
3828:         }
3829: 
3830:         if ($day instanceof Zend_Date) {
3831:             $day = $day->toString(self::DAY_SHORT, 'iso', $locale);
3832:         }
3833: 
3834:         if (is_numeric($day)) {
3835:             $type = self::DAY_SHORT;
3836:         } else if (is_array($day)) {
3837:             if (isset($day['day']) === true) {
3838:                 $day = $day['day'];
3839:                 $type = self::WEEKDAY;
3840:             } else {
3841:                 #require_once 'Zend/Date/Exception.php';
3842:                 throw new Zend_Date_Exception("no day given in array");
3843:             }
3844:         } else {
3845:             switch (iconv_strlen($day, 'UTF-8')) {
3846:                 case 1 :
3847:                    $type = self::WEEKDAY_NARROW;
3848:                     break;
3849:                 case 2:
3850:                     $type = self::WEEKDAY_NAME;
3851:                     break;
3852:                 case 3:
3853:                     $type = self::WEEKDAY_SHORT;
3854:                     break;
3855:                 default:
3856:                     $type = self::WEEKDAY;
3857:                     break;
3858:             }
3859:         }
3860:         $return = $this->_calcdetail($calc, $day, $type, $locale);
3861:         if ($calc != 'cmp') {
3862:             return $this;
3863:         }
3864:         return $return;
3865:     }
3866: 
3867: 
3868:     /**
3869:      * Sets a new day
3870:      * The day can be a number or a string. Setting days lower then 0 or greater than the number of this months days
3871:      * will result in adding or subtracting the relevant month.
3872:      * If a localized dayname is given it will be parsed with the default locale or the optional
3873:      * set locale.
3874:      * Returned is the new date object
3875:      * Example: setDay('Montag', 'de_AT'); will set the monday of this week as day.
3876:      *
3877:      * @param  string|integer|array|Zend_Date  $month   Day to set
3878:      * @param  string|Zend_Locale              $locale  OPTIONAL Locale for parsing input
3879:      * @return Zend_Date Provides fluid interface
3880:      * @throws Zend_Date_Exception
3881:      */
3882:     public function setDay($day, $locale = null)
3883:     {
3884:         return $this->_day('set', $day, $locale);
3885:     }
3886: 
3887: 
3888:     /**
3889:      * Adds days to the existing date object.
3890:      * The day can be a number or a string. Adding days lower then 0 or greater than the number of this months days
3891:      * will result in adding or subtracting the relevant month.
3892:      * If a localized dayname is given it will be parsed with the default locale or the optional
3893:      * set locale.
3894:      *
3895:      * @param  string|integer|array|Zend_Date  $month   Day to add
3896:      * @param  string|Zend_Locale              $locale  OPTIONAL Locale for parsing input
3897:      * @return Zend_Date Provides fluid interface
3898:      * @throws Zend_Date_Exception
3899:      */
3900:     public function addDay($day, $locale = null)
3901:     {
3902:         return $this->_day('add', $day, $locale);
3903:     }
3904: 
3905: 
3906:     /**
3907:      * Subtracts days from the existing date object.
3908:      * The day can be a number or a string. Subtracting days lower then 0 or greater than the number of this months days
3909:      * will result in adding or subtracting the relevant month.
3910:      * If a localized dayname is given it will be parsed with the default locale or the optional
3911:      * set locale.
3912:      *
3913:      * @param  string|integer|array|Zend_Date  $month   Day to sub
3914:      * @param  string|Zend_Locale              $locale  OPTIONAL Locale for parsing input
3915:      * @return Zend_Date Provides fluid interface
3916:      * @throws Zend_Date_Exception
3917:      */
3918:     public function subDay($day, $locale = null)
3919:     {
3920:         return $this->_day('sub', $day, $locale);
3921:     }
3922: 
3923: 
3924:     /**
3925:      * Compares the day with the existing date object, ignoring other date parts.
3926:      * For example: 'Monday', 'en' -> 08.Jan.2007 -> 0
3927:      * Returns if equal, earlier or later
3928:      *
3929:      * @param  string|integer|array|Zend_Date  $day     Day to compare
3930:      * @param  string|Zend_Locale              $locale  OPTIONAL Locale for parsing input
3931:      * @return integer  0 = equal, 1 = later, -1 = earlier
3932:      * @throws Zend_Date_Exception
3933:      */
3934:     public function compareDay($day, $locale = null)
3935:     {
3936:         return $this->_day('cmp', $day, $locale);
3937:     }
3938: 
3939: 
3940:     /**
3941:      * Returns the weekday as new date object
3942:      * Weekday is always from 1-7
3943:      * Example: 09-Jan-2007 -> 2 = Tuesday -> 02-Jan-1970 (when 02.01.1970 is also Tuesday)
3944:      *
3945:      * @param $locale  string|Zend_Locale  OPTIONAL Locale for parsing input
3946:      * @return Zend_Date
3947:      */
3948:     public function getWeekday($locale = null)
3949:     {
3950:         if (self::$_options['format_type'] == 'php') {
3951:             $format = 'l';
3952:         } else {
3953:             $format = self::WEEKDAY;
3954:         }
3955: 
3956:         return $this->copyPart($format, $locale);
3957:     }
3958: 
3959: 
3960:     /**
3961:      * Returns the calculated weekday
3962:      *
3963:      * @param  $calc     string                          Type of calculation to make
3964:      * @param  $weekday  string|integer|array|Zend_Date  Weekday to calculate, when null the actual weekday is calculated
3965:      * @param  $locale   string|Zend_Locale              Locale for parsing input
3966:      * @return Zend_Date|integer
3967:      * @throws Zend_Date_Exception
3968:      */
3969:     private function _weekday($calc, $weekday, $locale)
3970:     {
3971:         if ($weekday === null) {
3972:             #require_once 'Zend/Date/Exception.php';
3973:             throw new Zend_Date_Exception('parameter $weekday must be set, null is not allowed');
3974:         }
3975: 
3976:         if ($locale === null) {
3977:             $locale = $this->getLocale();
3978:         }
3979: 
3980:         if ($weekday instanceof Zend_Date) {
3981:             $weekday = $weekday->toString(self::WEEKDAY_8601, 'iso', $locale);
3982:         }
3983: 
3984:         if (is_numeric($weekday)) {
3985:             $type = self::WEEKDAY_8601;
3986:         } else if (is_array($weekday)) {
3987:             if (isset($weekday['weekday']) === true) {
3988:                 $weekday = $weekday['weekday'];
3989:                 $type = self::WEEKDAY;
3990:             } else {
3991:                 #require_once 'Zend/Date/Exception.php';
3992:                 throw new Zend_Date_Exception("no weekday given in array");
3993:             }
3994:         } else {
3995:             switch(iconv_strlen($weekday, 'UTF-8')) {
3996:                 case 1:
3997:                    $type = self::WEEKDAY_NARROW;
3998:                     break;
3999:                 case 2:
4000:                     $type = self::WEEKDAY_NAME;
4001:                     break;
4002:                 case 3:
4003:                     $type = self::WEEKDAY_SHORT;
4004:                     break;
4005:                 default:
4006:                     $type = self::WEEKDAY;
4007:                     break;
4008:             }
4009:         }
4010:         $return = $this->_calcdetail($calc, $weekday, $type, $locale);
4011:         if ($calc != 'cmp') {
4012:             return $this;
4013:         }
4014:         return $return;
4015:     }
4016: 
4017: 
4018:     /**
4019:      * Sets a new weekday
4020:      * The weekday can be a number or a string. If a localized weekday name is given,
4021:      * then it will be parsed as a date in $locale (defaults to the same locale as $this).
4022:      * Returned is the new date object.
4023:      * Example: setWeekday(3); will set the wednesday of this week as day.
4024:      *
4025:      * @param  string|integer|array|Zend_Date  $month   Weekday to set
4026:      * @param  string|Zend_Locale              $locale  OPTIONAL Locale for parsing input
4027:      * @return Zend_Date Provides fluid interface
4028:      * @throws Zend_Date_Exception
4029:      */
4030:     public function setWeekday($weekday, $locale = null)
4031:     {
4032:         return $this->_weekday('set', $weekday, $locale);
4033:     }
4034: 
4035: 
4036:     /**
4037:      * Adds weekdays to the existing date object.
4038:      * The weekday can be a number or a string.
4039:      * If a localized dayname is given it will be parsed with the default locale or the optional
4040:      * set locale.
4041:      * Returned is the new date object
4042:      * Example: addWeekday(3); will add the difference of days from the begining of the month until
4043:      * wednesday.
4044:      *
4045:      * @param  string|integer|array|Zend_Date  $month   Weekday to add
4046:      * @param  string|Zend_Locale              $locale  OPTIONAL Locale for parsing input
4047:      * @return Zend_Date Provides fluid interface
4048:      * @throws Zend_Date_Exception
4049:      */
4050:     public function addWeekday($weekday, $locale = null)
4051:     {
4052:         return $this->_weekday('add', $weekday, $locale);
4053:     }
4054: 
4055: 
4056:     /**
4057:      * Subtracts weekdays from the existing date object.
4058:      * The weekday can be a number or a string.
4059:      * If a localized dayname is given it will be parsed with the default locale or the optional
4060:      * set locale.
4061:      * Returned is the new date object
4062:      * Example: subWeekday(3); will subtract the difference of days from the begining of the month until
4063:      * wednesday.
4064:      *
4065:      * @param  string|integer|array|Zend_Date  $month   Weekday to sub
4066:      * @param  string|Zend_Locale              $locale  OPTIONAL Locale for parsing input
4067:      * @return Zend_Date Provides fluid interface
4068:      * @throws Zend_Date_Exception
4069:      */
4070:     public function subWeekday($weekday, $locale = null)
4071:     {
4072:         return $this->_weekday('sub', $weekday, $locale);
4073:     }
4074: 
4075: 
4076:     /**
4077:      * Compares the weekday with the existing date object, ignoring other date parts.
4078:      * For example: 'Monday', 'en' -> 08.Jan.2007 -> 0
4079:      * Returns if equal, earlier or later
4080:      *
4081:      * @param  string|integer|array|Zend_Date  $weekday  Weekday to compare
4082:      * @param  string|Zend_Locale              $locale   OPTIONAL Locale for parsing input
4083:      * @return integer  0 = equal, 1 = later, -1 = earlier
4084:      * @throws Zend_Date_Exception
4085:      */
4086:     public function compareWeekday($weekday, $locale = null)
4087:     {
4088:         return $this->_weekday('cmp', $weekday, $locale);
4089:     }
4090: 
4091: 
4092:     /**
4093:      * Returns the day of year as new date object
4094:      * Example: 02.Feb.1986 10:00:00 -> 02.Feb.1970 00:00:00
4095:      *
4096:      * @param  string|Zend_Locale  $locale  OPTIONAL Locale for parsing input
4097:      * @return Zend_Date
4098:      */
4099:     public function getDayOfYear($locale = null)
4100:     {
4101:         if (self::$_options['format_type'] == 'php') {
4102:             $format = 'D';
4103:         } else {
4104:             $format = self::DAY_OF_YEAR;
4105:         }
4106: 
4107:         return $this->copyPart($format, $locale);
4108:     }
4109: 
4110: 
4111:     /**
4112:      * Sets a new day of year
4113:      * The day of year is always a number.
4114:      * Returned is the new date object
4115:      * Example: 04.May.2004 -> setDayOfYear(10) -> 10.Jan.2004
4116:      *
4117:      * @param  string|integer|array|Zend_Date  $day     Day of Year to set
4118:      * @param  string|Zend_Locale              $locale  OPTIONAL Locale for parsing input
4119:      * @return Zend_Date Provides fluid interface
4120:      * @throws Zend_Date_Exception
4121:      */
4122:     public function setDayOfYear($day, $locale = null)
4123:     {
4124:         return $this->_calcvalue('set', $day, 'day of year', self::DAY_OF_YEAR, $locale);
4125:     }
4126: 
4127: 
4128:     /**
4129:      * Adds a day of year to the existing date object.
4130:      * The day of year is always a number.
4131:      * Returned is the new date object
4132:      * Example: addDayOfYear(10); will add 10 days to the existing date object.
4133:      *
4134:      * @param  string|integer|array|Zend_Date  $day     Day of Year to add
4135:      * @param  string|Zend_Locale              $locale  OPTIONAL Locale for parsing input
4136:      * @return Zend_Date Provides fluid interface
4137:      * @throws Zend_Date_Exception
4138:      */
4139:     public function addDayOfYear($day, $locale = null)
4140:     {
4141:         return $this->_calcvalue('add', $day, 'day of year', self::DAY_OF_YEAR, $locale);
4142:     }
4143: 
4144: 
4145:     /**
4146:      * Subtracts a day of year from the existing date object.
4147:      * The day of year is always a number.
4148:      * Returned is the new date object
4149:      * Example: subDayOfYear(10); will subtract 10 days from the existing date object.
4150:      *
4151:      * @param  string|integer|array|Zend_Date  $day     Day of Year to sub
4152:      * @param  string|Zend_Locale              $locale  OPTIONAL Locale for parsing input
4153:      * @return Zend_Date Provides fluid interface
4154:      * @throws Zend_Date_Exception
4155:      */
4156:     public function subDayOfYear($day, $locale = null)
4157:     {
4158:         return $this->_calcvalue('sub', $day, 'day of year', self::DAY_OF_YEAR, $locale);
4159:     }
4160: 
4161: 
4162:     /**
4163:      * Compares the day of year with the existing date object.
4164:      * For example: compareDayOfYear(33) -> 02.Feb.2007 -> 0
4165:      * Returns if equal, earlier or later
4166:      *
4167:      * @param  string|integer|array|Zend_Date  $day     Day of Year to compare
4168:      * @param  string|Zend_Locale              $locale  OPTIONAL Locale for parsing input
4169:      * @return integer  0 = equal, 1 = later, -1 = earlier
4170:      * @throws Zend_Date_Exception
4171:      */
4172:     public function compareDayOfYear($day, $locale = null)
4173:     {
4174:         return $this->_calcvalue('cmp', $day, 'day of year', self::DAY_OF_YEAR, $locale);
4175:     }
4176: 
4177: 
4178:     /**
4179:      * Returns the hour as new date object
4180:      * Example: 02.Feb.1986 10:30:25 -> 01.Jan.1970 10:00:00
4181:      *
4182:      * @param $locale  string|Zend_Locale  OPTIONAL Locale for parsing input
4183:      * @return Zend_Date
4184:      */
4185:     public function getHour($locale = null)
4186:     {
4187:         return $this->copyPart(self::HOUR, $locale);
4188:     }
4189: 
4190: 
4191:     /**
4192:      * Sets a new hour
4193:      * The hour is always a number.
4194:      * Returned is the new date object
4195:      * Example: 04.May.1993 13:07:25 -> setHour(7); -> 04.May.1993 07:07:25
4196:      *
4197:      * @param  string|integer|array|Zend_Date  $hour    Hour to set
4198:      * @param  string|Zend_Locale              $locale  OPTIONAL Locale for parsing input
4199:      * @return Zend_Date Provides fluid interface
4200:      * @throws Zend_Date_Exception
4201:      */
4202:     public function setHour($hour, $locale = null)
4203:     {
4204:         return $this->_calcvalue('set', $hour, 'hour', self::HOUR_SHORT, $locale);
4205:     }
4206: 
4207: 
4208:     /**
4209:      * Adds hours to the existing date object.
4210:      * The hour is always a number.
4211:      * Returned is the new date object
4212:      * Example: 04.May.1993 13:07:25 -> addHour(12); -> 05.May.1993 01:07:25
4213:      *
4214:      * @param  string|integer|array|Zend_Date  $hour    Hour to add
4215:      * @param  string|Zend_Locale              $locale  OPTIONAL Locale for parsing input
4216:      * @return Zend_Date Provides fluid interface
4217:      * @throws Zend_Date_Exception
4218:      */
4219:     public function addHour($hour, $locale = null)
4220:     {
4221:         return $this->_calcvalue('add', $hour, 'hour', self::HOUR_SHORT, $locale);
4222:     }
4223: 
4224: 
4225:     /**
4226:      * Subtracts hours from the existing date object.
4227:      * The hour is always a number.
4228:      * Returned is the new date object
4229:      * Example: 04.May.1993 13:07:25 -> subHour(6); -> 05.May.1993 07:07:25
4230:      *
4231:      * @param  string|integer|array|Zend_Date  $hour    Hour to sub
4232:      * @param  string|Zend_Locale              $locale  OPTIONAL Locale for parsing input
4233:      * @return Zend_Date Provides fluid interface
4234:      * @throws Zend_Date_Exception
4235:      */
4236:     public function subHour($hour, $locale = null)
4237:     {
4238:         return $this->_calcvalue('sub', $hour, 'hour', self::HOUR_SHORT, $locale);
4239:     }
4240: 
4241: 
4242:     /**
4243:      * Compares the hour with the existing date object.
4244:      * For example: 10:30:25 -> compareHour(10) -> 0
4245:      * Returns if equal, earlier or later
4246:      *
4247:      * @param  string|integer|array|Zend_Date  $hour    Hour to compare
4248:      * @param  string|Zend_Locale              $locale  OPTIONAL Locale for parsing input
4249:      * @return integer  0 = equal, 1 = later, -1 = earlier
4250:      * @throws Zend_Date_Exception
4251:      */
4252:     public function compareHour($hour, $locale = null)
4253:     {
4254:         return $this->_calcvalue('cmp', $hour, 'hour', self::HOUR_SHORT, $locale);
4255:     }
4256: 
4257: 
4258:     /**
4259:      * Returns the minute as new date object
4260:      * Example: 02.Feb.1986 10:30:25 -> 01.Jan.1970 00:30:00
4261:      *
4262:      * @param  string|Zend_Locale  $locale  OPTIONAL Locale for parsing input
4263:      * @return Zend_Date
4264:      */
4265:     public function getMinute($locale = null)
4266:     {
4267:         if (self::$_options['format_type'] == 'php') {
4268:             $format = 'i';
4269:         } else {
4270:             $format = self::MINUTE;
4271:         }
4272: 
4273:         return $this->copyPart($format, $locale);
4274:     }
4275: 
4276: 
4277:     /**
4278:      * Sets a new minute
4279:      * The minute is always a number.
4280:      * Returned is the new date object
4281:      * Example: 04.May.1993 13:07:25 -> setMinute(29); -> 04.May.1993 13:29:25
4282:      *
4283:      * @param  string|integer|array|Zend_Date  $minute  Minute to set
4284:      * @param  string|Zend_Locale              $locale  OPTIONAL Locale for parsing input
4285:      * @return Zend_Date Provides fluid interface
4286:      * @throws Zend_Date_Exception
4287:      */
4288:     public function setMinute($minute, $locale = null)
4289:     {
4290:         return $this->_calcvalue('set', $minute, 'minute', self::MINUTE_SHORT, $locale);
4291:     }
4292: 
4293: 
4294:     /**
4295:      * Adds minutes to the existing date object.
4296:      * The minute is always a number.
4297:      * Returned is the new date object
4298:      * Example: 04.May.1993 13:07:25 -> addMinute(65); -> 04.May.1993 13:12:25
4299:      *
4300:      * @param  string|integer|array|Zend_Date  $minute  Minute to add
4301:      * @param  string|Zend_Locale              $locale  OPTIONAL Locale for parsing input
4302:      * @return Zend_Date Provides fluid interface
4303:      * @throws Zend_Date_Exception
4304:      */
4305:     public function addMinute($minute, $locale = null)
4306:     {
4307:         return $this->_calcvalue('add', $minute, 'minute', self::MINUTE_SHORT, $locale);
4308:     }
4309: 
4310: 
4311:     /**
4312:      * Subtracts minutes from the existing date object.
4313:      * The minute is always a number.
4314:      * Returned is the new date object
4315:      * Example: 04.May.1993 13:07:25 -> subMinute(9); -> 04.May.1993 12:58:25
4316:      *
4317:      * @param  string|integer|array|Zend_Date  $minute  Minute to sub
4318:      * @param  string|Zend_Locale              $locale  OPTIONAL Locale for parsing input
4319:      * @return Zend_Date Provides fluid interface
4320:      * @throws Zend_Date_Exception
4321:      */
4322:     public function subMinute($minute, $locale = null)
4323:     {
4324:         return $this->_calcvalue('sub', $minute, 'minute', self::MINUTE_SHORT, $locale);
4325:     }
4326: 
4327: 
4328:     /**
4329:      * Compares the minute with the existing date object.
4330:      * For example: 10:30:25 -> compareMinute(30) -> 0
4331:      * Returns if equal, earlier or later
4332:      *
4333:      * @param  string|integer|array|Zend_Date  $minute  Hour to compare
4334:      * @param  string|Zend_Locale              $locale  OPTIONAL Locale for parsing input
4335:      * @return integer  0 = equal, 1 = later, -1 = earlier
4336:      * @throws Zend_Date_Exception
4337:      */
4338:     public function compareMinute($minute, $locale = null)
4339:     {
4340:         return $this->_calcvalue('cmp', $minute, 'minute', self::MINUTE_SHORT, $locale);
4341:     }
4342: 
4343: 
4344:     /**
4345:      * Returns the second as new date object
4346:      * Example: 02.Feb.1986 10:30:25 -> 01.Jan.1970 00:00:25
4347:      *
4348:      * @param  string|Zend_Locale  $locale  OPTIONAL Locale for parsing input
4349:      * @return Zend_Date
4350:      */
4351:     public function getSecond($locale = null)
4352:     {
4353:         if (self::$_options['format_type'] == 'php') {
4354:             $format = 's';
4355:         } else {
4356:             $format = self::SECOND;
4357:         }
4358: 
4359:         return $this->copyPart($format, $locale);
4360:     }
4361: 
4362: 
4363:     /**
4364:      * Sets new seconds to the existing date object.
4365:      * The second is always a number.
4366:      * Returned is the new date object
4367:      * Example: 04.May.1993 13:07:25 -> setSecond(100); -> 04.May.1993 13:08:40
4368:      *
4369:      * @param  string|integer|array|Zend_Date $second Second to set
4370:      * @param  string|Zend_Locale             $locale (Optional) Locale for parsing input
4371:      * @return Zend_Date Provides fluid interface
4372:      * @throws Zend_Date_Exception
4373:      */
4374:     public function setSecond($second, $locale = null)
4375:     {
4376:         return $this->_calcvalue('set', $second, 'second', self::SECOND_SHORT, $locale);
4377:     }
4378: 
4379: 
4380:     /**
4381:      * Adds seconds to the existing date object.
4382:      * The second is always a number.
4383:      * Returned is the new date object
4384:      * Example: 04.May.1993 13:07:25 -> addSecond(65); -> 04.May.1993 13:08:30
4385:      *
4386:      * @param  string|integer|array|Zend_Date $second Second to add
4387:      * @param  string|Zend_Locale             $locale (Optional) Locale for parsing input
4388:      * @return Zend_Date Provides fluid interface
4389:      * @throws Zend_Date_Exception
4390:      */
4391:     public function addSecond($second, $locale = null)
4392:     {
4393:         return $this->_calcvalue('add', $second, 'second', self::SECOND_SHORT, $locale);
4394:     }
4395: 
4396: 
4397:     /**
4398:      * Subtracts seconds from the existing date object.
4399:      * The second is always a number.
4400:      * Returned is the new date object
4401:      * Example: 04.May.1993 13:07:25 -> subSecond(10); -> 04.May.1993 13:07:15
4402:      *
4403:      * @param  string|integer|array|Zend_Date $second Second to sub
4404:      * @param  string|Zend_Locale             $locale (Optional) Locale for parsing input
4405:      * @return Zend_Date Provides fluid interface
4406:      * @throws Zend_Date_Exception
4407:      */
4408:     public function subSecond($second, $locale = null)
4409:     {
4410:         return $this->_calcvalue('sub', $second, 'second', self::SECOND_SHORT, $locale);
4411:     }
4412: 
4413: 
4414:     /**
4415:      * Compares the second with the existing date object.
4416:      * For example: 10:30:25 -> compareSecond(25) -> 0
4417:      * Returns if equal, earlier or later
4418:      *
4419:      * @param  string|integer|array|Zend_Date $second Second to compare
4420:      * @param  string|Zend_Locale             $locale (Optional) Locale for parsing input
4421:      * @return integer  0 = equal, 1 = later, -1 = earlier
4422:      * @throws Zend_Date_Exception
4423:      */
4424:     public function compareSecond($second, $locale = null)
4425:     {
4426:         return $this->_calcvalue('cmp', $second, 'second', self::SECOND_SHORT, $locale);
4427:     }
4428: 
4429: 
4430:     /**
4431:      * Returns the precision for fractional seconds
4432:      *
4433:      * @return integer
4434:      */
4435:     public function getFractionalPrecision()
4436:     {
4437:         return $this->_precision;
4438:     }
4439: 
4440: 
4441:     /**
4442:      * Sets a new precision for fractional seconds
4443:      *
4444:      * @param  integer $precision Precision for the fractional datepart 3 = milliseconds
4445:      * @throws Zend_Date_Exception
4446:      * @return Zend_Date Provides fluid interface
4447:      */
4448:     public function setFractionalPrecision($precision)
4449:     {
4450:         if (!intval($precision) or ($precision < 0) or ($precision > 9)) {
4451:             #require_once 'Zend/Date/Exception.php';
4452:             throw new Zend_Date_Exception("precision ($precision) must be a positive integer less than 10", 0, null, $precision);
4453:         }
4454: 
4455:         $this->_precision = (int) $precision;
4456:         if ($this->_precision < strlen($this->_fractional)) {
4457:             $this->_fractional = substr($this->_fractional, 0, $this->_precision);
4458:         } else {
4459:             $this->_fractional = str_pad($this->_fractional, $this->_precision, '0', STR_PAD_RIGHT);
4460:         }
4461: 
4462:         return $this;
4463:     }
4464: 
4465: 
4466:     /**
4467:      * Returns the milliseconds of the date object
4468:      *
4469:      * @return string
4470:      */
4471:     public function getMilliSecond()
4472:     {
4473:         return $this->_fractional;
4474:     }
4475: 
4476: 
4477:     /**
4478:      * Sets new milliseconds for the date object
4479:      * Example: setMilliSecond(550, 2) -> equals +5 Sec +50 MilliSec
4480:      *
4481:      * @param  integer|Zend_Date $milli     (Optional) Millisecond to set, when null the actual millisecond is set
4482:      * @param  integer           $precision (Optional) Fraction precision of the given milliseconds
4483:      * @return Zend_Date Provides fluid interface
4484:      */
4485:     public function setMilliSecond($milli = null, $precision = null)
4486:     {
4487:         if ($milli === null) {
4488:             list($milli, $time) = explode(" ", microtime());
4489:             $milli = intval($milli);
4490:             $precision = 6;
4491:         } else if (!is_numeric($milli)) {
4492:             #require_once 'Zend/Date/Exception.php';
4493:             throw new Zend_Date_Exception("invalid milli second ($milli) operand", 0, null, $milli);
4494:         }
4495: 
4496:         if ($precision === null) {
4497:             $precision = $this->_precision;
4498:         }
4499: 
4500:         if (!is_int($precision) || $precision < 1 || $precision > 9) {
4501:             #require_once 'Zend/Date/Exception.php';
4502:             throw new Zend_Date_Exception("precision ($precision) must be a positive integer less than 10", 0, null, $precision);
4503:         }
4504: 
4505:         $this->_fractional = 0;
4506:         $this->addMilliSecond($milli, $precision);
4507:         return $this;
4508:     }
4509: 
4510: 
4511:     /**
4512:      * Adds milliseconds to the date object
4513:      *
4514:      * @param  integer|Zend_Date $milli     (Optional) Millisecond to add, when null the actual millisecond is added
4515:      * @param  integer           $precision (Optional) Fractional precision for the given milliseconds
4516:      * @return Zend_Date Provides fluid interface
4517:      */
4518:     public function addMilliSecond($milli = null, $precision = null)
4519:     {
4520:         if ($milli === null) {
4521:             list($milli, $time) = explode(" ", microtime());
4522:             $milli = intval($milli);
4523:         } else if (!is_numeric($milli)) {
4524:             #require_once 'Zend/Date/Exception.php';
4525:             throw new Zend_Date_Exception("invalid milli second ($milli) operand", 0, null, $milli);
4526:         }
4527: 
4528:         if ($precision === null) {
4529:             $precision = strlen($milli);
4530:             if ($milli < 0) {
4531:                 --$precision;
4532:             }
4533:         }
4534: 
4535:         if (!is_int($precision) || $precision < 1 || $precision > 9) {
4536:             #require_once 'Zend/Date/Exception.php';
4537:             throw new Zend_Date_Exception("precision ($precision) must be a positive integer less than 10", 0, null, $precision);
4538:         }
4539: 
4540:         $this->_fractional += $milli;
4541: 
4542:         // Add/sub milliseconds + add/sub seconds
4543:         $max = pow(10, $this->_precision);
4544:         // Milli includes seconds
4545:         if ($this->_fractional >= $max) {
4546:             while ($this->_fractional >= $max) {
4547:                 $this->addSecond(1);
4548:                 $this->_fractional -= $max;
4549:             }
4550:         }
4551: 
4552:         if ($this->_fractional < 0) {
4553:             while ($this->_fractional < 0) {
4554:                 $this->subSecond(1);
4555:                 $this->_fractional += $max;
4556:             }
4557:         }
4558: 
4559:         if ($this->_precision > strlen($this->_fractional)) {
4560:             $this->_fractional = str_pad($this->_fractional, $this->_precision, '0', STR_PAD_LEFT);
4561:         }
4562: 
4563:         return $this;
4564:     }
4565: 
4566: 
4567:     /**
4568:      * Subtracts a millisecond
4569:      *
4570:      * @param  integer|Zend_Date $milli     (Optional) Millisecond to sub, when null the actual millisecond is subtracted
4571:      * @param  integer           $precision (Optional) Fractional precision for the given milliseconds
4572:      * @return Zend_Date Provides fluid interface
4573:      */
4574:     public function subMilliSecond($milli = null, $precision = null)
4575:     {
4576:         $this->addMilliSecond(0 - $milli, $precision);
4577:         return $this;
4578:     }
4579: 
4580:     /**
4581:      * Compares only the millisecond part, returning the difference
4582:      *
4583:      * @param  integer|Zend_Date  $milli  OPTIONAL Millisecond to compare, when null the actual millisecond is compared
4584:      * @param  integer            $precision  OPTIONAL Fractional precision for the given milliseconds
4585:      * @throws Zend_Date_Exception On invalid input
4586:      * @return integer  0 = equal, 1 = later, -1 = earlier
4587:      */
4588:     public function compareMilliSecond($milli = null, $precision = null)
4589:     {
4590:         if ($milli === null) {
4591:             list($milli, $time) = explode(" ", microtime());
4592:             $milli = intval($milli);
4593:         } else if (is_numeric($milli) === false) {
4594:             #require_once 'Zend/Date/Exception.php';
4595:             throw new Zend_Date_Exception("invalid milli second ($milli) operand", 0, null, $milli);
4596:         }
4597: 
4598:         if ($precision === null) {
4599:             $precision = strlen($milli);
4600:         } else if (!is_int($precision) || $precision < 1 || $precision > 9) {
4601:             #require_once 'Zend/Date/Exception.php';
4602:             throw new Zend_Date_Exception("precision ($precision) must be a positive integer less than 10", 0, null, $precision);
4603:         }
4604: 
4605:         if ($precision === 0) {
4606:             #require_once 'Zend/Date/Exception.php';
4607:             throw new Zend_Date_Exception('precision is 0');
4608:         }
4609: 
4610:         if ($precision != $this->_precision) {
4611:             if ($precision > $this->_precision) {
4612:                 $diff = $precision - $this->_precision;
4613:                 $milli = (int) ($milli / (10 * $diff));
4614:             } else {
4615:                 $diff = $this->_precision - $precision;
4616:                 $milli = (int) ($milli * (10 * $diff));
4617:             }
4618:         }
4619: 
4620:         $comp = $this->_fractional - $milli;
4621:         if ($comp < 0) {
4622:             return -1;
4623:         } else if ($comp > 0) {
4624:             return 1;
4625:         }
4626:         return 0;
4627:     }
4628: 
4629:     /**
4630:      * Returns the week as new date object using monday as begining of the week
4631:      * Example: 12.Jan.2007 -> 08.Jan.1970 00:00:00
4632:      *
4633:      * @param $locale  string|Zend_Locale  OPTIONAL Locale for parsing input
4634:      * @return Zend_Date
4635:      */
4636:     public function getWeek($locale = null)
4637:     {
4638:         if (self::$_options['format_type'] == 'php') {
4639:             $format = 'W';
4640:         } else {
4641:             $format = self::WEEK;
4642:         }
4643: 
4644:         return $this->copyPart($format, $locale);
4645:     }
4646: 
4647:     /**
4648:      * Sets a new week. The week is always a number. The day of week is not changed.
4649:      * Returned is the new date object
4650:      * Example: 09.Jan.2007 13:07:25 -> setWeek(1); -> 02.Jan.2007 13:07:25
4651:      *
4652:      * @param  string|integer|array|Zend_Date  $week    Week to set
4653:      * @param  string|Zend_Locale              $locale  OPTIONAL Locale for parsing input
4654:      * @return Zend_Date Provides fluid interface
4655:      * @throws Zend_Date_Exception
4656:      */
4657:     public function setWeek($week, $locale = null)
4658:     {
4659:         return $this->_calcvalue('set', $week, 'week', self::WEEK, $locale);
4660:     }
4661: 
4662:     /**
4663:      * Adds a week. The week is always a number. The day of week is not changed.
4664:      * Returned is the new date object
4665:      * Example: 09.Jan.2007 13:07:25 -> addWeek(1); -> 16.Jan.2007 13:07:25
4666:      *
4667:      * @param  string|integer|array|Zend_Date  $week    Week to add
4668:      * @param  string|Zend_Locale              $locale  OPTIONAL Locale for parsing input
4669:      * @return Zend_Date Provides fluid interface
4670:      * @throws Zend_Date_Exception
4671:      */
4672:     public function addWeek($week, $locale = null)
4673:     {
4674:         return $this->_calcvalue('add', $week, 'week', self::WEEK, $locale);
4675:     }
4676: 
4677:     /**
4678:      * Subtracts a week. The week is always a number. The day of week is not changed.
4679:      * Returned is the new date object
4680:      * Example: 09.Jan.2007 13:07:25 -> subWeek(1); -> 02.Jan.2007 13:07:25
4681:      *
4682:      * @param  string|integer|array|Zend_Date  $week    Week to sub
4683:      * @param  string|Zend_Locale              $locale  OPTIONAL Locale for parsing input
4684:      * @return Zend_Date Provides fluid interface
4685:      * @throws Zend_Date_Exception
4686:      */
4687:     public function subWeek($week, $locale = null)
4688:     {
4689:         return $this->_calcvalue('sub', $week, 'week', self::WEEK, $locale);
4690:     }
4691: 
4692:     /**
4693:      * Compares only the week part, returning the difference
4694:      * Returned is the new date object
4695:      * Returns if equal, earlier or later
4696:      * Example: 09.Jan.2007 13:07:25 -> compareWeek(2); -> 0
4697:      *
4698:      * @param  string|integer|array|Zend_Date  $week    Week to compare
4699:      * @param  string|Zend_Locale              $locale  OPTIONAL Locale for parsing input
4700:      * @return integer 0 = equal, 1 = later, -1 = earlier
4701:      */
4702:     public function compareWeek($week, $locale = null)
4703:     {
4704:         return $this->_calcvalue('cmp', $week, 'week', self::WEEK, $locale);
4705:     }
4706: 
4707:     /**
4708:      * Sets a new standard locale for the date object.
4709:      * This locale will be used for all functions
4710:      * Returned is the really set locale.
4711:      * Example: 'de_XX' will be set to 'de' because 'de_XX' does not exist
4712:      * 'xx_YY' will be set to 'root' because 'xx' does not exist
4713:      *
4714:      * @param  string|Zend_Locale $locale (Optional) Locale for parsing input
4715:      * @throws Zend_Date_Exception When the given locale does not exist
4716:      * @return Zend_Date Provides fluent interface
4717:      */
4718:     public function setLocale($locale = null)
4719:     {
4720:         try {
4721:             $this->_locale = Zend_Locale::findLocale($locale);
4722:         } catch (Zend_Locale_Exception $e) {
4723:             #require_once 'Zend/Date/Exception.php';
4724:             throw new Zend_Date_Exception($e->getMessage(), 0, $e);
4725:         }
4726: 
4727:         return $this;
4728:     }
4729: 
4730:     /**
4731:      * Returns the actual set locale
4732:      *
4733:      * @return string
4734:      */
4735:     public function getLocale()
4736:     {
4737:         return $this->_locale;
4738:     }
4739: 
4740:     /**
4741:      * Checks if the given date is a real date or datepart.
4742:      * Returns false if a expected datepart is missing or a datepart exceeds its possible border.
4743:      * But the check will only be done for the expected dateparts which are given by format.
4744:      * If no format is given the standard dateformat for the actual locale is used.
4745:      * f.e. 30.February.2007 will return false if format is 'dd.MMMM.YYYY'
4746:      *
4747:      * @param  string|array|Zend_Date $date   Date to parse for correctness
4748:      * @param  string                 $format (Optional) Format for parsing the date string
4749:      * @param  string|Zend_Locale     $locale (Optional) Locale for parsing date parts
4750:      * @return boolean                True when all date parts are correct
4751:      */
4752:     public static function isDate($date, $format = null, $locale = null)
4753:     {
4754:         if (!is_string($date) && !is_numeric($date) && !($date instanceof Zend_Date) &&
4755:             !is_array($date)) {
4756:             return false;
4757:         }
4758: 
4759:         if (($format !== null) && ($format != 'ee') && ($format != 'ss') && ($format != 'GG') && ($format != 'MM') && ($format != 'EE') && ($format != 'TT')
4760:             && (Zend_Locale::isLocale($format, null, false))) {
4761:             $locale = $format;
4762:             $format = null;
4763:         }
4764: 
4765:         $locale = Zend_Locale::findLocale($locale);
4766: 
4767:         if ($format === null) {
4768:             $format = Zend_Locale_Format::getDateFormat($locale);
4769:         } else if ((self::$_options['format_type'] == 'php') && !defined($format)) {
4770:             $format = Zend_Locale_Format::convertPhpToIsoFormat($format);
4771:         }
4772: 
4773:         $format = self::_getLocalizedToken($format, $locale);
4774:         if (!is_array($date)) {
4775:             try {
4776:                 $parsed = Zend_Locale_Format::getDate($date, array('locale' => $locale,
4777:                                                       'date_format' => $format, 'format_type' => 'iso',
4778:                                                       'fix_date' => false));
4779:             } catch (Zend_Locale_Exception $e) {
4780:                 // Date can not be parsed
4781:                 return false;
4782:             }
4783:         } else {
4784:             $parsed = $date;
4785:         }
4786: 
4787:         if (((strpos($format, 'Y') !== false) or (strpos($format, 'y') !== false)) and
4788:             (!isset($parsed['year']))) {
4789:             // Year expected but not found
4790:                 return false;
4791:         }
4792: 
4793:         if ((strpos($format, 'M') !== false) and (!isset($parsed['month']))) {
4794:             // Month expected but not found
4795:             return false;
4796:         }
4797: 
4798:         if ((strpos($format, 'd') !== false) and (!isset($parsed['day']))) {
4799:             // Day expected but not found
4800:             return false;
4801:         }
4802: 
4803:         if (((strpos($format, 'H') !== false) or (strpos($format, 'h') !== false)) and
4804:             (!isset($parsed['hour']))) {
4805:             // Hour expected but not found
4806:                 return false;
4807:         }
4808: 
4809:         if ((strpos($format, 'm') !== false) and (!isset($parsed['minute']))) {
4810:             // Minute expected but not found
4811:             return false;
4812:         }
4813: 
4814:         if ((strpos($format, 's') !== false) and (!isset($parsed['second']))) {
4815:             // Second expected  but not found
4816:             return false;
4817:         }
4818: 
4819:         // Set not given dateparts
4820:         if (isset($parsed['hour']) === false) {
4821:             $parsed['hour'] = 12;
4822:         }
4823: 
4824:         if (isset($parsed['minute']) === false) {
4825:             $parsed['minute'] = 0;
4826:         }
4827: 
4828:         if (isset($parsed['second']) === false) {
4829:             $parsed['second'] = 0;
4830:         }
4831: 
4832:         if (isset($parsed['month']) === false) {
4833:             $parsed['month'] = 1;
4834:         }
4835: 
4836:         if (isset($parsed['day']) === false) {
4837:             $parsed['day'] = 1;
4838:         }
4839: 
4840:         if (isset($parsed['year']) === false) {
4841:             $parsed['year'] = 1970;
4842:         }
4843: 
4844:         if (self::isYearLeapYear($parsed['year'])) {
4845:             $parsed['year'] = 1972;
4846:         } else {
4847:             $parsed['year'] = 1971;
4848:         }
4849: 
4850:         $date      = new self($parsed, null, $locale);
4851:         $timestamp = $date->mktime($parsed['hour'], $parsed['minute'], $parsed['second'],
4852:                                    $parsed['month'], $parsed['day'], $parsed['year']);
4853: 
4854:         if ($parsed['year'] != $date->date('Y', $timestamp)) {
4855:             // Given year differs from parsed year
4856:             return false;
4857:         }
4858: 
4859:         if ($parsed['month'] != $date->date('n', $timestamp)) {
4860:             // Given month differs from parsed month
4861:             return false;
4862:         }
4863: 
4864:         if ($parsed['day'] != $date->date('j', $timestamp)) {
4865:             // Given day differs from parsed day
4866:             return false;
4867:         }
4868: 
4869:         if ($parsed['hour'] != $date->date('G', $timestamp)) {
4870:             // Given hour differs from parsed hour
4871:             return false;
4872:         }
4873: 
4874:         if ($parsed['minute'] != $date->date('i', $timestamp)) {
4875:             // Given minute differs from parsed minute
4876:             return false;
4877:         }
4878: 
4879:         if ($parsed['second'] != $date->date('s', $timestamp)) {
4880:             // Given second differs from parsed second
4881:             return false;
4882:         }
4883: 
4884:         return true;
4885:     }
4886: 
4887:     /**
4888:      * Returns the ISO Token for all localized constants
4889:      *
4890:      * @param string $token Token to normalize
4891:      * @param string $locale Locale to search
4892:      * @return string
4893:      */
4894:     protected static function _getLocalizedToken($token, $locale)
4895:     {
4896:         switch($token) {
4897:             case self::ISO_8601 :
4898:                 return "yyyy-MM-ddThh:mm:ss";
4899:                 break;
4900:             case self::RFC_2822 :
4901:                 return "EEE, dd MMM yyyy HH:mm:ss";
4902:                 break;
4903:             case self::DATES :
4904:                 return Zend_Locale_Data::getContent($locale, 'date');
4905:                 break;
4906:             case self::DATE_FULL :
4907:                 return Zend_Locale_Data::getContent($locale, 'date', array('gregorian', 'full'));
4908:                 break;
4909:             case self::DATE_LONG :
4910:                 return Zend_Locale_Data::getContent($locale, 'date', array('gregorian', 'long'));
4911:                 break;
4912:             case self::DATE_MEDIUM :
4913:                 return Zend_Locale_Data::getContent($locale, 'date', array('gregorian', 'medium'));
4914:                 break;
4915:             case self::DATE_SHORT :
4916:                 return Zend_Locale_Data::getContent($locale, 'date', array('gregorian', 'short'));
4917:                 break;
4918:             case self::TIMES :
4919:                 return Zend_Locale_Data::getContent($locale, 'time');
4920:                 break;
4921:             case self::TIME_FULL :
4922:                 return Zend_Locale_Data::getContent($locale, 'time', array('gregorian', 'full'));
4923:                 break;
4924:             case self::TIME_LONG :
4925:                 return Zend_Locale_Data::getContent($locale, 'time', array('gregorian', 'long'));
4926:                 break;
4927:             case self::TIME_MEDIUM :
4928:                 return Zend_Locale_Data::getContent($locale, 'time', array('gregorian', 'medium'));
4929:                 break;
4930:             case self::TIME_SHORT :
4931:                 return Zend_Locale_Data::getContent($locale, 'time', array('gregorian', 'short'));
4932:                 break;
4933:             case self::DATETIME :
4934:                 return Zend_Locale_Data::getContent($locale, 'datetime');
4935:                 break;
4936:             case self::DATETIME_FULL :
4937:                 return Zend_Locale_Data::getContent($locale, 'datetime', array('gregorian', 'full'));
4938:                 break;
4939:             case self::DATETIME_LONG :
4940:                 return Zend_Locale_Data::getContent($locale, 'datetime', array('gregorian', 'long'));
4941:                 break;
4942:             case self::DATETIME_MEDIUM :
4943:                 return Zend_Locale_Data::getContent($locale, 'datetime', array('gregorian', 'medium'));
4944:                 break;
4945:             case self::DATETIME_SHORT :
4946:                 return Zend_Locale_Data::getContent($locale, 'datetime', array('gregorian', 'short'));
4947:                 break;
4948:             case self::ATOM :
4949:             case self::RFC_3339 :
4950:             case self::W3C :
4951:                 return "yyyy-MM-DD HH:mm:ss";
4952:                 break;
4953:             case self::COOKIE :
4954:             case self::RFC_850 :
4955:                 return "EEEE, dd-MM-yyyy HH:mm:ss";
4956:                 break;
4957:             case self::RFC_822 :
4958:             case self::RFC_1036 :
4959:             case self::RFC_1123 :
4960:             case self::RSS :
4961:                 return "EEE, dd MM yyyy HH:mm:ss";
4962:                 break;
4963:         }
4964: 
4965:         return $token;
4966:     }
4967: 
4968:     /**
4969:      * Get unix timestamp.
4970:      * Added limitation: $year value must be between -10 000 and 10 000
4971:      * Parent method implementation causes 504 error if it gets too big(small) year value
4972:      *
4973:      * @see Zend_Date_DateObject::mktime
4974:      * @throws Zend_Date_Exception
4975:      * @param $hour
4976:      * @param $minute
4977:      * @param $second
4978:      * @param $month
4979:      * @param $day
4980:      * @param $year
4981:      * @param bool $gmt
4982:      * @return float|int
4983:      */
4984:     protected function mktime($hour, $minute, $second, $month, $day, $year, $gmt = false)
4985:     {
4986:         $day   = intval($day);
4987:         $month = intval($month);
4988:         $year  = intval($year);
4989: 
4990:         // correct months > 12 and months < 1
4991:         if ($month > 12) {
4992:             $overlap = floor($month / 12);
4993:             $year   += $overlap;
4994:             $month  -= $overlap * 12;
4995:         } else {
4996:             $overlap = ceil((1 - $month) / 12);
4997:             $year   -= $overlap;
4998:             $month  += $overlap * 12;
4999:         }
5000: 
5001:         if ($year > self::YEAR_MAX_VALUE || $year < self::YEAR_MIN_VALUE) {
5002:             throw new Zend_Date_Exception('Invalid year, it must be between ' . self::YEAR_MIN_VALUE . ' and '
5003:                 . self::YEAR_MAX_VALUE);
5004:         }
5005: 
5006:         return parent::mktime($hour, $minute, $second, $month, $day, $year, $gmt);
5007:     }
5008: }
5009: 
Magento 1.7.0.2 API documentation generated by ApiGen 2.8.0