web/lib/Zend/Date.php
changeset 807 877f952ae2bd
parent 207 621fa6caec0c
child 1230 68c69c656a2c
equal deleted inserted replaced
805:5e7a0fedabdf 807:877f952ae2bd
    12  * obtain it through the world-wide-web, please send an email
    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.
    13  * to license@zend.com so we can send you a copy immediately.
    14  *
    14  *
    15  * @category  Zend
    15  * @category  Zend
    16  * @package   Zend_Date
    16  * @package   Zend_Date
    17  * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
    17  * @copyright  Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
    18  * @license   http://framework.zend.com/license/new-bsd     New BSD License
    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 $
    19  * @version   $Id: Date.php 24880 2012-06-12 20:35:18Z matthew $
    20  */
    20  */
    21 
    21 
    22 /**
    22 /**
    23  * Include needed Date classes
    23  * Include needed Date classes
    24  */
    24  */
    28 require_once 'Zend/Locale/Math.php';
    28 require_once 'Zend/Locale/Math.php';
    29 
    29 
    30 /**
    30 /**
    31  * @category  Zend
    31  * @category  Zend
    32  * @package   Zend_Date
    32  * @package   Zend_Date
    33  * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
    33  * @copyright  Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
    34  * @license   http://framework.zend.com/license/new-bsd     New BSD License
    34  * @license   http://framework.zend.com/license/new-bsd     New BSD License
    35  */
    35  */
    36 class Zend_Date extends Zend_Date_DateObject
    36 class Zend_Date extends Zend_Date_DateObject
    37 {
    37 {
    38     private $_locale  = null;
    38     private $_locale  = null;
  1199         if (!empty($match)) {
  1199         if (!empty($match)) {
  1200             return "Etc/UTC";
  1200             return "Etc/UTC";
  1201         }
  1201         }
  1202 
  1202 
  1203         preg_match('/([+-]\d{2}):{0,1}\d{2}/', $zone, $match);
  1203         preg_match('/([+-]\d{2}):{0,1}\d{2}/', $zone, $match);
  1204         if (!empty($match) and ($match[count($match) - 1] <= 12) and ($match[count($match) - 1] >= -12)) {
  1204         if (!empty($match) and ($match[count($match) - 1] <= 14) and ($match[count($match) - 1] >= -12)) {
  1205             $zone = "Etc/GMT";
  1205             $zone = "Etc/GMT";
  1206             $zone .= ($match[count($match) - 1] < 0) ? "+" : "-";
  1206             $zone .= ($match[count($match) - 1] < 0) ? "+" : "-";
  1207             $zone .= (int) abs($match[count($match) - 1]);
  1207             $zone .= (int) abs($match[count($match) - 1]);
  1208             return $zone;
  1208             return $zone;
  1209         }
  1209         }
  2105                 return $this->_assign($calc, $this->mktime($timematch[1], $timematch[2], $timematch[3], 1 + $datematch[2], 1 + $datematch[3], 1970 + $datematch[1], false),
  2105                 return $this->_assign($calc, $this->mktime($timematch[1], $timematch[2], $timematch[3], 1 + $datematch[2], 1 + $datematch[3], 1970 + $datematch[1], false),
  2106                                              $this->mktime($hour,         $minute,       $second,       1 + $month,        1 + $day,          1970 + $year,         false), false);
  2106                                              $this->mktime($hour,         $minute,       $second,       1 + $month,        1 + $day,          1970 + $year,         false), false);
  2107                 break;
  2107                 break;
  2108 
  2108 
  2109             case self::RFC_2822:
  2109             case self::RFC_2822:
  2110                 $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);
  2110                  $result = preg_match('/^\w{3},\s(\d{1,2})\s(\w{3})\s(\d{4})\s'
       
  2111                                     . '(\d{2}):(\d{2}):{0,1}(\d{0,2})\s([+-]'
       
  2112                                     . '{1}\d{4}|\w{1,20})$/', $date, $match);
       
  2113 
  2111                 if (!$result) {
  2114                 if (!$result) {
  2112                     require_once 'Zend/Date/Exception.php';
  2115                     require_once 'Zend/Date/Exception.php';
  2113                     throw new Zend_Date_Exception("no RFC 2822 format ($date)", 0, null, $date);
  2116                     throw new Zend_Date_Exception("no RFC 2822 format ($date)", 0, null, $date);
  2114                 }
  2117                 }
  2115 
  2118 
  2639                                 --$parsed['day'];
  2642                                 --$parsed['day'];
  2640                             } else {
  2643                             } else {
  2641                                 $parsed['day'] = 0;
  2644                                 $parsed['day'] = 0;
  2642                             }
  2645                             }
  2643 
  2646 
  2644                             if (isset($parsed['year'])) {
  2647                             if (!isset($parsed['year'])) {
  2645                                 $parsed['year'] -= 1970;
  2648                                 $parsed['year'] = 1970;
  2646                             } else {
       
  2647                                 $parsed['year'] = 0;
       
  2648                             }
  2649                             }
  2649                         }
  2650                         }
  2650 
  2651 
  2651                         return $this->_assign($calc, $this->mktime(
  2652                         return $this->_assign($calc, $this->mktime(
  2652                             isset($parsed['hour']) ? $parsed['hour'] : 0,
  2653                             isset($parsed['hour']) ? $parsed['hour'] : 0,
  2653                             isset($parsed['minute']) ? $parsed['minute'] : 0,
  2654                             isset($parsed['minute']) ? $parsed['minute'] : 0,
  2654                             isset($parsed['second']) ? $parsed['second'] : 0,
  2655                             isset($parsed['second']) ? $parsed['second'] : 0,
  2655                             isset($parsed['month']) ? (1 + $parsed['month']) : 1,
  2656                             isset($parsed['month']) ? (1 + $parsed['month']) : 1,
  2656                             isset($parsed['day']) ? (1 + $parsed['day']) : 1,
  2657                             isset($parsed['day']) ? (1 + $parsed['day']) : 1,
  2657                             isset($parsed['year']) ? (1970 + $parsed['year']) : 1970,
  2658                             $parsed['year'],
  2658                             false), $this->getUnixTimestamp(), false);
  2659                             false), $this->getUnixTimestamp(), false);
  2659                     } catch (Zend_Locale_Exception $e) {
  2660                     } catch (Zend_Locale_Exception $e) {
  2660                         if (!is_numeric($date)) {
  2661                         if (!is_numeric($date)) {
  2661                             require_once 'Zend/Date/Exception.php';
  2662                             require_once 'Zend/Date/Exception.php';
  2662                             throw new Zend_Date_Exception($e->getMessage(), 0, $e, $date);
  2663                             throw new Zend_Date_Exception($e->getMessage(), 0, $e, $date);
  3236 
  3237 
  3237 
  3238 
  3238     /**
  3239     /**
  3239      * Check if location is supported
  3240      * Check if location is supported
  3240      *
  3241      *
  3241      * @param $location array - locations array
  3242      * @param array $location locations array
  3242      * @return $horizon float
  3243      * @return $horizon float
  3243      */
  3244      */
  3244     private function _checkLocation($location)
  3245     private function _checkLocation($location)
  3245     {
  3246     {
  3246         if (!isset($location['longitude']) or !isset($location['latitude'])) {
  3247         if (!isset($location['longitude']) or !isset($location['latitude'])) {
  3279 
  3280 
  3280     /**
  3281     /**
  3281      * Returns the time of sunrise for this date and a given location as new date object
  3282      * Returns the time of sunrise for this date and a given location as new date object
  3282      * For a list of cities and correct locations use the class Zend_Date_Cities
  3283      * For a list of cities and correct locations use the class Zend_Date_Cities
  3283      *
  3284      *
  3284      * @param  $location array - location of sunrise
  3285      * @param array $location location of sunrise
  3285      *                   ['horizon']   -> civil, nautic, astronomical, effective (default)
  3286      *                   ['horizon']   -> civil, nautic, astronomical, effective (default)
  3286      *                   ['longitude'] -> longitude of location
  3287      *                   ['longitude'] -> longitude of location
  3287      *                   ['latitude']  -> latitude of location
  3288      *                   ['latitude']  -> latitude of location
  3288      * @return Zend_Date
  3289      * @return Zend_Date
  3289      * @throws Zend_Date_Exception
  3290      * @throws Zend_Date_Exception
  3299 
  3300 
  3300     /**
  3301     /**
  3301      * Returns the time of sunset for this date and a given location as new date object
  3302      * Returns the time of sunset for this date and a given location as new date object
  3302      * For a list of cities and correct locations use the class Zend_Date_Cities
  3303      * For a list of cities and correct locations use the class Zend_Date_Cities
  3303      *
  3304      *
  3304      * @param  $location array - location of sunset
  3305      * @param array $location location of sunset
  3305      *                   ['horizon']   -> civil, nautic, astronomical, effective (default)
  3306      *                   ['horizon']   -> civil, nautic, astronomical, effective (default)
  3306      *                   ['longitude'] -> longitude of location
  3307      *                   ['longitude'] -> longitude of location
  3307      *                   ['latitude']  -> latitude of location
  3308      *                   ['latitude']  -> latitude of location
  3308      * @return Zend_Date
  3309      * @return Zend_Date
  3309      * @throws Zend_Date_Exception
  3310      * @throws Zend_Date_Exception
  3319 
  3320 
  3320     /**
  3321     /**
  3321      * Returns an array with the sunset and sunrise dates for all horizon types
  3322      * Returns an array with the sunset and sunrise dates for all horizon types
  3322      * For a list of cities and correct locations use the class Zend_Date_Cities
  3323      * For a list of cities and correct locations use the class Zend_Date_Cities
  3323      *
  3324      *
  3324      * @param  $location array - location of suninfo
  3325      * @param array $location location of suninfo
  3325      *                   ['horizon']   -> civil, nautic, astronomical, effective (default)
  3326      *                   ['horizon']   -> civil, nautic, astronomical, effective (default)
  3326      *                   ['longitude'] -> longitude of location
  3327      *                   ['longitude'] -> longitude of location
  3327      *                   ['latitude']  -> latitude of location
  3328      *                   ['latitude']  -> latitude of location
  3328      * @return array - [sunset|sunrise][effective|civil|nautic|astronomic]
  3329      * @return array - [sunset|sunrise][effective|civil|nautic|astronomic]
  3329      * @throws Zend_Date_Exception
  3330      * @throws Zend_Date_Exception
  3784 
  3785 
  3785     /**
  3786     /**
  3786      * Returns the day as new date object
  3787      * Returns the day as new date object
  3787      * Example: 20.May.1986 -> 20.Jan.1970 00:00:00
  3788      * Example: 20.May.1986 -> 20.Jan.1970 00:00:00
  3788      *
  3789      *
  3789      * @param $locale  string|Zend_Locale  OPTIONAL Locale for parsing input
  3790      * @param Zend_Locale $locale OPTIONAL Locale for parsing input
  3790      * @return Zend_Date
  3791      * @return Zend_Date
  3791      */
  3792      */
  3792     public function getDay($locale = null)
  3793     public function getDay($locale = null)
  3793     {
  3794     {
  3794         return $this->copyPart(self::DAY_SHORT, $locale);
  3795         return $this->copyPart(self::DAY_SHORT, $locale);
  3796 
  3797 
  3797 
  3798 
  3798     /**
  3799     /**
  3799      * Returns the calculated day
  3800      * Returns the calculated day
  3800      *
  3801      *
  3801      * @param $calc    string                    Type of calculation to make
  3802      * @param string      $calc    Type of calculation to make
  3802      * @param $day     string|integer|Zend_Date  Day to calculate, when null the actual day is calculated
  3803      * @param Zend_Date   $day     Day to calculate, when null the actual day is calculated
  3803      * @param $locale  string|Zend_Locale        Locale for parsing input
  3804      * @param Zend_Locale $locale  Locale for parsing input
  3804      * @return Zend_Date|integer
  3805      * @return Zend_Date|integer
  3805      */
  3806      */
  3806     private function _day($calc, $day, $locale)
  3807     private function _day($calc, $day, $locale)
  3807     {
  3808     {
  3808         if ($day === null) {
  3809         if ($day === null) {
  3927     /**
  3928     /**
  3928      * Returns the weekday as new date object
  3929      * Returns the weekday as new date object
  3929      * Weekday is always from 1-7
  3930      * Weekday is always from 1-7
  3930      * Example: 09-Jan-2007 -> 2 = Tuesday -> 02-Jan-1970 (when 02.01.1970 is also Tuesday)
  3931      * Example: 09-Jan-2007 -> 2 = Tuesday -> 02-Jan-1970 (when 02.01.1970 is also Tuesday)
  3931      *
  3932      *
  3932      * @param $locale  string|Zend_Locale  OPTIONAL Locale for parsing input
  3933      * @param Zend_Locale $locale OPTIONAL Locale for parsing input
  3933      * @return Zend_Date
  3934      * @return Zend_Date
  3934      */
  3935      */
  3935     public function getWeekday($locale = null)
  3936     public function getWeekday($locale = null)
  3936     {
  3937     {
  3937         if (self::$_options['format_type'] == 'php') {
  3938         if (self::$_options['format_type'] == 'php') {
  3945 
  3946 
  3946 
  3947 
  3947     /**
  3948     /**
  3948      * Returns the calculated weekday
  3949      * Returns the calculated weekday
  3949      *
  3950      *
  3950      * @param  $calc     string                          Type of calculation to make
  3951      * @param  string      $calc     Type of calculation to make
  3951      * @param  $weekday  string|integer|array|Zend_Date  Weekday to calculate, when null the actual weekday is calculated
  3952      * @param  Zend_Date   $weekday  Weekday to calculate, when null the actual weekday is calculated
  3952      * @param  $locale   string|Zend_Locale              Locale for parsing input
  3953      * @param  Zend_Locale $locale   Locale for parsing input
  3953      * @return Zend_Date|integer
  3954      * @return Zend_Date|integer
  3954      * @throws Zend_Date_Exception
  3955      * @throws Zend_Date_Exception
  3955      */
  3956      */
  3956     private function _weekday($calc, $weekday, $locale)
  3957     private function _weekday($calc, $weekday, $locale)
  3957     {
  3958     {
  4164 
  4165 
  4165     /**
  4166     /**
  4166      * Returns the hour as new date object
  4167      * Returns the hour as new date object
  4167      * Example: 02.Feb.1986 10:30:25 -> 01.Jan.1970 10:00:00
  4168      * Example: 02.Feb.1986 10:30:25 -> 01.Jan.1970 10:00:00
  4168      *
  4169      *
  4169      * @param $locale  string|Zend_Locale  OPTIONAL Locale for parsing input
  4170      * @param Zend_Locale $locale OPTIONAL Locale for parsing input
  4170      * @return Zend_Date
  4171      * @return Zend_Date
  4171      */
  4172      */
  4172     public function getHour($locale = null)
  4173     public function getHour($locale = null)
  4173     {
  4174     {
  4174         return $this->copyPart(self::HOUR, $locale);
  4175         return $this->copyPart(self::HOUR, $locale);
  4615 
  4616 
  4616     /**
  4617     /**
  4617      * Returns the week as new date object using monday as begining of the week
  4618      * Returns the week as new date object using monday as begining of the week
  4618      * Example: 12.Jan.2007 -> 08.Jan.1970 00:00:00
  4619      * Example: 12.Jan.2007 -> 08.Jan.1970 00:00:00
  4619      *
  4620      *
  4620      * @param $locale  string|Zend_Locale  OPTIONAL Locale for parsing input
  4621      * @param Zend_Locale $locale OPTIONAL Locale for parsing input
  4621      * @return Zend_Date
  4622      * @return Zend_Date
  4622      */
  4623      */
  4623     public function getWeek($locale = null)
  4624     public function getWeek($locale = null)
  4624     {
  4625     {
  4625         if (self::$_options['format_type'] == 'php') {
  4626         if (self::$_options['format_type'] == 'php') {