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-2012 Zend Technologies USA Inc. (http://www.zend.com) |
17 * @copyright Copyright (c) 2005-2015 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 24880 2012-06-12 20:35:18Z matthew $ |
19 * @version $Id$ |
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-2012 Zend Technologies USA Inc. (http://www.zend.com) |
33 * @copyright Copyright (c) 2005-2015 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; |
352 |
352 |
353 /** |
353 /** |
354 * Sets a new timestamp |
354 * Sets a new timestamp |
355 * |
355 * |
356 * @param integer|string|array|Zend_Date $timestamp Timestamp to set |
356 * @param integer|string|array|Zend_Date $timestamp Timestamp to set |
357 * @return Zend_Date Provides fluid interface |
357 * @return Zend_Date Provides a fluent interface |
358 * @throws Zend_Date_Exception |
358 * @throws Zend_Date_Exception |
359 */ |
359 */ |
360 public function setTimestamp($timestamp) |
360 public function setTimestamp($timestamp) |
361 { |
361 { |
362 return $this->_timestamp('set', $timestamp); |
362 return $this->_timestamp('set', $timestamp); |
364 |
364 |
365 /** |
365 /** |
366 * Adds a timestamp |
366 * Adds a timestamp |
367 * |
367 * |
368 * @param integer|string|array|Zend_Date $timestamp Timestamp to add |
368 * @param integer|string|array|Zend_Date $timestamp Timestamp to add |
369 * @return Zend_Date Provides fluid interface |
369 * @return Zend_Date Provides a fluent interface |
370 * @throws Zend_Date_Exception |
370 * @throws Zend_Date_Exception |
371 */ |
371 */ |
372 public function addTimestamp($timestamp) |
372 public function addTimestamp($timestamp) |
373 { |
373 { |
374 return $this->_timestamp('add', $timestamp); |
374 return $this->_timestamp('add', $timestamp); |
376 |
376 |
377 /** |
377 /** |
378 * Subtracts a timestamp |
378 * Subtracts a timestamp |
379 * |
379 * |
380 * @param integer|string|array|Zend_Date $timestamp Timestamp to sub |
380 * @param integer|string|array|Zend_Date $timestamp Timestamp to sub |
381 * @return Zend_Date Provides fluid interface |
381 * @return Zend_Date Provides a fluent interface |
382 * @throws Zend_Date_Exception |
382 * @throws Zend_Date_Exception |
383 */ |
383 */ |
384 public function subTimestamp($timestamp) |
384 public function subTimestamp($timestamp) |
385 { |
385 { |
386 return $this->_timestamp('sub', $timestamp); |
386 return $this->_timestamp('sub', $timestamp); |
1061 * For a complete list of supported datepart values look into the docu |
1061 * For a complete list of supported datepart values look into the docu |
1062 * |
1062 * |
1063 * @param string|integer|array|Zend_Date $date Date or datepart to set |
1063 * @param string|integer|array|Zend_Date $date Date or datepart to set |
1064 * @param string $part OPTIONAL Part of the date to set, if null the timestamp is set |
1064 * @param string $part OPTIONAL Part of the date to set, if null the timestamp is set |
1065 * @param string|Zend_Locale $locale OPTIONAL Locale for parsing input |
1065 * @param string|Zend_Locale $locale OPTIONAL Locale for parsing input |
1066 * @return Zend_Date Provides fluid interface |
1066 * @return Zend_Date Provides a fluent interface |
1067 * @throws Zend_Date_Exception |
1067 * @throws Zend_Date_Exception |
1068 */ |
1068 */ |
1069 public function set($date, $part = null, $locale = null) |
1069 public function set($date, $part = null, $locale = null) |
1070 { |
1070 { |
1071 if (self::$_options['format_type'] == 'php') { |
1071 if (self::$_options['format_type'] == 'php') { |
1089 * For a complete list of supported datepart values look into the docu. |
1089 * For a complete list of supported datepart values look into the docu. |
1090 * |
1090 * |
1091 * @param string|integer|array|Zend_Date $date Date or datepart to add |
1091 * @param string|integer|array|Zend_Date $date Date or datepart to add |
1092 * @param string $part OPTIONAL Part of the date to add, if null the timestamp is added |
1092 * @param string $part OPTIONAL Part of the date to add, if null the timestamp is added |
1093 * @param string|Zend_Locale $locale OPTIONAL Locale for parsing input |
1093 * @param string|Zend_Locale $locale OPTIONAL Locale for parsing input |
1094 * @return Zend_Date Provides fluid interface |
1094 * @return Zend_Date Provides a fluent interface |
1095 * @throws Zend_Date_Exception |
1095 * @throws Zend_Date_Exception |
1096 */ |
1096 */ |
1097 public function add($date, $part = self::TIMESTAMP, $locale = null) |
1097 public function add($date, $part = self::TIMESTAMP, $locale = null) |
1098 { |
1098 { |
1099 if (self::$_options['format_type'] == 'php') { |
1099 if (self::$_options['format_type'] == 'php') { |
1112 * Be aware: Adding -2 Months is not equal to Subtracting 2 Months !!! |
1112 * Be aware: Adding -2 Months is not equal to Subtracting 2 Months !!! |
1113 * |
1113 * |
1114 * @param string|integer|array|Zend_Date $date Date or datepart to subtract |
1114 * @param string|integer|array|Zend_Date $date Date or datepart to subtract |
1115 * @param string $part OPTIONAL Part of the date to sub, if null the timestamp is subtracted |
1115 * @param string $part OPTIONAL Part of the date to sub, if null the timestamp is subtracted |
1116 * @param string|Zend_Locale $locale OPTIONAL Locale for parsing input |
1116 * @param string|Zend_Locale $locale OPTIONAL Locale for parsing input |
1117 * @return Zend_Date Provides fluid interface |
1117 * @return Zend_Date Provides a fluent interface |
1118 * @throws Zend_Date_Exception |
1118 * @throws Zend_Date_Exception |
1119 */ |
1119 */ |
1120 public function sub($date, $part = self::TIMESTAMP, $locale = null) |
1120 public function sub($date, $part = self::TIMESTAMP, $locale = null) |
1121 { |
1121 { |
1122 if (self::$_options['format_type'] == 'php') { |
1122 if (self::$_options['format_type'] == 'php') { |
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 } |
1210 |
1210 |
1211 preg_match('/([[:alpha:]\/]{3,30})(?!.*([[:alpha:]\/]{3,30}))/', $zone, $match); |
1211 preg_match('/([[:alpha:]\/_]{3,30})(?!.*([[:alpha:]\/]{3,30}))/', $zone, $match); |
1212 try { |
1212 try { |
1213 if (!empty($match) and (!is_int($match[count($match) - 1]))) { |
1213 if (!empty($match) and (!is_int($match[count($match) - 1]))) { |
1214 $oldzone = $this->getTimezone(); |
1214 $oldzone = $this->getTimezone(); |
1215 $this->setTimezone($match[count($match) - 1]); |
1215 $this->setTimezone($match[count($match) - 1]); |
1216 $result = $this->getTimezone(); |
1216 $result = $this->getTimezone(); |
2065 iconv_strlen($date, 'UTF-8') - $dateMatchCharCount, |
2065 iconv_strlen($date, 'UTF-8') - $dateMatchCharCount, |
2066 'UTF-8'); |
2066 'UTF-8'); |
2067 } |
2067 } |
2068 // (T)hh:mm:ss |
2068 // (T)hh:mm:ss |
2069 preg_match('/[T,\s]{0,1}(\d{2}):(\d{2}):(\d{2})/', $tmpdate, $timematch); |
2069 preg_match('/[T,\s]{0,1}(\d{2}):(\d{2}):(\d{2})/', $tmpdate, $timematch); |
|
2070 // (T)hhmmss |
2070 if (empty($timematch)) { |
2071 if (empty($timematch)) { |
2071 preg_match('/[T,\s]{0,1}(\d{2})(\d{2})(\d{2})/', $tmpdate, $timematch); |
2072 preg_match('/[T,\s]{0,1}(\d{2})(\d{2})(\d{2})/', $tmpdate, $timematch); |
|
2073 } |
|
2074 // (T)hh:mm |
|
2075 if (empty($timematch)) { |
|
2076 preg_match('/[T,\s]{0,1}(\d{2}):(\d{2})/', $tmpdate, $timematch); |
|
2077 } |
|
2078 // (T)hhmm |
|
2079 if (empty($timematch)) { |
|
2080 preg_match('/[T,\s]{0,1}(\d{2})(\d{2})/', $tmpdate, $timematch); |
2072 } |
2081 } |
2073 if (empty($datematch) and empty($timematch)) { |
2082 if (empty($datematch) and empty($timematch)) { |
2074 require_once 'Zend/Date/Exception.php'; |
2083 require_once 'Zend/Date/Exception.php'; |
2075 throw new Zend_Date_Exception("unsupported ISO8601 format ($date)", 0, null, $date); |
2084 throw new Zend_Date_Exception("unsupported ISO8601 format ($date)", 0, null, $date); |
2076 } |
2085 } |
2834 * Returned is the new date object and the existing date is left as it was before |
2846 * Returned is the new date object and the existing date is left as it was before |
2835 * |
2847 * |
2836 * @param string|integer|array|Zend_Date $time Time to set |
2848 * @param string|integer|array|Zend_Date $time Time to set |
2837 * @param string $format OPTIONAL Timeformat for parsing input |
2849 * @param string $format OPTIONAL Timeformat for parsing input |
2838 * @param string|Zend_Locale $locale OPTIONAL Locale for parsing input |
2850 * @param string|Zend_Locale $locale OPTIONAL Locale for parsing input |
2839 * @return Zend_Date Provides fluid interface |
2851 * @return Zend_Date Provides a fluent interface |
2840 * @throws Zend_Date_Exception |
2852 * @throws Zend_Date_Exception |
2841 */ |
2853 */ |
2842 public function setTime($time, $format = null, $locale = null) |
2854 public function setTime($time, $format = null, $locale = null) |
2843 { |
2855 { |
2844 return $this->_time('set', $time, $format, $locale); |
2856 return $this->_time('set', $time, $format, $locale); |
2852 * For example: HH:mm:ss -> 10 -> +10 hours |
2864 * For example: HH:mm:ss -> 10 -> +10 hours |
2853 * |
2865 * |
2854 * @param string|integer|array|Zend_Date $time Time to add |
2866 * @param string|integer|array|Zend_Date $time Time to add |
2855 * @param string $format OPTIONAL Timeformat for parsing input |
2867 * @param string $format OPTIONAL Timeformat for parsing input |
2856 * @param string|Zend_Locale $locale OPTIONAL Locale for parsing input |
2868 * @param string|Zend_Locale $locale OPTIONAL Locale for parsing input |
2857 * @return Zend_Date Provides fluid interface |
2869 * @return Zend_Date Provides a fluent interface |
2858 * @throws Zend_Date_Exception |
2870 * @throws Zend_Date_Exception |
2859 */ |
2871 */ |
2860 public function addTime($time, $format = null, $locale = null) |
2872 public function addTime($time, $format = null, $locale = null) |
2861 { |
2873 { |
2862 return $this->_time('add', $time, $format, $locale); |
2874 return $this->_time('add', $time, $format, $locale); |
2870 * For example: HH:mm:ss -> 10 -> -10 hours |
2882 * For example: HH:mm:ss -> 10 -> -10 hours |
2871 * |
2883 * |
2872 * @param string|integer|array|Zend_Date $time Time to sub |
2884 * @param string|integer|array|Zend_Date $time Time to sub |
2873 * @param string $format OPTIONAL Timeformat for parsing input |
2885 * @param string $format OPTIONAL Timeformat for parsing input |
2874 * @param string|Zend_Locale $locale OPTIONAL Locale for parsing input |
2886 * @param string|Zend_Locale $locale OPTIONAL Locale for parsing input |
2875 * @return Zend_Date Provides fluid inteface |
2887 * @return Zend_Date Provides a fluent inteface |
2876 * @throws Zend_Date_Exception |
2888 * @throws Zend_Date_Exception |
2877 */ |
2889 */ |
2878 public function subTime($time, $format = null, $locale = null) |
2890 public function subTime($time, $format = null, $locale = null) |
2879 { |
2891 { |
2880 return $this->_time('sub', $time, $format, $locale); |
2892 return $this->_time('sub', $time, $format, $locale); |
2996 * Returned is the new date object and the existing time is left as it was before |
3008 * Returned is the new date object and the existing time is left as it was before |
2997 * |
3009 * |
2998 * @param string|integer|array|Zend_Date $date Date to set |
3010 * @param string|integer|array|Zend_Date $date Date to set |
2999 * @param string $format OPTIONAL Date format for parsing |
3011 * @param string $format OPTIONAL Date format for parsing |
3000 * @param string|Zend_Locale $locale OPTIONAL Locale for parsing input |
3012 * @param string|Zend_Locale $locale OPTIONAL Locale for parsing input |
3001 * @return Zend_Date Provides fluid interface |
3013 * @return Zend_Date Provides a fluent interface |
3002 * @throws Zend_Date_Exception |
3014 * @throws Zend_Date_Exception |
3003 */ |
3015 */ |
3004 public function setDate($date, $format = null, $locale = null) |
3016 public function setDate($date, $format = null, $locale = null) |
3005 { |
3017 { |
3006 return $this->_date('set', $date, $format, $locale); |
3018 return $this->_date('set', $date, $format, $locale); |
3014 * For example: MM.dd.YYYY -> 10 -> +10 months |
3026 * For example: MM.dd.YYYY -> 10 -> +10 months |
3015 * |
3027 * |
3016 * @param string|integer|array|Zend_Date $date Date to add |
3028 * @param string|integer|array|Zend_Date $date Date to add |
3017 * @param string $format OPTIONAL Date format for parsing input |
3029 * @param string $format OPTIONAL Date format for parsing input |
3018 * @param string|Zend_Locale $locale OPTIONAL Locale for parsing input |
3030 * @param string|Zend_Locale $locale OPTIONAL Locale for parsing input |
3019 * @return Zend_Date Provides fluid interface |
3031 * @return Zend_Date Provides a fluent interface |
3020 * @throws Zend_Date_Exception |
3032 * @throws Zend_Date_Exception |
3021 */ |
3033 */ |
3022 public function addDate($date, $format = null, $locale = null) |
3034 public function addDate($date, $format = null, $locale = null) |
3023 { |
3035 { |
3024 return $this->_date('add', $date, $format, $locale); |
3036 return $this->_date('add', $date, $format, $locale); |
3033 * Be aware: Subtracting 2 months is not equal to Adding -2 months !!! |
3045 * Be aware: Subtracting 2 months is not equal to Adding -2 months !!! |
3034 * |
3046 * |
3035 * @param string|integer|array|Zend_Date $date Date to sub |
3047 * @param string|integer|array|Zend_Date $date Date to sub |
3036 * @param string $format OPTIONAL Date format for parsing input |
3048 * @param string $format OPTIONAL Date format for parsing input |
3037 * @param string|Zend_Locale $locale OPTIONAL Locale for parsing input |
3049 * @param string|Zend_Locale $locale OPTIONAL Locale for parsing input |
3038 * @return Zend_Date Provides fluid interface |
3050 * @return Zend_Date Provides a fluent interface |
3039 * @throws Zend_Date_Exception |
3051 * @throws Zend_Date_Exception |
3040 */ |
3052 */ |
3041 public function subDate($date, $format = null, $locale = null) |
3053 public function subDate($date, $format = null, $locale = null) |
3042 { |
3054 { |
3043 return $this->_date('sub', $date, $format, $locale); |
3055 return $this->_date('sub', $date, $format, $locale); |
3084 * For example: 050901 -> 01.Sept.2005 00:00:00, 20050201T10:00:30 -> 01.Feb.2005 10h00m30s |
3096 * For example: 050901 -> 01.Sept.2005 00:00:00, 20050201T10:00:30 -> 01.Feb.2005 10h00m30s |
3085 * Returned is the new date object |
3097 * Returned is the new date object |
3086 * |
3098 * |
3087 * @param string|integer|Zend_Date $date ISO Date to set |
3099 * @param string|integer|Zend_Date $date ISO Date to set |
3088 * @param string|Zend_Locale $locale OPTIONAL Locale for parsing input |
3100 * @param string|Zend_Locale $locale OPTIONAL Locale for parsing input |
3089 * @return Zend_Date Provides fluid interface |
3101 * @return Zend_Date Provides a fluent interface |
3090 * @throws Zend_Date_Exception |
3102 * @throws Zend_Date_Exception |
3091 */ |
3103 */ |
3092 public function setIso($date, $locale = null) |
3104 public function setIso($date, $locale = null) |
3093 { |
3105 { |
3094 return $this->_calcvalue('set', $date, 'iso', self::ISO_8601, $locale); |
3106 return $this->_calcvalue('set', $date, 'iso', self::ISO_8601, $locale); |
3101 * For example: 050901 -> + 01.Sept.2005 00:00:00, 10:00:00 -> +10h |
3113 * For example: 050901 -> + 01.Sept.2005 00:00:00, 10:00:00 -> +10h |
3102 * Returned is the new date object |
3114 * Returned is the new date object |
3103 * |
3115 * |
3104 * @param string|integer|Zend_Date $date ISO Date to add |
3116 * @param string|integer|Zend_Date $date ISO Date to add |
3105 * @param string|Zend_Locale $locale OPTIONAL Locale for parsing input |
3117 * @param string|Zend_Locale $locale OPTIONAL Locale for parsing input |
3106 * @return Zend_Date Provides fluid interface |
3118 * @return Zend_Date Provides a fluent interface |
3107 * @throws Zend_Date_Exception |
3119 * @throws Zend_Date_Exception |
3108 */ |
3120 */ |
3109 public function addIso($date, $locale = null) |
3121 public function addIso($date, $locale = null) |
3110 { |
3122 { |
3111 return $this->_calcvalue('add', $date, 'iso', self::ISO_8601, $locale); |
3123 return $this->_calcvalue('add', $date, 'iso', self::ISO_8601, $locale); |
3118 * For example: 050901 -> - 01.Sept.2005 00:00:00, 10:00:00 -> -10h |
3130 * For example: 050901 -> - 01.Sept.2005 00:00:00, 10:00:00 -> -10h |
3119 * Returned is the new date object |
3131 * Returned is the new date object |
3120 * |
3132 * |
3121 * @param string|integer|Zend_Date $date ISO Date to sub |
3133 * @param string|integer|Zend_Date $date ISO Date to sub |
3122 * @param string|Zend_Locale $locale OPTIONAL Locale for parsing input |
3134 * @param string|Zend_Locale $locale OPTIONAL Locale for parsing input |
3123 * @return Zend_Date Provides fluid interface |
3135 * @return Zend_Date Provides a fluent interface |
3124 * @throws Zend_Date_Exception |
3136 * @throws Zend_Date_Exception |
3125 */ |
3137 */ |
3126 public function subIso($date, $locale = null) |
3138 public function subIso($date, $locale = null) |
3127 { |
3139 { |
3128 return $this->_calcvalue('sub', $date, 'iso', self::ISO_8601, $locale); |
3140 return $this->_calcvalue('sub', $date, 'iso', self::ISO_8601, $locale); |
3171 * For example: Sat, 14 Feb 09 00:31:30 +0100 |
3183 * For example: Sat, 14 Feb 09 00:31:30 +0100 |
3172 * Returned is the new date object |
3184 * Returned is the new date object |
3173 * |
3185 * |
3174 * @param string|integer|Zend_Date $date RFC 822 to set |
3186 * @param string|integer|Zend_Date $date RFC 822 to set |
3175 * @param string|Zend_Locale $locale OPTIONAL Locale for parsing input |
3187 * @param string|Zend_Locale $locale OPTIONAL Locale for parsing input |
3176 * @return Zend_Date Provides fluid interface |
3188 * @return Zend_Date Provides a fluent interface |
3177 * @throws Zend_Date_Exception |
3189 * @throws Zend_Date_Exception |
3178 */ |
3190 */ |
3179 public function setArpa($date, $locale = null) |
3191 public function setArpa($date, $locale = null) |
3180 { |
3192 { |
3181 return $this->_calcvalue('set', $date, 'arpa', self::RFC_822, $locale); |
3193 return $this->_calcvalue('set', $date, 'arpa', self::RFC_822, $locale); |
3189 * For example: Sat, 14 Feb 09 00:31:30 +0100 |
3201 * For example: Sat, 14 Feb 09 00:31:30 +0100 |
3190 * Returned is the new date object |
3202 * Returned is the new date object |
3191 * |
3203 * |
3192 * @param string|integer|Zend_Date $date RFC 822 Date to add |
3204 * @param string|integer|Zend_Date $date RFC 822 Date to add |
3193 * @param string|Zend_Locale $locale OPTIONAL Locale for parsing input |
3205 * @param string|Zend_Locale $locale OPTIONAL Locale for parsing input |
3194 * @return Zend_Date Provides fluid interface |
3206 * @return Zend_Date Provides a fluent interface |
3195 * @throws Zend_Date_Exception |
3207 * @throws Zend_Date_Exception |
3196 */ |
3208 */ |
3197 public function addArpa($date, $locale = null) |
3209 public function addArpa($date, $locale = null) |
3198 { |
3210 { |
3199 return $this->_calcvalue('add', $date, 'arpa', self::RFC_822, $locale); |
3211 return $this->_calcvalue('add', $date, 'arpa', self::RFC_822, $locale); |
3207 * For example: Sat, 14 Feb 09 00:31:30 +0100 |
3219 * For example: Sat, 14 Feb 09 00:31:30 +0100 |
3208 * Returned is the new date object |
3220 * Returned is the new date object |
3209 * |
3221 * |
3210 * @param string|integer|Zend_Date $date RFC 822 Date to sub |
3222 * @param string|integer|Zend_Date $date RFC 822 Date to sub |
3211 * @param string|Zend_Locale $locale OPTIONAL Locale for parsing input |
3223 * @param string|Zend_Locale $locale OPTIONAL Locale for parsing input |
3212 * @return Zend_Date Provides fluid interface |
3224 * @return Zend_Date Provides a fluent interface |
3213 * @throws Zend_Date_Exception |
3225 * @throws Zend_Date_Exception |
3214 */ |
3226 */ |
3215 public function subArpa($date, $locale = null) |
3227 public function subArpa($date, $locale = null) |
3216 { |
3228 { |
3217 return $this->_calcvalue('sub', $date, 'arpa', self::RFC_822, $locale); |
3229 return $this->_calcvalue('sub', $date, 'arpa', self::RFC_822, $locale); |
3233 public function compareArpa($date, $locale = null) |
3245 public function compareArpa($date, $locale = null) |
3234 { |
3246 { |
3235 return $this->_calcvalue('cmp', $date, 'arpa', self::RFC_822, $locale); |
3247 return $this->_calcvalue('cmp', $date, 'arpa', self::RFC_822, $locale); |
3236 } |
3248 } |
3237 |
3249 |
3238 |
|
3239 /** |
3250 /** |
3240 * Check if location is supported |
3251 * Check if location is supported |
3241 * |
3252 * |
3242 * @param array $location locations array |
3253 * @param array $location locations array |
3243 * @return $horizon float |
3254 * @throws Zend_Date_Exception |
|
3255 * @return float $horizon float |
3244 */ |
3256 */ |
3245 private function _checkLocation($location) |
3257 private function _checkLocation($location) |
3246 { |
3258 { |
3247 if (!isset($location['longitude']) or !isset($location['latitude'])) { |
3259 if (!isset($location['longitude']) or !isset($location['latitude'])) { |
3248 require_once 'Zend/Date/Exception.php'; |
3260 require_once 'Zend/Date/Exception.php'; |
3356 $suninfo['sunset'][$location['horizon']] = $result; |
3368 $suninfo['sunset'][$location['horizon']] = $result; |
3357 } |
3369 } |
3358 return $suninfo; |
3370 return $suninfo; |
3359 } |
3371 } |
3360 |
3372 |
3361 |
|
3362 /** |
3373 /** |
3363 * Check a given year for leap year. |
3374 * Check a given year for leap year. |
3364 * |
3375 * |
3365 * @param integer|array|Zend_Date $year Year to check |
3376 * @param integer|array|Zend_Date $year Year to check |
|
3377 * @throws Zend_Date_Exception |
3366 * @return boolean |
3378 * @return boolean |
3367 */ |
3379 */ |
3368 public static function checkLeapYear($year) |
3380 public static function checkLeapYear($year) |
3369 { |
3381 { |
3370 if ($year instanceof Zend_Date) { |
3382 if ($year instanceof Zend_Date) { |
3456 /** |
3468 /** |
3457 * Calculate date details |
3469 * Calculate date details |
3458 * |
3470 * |
3459 * @param string $calc Calculation to make |
3471 * @param string $calc Calculation to make |
3460 * @param string|integer|array|Zend_Date $date Date or Part to calculate |
3472 * @param string|integer|array|Zend_Date $date Date or Part to calculate |
3461 * @param string $part Datepart for Calculation |
3473 * @param string $type Datepart for Calculation |
3462 * @param string|Zend_Locale $locale Locale for parsing input |
3474 * @param string|Zend_Locale $locale Locale for parsing input |
3463 * @return integer|string new date |
3475 * @return integer|string new date |
3464 * @throws Zend_Date_Exception |
3476 * @throws Zend_Date_Exception |
3465 */ |
3477 */ |
3466 private function _calcdetail($calc, $date, $type, $locale) |
3478 private function _calcdetail($calc, $date, $type, $locale) |
3494 } |
3506 } |
3495 |
3507 |
3496 /** |
3508 /** |
3497 * Internal calculation, returns the requested date type |
3509 * Internal calculation, returns the requested date type |
3498 * |
3510 * |
3499 * @param string $calc Calculation to make |
3511 * @param string $calc Calculation to make |
3500 * @param string|integer|Zend_Date $value Datevalue to calculate with, if null the actual value is taken |
3512 * @param string|integer|Zend_Date $value Datevalue to calculate with, if null the actual value is taken |
3501 * @param string|Zend_Locale $locale Locale for parsing input |
3513 * @param string $type |
|
3514 * @param string $parameter |
|
3515 * @param string|Zend_Locale $locale Locale for parsing input |
|
3516 * @throws Zend_Date_Exception |
3502 * @return integer|Zend_Date new date |
3517 * @return integer|Zend_Date new date |
3503 * @throws Zend_Date_Exception |
|
3504 */ |
3518 */ |
3505 private function _calcvalue($calc, $value, $type, $parameter, $locale) |
3519 private function _calcvalue($calc, $value, $type, $parameter, $locale) |
3506 { |
3520 { |
3507 if ($value === null) { |
3521 if ($value === null) { |
3508 require_once 'Zend/Date/Exception.php'; |
3522 require_once 'Zend/Date/Exception.php'; |
3554 * If the year if between 70 and 99, 1999 will be set (1970-1999) |
3568 * If the year if between 70 and 99, 1999 will be set (1970-1999) |
3555 * 3 or 4 digit years are set as expected. If you need to set year 0-99 |
3569 * 3 or 4 digit years are set as expected. If you need to set year 0-99 |
3556 * use set() instead. |
3570 * use set() instead. |
3557 * Returned is the new date object |
3571 * Returned is the new date object |
3558 * |
3572 * |
3559 * @param string|integer|array|Zend_Date $date Year to set |
3573 * @param string|integer|array|Zend_Date $year Year to set |
3560 * @param string|Zend_Locale $locale OPTIONAL Locale for parsing input |
3574 * @param string|Zend_Locale $locale OPTIONAL Locale for parsing input |
3561 * @return Zend_Date Provides fluid interface |
3575 * @return Zend_Date Provides a fluent interface |
3562 * @throws Zend_Date_Exception |
3576 * @throws Zend_Date_Exception |
3563 */ |
3577 */ |
3564 public function setYear($year, $locale = null) |
3578 public function setYear($year, $locale = null) |
3565 { |
3579 { |
3566 return $this->_calcvalue('set', $year, 'year', self::YEAR, $locale); |
3580 return $this->_calcvalue('set', $year, 'year', self::YEAR, $locale); |
3573 * If the year if between 70 and 99, 1999 will be added (1970-1999) |
3587 * If the year if between 70 and 99, 1999 will be added (1970-1999) |
3574 * 3 or 4 digit years are added as expected. If you need to add years from 0-99 |
3588 * 3 or 4 digit years are added as expected. If you need to add years from 0-99 |
3575 * use add() instead. |
3589 * use add() instead. |
3576 * Returned is the new date object |
3590 * Returned is the new date object |
3577 * |
3591 * |
3578 * @param string|integer|array|Zend_Date $date Year to add |
3592 * @param string|integer|array|Zend_Date $year Year to add |
3579 * @param string|Zend_Locale $locale OPTIONAL Locale for parsing input |
3593 * @param string|Zend_Locale $locale OPTIONAL Locale for parsing input |
3580 * @return Zend_Date Provides fluid interface |
3594 * @return Zend_Date Provides a fluent interface |
3581 * @throws Zend_Date_Exception |
3595 * @throws Zend_Date_Exception |
3582 */ |
3596 */ |
3583 public function addYear($year, $locale = null) |
3597 public function addYear($year, $locale = null) |
3584 { |
3598 { |
3585 return $this->_calcvalue('add', $year, 'year', self::YEAR, $locale); |
3599 return $this->_calcvalue('add', $year, 'year', self::YEAR, $locale); |
3592 * If the year if between 70 and 99, 1999 will be subtracted (1970-1999) |
3606 * If the year if between 70 and 99, 1999 will be subtracted (1970-1999) |
3593 * 3 or 4 digit years are subtracted as expected. If you need to subtract years from 0-99 |
3607 * 3 or 4 digit years are subtracted as expected. If you need to subtract years from 0-99 |
3594 * use sub() instead. |
3608 * use sub() instead. |
3595 * Returned is the new date object |
3609 * Returned is the new date object |
3596 * |
3610 * |
3597 * @param string|integer|array|Zend_Date $date Year to sub |
3611 * @param string|integer|array|Zend_Date $year Year to sub |
3598 * @param string|Zend_Locale $locale OPTIONAL Locale for parsing input |
3612 * @param string|Zend_Locale $locale OPTIONAL Locale for parsing input |
3599 * @return Zend_Date Provides fluid interface |
3613 * @return Zend_Date Provides a fluent interface |
3600 * @throws Zend_Date_Exception |
3614 * @throws Zend_Date_Exception |
3601 */ |
3615 */ |
3602 public function subYear($year, $locale = null) |
3616 public function subYear($year, $locale = null) |
3603 { |
3617 { |
3604 return $this->_calcvalue('sub', $year, 'year', self::YEAR, $locale); |
3618 return $this->_calcvalue('sub', $year, 'year', self::YEAR, $locale); |
3718 * set locale. |
3732 * set locale. |
3719 * Returned is the new date object |
3733 * Returned is the new date object |
3720 * |
3734 * |
3721 * @param string|integer|array|Zend_Date $month Month to set |
3735 * @param string|integer|array|Zend_Date $month Month to set |
3722 * @param string|Zend_Locale $locale OPTIONAL Locale for parsing input |
3736 * @param string|Zend_Locale $locale OPTIONAL Locale for parsing input |
3723 * @return Zend_Date Provides fluid interface |
3737 * @return Zend_Date Provides a fluent interface |
3724 * @throws Zend_Date_Exception |
3738 * @throws Zend_Date_Exception |
3725 */ |
3739 */ |
3726 public function setMonth($month, $locale = null) |
3740 public function setMonth($month, $locale = null) |
3727 { |
3741 { |
3728 return $this->_month('set', $month, $locale); |
3742 return $this->_month('set', $month, $locale); |
3737 * set locale. |
3751 * set locale. |
3738 * Returned is the new date object |
3752 * Returned is the new date object |
3739 * |
3753 * |
3740 * @param string|integer|array|Zend_Date $month Month to add |
3754 * @param string|integer|array|Zend_Date $month Month to add |
3741 * @param string|Zend_Locale $locale OPTIONAL Locale for parsing input |
3755 * @param string|Zend_Locale $locale OPTIONAL Locale for parsing input |
3742 * @return Zend_Date Provides fluid interface |
3756 * @return Zend_Date Provides a fluent interface |
3743 * @throws Zend_Date_Exception |
3757 * @throws Zend_Date_Exception |
3744 */ |
3758 */ |
3745 public function addMonth($month, $locale = null) |
3759 public function addMonth($month, $locale = null) |
3746 { |
3760 { |
3747 return $this->_month('add', $month, $locale); |
3761 return $this->_month('add', $month, $locale); |
3756 * set locale. |
3770 * set locale. |
3757 * Returned is the new date object |
3771 * Returned is the new date object |
3758 * |
3772 * |
3759 * @param string|integer|array|Zend_Date $month Month to sub |
3773 * @param string|integer|array|Zend_Date $month Month to sub |
3760 * @param string|Zend_Locale $locale OPTIONAL Locale for parsing input |
3774 * @param string|Zend_Locale $locale OPTIONAL Locale for parsing input |
3761 * @return Zend_Date Provides fluid interface |
3775 * @return Zend_Date Provides a fluent interface |
3762 * @throws Zend_Date_Exception |
3776 * @throws Zend_Date_Exception |
3763 */ |
3777 */ |
3764 public function subMonth($month, $locale = null) |
3778 public function subMonth($month, $locale = null) |
3765 { |
3779 { |
3766 return $this->_month('sub', $month, $locale); |
3780 return $this->_month('sub', $month, $locale); |
3793 public function getDay($locale = null) |
3807 public function getDay($locale = null) |
3794 { |
3808 { |
3795 return $this->copyPart(self::DAY_SHORT, $locale); |
3809 return $this->copyPart(self::DAY_SHORT, $locale); |
3796 } |
3810 } |
3797 |
3811 |
3798 |
|
3799 /** |
3812 /** |
3800 * Returns the calculated day |
3813 * Returns the calculated day |
3801 * |
3814 * |
3802 * @param string $calc Type of calculation to make |
3815 * @param string $calc Type of calculation to make |
3803 * @param Zend_Date $day Day to calculate, when null the actual day is calculated |
3816 * @param Zend_Date $day Day to calculate, when null the actual day is calculated |
3804 * @param Zend_Locale $locale Locale for parsing input |
3817 * @param Zend_Locale $locale Locale for parsing input |
|
3818 * @throws Zend_Date_Exception |
3805 * @return Zend_Date|integer |
3819 * @return Zend_Date|integer |
3806 */ |
3820 */ |
3807 private function _day($calc, $day, $locale) |
3821 private function _day($calc, $day, $locale) |
3808 { |
3822 { |
3809 if ($day === null) { |
3823 if ($day === null) { |
3860 * If a localized dayname is given it will be parsed with the default locale or the optional |
3874 * If a localized dayname is given it will be parsed with the default locale or the optional |
3861 * set locale. |
3875 * set locale. |
3862 * Returned is the new date object |
3876 * Returned is the new date object |
3863 * Example: setDay('Montag', 'de_AT'); will set the monday of this week as day. |
3877 * Example: setDay('Montag', 'de_AT'); will set the monday of this week as day. |
3864 * |
3878 * |
3865 * @param string|integer|array|Zend_Date $month Day to set |
3879 * @param string|integer|array|Zend_Date $day Day to set |
3866 * @param string|Zend_Locale $locale OPTIONAL Locale for parsing input |
3880 * @param string|Zend_Locale $locale OPTIONAL Locale for parsing input |
3867 * @return Zend_Date Provides fluid interface |
3881 * @return Zend_Date Provides a fluent interface |
3868 * @throws Zend_Date_Exception |
3882 * @throws Zend_Date_Exception |
3869 */ |
3883 */ |
3870 public function setDay($day, $locale = null) |
3884 public function setDay($day, $locale = null) |
3871 { |
3885 { |
3872 return $this->_day('set', $day, $locale); |
3886 return $this->_day('set', $day, $locale); |
3878 * The day can be a number or a string. Adding days lower then 0 or greater than the number of this months days |
3892 * The day can be a number or a string. Adding days lower then 0 or greater than the number of this months days |
3879 * will result in adding or subtracting the relevant month. |
3893 * will result in adding or subtracting the relevant month. |
3880 * If a localized dayname is given it will be parsed with the default locale or the optional |
3894 * If a localized dayname is given it will be parsed with the default locale or the optional |
3881 * set locale. |
3895 * set locale. |
3882 * |
3896 * |
3883 * @param string|integer|array|Zend_Date $month Day to add |
3897 * @param string|integer|array|Zend_Date $day Day to add |
3884 * @param string|Zend_Locale $locale OPTIONAL Locale for parsing input |
3898 * @param string|Zend_Locale $locale OPTIONAL Locale for parsing input |
3885 * @return Zend_Date Provides fluid interface |
3899 * @return Zend_Date Provides a fluent interface |
3886 * @throws Zend_Date_Exception |
3900 * @throws Zend_Date_Exception |
3887 */ |
3901 */ |
3888 public function addDay($day, $locale = null) |
3902 public function addDay($day, $locale = null) |
3889 { |
3903 { |
3890 return $this->_day('add', $day, $locale); |
3904 return $this->_day('add', $day, $locale); |
3896 * The day can be a number or a string. Subtracting days lower then 0 or greater than the number of this months days |
3910 * The day can be a number or a string. Subtracting days lower then 0 or greater than the number of this months days |
3897 * will result in adding or subtracting the relevant month. |
3911 * will result in adding or subtracting the relevant month. |
3898 * If a localized dayname is given it will be parsed with the default locale or the optional |
3912 * If a localized dayname is given it will be parsed with the default locale or the optional |
3899 * set locale. |
3913 * set locale. |
3900 * |
3914 * |
3901 * @param string|integer|array|Zend_Date $month Day to sub |
3915 * @param string|integer|array|Zend_Date $day Day to sub |
3902 * @param string|Zend_Locale $locale OPTIONAL Locale for parsing input |
3916 * @param string|Zend_Locale $locale OPTIONAL Locale for parsing input |
3903 * @return Zend_Date Provides fluid interface |
3917 * @return Zend_Date Provides a fluent interface |
3904 * @throws Zend_Date_Exception |
3918 * @throws Zend_Date_Exception |
3905 */ |
3919 */ |
3906 public function subDay($day, $locale = null) |
3920 public function subDay($day, $locale = null) |
3907 { |
3921 { |
3908 return $this->_day('sub', $day, $locale); |
3922 return $this->_day('sub', $day, $locale); |
4008 * The weekday can be a number or a string. If a localized weekday name is given, |
4022 * The weekday can be a number or a string. If a localized weekday name is given, |
4009 * then it will be parsed as a date in $locale (defaults to the same locale as $this). |
4023 * then it will be parsed as a date in $locale (defaults to the same locale as $this). |
4010 * Returned is the new date object. |
4024 * Returned is the new date object. |
4011 * Example: setWeekday(3); will set the wednesday of this week as day. |
4025 * Example: setWeekday(3); will set the wednesday of this week as day. |
4012 * |
4026 * |
4013 * @param string|integer|array|Zend_Date $month Weekday to set |
4027 * @param string|integer|array|Zend_Date $weekday Weekday to set |
4014 * @param string|Zend_Locale $locale OPTIONAL Locale for parsing input |
4028 * @param string|Zend_Locale $locale OPTIONAL Locale for parsing input |
4015 * @return Zend_Date Provides fluid interface |
4029 * @return Zend_Date Provides a fluent interface |
4016 * @throws Zend_Date_Exception |
4030 * @throws Zend_Date_Exception |
4017 */ |
4031 */ |
4018 public function setWeekday($weekday, $locale = null) |
4032 public function setWeekday($weekday, $locale = null) |
4019 { |
4033 { |
4020 return $this->_weekday('set', $weekday, $locale); |
4034 return $this->_weekday('set', $weekday, $locale); |
4028 * set locale. |
4042 * set locale. |
4029 * Returned is the new date object |
4043 * Returned is the new date object |
4030 * Example: addWeekday(3); will add the difference of days from the begining of the month until |
4044 * Example: addWeekday(3); will add the difference of days from the begining of the month until |
4031 * wednesday. |
4045 * wednesday. |
4032 * |
4046 * |
4033 * @param string|integer|array|Zend_Date $month Weekday to add |
4047 * @param string|integer|array|Zend_Date $weekday Weekday to add |
4034 * @param string|Zend_Locale $locale OPTIONAL Locale for parsing input |
4048 * @param string|Zend_Locale $locale OPTIONAL Locale for parsing input |
4035 * @return Zend_Date Provides fluid interface |
4049 * @return Zend_Date Provides a fluent interface |
4036 * @throws Zend_Date_Exception |
4050 * @throws Zend_Date_Exception |
4037 */ |
4051 */ |
4038 public function addWeekday($weekday, $locale = null) |
4052 public function addWeekday($weekday, $locale = null) |
4039 { |
4053 { |
4040 return $this->_weekday('add', $weekday, $locale); |
4054 return $this->_weekday('add', $weekday, $locale); |
4048 * set locale. |
4062 * set locale. |
4049 * Returned is the new date object |
4063 * Returned is the new date object |
4050 * Example: subWeekday(3); will subtract the difference of days from the begining of the month until |
4064 * Example: subWeekday(3); will subtract the difference of days from the begining of the month until |
4051 * wednesday. |
4065 * wednesday. |
4052 * |
4066 * |
4053 * @param string|integer|array|Zend_Date $month Weekday to sub |
4067 * @param string|integer|array|Zend_Date $weekday Weekday to sub |
4054 * @param string|Zend_Locale $locale OPTIONAL Locale for parsing input |
4068 * @param string|Zend_Locale $locale OPTIONAL Locale for parsing input |
4055 * @return Zend_Date Provides fluid interface |
4069 * @return Zend_Date Provides a fluent interface |
4056 * @throws Zend_Date_Exception |
4070 * @throws Zend_Date_Exception |
4057 */ |
4071 */ |
4058 public function subWeekday($weekday, $locale = null) |
4072 public function subWeekday($weekday, $locale = null) |
4059 { |
4073 { |
4060 return $this->_weekday('sub', $weekday, $locale); |
4074 return $this->_weekday('sub', $weekday, $locale); |
4102 * Returned is the new date object |
4116 * Returned is the new date object |
4103 * Example: 04.May.2004 -> setDayOfYear(10) -> 10.Jan.2004 |
4117 * Example: 04.May.2004 -> setDayOfYear(10) -> 10.Jan.2004 |
4104 * |
4118 * |
4105 * @param string|integer|array|Zend_Date $day Day of Year to set |
4119 * @param string|integer|array|Zend_Date $day Day of Year to set |
4106 * @param string|Zend_Locale $locale OPTIONAL Locale for parsing input |
4120 * @param string|Zend_Locale $locale OPTIONAL Locale for parsing input |
4107 * @return Zend_Date Provides fluid interface |
4121 * @return Zend_Date Provides a fluent interface |
4108 * @throws Zend_Date_Exception |
4122 * @throws Zend_Date_Exception |
4109 */ |
4123 */ |
4110 public function setDayOfYear($day, $locale = null) |
4124 public function setDayOfYear($day, $locale = null) |
4111 { |
4125 { |
4112 return $this->_calcvalue('set', $day, 'day of year', self::DAY_OF_YEAR, $locale); |
4126 return $this->_calcvalue('set', $day, 'day of year', self::DAY_OF_YEAR, $locale); |
4119 * Returned is the new date object |
4133 * Returned is the new date object |
4120 * Example: addDayOfYear(10); will add 10 days to the existing date object. |
4134 * Example: addDayOfYear(10); will add 10 days to the existing date object. |
4121 * |
4135 * |
4122 * @param string|integer|array|Zend_Date $day Day of Year to add |
4136 * @param string|integer|array|Zend_Date $day Day of Year to add |
4123 * @param string|Zend_Locale $locale OPTIONAL Locale for parsing input |
4137 * @param string|Zend_Locale $locale OPTIONAL Locale for parsing input |
4124 * @return Zend_Date Provides fluid interface |
4138 * @return Zend_Date Provides a fluent interface |
4125 * @throws Zend_Date_Exception |
4139 * @throws Zend_Date_Exception |
4126 */ |
4140 */ |
4127 public function addDayOfYear($day, $locale = null) |
4141 public function addDayOfYear($day, $locale = null) |
4128 { |
4142 { |
4129 return $this->_calcvalue('add', $day, 'day of year', self::DAY_OF_YEAR, $locale); |
4143 return $this->_calcvalue('add', $day, 'day of year', self::DAY_OF_YEAR, $locale); |
4136 * Returned is the new date object |
4150 * Returned is the new date object |
4137 * Example: subDayOfYear(10); will subtract 10 days from the existing date object. |
4151 * Example: subDayOfYear(10); will subtract 10 days from the existing date object. |
4138 * |
4152 * |
4139 * @param string|integer|array|Zend_Date $day Day of Year to sub |
4153 * @param string|integer|array|Zend_Date $day Day of Year to sub |
4140 * @param string|Zend_Locale $locale OPTIONAL Locale for parsing input |
4154 * @param string|Zend_Locale $locale OPTIONAL Locale for parsing input |
4141 * @return Zend_Date Provides fluid interface |
4155 * @return Zend_Date Provides a fluent interface |
4142 * @throws Zend_Date_Exception |
4156 * @throws Zend_Date_Exception |
4143 */ |
4157 */ |
4144 public function subDayOfYear($day, $locale = null) |
4158 public function subDayOfYear($day, $locale = null) |
4145 { |
4159 { |
4146 return $this->_calcvalue('sub', $day, 'day of year', self::DAY_OF_YEAR, $locale); |
4160 return $this->_calcvalue('sub', $day, 'day of year', self::DAY_OF_YEAR, $locale); |
4182 * Returned is the new date object |
4196 * Returned is the new date object |
4183 * Example: 04.May.1993 13:07:25 -> setHour(7); -> 04.May.1993 07:07:25 |
4197 * Example: 04.May.1993 13:07:25 -> setHour(7); -> 04.May.1993 07:07:25 |
4184 * |
4198 * |
4185 * @param string|integer|array|Zend_Date $hour Hour to set |
4199 * @param string|integer|array|Zend_Date $hour Hour to set |
4186 * @param string|Zend_Locale $locale OPTIONAL Locale for parsing input |
4200 * @param string|Zend_Locale $locale OPTIONAL Locale for parsing input |
4187 * @return Zend_Date Provides fluid interface |
4201 * @return Zend_Date Provides a fluent interface |
4188 * @throws Zend_Date_Exception |
4202 * @throws Zend_Date_Exception |
4189 */ |
4203 */ |
4190 public function setHour($hour, $locale = null) |
4204 public function setHour($hour, $locale = null) |
4191 { |
4205 { |
4192 return $this->_calcvalue('set', $hour, 'hour', self::HOUR_SHORT, $locale); |
4206 return $this->_calcvalue('set', $hour, 'hour', self::HOUR_SHORT, $locale); |
4199 * Returned is the new date object |
4213 * Returned is the new date object |
4200 * Example: 04.May.1993 13:07:25 -> addHour(12); -> 05.May.1993 01:07:25 |
4214 * Example: 04.May.1993 13:07:25 -> addHour(12); -> 05.May.1993 01:07:25 |
4201 * |
4215 * |
4202 * @param string|integer|array|Zend_Date $hour Hour to add |
4216 * @param string|integer|array|Zend_Date $hour Hour to add |
4203 * @param string|Zend_Locale $locale OPTIONAL Locale for parsing input |
4217 * @param string|Zend_Locale $locale OPTIONAL Locale for parsing input |
4204 * @return Zend_Date Provides fluid interface |
4218 * @return Zend_Date Provides a fluent interface |
4205 * @throws Zend_Date_Exception |
4219 * @throws Zend_Date_Exception |
4206 */ |
4220 */ |
4207 public function addHour($hour, $locale = null) |
4221 public function addHour($hour, $locale = null) |
4208 { |
4222 { |
4209 return $this->_calcvalue('add', $hour, 'hour', self::HOUR_SHORT, $locale); |
4223 return $this->_calcvalue('add', $hour, 'hour', self::HOUR_SHORT, $locale); |
4216 * Returned is the new date object |
4230 * Returned is the new date object |
4217 * Example: 04.May.1993 13:07:25 -> subHour(6); -> 05.May.1993 07:07:25 |
4231 * Example: 04.May.1993 13:07:25 -> subHour(6); -> 05.May.1993 07:07:25 |
4218 * |
4232 * |
4219 * @param string|integer|array|Zend_Date $hour Hour to sub |
4233 * @param string|integer|array|Zend_Date $hour Hour to sub |
4220 * @param string|Zend_Locale $locale OPTIONAL Locale for parsing input |
4234 * @param string|Zend_Locale $locale OPTIONAL Locale for parsing input |
4221 * @return Zend_Date Provides fluid interface |
4235 * @return Zend_Date Provides a fluent interface |
4222 * @throws Zend_Date_Exception |
4236 * @throws Zend_Date_Exception |
4223 */ |
4237 */ |
4224 public function subHour($hour, $locale = null) |
4238 public function subHour($hour, $locale = null) |
4225 { |
4239 { |
4226 return $this->_calcvalue('sub', $hour, 'hour', self::HOUR_SHORT, $locale); |
4240 return $this->_calcvalue('sub', $hour, 'hour', self::HOUR_SHORT, $locale); |
4268 * Returned is the new date object |
4282 * Returned is the new date object |
4269 * Example: 04.May.1993 13:07:25 -> setMinute(29); -> 04.May.1993 13:29:25 |
4283 * Example: 04.May.1993 13:07:25 -> setMinute(29); -> 04.May.1993 13:29:25 |
4270 * |
4284 * |
4271 * @param string|integer|array|Zend_Date $minute Minute to set |
4285 * @param string|integer|array|Zend_Date $minute Minute to set |
4272 * @param string|Zend_Locale $locale OPTIONAL Locale for parsing input |
4286 * @param string|Zend_Locale $locale OPTIONAL Locale for parsing input |
4273 * @return Zend_Date Provides fluid interface |
4287 * @return Zend_Date Provides a fluent interface |
4274 * @throws Zend_Date_Exception |
4288 * @throws Zend_Date_Exception |
4275 */ |
4289 */ |
4276 public function setMinute($minute, $locale = null) |
4290 public function setMinute($minute, $locale = null) |
4277 { |
4291 { |
4278 return $this->_calcvalue('set', $minute, 'minute', self::MINUTE_SHORT, $locale); |
4292 return $this->_calcvalue('set', $minute, 'minute', self::MINUTE_SHORT, $locale); |
4285 * Returned is the new date object |
4299 * Returned is the new date object |
4286 * Example: 04.May.1993 13:07:25 -> addMinute(65); -> 04.May.1993 13:12:25 |
4300 * Example: 04.May.1993 13:07:25 -> addMinute(65); -> 04.May.1993 13:12:25 |
4287 * |
4301 * |
4288 * @param string|integer|array|Zend_Date $minute Minute to add |
4302 * @param string|integer|array|Zend_Date $minute Minute to add |
4289 * @param string|Zend_Locale $locale OPTIONAL Locale for parsing input |
4303 * @param string|Zend_Locale $locale OPTIONAL Locale for parsing input |
4290 * @return Zend_Date Provides fluid interface |
4304 * @return Zend_Date Provides a fluent interface |
4291 * @throws Zend_Date_Exception |
4305 * @throws Zend_Date_Exception |
4292 */ |
4306 */ |
4293 public function addMinute($minute, $locale = null) |
4307 public function addMinute($minute, $locale = null) |
4294 { |
4308 { |
4295 return $this->_calcvalue('add', $minute, 'minute', self::MINUTE_SHORT, $locale); |
4309 return $this->_calcvalue('add', $minute, 'minute', self::MINUTE_SHORT, $locale); |
4302 * Returned is the new date object |
4316 * Returned is the new date object |
4303 * Example: 04.May.1993 13:07:25 -> subMinute(9); -> 04.May.1993 12:58:25 |
4317 * Example: 04.May.1993 13:07:25 -> subMinute(9); -> 04.May.1993 12:58:25 |
4304 * |
4318 * |
4305 * @param string|integer|array|Zend_Date $minute Minute to sub |
4319 * @param string|integer|array|Zend_Date $minute Minute to sub |
4306 * @param string|Zend_Locale $locale OPTIONAL Locale for parsing input |
4320 * @param string|Zend_Locale $locale OPTIONAL Locale for parsing input |
4307 * @return Zend_Date Provides fluid interface |
4321 * @return Zend_Date Provides a fluent interface |
4308 * @throws Zend_Date_Exception |
4322 * @throws Zend_Date_Exception |
4309 */ |
4323 */ |
4310 public function subMinute($minute, $locale = null) |
4324 public function subMinute($minute, $locale = null) |
4311 { |
4325 { |
4312 return $this->_calcvalue('sub', $minute, 'minute', self::MINUTE_SHORT, $locale); |
4326 return $this->_calcvalue('sub', $minute, 'minute', self::MINUTE_SHORT, $locale); |
4354 * Returned is the new date object |
4368 * Returned is the new date object |
4355 * Example: 04.May.1993 13:07:25 -> setSecond(100); -> 04.May.1993 13:08:40 |
4369 * Example: 04.May.1993 13:07:25 -> setSecond(100); -> 04.May.1993 13:08:40 |
4356 * |
4370 * |
4357 * @param string|integer|array|Zend_Date $second Second to set |
4371 * @param string|integer|array|Zend_Date $second Second to set |
4358 * @param string|Zend_Locale $locale (Optional) Locale for parsing input |
4372 * @param string|Zend_Locale $locale (Optional) Locale for parsing input |
4359 * @return Zend_Date Provides fluid interface |
4373 * @return Zend_Date Provides a fluent interface |
4360 * @throws Zend_Date_Exception |
4374 * @throws Zend_Date_Exception |
4361 */ |
4375 */ |
4362 public function setSecond($second, $locale = null) |
4376 public function setSecond($second, $locale = null) |
4363 { |
4377 { |
4364 return $this->_calcvalue('set', $second, 'second', self::SECOND_SHORT, $locale); |
4378 return $this->_calcvalue('set', $second, 'second', self::SECOND_SHORT, $locale); |
4371 * Returned is the new date object |
4385 * Returned is the new date object |
4372 * Example: 04.May.1993 13:07:25 -> addSecond(65); -> 04.May.1993 13:08:30 |
4386 * Example: 04.May.1993 13:07:25 -> addSecond(65); -> 04.May.1993 13:08:30 |
4373 * |
4387 * |
4374 * @param string|integer|array|Zend_Date $second Second to add |
4388 * @param string|integer|array|Zend_Date $second Second to add |
4375 * @param string|Zend_Locale $locale (Optional) Locale for parsing input |
4389 * @param string|Zend_Locale $locale (Optional) Locale for parsing input |
4376 * @return Zend_Date Provides fluid interface |
4390 * @return Zend_Date Provides a fluent interface |
4377 * @throws Zend_Date_Exception |
4391 * @throws Zend_Date_Exception |
4378 */ |
4392 */ |
4379 public function addSecond($second, $locale = null) |
4393 public function addSecond($second, $locale = null) |
4380 { |
4394 { |
4381 return $this->_calcvalue('add', $second, 'second', self::SECOND_SHORT, $locale); |
4395 return $this->_calcvalue('add', $second, 'second', self::SECOND_SHORT, $locale); |
4388 * Returned is the new date object |
4402 * Returned is the new date object |
4389 * Example: 04.May.1993 13:07:25 -> subSecond(10); -> 04.May.1993 13:07:15 |
4403 * Example: 04.May.1993 13:07:25 -> subSecond(10); -> 04.May.1993 13:07:15 |
4390 * |
4404 * |
4391 * @param string|integer|array|Zend_Date $second Second to sub |
4405 * @param string|integer|array|Zend_Date $second Second to sub |
4392 * @param string|Zend_Locale $locale (Optional) Locale for parsing input |
4406 * @param string|Zend_Locale $locale (Optional) Locale for parsing input |
4393 * @return Zend_Date Provides fluid interface |
4407 * @return Zend_Date Provides a fluent interface |
4394 * @throws Zend_Date_Exception |
4408 * @throws Zend_Date_Exception |
4395 */ |
4409 */ |
4396 public function subSecond($second, $locale = null) |
4410 public function subSecond($second, $locale = null) |
4397 { |
4411 { |
4398 return $this->_calcvalue('sub', $second, 'second', self::SECOND_SHORT, $locale); |
4412 return $this->_calcvalue('sub', $second, 'second', self::SECOND_SHORT, $locale); |
4429 /** |
4443 /** |
4430 * Sets a new precision for fractional seconds |
4444 * Sets a new precision for fractional seconds |
4431 * |
4445 * |
4432 * @param integer $precision Precision for the fractional datepart 3 = milliseconds |
4446 * @param integer $precision Precision for the fractional datepart 3 = milliseconds |
4433 * @throws Zend_Date_Exception |
4447 * @throws Zend_Date_Exception |
4434 * @return Zend_Date Provides fluid interface |
4448 * @return Zend_Date Provides a fluent interface |
4435 */ |
4449 */ |
4436 public function setFractionalPrecision($precision) |
4450 public function setFractionalPrecision($precision) |
4437 { |
4451 { |
4438 if (!intval($precision) or ($precision < 0) or ($precision > 9)) { |
4452 if (!intval($precision) or ($precision < 0) or ($precision > 9)) { |
4439 require_once 'Zend/Date/Exception.php'; |
4453 require_once 'Zend/Date/Exception.php'; |
4459 public function getMilliSecond() |
4473 public function getMilliSecond() |
4460 { |
4474 { |
4461 return $this->_fractional; |
4475 return $this->_fractional; |
4462 } |
4476 } |
4463 |
4477 |
4464 |
|
4465 /** |
4478 /** |
4466 * Sets new milliseconds for the date object |
4479 * Sets new milliseconds for the date object |
4467 * Example: setMilliSecond(550, 2) -> equals +5 Sec +50 MilliSec |
4480 * Example: setMilliSecond(550, 2) -> equals +5 Sec +50 MilliSec |
4468 * |
4481 * |
4469 * @param integer|Zend_Date $milli (Optional) Millisecond to set, when null the actual millisecond is set |
4482 * @param integer|Zend_Date $milli (Optional) Millisecond to set, when null the actual millisecond is set |
4470 * @param integer $precision (Optional) Fraction precision of the given milliseconds |
4483 * @param integer $precision (Optional) Fraction precision of the given milliseconds |
4471 * @return Zend_Date Provides fluid interface |
4484 * @throws Zend_Date_Exception |
|
4485 * @return Zend_Date Provides a fluent interface |
4472 */ |
4486 */ |
4473 public function setMilliSecond($milli = null, $precision = null) |
4487 public function setMilliSecond($milli = null, $precision = null) |
4474 { |
4488 { |
4475 if ($milli === null) { |
4489 if ($milli === null) { |
4476 list($milli, $time) = explode(" ", microtime()); |
4490 list($milli, $time) = explode(" ", microtime()); |
4493 $this->_fractional = 0; |
4507 $this->_fractional = 0; |
4494 $this->addMilliSecond($milli, $precision); |
4508 $this->addMilliSecond($milli, $precision); |
4495 return $this; |
4509 return $this; |
4496 } |
4510 } |
4497 |
4511 |
4498 |
|
4499 /** |
4512 /** |
4500 * Adds milliseconds to the date object |
4513 * Adds milliseconds to the date object |
4501 * |
4514 * |
4502 * @param integer|Zend_Date $milli (Optional) Millisecond to add, when null the actual millisecond is added |
4515 * @param integer|Zend_Date $milli (Optional) Millisecond to add, when null the actual millisecond is added |
4503 * @param integer $precision (Optional) Fractional precision for the given milliseconds |
4516 * @param integer $precision (Optional) Fractional precision for the given milliseconds |
4504 * @return Zend_Date Provides fluid interface |
4517 * @throws Zend_Date_Exception |
|
4518 * @return Zend_Date Provides a fluent interface |
4505 */ |
4519 */ |
4506 public function addMilliSecond($milli = null, $precision = null) |
4520 public function addMilliSecond($milli = null, $precision = null) |
4507 { |
4521 { |
4508 if ($milli === null) { |
4522 if ($milli === null) { |
4509 list($milli, $time) = explode(" ", microtime()); |
4523 list($milli, $time) = explode(" ", microtime()); |
4512 require_once 'Zend/Date/Exception.php'; |
4526 require_once 'Zend/Date/Exception.php'; |
4513 throw new Zend_Date_Exception("invalid milli second ($milli) operand", 0, null, $milli); |
4527 throw new Zend_Date_Exception("invalid milli second ($milli) operand", 0, null, $milli); |
4514 } |
4528 } |
4515 |
4529 |
4516 if ($precision === null) { |
4530 if ($precision === null) { |
4517 $precision = strlen($milli); |
4531 // Use internal default precision |
4518 if ($milli < 0) { |
4532 // Is not as logic as using the length of the input. But this would break tests and maybe other things |
4519 --$precision; |
4533 // as an input value of integer 10, which is used in tests, must be parsed as 10 milliseconds (real milliseconds, precision 3) |
4520 } |
4534 // but with auto-detect of precision, 100 milliseconds would be added. |
|
4535 $precision = $this->_precision; |
4521 } |
4536 } |
4522 |
4537 |
4523 if (!is_int($precision) || $precision < 1 || $precision > 9) { |
4538 if (!is_int($precision) || $precision < 1 || $precision > 9) { |
4524 require_once 'Zend/Date/Exception.php'; |
4539 require_once 'Zend/Date/Exception.php'; |
4525 throw new Zend_Date_Exception("precision ($precision) must be a positive integer less than 10", 0, null, $precision); |
4540 throw new Zend_Date_Exception( |
|
4541 "precision ($precision) must be a positive integer less than 10", 0, null, $precision |
|
4542 ); |
|
4543 } |
|
4544 |
|
4545 if ($this->_precision > $precision) { |
|
4546 $milli = $milli * pow(10, $this->_precision - $precision); |
|
4547 } elseif ($this->_precision < $precision) { |
|
4548 $milli = round($milli / pow(10, $precision - $this->_precision)); |
4526 } |
4549 } |
4527 |
4550 |
4528 $this->_fractional += $milli; |
4551 $this->_fractional += $milli; |
4529 |
4552 |
4530 // Add/sub milliseconds + add/sub seconds |
4553 // Add/sub milliseconds + add/sub seconds |
4555 /** |
4578 /** |
4556 * Subtracts a millisecond |
4579 * Subtracts a millisecond |
4557 * |
4580 * |
4558 * @param integer|Zend_Date $milli (Optional) Millisecond to sub, when null the actual millisecond is subtracted |
4581 * @param integer|Zend_Date $milli (Optional) Millisecond to sub, when null the actual millisecond is subtracted |
4559 * @param integer $precision (Optional) Fractional precision for the given milliseconds |
4582 * @param integer $precision (Optional) Fractional precision for the given milliseconds |
4560 * @return Zend_Date Provides fluid interface |
4583 * @return Zend_Date Provides a fluent interface |
4561 */ |
4584 */ |
4562 public function subMilliSecond($milli = null, $precision = null) |
4585 public function subMilliSecond($milli = null, $precision = null) |
4563 { |
4586 { |
4564 $this->addMilliSecond(0 - $milli, $precision); |
4587 $this->addMilliSecond(0 - $milli, $precision); |
4565 return $this; |
4588 return $this; |
4637 * Returned is the new date object |
4660 * Returned is the new date object |
4638 * Example: 09.Jan.2007 13:07:25 -> setWeek(1); -> 02.Jan.2007 13:07:25 |
4661 * Example: 09.Jan.2007 13:07:25 -> setWeek(1); -> 02.Jan.2007 13:07:25 |
4639 * |
4662 * |
4640 * @param string|integer|array|Zend_Date $week Week to set |
4663 * @param string|integer|array|Zend_Date $week Week to set |
4641 * @param string|Zend_Locale $locale OPTIONAL Locale for parsing input |
4664 * @param string|Zend_Locale $locale OPTIONAL Locale for parsing input |
4642 * @return Zend_Date Provides fluid interface |
4665 * @return Zend_Date Provides a fluent interface |
4643 * @throws Zend_Date_Exception |
4666 * @throws Zend_Date_Exception |
4644 */ |
4667 */ |
4645 public function setWeek($week, $locale = null) |
4668 public function setWeek($week, $locale = null) |
4646 { |
4669 { |
4647 return $this->_calcvalue('set', $week, 'week', self::WEEK, $locale); |
4670 return $this->_calcvalue('set', $week, 'week', self::WEEK, $locale); |
4652 * Returned is the new date object |
4675 * Returned is the new date object |
4653 * Example: 09.Jan.2007 13:07:25 -> addWeek(1); -> 16.Jan.2007 13:07:25 |
4676 * Example: 09.Jan.2007 13:07:25 -> addWeek(1); -> 16.Jan.2007 13:07:25 |
4654 * |
4677 * |
4655 * @param string|integer|array|Zend_Date $week Week to add |
4678 * @param string|integer|array|Zend_Date $week Week to add |
4656 * @param string|Zend_Locale $locale OPTIONAL Locale for parsing input |
4679 * @param string|Zend_Locale $locale OPTIONAL Locale for parsing input |
4657 * @return Zend_Date Provides fluid interface |
4680 * @return Zend_Date Provides a fluent interface |
4658 * @throws Zend_Date_Exception |
4681 * @throws Zend_Date_Exception |
4659 */ |
4682 */ |
4660 public function addWeek($week, $locale = null) |
4683 public function addWeek($week, $locale = null) |
4661 { |
4684 { |
4662 return $this->_calcvalue('add', $week, 'week', self::WEEK, $locale); |
4685 return $this->_calcvalue('add', $week, 'week', self::WEEK, $locale); |
4667 * Returned is the new date object |
4690 * Returned is the new date object |
4668 * Example: 09.Jan.2007 13:07:25 -> subWeek(1); -> 02.Jan.2007 13:07:25 |
4691 * Example: 09.Jan.2007 13:07:25 -> subWeek(1); -> 02.Jan.2007 13:07:25 |
4669 * |
4692 * |
4670 * @param string|integer|array|Zend_Date $week Week to sub |
4693 * @param string|integer|array|Zend_Date $week Week to sub |
4671 * @param string|Zend_Locale $locale OPTIONAL Locale for parsing input |
4694 * @param string|Zend_Locale $locale OPTIONAL Locale for parsing input |
4672 * @return Zend_Date Provides fluid interface |
4695 * @return Zend_Date Provides a fluent interface |
4673 * @throws Zend_Date_Exception |
4696 * @throws Zend_Date_Exception |
4674 */ |
4697 */ |
4675 public function subWeek($week, $locale = null) |
4698 public function subWeek($week, $locale = null) |
4676 { |
4699 { |
4677 return $this->_calcvalue('sub', $week, 'week', self::WEEK, $locale); |
4700 return $this->_calcvalue('sub', $week, 'week', self::WEEK, $locale); |