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'; 38 private $_locale =
null;
41 private $_fractional = 0;
42 private $_precision = 3;
44 private static $_options = array(
45 'format_type' =>
'iso',
47 'extend_month' =>
false,
54 const DAY_SHORT =
'd';
55 const DAY_SUFFIX =
'SS';
56 const DAY_OF_YEAR =
'D';
57 const WEEKDAY =
'EEEE';
58 const WEEKDAY_SHORT =
'EEE';
59 const WEEKDAY_NARROW =
'E';
60 const WEEKDAY_NAME =
'EE';
61 const WEEKDAY_8601 =
'eee';
62 const WEEKDAY_DIGIT =
'e';
65 const MONTH_SHORT =
'M';
66 const MONTH_DAYS =
'ddd';
67 const MONTH_NAME =
'MMMM';
68 const MONTH_NAME_SHORT =
'MMM';
69 const MONTH_NAME_NARROW =
'MMMMM';
71 const YEAR_SHORT =
'yy';
72 const YEAR_8601 =
'Y';
73 const YEAR_SHORT_8601 =
'YY';
78 const HOUR_SHORT =
'H';
80 const HOUR_SHORT_AM =
'h';
82 const MINUTE_SHORT =
'm';
84 const SECOND_SHORT =
's';
85 const MILLISECOND =
'S';
86 const TIMEZONE_NAME =
'zzzz';
89 const GMT_DIFF_SEP =
'ZZZZ';
91 const TIMEZONE_SECS =
'X';
94 const TIMESTAMP =
'U';
96 const ERA_NAME =
'GGGG';
97 const ERA_NARROW =
'GGGGG';
99 const DATE_FULL =
'FFFFF';
100 const DATE_LONG =
'FFFF';
101 const DATE_MEDIUM =
'FFF';
102 const DATE_SHORT =
'FF';
104 const TIME_FULL =
'TTTTT';
105 const TIME_LONG =
'TTTT';
106 const TIME_MEDIUM =
'TTT';
107 const TIME_SHORT =
'TT';
108 const DATETIME =
'K';
109 const DATETIME_FULL =
'KKKKK';
110 const DATETIME_LONG =
'KKKK';
111 const DATETIME_MEDIUM =
'KKK';
112 const DATETIME_SHORT =
'KK';
114 const COOKIE =
'CCC';
116 const RFC_850 =
'RR';
117 const RFC_1036 =
'RRR';
118 const RFC_1123 =
'RRRR';
119 const RFC_3339 =
'RRRRR';
126 const YEAR_MIN_VALUE = -10000;
131 const YEAR_MAX_VALUE = 10000;
147 public function __construct($date =
null, $part =
null, $locale =
null)
156 $date = (string) $date;
170 $this->setLocale($locale);
171 if (is_string($date) && ($part ===
null) && (strlen($date) <= 5)) {
176 if ($date ===
null) {
177 if ($part ===
null) {
179 }
else if ($part !== self::TIMESTAMP) {
180 $date = self::now($locale);
181 $date = $date->get($part);
186 $date = $date->getInfo();
187 $date = $this->
_getTime($date[
'offset']);
189 }
else if (parent::$_defaultOffset != 0) {
190 $date = $this->
_getTime(parent::$_defaultOffset);
194 $zone = @date_default_timezone_get();
198 if (!is_int($date)) {
199 $zone = $this->getTimezoneFromString($date);
204 if (($part !==
null && $part !== self::TIMESTAMP) or (!is_numeric($date))) {
207 $this->
set($date, $part, $this->_locale);
210 if (is_array($date) ===
true) {
211 if (!isset($date[
'hour'])) {
215 $hour = $this->toString(
'H',
'iso',
true);
216 $hour = $date[
'hour'] - $hour;
220 $this->addTimestamp(3600);
224 $this->subTimestamp(3600);
228 $this->addTimestamp(7200);
232 $this->subTimestamp(7200);
248 public static function setOptions(array
$options = array())
251 return self::$_options;
257 if (array_key_exists(
$name, self::$_options)) {
260 if ((strtolower(
$value) !=
'php') && (strtolower(
$value) !=
'iso')) {
261 #require_once 'Zend/Date/Exception.php'; 262 throw new Zend_Date_Exception(
"Unknown format type ($value) for dates, only 'iso' and 'php' supported", 0,
null,
$value);
267 #require_once 'Zend/Date/Exception.php'; 271 case 'extend_month' :
273 #require_once 'Zend/Date/Exception.php'; 279 parent::$_cache =
null;
282 #require_once 'Zend/Date/Exception.php'; 293 parent::$_defaultOffset = 0;
296 #require_once 'Zend/Date/Exception.php'; 300 $date =
$value->getInfo();
301 parent::$_defaultOffset = $date[
'offset'];
308 #require_once 'Zend/Date/Exception.php'; 322 public function getTimestamp()
336 private function _timestamp($calc, $stamp)
340 $stamp = $stamp->getTimestamp();
343 if (is_array($stamp)) {
344 if (isset($stamp[
'timestamp']) ===
true) {
345 $stamp = $stamp[
'timestamp'];
347 #require_once 'Zend/Date/Exception.php'; 352 if ($calc ===
'set') {
355 $return = $this->_calcdetail($calc, $stamp, self::TIMESTAMP,
null);
357 if ($calc !=
'cmp') {
370 public function setTimestamp($timestamp)
372 return $this->_timestamp(
'set', $timestamp);
382 public function addTimestamp($timestamp)
384 return $this->_timestamp(
'add', $timestamp);
394 public function subTimestamp($timestamp)
396 return $this->_timestamp(
'sub', $timestamp);
406 public function compareTimestamp($timestamp)
408 return $this->_timestamp(
'cmp', $timestamp);
433 public function toString(
$format =
null,
$type =
null, $locale =
null)
444 if (is_object(
$type)) {
466 if ($locale ===
null) {
467 $locale = $this->getLocale();
472 }
else if (((self::$_options[
'format_type'] ==
'php') && (
$type ===
null)) or (
$type ==
'php')) {
484 public function __toString()
486 return $this->toString(
null, $this->_locale);
496 public function toValue($part =
null)
500 return intval(
"$result");
511 public function toArray()
513 return array(
'day' => $this->toString(self::DAY_SHORT,
'iso'),
514 'month' => $this->toString(self::MONTH_SHORT,
'iso'),
515 'year' => $this->toString(self::YEAR,
'iso'),
516 'hour' => $this->toString(self::HOUR_SHORT,
'iso'),
517 'minute' => $this->toString(self::MINUTE_SHORT,
'iso'),
518 'second' => $this->toString(self::SECOND_SHORT,
'iso'),
519 'timezone' => $this->toString(self::TIMEZONE,
'iso'),
520 'timestamp' => $this->toString(self::TIMESTAMP,
'iso'),
521 'weekday' => $this->toString(self::WEEKDAY_8601,
'iso'),
522 'dayofyear' => $this->toString(self::DAY_OF_YEAR,
'iso'),
523 'week' => $this->toString(self::WEEK,
'iso'),
524 'gmtsecs' => $this->toString(self::TIMEZONE_SECS,
'iso'));
537 public function get($part =
null, $locale =
null)
539 if ($locale ===
null) {
540 $locale = $this->getLocale();
543 if (($part !==
null) && !defined($part)
544 && ($part !=
'ee') && ($part !=
'ss') && ($part !=
'GG') && ($part !=
'MM') && ($part !=
'EE') && ($part !=
'TT')
550 if ($part ===
null) {
551 $part = self::TIMESTAMP;
552 }
else if (self::$_options[
'format_type'] ==
'php') {
566 private function _toToken($part, $locale) {
571 for (
$i = 0; isset($part[
$i]); ++
$i) {
572 if ($part[
$i] ==
"'") {
573 $comment = $comment ?
false :
true;
574 if (isset($part[
$i+1]) && ($part[
$i+1] ==
"'")) {
575 $comment = $comment ?
false :
true;
589 if (!isset($part[
$i+1]) || (isset($orig[0]) && ($orig[0] != $part[
$i+1]))) {
590 $format .= $this->_parseIsoToDate($orig, $locale);
606 private function _parseIsoToDate(
$token, $locale) {
612 case self::WEEKDAY_SHORT :
615 return $this->_toComment(iconv_substr($day, 0, 3,
'UTF-8'));
618 case self::DAY_SHORT :
627 case self::WEEKDAY_8601 :
632 return $this->_toComment(str_pad($this->
date(
'N', $this->
getUnixTimestamp(),
false), 2,
'0', STR_PAD_LEFT));
635 case self::DAY_SUFFIX :
639 case self::WEEKDAY_DIGIT :
643 case self::DAY_OF_YEAR :
648 return $this->_toComment(str_pad($this->
date(
'z', $this->
getUnixTimestamp(),
false), 3,
'0', STR_PAD_LEFT));
652 return $this->_toComment(str_pad($this->
date(
'z', $this->
getUnixTimestamp(),
false), 2,
'0', STR_PAD_LEFT));
655 case self::WEEKDAY_NARROW :
659 return $this->_toComment(iconv_substr($day, 0, 1,
'UTF-8'));
662 case self::WEEKDAY_NAME :
669 return $this->_toComment(($week[0] ==
'0') ? $week[1] : $week);
676 case self::MONTH_NAME :
685 case self::MONTH_NAME_SHORT :
690 case self::MONTH_SHORT :
694 case self::MONTH_DAYS :
698 case self::MONTH_NAME_NARROW :
701 return $this->_toComment(iconv_substr($mon, 0, 1,
'UTF-8'));
704 case self::LEAPYEAR :
708 case self::YEAR_8601 :
716 case self::YEAR_SHORT :
720 case self::YEAR_SHORT_8601 :
724 case self::MERIDIEM :
737 case self::HOUR_SHORT_AM :
741 case self::HOUR_SHORT :
754 return $this->_toComment(str_pad($this->
date(
'i', $this->
getUnixTimestamp(),
false), 2,
'0', STR_PAD_LEFT));
758 return $this->_toComment(str_pad($this->
date(
's', $this->
getUnixTimestamp(),
false), 2,
'0', STR_PAD_LEFT));
761 case self::MINUTE_SHORT :
765 case self::SECOND_SHORT :
769 case self::MILLISECOND :
770 return $this->_toComment($this->getMilliSecond());
773 case self::TIMEZONE_NAME :
778 case self::DAYLIGHT :
782 case self::GMT_DIFF :
788 case self::GMT_DIFF_SEP :
792 case self::TIMEZONE :
799 case self::TIMEZONE_SECS :
803 case self::ISO_8601 :
807 case self::RFC_2822 :
811 case self::TIMESTAMP :
826 case self::ERA_NARROW :
829 return $this->_toComment(iconv_substr(
Zend_Locale_Data::getContent($locale,
'era', array(
'gregorian',
'Abbr',
'0')), 0, 1,
'UTF-8')) .
'.';
832 return $this->_toComment(iconv_substr(
Zend_Locale_Data::getContent($locale,
'era', array(
'gregorian',
'Abbr',
'1')), 0, 1,
'UTF-8')) .
'.';
835 case self::ERA_NAME :
848 case self::DATE_FULL :
852 case self::DATE_LONG :
856 case self::DATE_MEDIUM :
860 case self::DATE_SHORT :
868 case self::TIME_FULL :
872 case self::TIME_LONG :
876 case self::TIME_MEDIUM :
880 case self::TIME_SHORT :
884 case self::DATETIME :
888 case self::DATETIME_FULL :
892 case self::DATETIME_LONG :
896 case self::DATETIME_MEDIUM :
900 case self::DATETIME_SHORT :
905 return 'Y\-m\-d\TH\:i\:sP';
909 return 'l\, d\-M\-y H\:i\:s e';
913 return 'D\, d M y H\:i\:s O';
917 return 'l\, d\-M\-y H\:i\:s e';
920 case self::RFC_1036 :
921 return 'D\, d M y H\:i\:s O';
924 case self::RFC_1123 :
925 return 'D\, d M Y H\:i\:s O';
928 case self::RFC_3339 :
929 return 'Y\-m\-d\TH\:i\:sP';
933 return 'D\, d M Y H\:i\:s O';
937 return 'Y\-m\-d\TH\:i\:sP';
951 $length = iconv_strlen(
$token,
'UTF-8');
952 return $this->_toComment(str_pad($this->
date(
'Y', $this->
getUnixTimestamp(),
false), $length,
'0', STR_PAD_LEFT));
960 $length = iconv_strlen(
$token,
'UTF-8');
961 return $this->_toComment(str_pad($this->
date(
'o', $this->
getUnixTimestamp(),
false), $length,
'0', STR_PAD_LEFT));
965 $length = iconv_strlen(
$token,
'UTF-8');
966 $result = substr($this->getMilliSecond(), 0, 3);
971 return $this->_toComment(str_pad(
$result, $length,
'0', STR_PAD_LEFT));
975 return $this->_toComment(
$token);
984 private function _toComment(
$token)
988 foreach (
$token as $tok) {
1003 private function _getDigitFromName(
$name)
1043 #require_once 'Zend/Date/Exception.php'; 1055 public static function getFullYear(
$value)
1060 }
else if (
$value < 100) {
1079 public function set($date, $part =
null, $locale =
null)
1081 if (self::$_options[
'format_type'] ==
'php') {
1085 $zone = $this->getTimezoneFromString($date);
1088 $this->_calculate(
'set', $date, $part, $locale);
1107 public function add($date, $part = self::TIMESTAMP, $locale =
null)
1109 if (self::$_options[
'format_type'] ==
'php') {
1113 $this->_calculate(
'add', $date, $part, $locale);
1130 public function sub($date, $part = self::TIMESTAMP, $locale =
null)
1132 if (self::$_options[
'format_type'] ==
'php') {
1136 $this->_calculate(
'sub', $date, $part, $locale);
1150 public function compare($date, $part = self::TIMESTAMP, $locale =
null)
1152 if (self::$_options[
'format_type'] ==
'php') {
1156 $compare = $this->_calculate(
'cmp', $date, $part, $locale);
1160 }
else if ($compare < 0) {
1180 public function copyPart($part, $locale =
null)
1182 $clone = clone $this;
1183 $clone->setUnixTimestamp(0);
1184 if ($locale !=
null) {
1185 $clone->setLocale($locale);
1187 $clone->set($this, $part);
1197 public function getTimezoneFromString($zone)
1199 if (is_array($zone)) {
1204 return $zone->getTimezone();
1208 preg_match(
'/\dZ$/', $zone, $match);
1209 if (!empty($match)) {
1213 preg_match(
'/([+-]\d{2}):{0,1}\d{2}/', $zone, $match);
1214 if (!empty($match) and ($match[count($match) - 1] <= 14) and ($match[count($match) - 1] >= -12)) {
1216 $zone .= ($match[count($match) - 1] < 0) ?
"+" :
"-";
1217 $zone .= (int) abs($match[count($match) - 1]);
1221 preg_match(
'/([[:alpha:]\/_]{3,30})(?!.*([[:alpha:]\/]{3,30}))/', $zone, $match);
1223 if (!empty($match) and (!is_int($match[count($match) - 1]))) {
1229 return $match[count($match) - 1];
1232 }
catch (Exception $e) {
1248 private function _assign($calc, $date, $comp = 0, $dst =
false)
1252 if (!empty($comp)) {
1273 if ((self::$_options[
'fix_dst'] ===
true) and ($dst !==
false) and ($this->_dst ===
true)) {
1274 $hour = $this->toString(self::HOUR,
'iso');
1275 if ($hour != $dst) {
1276 if (($dst == ($hour + 1)) or ($dst == ($hour - 23))) {
1278 }
else if (($dst == ($hour - 1)) or ($dst == ($hour + 23))) {
1298 private function _calculate($calc, $date, $part, $locale)
1300 if ($date ===
null) {
1301 #require_once 'Zend/Date/Exception.php'; 1310 if ($locale ===
null) {
1311 $locale = $this->getLocale();
1314 $locale = (string) $locale;
1317 $year = $this->toString(self::YEAR,
'iso');
1318 $month = $this->toString(self::MONTH_SHORT,
'iso');
1319 $day = $this->toString(self::DAY_SHORT,
'iso');
1320 $hour = $this->toString(self::HOUR_SHORT,
'iso');
1321 $minute = $this->toString(self::MINUTE_SHORT,
'iso');
1322 $second = $this->toString(self::SECOND_SHORT,
'iso');
1325 $date = $date->toString($part,
'iso', $locale);
1328 if (is_array($date) ===
true) {
1329 if (empty($part) ===
false) {
1333 case self::DAY_SHORT:
1334 if (isset($date[
'day']) ===
true) {
1335 $date = $date[
'day'];
1339 case self::WEEKDAY_SHORT:
1341 case self::WEEKDAY_8601:
1342 case self::WEEKDAY_DIGIT:
1343 case self::WEEKDAY_NARROW:
1344 case self::WEEKDAY_NAME:
1345 if (isset($date[
'weekday']) ===
true) {
1346 $date = $date[
'weekday'];
1347 $part = self::WEEKDAY_DIGIT;
1350 case self::DAY_OF_YEAR:
1351 if (isset($date[
'day_of_year']) ===
true) {
1352 $date = $date[
'day_of_year'];
1357 case self::MONTH_SHORT:
1358 case self::MONTH_NAME:
1359 case self::MONTH_NAME_SHORT:
1360 case self::MONTH_NAME_NARROW:
1361 if (isset($date[
'month']) ===
true) {
1362 $date = $date[
'month'];
1367 case self::YEAR_SHORT:
1368 case self::YEAR_8601:
1369 case self::YEAR_SHORT_8601:
1370 if (isset($date[
'year']) ===
true) {
1371 $date = $date[
'year'];
1377 case self::HOUR_SHORT:
1378 case self::HOUR_SHORT_AM:
1379 if (isset($date[
'hour']) ===
true) {
1380 $date = $date[
'hour'];
1385 case self::MINUTE_SHORT:
1386 if (isset($date[
'minute']) ===
true) {
1387 $date = $date[
'minute'];
1392 case self::SECOND_SHORT:
1393 if (isset($date[
'second']) ===
true) {
1394 $date = $date[
'second'];
1398 case self::TIMEZONE:
1399 case self::TIMEZONE_NAME:
1400 if (isset($date[
'timezone']) ===
true) {
1401 $date = $date[
'timezone'];
1404 case self::TIMESTAMP:
1405 if (isset($date[
'timestamp']) ===
true) {
1406 $date = $date[
'timestamp'];
1410 if (isset($date[
'week']) ===
true) {
1411 $date = $date[
'week'];
1414 case self::TIMEZONE_SECS:
1415 if (isset($date[
'gmtsecs']) ===
true) {
1416 $date = $date[
'gmtsecs'];
1420 #require_once 'Zend/Date/Exception.php'; 1426 if (isset($date[
'hour']) ===
true) {
1427 $hours = $date[
'hour'];
1430 if (isset($date[
'minute']) ===
true) {
1431 $minutes = $date[
'minute'];
1434 if (isset($date[
'second']) ===
true) {
1435 $seconds = $date[
'second'];
1438 if (isset($date[
'month']) ===
true) {
1439 $months = $date[
'month'];
1442 if (isset($date[
'day']) ===
true) {
1443 $days = $date[
'day'];
1446 if (isset($date[
'year']) ===
true) {
1447 $years = $date[
'year'];
1449 return $this->_assign($calc, $this->
mktime($hours, $minutes, $seconds, $months, $days, $years,
true),
1450 $this->
mktime($hour, $minute, $second, $month, $day, $year,
true), $hour);
1459 if (is_numeric($date)) {
1460 return $this->_assign($calc, $this->
mktime(0, 0, 0, 1, 1 + intval($date), 1970,
true),
1461 $this->
mktime(0, 0, 0, 1, 1 + intval($day), 1970,
true), $hour);
1464 #require_once 'Zend/Date/Exception.php'; 1465 throw new Zend_Date_Exception(
"invalid date ($date) operand, day expected", 0,
null, $date);
1468 case self::WEEKDAY_SHORT:
1470 $weekday = (int) $this->toString(self::WEEKDAY_DIGIT,
'iso', $locale);
1473 foreach ($daylist as $key =>
$value) {
1474 if (strtoupper(iconv_substr(
$value, 0, 3,
'UTF-8')) == strtoupper($date)) {
1483 return $this->_assign($calc, $this->
mktime(0, 0, 0, 1, 1 + $found, 1970,
true),
1484 $this->
mktime(0, 0, 0, 1, 1 + $weekday, 1970,
true), $hour);
1488 #require_once 'Zend/Date/Exception.php'; 1489 throw new Zend_Date_Exception(
"invalid date ($date) operand, weekday expected", 0,
null, $date);
1492 case self::DAY_SHORT:
1493 if (is_numeric($date)) {
1494 return $this->_assign($calc, $this->
mktime(0, 0, 0, 1, 1 + intval($date), 1970,
true),
1495 $this->
mktime(0, 0, 0, 1, 1 + intval($day), 1970,
true), $hour);
1498 #require_once 'Zend/Date/Exception.php'; 1499 throw new Zend_Date_Exception(
"invalid date ($date) operand, day expected", 0,
null, $date);
1504 $weekday = (int) $this->toString(self::WEEKDAY_DIGIT,
'iso', $locale);
1507 foreach ($daylist as $key =>
$value) {
1508 if (strtoupper(
$value) == strtoupper($date)) {
1517 return $this->_assign($calc, $this->
mktime(0, 0, 0, 1, 1 + $found, 1970,
true),
1518 $this->
mktime(0, 0, 0, 1, 1 + $weekday, 1970,
true), $hour);
1522 #require_once 'Zend/Date/Exception.php'; 1523 throw new Zend_Date_Exception(
"invalid date ($date) operand, weekday expected", 0,
null, $date);
1526 case self::WEEKDAY_8601:
1527 $weekday = (int) $this->toString(self::WEEKDAY_8601,
'iso', $locale);
1528 if ((intval($date) > 0) and (intval($date) < 8)) {
1529 return $this->_assign($calc, $this->
mktime(0, 0, 0, 1, 1 + intval($date), 1970,
true),
1530 $this->
mktime(0, 0, 0, 1, 1 + $weekday, 1970,
true), $hour);
1534 #require_once 'Zend/Date/Exception.php'; 1535 throw new Zend_Date_Exception(
"invalid date ($date) operand, weekday expected", 0,
null, $date);
1538 case self::DAY_SUFFIX:
1539 #require_once 'Zend/Date/Exception.php'; 1543 case self::WEEKDAY_DIGIT:
1544 $weekday = (int) $this->toString(self::WEEKDAY_DIGIT,
'iso', $locale);
1545 if (is_numeric($date) and (intval($date) >= 0) and (intval($date) < 7)) {
1546 return $this->_assign($calc, $this->
mktime(0, 0, 0, 1, 1 + $date, 1970,
true),
1547 $this->
mktime(0, 0, 0, 1, 1 + $weekday, 1970,
true), $hour);
1551 #require_once 'Zend/Date/Exception.php'; 1552 throw new Zend_Date_Exception(
"invalid date ($date) operand, weekday expected", 0,
null, $date);
1555 case self::DAY_OF_YEAR:
1556 if (is_numeric($date)) {
1557 if (($calc ==
'add') || ($calc ==
'sub')) {
1563 return $this->_assign($calc, $this->
mktime(0, 0, 0, 1, $date, $year,
true),
1564 $this->
mktime(0, 0, 0, $month, $day, $year,
true), $hour);
1567 #require_once 'Zend/Date/Exception.php'; 1568 throw new Zend_Date_Exception(
"invalid date ($date) operand, day expected", 0,
null, $date);
1571 case self::WEEKDAY_NARROW:
1573 $weekday = (int) $this->toString(self::WEEKDAY_DIGIT,
'iso', $locale);
1575 foreach ($daylist as $key =>
$value) {
1576 if (strtoupper(iconv_substr(
$value, 0, 1,
'UTF-8')) == strtoupper($date)) {
1585 return $this->_assign($calc, $this->
mktime(0, 0, 0, 1, 1 + $found, 1970,
true),
1586 $this->
mktime(0, 0, 0, 1, 1 + $weekday, 1970,
true), $hour);
1590 #require_once 'Zend/Date/Exception.php'; 1591 throw new Zend_Date_Exception(
"invalid date ($date) operand, weekday expected", 0,
null, $date);
1594 case self::WEEKDAY_NAME:
1596 $weekday = (int) $this->toString(self::WEEKDAY_DIGIT,
'iso', $locale);
1598 foreach ($daylist as $key =>
$value) {
1599 if (strtoupper(
$value) == strtoupper($date)) {
1608 return $this->_assign($calc, $this->
mktime(0, 0, 0, 1, 1 + $found, 1970,
true),
1609 $this->
mktime(0, 0, 0, 1, 1 + $weekday, 1970,
true), $hour);
1613 #require_once 'Zend/Date/Exception.php'; 1614 throw new Zend_Date_Exception(
"invalid date ($date) operand, weekday expected", 0,
null, $date);
1619 if (is_numeric($date)) {
1620 $week = (int) $this->toString(self::WEEK,
'iso', $locale);
1621 return $this->_assign($calc, parent::mktime(0, 0, 0, 1, 1 + ($date * 7), 1970,
true),
1622 parent::mktime(0, 0, 0, 1, 1 + ($week * 7), 1970,
true), $hour);
1625 #require_once 'Zend/Date/Exception.php'; 1626 throw new Zend_Date_Exception(
"invalid date ($date) operand, week expected", 0,
null, $date);
1630 case self::MONTH_NAME:
1633 foreach ($monthlist as $key =>
$value) {
1634 if (strtoupper(
$value) == strtoupper($date)) {
1640 $date = array_search($date, $monthlist);
1645 if ($calc ==
'add') {
1648 if (self::$_options[
'extend_month'] ==
false) {
1649 $parts = $this->
getDateParts($this->
mktime($hour, $minute, $second, $date, $day, $year,
false));
1650 if ($parts[
'mday'] != $day) {
1651 $fixday = ($parts[
'mday'] < $day) ? -$parts[
'mday'] : ($parts[
'mday'] - $day);
1654 }
else if ($calc ==
'sub') {
1655 $date = $month - $found;
1657 if (self::$_options[
'extend_month'] ==
false) {
1658 $parts = $this->
getDateParts($this->
mktime($hour, $minute, $second, $date, $day, $year,
false));
1659 if ($parts[
'mday'] != $day) {
1660 $fixday = ($parts[
'mday'] < $day) ? -$parts[
'mday'] : ($parts[
'mday'] - $day);
1664 return $this->_assign($calc, $this->
mktime(0, 0, 0, $date, $day + $fixday, $year,
true),
1665 $this->
mktime(0, 0, 0, $month, $day, $year,
true), $hour);
1669 #require_once 'Zend/Date/Exception.php'; 1670 throw new Zend_Date_Exception(
"invalid date ($date) operand, month expected", 0,
null, $date);
1674 if (is_numeric($date)) {
1676 if ($calc ==
'add') {
1679 if (self::$_options[
'extend_month'] ==
false) {
1680 $parts = $this->
getDateParts($this->
mktime($hour, $minute, $second, $date, $day, $year,
false));
1681 if ($parts[
'mday'] != $day) {
1682 $fixday = ($parts[
'mday'] < $day) ? -$parts[
'mday'] : ($parts[
'mday'] - $day);
1685 }
else if ($calc ==
'sub') {
1686 $date = $month - $date;
1688 if (self::$_options[
'extend_month'] ==
false) {
1689 $parts = $this->
getDateParts($this->
mktime($hour, $minute, $second, $date, $day, $year,
false));
1690 if ($parts[
'mday'] != $day) {
1691 $fixday = ($parts[
'mday'] < $day) ? -$parts[
'mday'] : ($parts[
'mday'] - $day);
1695 return $this->_assign($calc, $this->
mktime(0, 0, 0, $date, $day + $fixday, $year,
true),
1696 $this->
mktime(0, 0, 0, $month, $day, $year,
true), $hour);
1699 #require_once 'Zend/Date/Exception.php'; 1700 throw new Zend_Date_Exception(
"invalid date ($date) operand, month expected", 0,
null, $date);
1703 case self::MONTH_NAME_SHORT:
1706 foreach ($monthlist as $key =>
$value) {
1707 if (strtoupper(
$value) == strtoupper($date)) {
1713 $date = array_search($date, $monthlist);
1718 if ($calc ==
'add') {
1721 if (self::$_options[
'extend_month'] ===
false) {
1722 $parts = $this->
getDateParts($this->
mktime($hour, $minute, $second, $date, $day, $year,
false));
1723 if ($parts[
'mday'] != $day) {
1724 $fixday = ($parts[
'mday'] < $day) ? -$parts[
'mday'] : ($parts[
'mday'] - $day);
1727 }
else if ($calc ==
'sub') {
1728 $date = $month - $found;
1730 if (self::$_options[
'extend_month'] ===
false) {
1731 $parts = $this->
getDateParts($this->
mktime($hour, $minute, $second, $date, $day, $year,
false));
1732 if ($parts[
'mday'] != $day) {
1733 $fixday = ($parts[
'mday'] < $day) ? -$parts[
'mday'] : ($parts[
'mday'] - $day);
1737 return $this->_assign($calc, $this->
mktime(0, 0, 0, $date, $day + $fixday, $year,
true),
1738 $this->
mktime(0, 0, 0, $month, $day, $year,
true), $hour);
1742 #require_once 'Zend/Date/Exception.php'; 1743 throw new Zend_Date_Exception(
"invalid date ($date) operand, month expected", 0,
null, $date);
1746 case self::MONTH_SHORT:
1747 if (is_numeric($date) ===
true) {
1749 if ($calc ===
'add') {
1752 if (self::$_options[
'extend_month'] ===
false) {
1753 $parts = $this->
getDateParts($this->
mktime($hour, $minute, $second, $date, $day, $year,
false));
1754 if ($parts[
'mday'] != $day) {
1755 $fixday = ($parts[
'mday'] < $day) ? -$parts[
'mday'] : ($parts[
'mday'] - $day);
1758 }
else if ($calc ===
'sub') {
1759 $date = $month - $date;
1761 if (self::$_options[
'extend_month'] ===
false) {
1762 $parts = $this->
getDateParts($this->
mktime($hour, $minute, $second, $date, $day, $year,
false));
1763 if ($parts[
'mday'] != $day) {
1764 $fixday = ($parts[
'mday'] < $day) ? -$parts[
'mday'] : ($parts[
'mday'] - $day);
1769 return $this->_assign($calc, $this->
mktime(0, 0, 0, $date, $day + $fixday, $year,
true),
1770 $this->
mktime(0, 0, 0, $month, $day, $year,
true), $hour);
1773 #require_once 'Zend/Date/Exception.php'; 1774 throw new Zend_Date_Exception(
"invalid date ($date) operand, month expected", 0,
null, $date);
1777 case self::MONTH_DAYS:
1778 #require_once 'Zend/Date/Exception.php'; 1782 case self::MONTH_NAME_NARROW:
1785 foreach ($monthlist as $key =>
$value) {
1786 if (strtoupper(
$value) === strtoupper($date)) {
1792 $date = array_search($date, $monthlist);
1797 if ($calc ===
'add') {
1800 if (self::$_options[
'extend_month'] ===
false) {
1801 $parts = $this->
getDateParts($this->
mktime($hour, $minute, $second, $date, $day, $year,
false));
1802 if ($parts[
'mday'] != $day) {
1803 $fixday = ($parts[
'mday'] < $day) ? -$parts[
'mday'] : ($parts[
'mday'] - $day);
1806 }
else if ($calc ===
'sub') {
1807 $date = $month - $found;
1809 if (self::$_options[
'extend_month'] ===
false) {
1810 $parts = $this->
getDateParts($this->
mktime($hour, $minute, $second, $date, $day, $year,
false));
1811 if ($parts[
'mday'] != $day) {
1812 $fixday = ($parts[
'mday'] < $day) ? -$parts[
'mday'] : ($parts[
'mday'] - $day);
1816 return $this->_assign($calc, $this->
mktime(0, 0, 0, $date, $day + $fixday, $year,
true),
1817 $this->
mktime(0, 0, 0, $month, $day, $year,
true), $hour);
1821 #require_once 'Zend/Date/Exception.php'; 1822 throw new Zend_Date_Exception(
"invalid date ($date) operand, month expected", 0,
null, $date);
1826 case self::LEAPYEAR:
1827 #require_once 'Zend/Date/Exception.php'; 1831 case self::YEAR_8601:
1832 if (is_numeric($date)) {
1833 if ($calc ===
'add') {
1836 }
else if ($calc ===
'sub') {
1837 $date = $year - $date;
1841 return $this->_assign($calc, $this->
mktime(0, 0, 0, $month, $day, intval($date),
true),
1842 $this->
mktime(0, 0, 0, $month, $day, $year,
true),
false);
1845 #require_once 'Zend/Date/Exception.php'; 1846 throw new Zend_Date_Exception(
"invalid date ($date) operand, year expected", 0,
null, $date);
1850 if (is_numeric($date)) {
1851 if ($calc ===
'add') {
1854 }
else if ($calc ===
'sub') {
1855 $date = $year - $date;
1859 return $this->_assign($calc, $this->
mktime(0, 0, 0, $month, $day, intval($date),
true),
1860 $this->
mktime(0, 0, 0, $month, $day, $year,
true),
false);
1863 #require_once 'Zend/Date/Exception.php'; 1864 throw new Zend_Date_Exception(
"invalid date ($date) operand, year expected", 0,
null, $date);
1867 case self::YEAR_SHORT:
1868 if (is_numeric($date)) {
1869 $date = intval($date);
1870 if (($calc ==
'set') || ($calc ==
'cmp')) {
1871 $date = self::getFullYear($date);
1873 if ($calc ===
'add') {
1876 }
else if ($calc ===
'sub') {
1877 $date = $year - $date;
1881 return $this->_assign($calc, $this->
mktime(0, 0, 0, $month, $day, $date,
true),
1882 $this->
mktime(0, 0, 0, $month, $day, $year,
true),
false);
1885 #require_once 'Zend/Date/Exception.php'; 1886 throw new Zend_Date_Exception(
"invalid date ($date) operand, year expected", 0,
null, $date);
1889 case self::YEAR_SHORT_8601:
1890 if (is_numeric($date)) {
1891 $date = intval($date);
1892 if (($calc ===
'set') || ($calc ===
'cmp')) {
1893 $date = self::getFullYear($date);
1895 if ($calc ===
'add') {
1898 }
else if ($calc ===
'sub') {
1899 $date = $year - $date;
1903 return $this->_assign($calc, $this->
mktime(0, 0, 0, $month, $day, $date,
true),
1904 $this->
mktime(0, 0, 0, $month, $day, $year,
true),
false);
1907 #require_once 'Zend/Date/Exception.php'; 1908 throw new Zend_Date_Exception(
"invalid date ($date) operand, year expected", 0,
null, $date);
1912 case self::MERIDIEM:
1913 #require_once 'Zend/Date/Exception.php'; 1918 if (is_numeric($date)) {
1919 $rest = intval($date);
1920 $hours = floor($rest * 24 / 1000);
1921 $rest = $rest - ($hours * 1000 / 24);
1922 $minutes = floor($rest * 1440 / 1000);
1923 $rest = $rest - ($minutes * 1000 / 1440);
1924 $seconds = floor($rest * 86400 / 1000);
1925 return $this->_assign($calc, $this->
mktime($hours, $minutes, $seconds, 1, 1, 1970,
true),
1926 $this->
mktime($hour, $minute, $second, 1, 1, 1970,
true),
false);
1929 #require_once 'Zend/Date/Exception.php'; 1930 throw new Zend_Date_Exception(
"invalid date ($date) operand, swatchstamp expected", 0,
null, $date);
1933 case self::HOUR_SHORT_AM:
1934 if (is_numeric($date)) {
1935 return $this->_assign($calc, $this->
mktime(intval($date), 0, 0, 1, 1, 1970,
true),
1936 $this->
mktime($hour, 0, 0, 1, 1, 1970,
true),
false);
1939 #require_once 'Zend/Date/Exception.php'; 1940 throw new Zend_Date_Exception(
"invalid date ($date) operand, hour expected", 0,
null, $date);
1943 case self::HOUR_SHORT:
1944 if (is_numeric($date)) {
1945 return $this->_assign($calc, $this->
mktime(intval($date), 0, 0, 1, 1, 1970,
true),
1946 $this->
mktime($hour, 0, 0, 1, 1, 1970,
true),
false);
1949 #require_once 'Zend/Date/Exception.php'; 1950 throw new Zend_Date_Exception(
"invalid date ($date) operand, hour expected", 0,
null, $date);
1954 if (is_numeric($date)) {
1955 return $this->_assign($calc, $this->
mktime(intval($date), 0, 0, 1, 1, 1970,
true),
1956 $this->
mktime($hour, 0, 0, 1, 1, 1970,
true),
false);
1959 #require_once 'Zend/Date/Exception.php'; 1960 throw new Zend_Date_Exception(
"invalid date ($date) operand, hour expected", 0,
null, $date);
1964 if (is_numeric($date)) {
1965 return $this->_assign($calc, $this->
mktime(intval($date), 0, 0, 1, 1, 1970,
true),
1966 $this->
mktime($hour, 0, 0, 1, 1, 1970,
true),
false);
1969 #require_once 'Zend/Date/Exception.php'; 1970 throw new Zend_Date_Exception(
"invalid date ($date) operand, hour expected", 0,
null, $date);
1974 if (is_numeric($date)) {
1975 return $this->_assign($calc, $this->
mktime(0, intval($date), 0, 1, 1, 1970,
true),
1976 $this->
mktime(0, $minute, 0, 1, 1, 1970,
true),
false);
1979 #require_once 'Zend/Date/Exception.php'; 1980 throw new Zend_Date_Exception(
"invalid date ($date) operand, minute expected", 0,
null, $date);
1984 if (is_numeric($date)) {
1985 return $this->_assign($calc, $this->
mktime(0, 0, intval($date), 1, 1, 1970,
true),
1986 $this->
mktime(0, 0, $second, 1, 1, 1970,
true),
false);
1989 #require_once 'Zend/Date/Exception.php'; 1990 throw new Zend_Date_Exception(
"invalid date ($date) operand, second expected", 0,
null, $date);
1993 case self::MILLISECOND:
1994 if (is_numeric($date)) {
1997 return $this->setMillisecond($date);
2000 return $this->addMillisecond($date);
2003 return $this->subMillisecond($date);
2007 return $this->compareMillisecond($date);
2010 #require_once 'Zend/Date/Exception.php'; 2011 throw new Zend_Date_Exception(
"invalid date ($date) operand, milliseconds expected", 0,
null, $date);
2014 case self::MINUTE_SHORT:
2015 if (is_numeric($date)) {
2016 return $this->_assign($calc, $this->
mktime(0, intval($date), 0, 1, 1, 1970,
true),
2017 $this->
mktime(0, $minute, 0, 1, 1, 1970,
true),
false);
2020 #require_once 'Zend/Date/Exception.php'; 2021 throw new Zend_Date_Exception(
"invalid date ($date) operand, minute expected", 0,
null, $date);
2024 case self::SECOND_SHORT:
2025 if (is_numeric($date)) {
2026 return $this->_assign($calc, $this->
mktime(0, 0, intval($date), 1, 1, 1970,
true),
2027 $this->
mktime(0, 0, $second, 1, 1, 1970,
true),
false);
2030 #require_once 'Zend/Date/Exception.php'; 2031 throw new Zend_Date_Exception(
"invalid date ($date) operand, second expected", 0,
null, $date);
2036 case self::TIMEZONE_NAME:
2037 case self::TIMEZONE:
2038 case self::TIMEZONE_SECS:
2039 #require_once 'Zend/Date/Exception.php'; 2043 case self::DAYLIGHT:
2044 #require_once 'Zend/Date/Exception.php'; 2048 case self::GMT_DIFF:
2049 case self::GMT_DIFF_SEP:
2050 #require_once 'Zend/Date/Exception.php'; 2055 case self::ISO_8601:
2057 preg_match(
'/^(-{0,1}\d{4})-(\d{2})-(\d{2})/', $date, $datematch);
2059 if (empty($datematch)) {
2060 preg_match(
'/^(-{0,1}\d{2})-(\d{2})-(\d{2})/', $date, $datematch);
2063 if (empty($datematch)) {
2064 preg_match(
'/^(-{0,1}\d{4})(\d{2})(\d{2})/', $date, $datematch);
2067 if (empty($datematch)) {
2068 preg_match(
'/^(-{0,1}\d{2})(\d{2})(\d{2})/', $date, $datematch);
2071 if (!empty($datematch)) {
2072 $dateMatchCharCount = iconv_strlen($datematch[0],
'UTF-8');
2073 $tmpdate = iconv_substr($date,
2074 $dateMatchCharCount,
2075 iconv_strlen($date,
'UTF-8') - $dateMatchCharCount,
2079 preg_match(
'/[T,\s]{0,1}(\d{2}):(\d{2}):(\d{2})/', $tmpdate, $timematch);
2081 if (empty($timematch)) {
2082 preg_match(
'/[T,\s]{0,1}(\d{2})(\d{2})(\d{2})/', $tmpdate, $timematch);
2085 if (empty($timematch)) {
2086 preg_match(
'/[T,\s]{0,1}(\d{2}):(\d{2})/', $tmpdate, $timematch);
2089 if (empty($timematch)) {
2090 preg_match(
'/[T,\s]{0,1}(\d{2})(\d{2})/', $tmpdate, $timematch);
2092 if (empty($datematch) and empty($timematch)) {
2093 #require_once 'Zend/Date/Exception.php'; 2096 if (!empty($timematch)) {
2097 $timeMatchCharCount = iconv_strlen($timematch[0],
'UTF-8');
2098 $tmpdate = iconv_substr($tmpdate,
2099 $timeMatchCharCount,
2100 iconv_strlen($tmpdate,
'UTF-8') - $timeMatchCharCount,
2103 if (empty($datematch)) {
2104 $datematch[1] = 1970;
2107 }
else if (iconv_strlen($datematch[1],
'UTF-8') == 2) {
2108 $datematch[1] = self::getFullYear($datematch[1]);
2110 if (empty($timematch)) {
2115 if (!isset($timematch[3])) {
2119 if (($calc ==
'set') || ($calc ==
'cmp')) {
2124 $datematch[1] -= 1970;
2127 return $this->_assign($calc, $this->
mktime($timematch[1], $timematch[2], $timematch[3], 1 + $datematch[2], 1 + $datematch[3], 1970 + $datematch[1],
false),
2128 $this->
mktime($hour, $minute, $second, 1 + $month, 1 + $day, 1970 + $year,
false),
false);
2131 case self::RFC_2822:
2132 $result = preg_match(
'/^\w{3},\s(\d{1,2})\s(\w{3})\s(\d{4})\s' 2133 .
'(\d{2}):(\d{2}):{0,1}(\d{0,2})\s([+-]' 2134 .
'{1}\d{4}|\w{1,20})$/', $date, $match);
2137 #require_once 'Zend/Date/Exception.php'; 2141 $months = $this->_getDigitFromName($match[2]);
2143 if (($calc ==
'set') || ($calc ==
'cmp')) {
2151 return $this->_assign($calc, $this->
mktime($match[4], $match[5], $match[6], 1 + $months, 1 + $match[1], 1970 + $match[3],
false),
2152 $this->
mktime($hour, $minute, $second, 1 + $month, 1 + $day, 1970 + $year,
false),
false);
2155 case self::TIMESTAMP:
2156 if (is_numeric($date)) {
2160 #require_once 'Zend/Date/Exception.php'; 2161 throw new Zend_Date_Exception(
"invalid date ($date) operand, timestamp expected", 0,
null, $date);
2167 case self::ERA_NAME:
2168 #require_once 'Zend/Date/Exception.php'; 2176 if (($calc ==
'set') || ($calc ==
'cmp')) {
2181 $parsed[
'year'] -= 1970;
2185 return $this->_assign($calc, $this->
mktime(0, 0, 0, 1 + $parsed[
'month'], 1 + $parsed[
'day'], 1970 + $parsed[
'year'],
true),
2186 $this->
mktime(0, 0, 0, 1 + $month, 1 + $day, 1970 + $year,
true), $hour);
2188 #require_once 'Zend/Date/Exception.php'; 2193 case self::DATE_FULL:
2198 if (($calc ==
'set') || ($calc ==
'cmp')) {
2203 $parsed[
'year'] -= 1970;
2206 return $this->_assign($calc, $this->
mktime(0, 0, 0, 1 + $parsed[
'month'], 1 + $parsed[
'day'], 1970 + $parsed[
'year'],
true),
2207 $this->
mktime(0, 0, 0, 1 + $month, 1 + $day, 1970 + $year,
true), $hour);
2209 #require_once 'Zend/Date/Exception.php'; 2214 case self::DATE_LONG:
2219 if (($calc ==
'set') || ($calc ==
'cmp')){
2224 $parsed[
'year'] -= 1970;
2227 return $this->_assign($calc, $this->
mktime(0, 0, 0, 1 + $parsed[
'month'], 1 + $parsed[
'day'], 1970 + $parsed[
'year'],
true),
2228 $this->
mktime(0, 0, 0, 1 + $month, 1 + $day, 1970 + $year,
true), $hour);
2230 #require_once 'Zend/Date/Exception.php'; 2235 case self::DATE_MEDIUM:
2240 if (($calc ==
'set') || ($calc ==
'cmp')) {
2245 $parsed[
'year'] -= 1970;
2248 return $this->_assign($calc, $this->
mktime(0, 0, 0, 1 + $parsed[
'month'], 1 + $parsed[
'day'], 1970 + $parsed[
'year'],
true),
2249 $this->
mktime(0, 0, 0, 1 + $month, 1 + $day, 1970 + $year,
true), $hour);
2251 #require_once 'Zend/Date/Exception.php'; 2256 case self::DATE_SHORT:
2261 $parsed[
'year'] = self::getFullYear($parsed[
'year']);
2263 if (($calc ==
'set') || ($calc ==
'cmp')) {
2268 $parsed[
'year'] -= 1970;
2271 return $this->_assign($calc, $this->
mktime(0, 0, 0, 1 + $parsed[
'month'], 1 + $parsed[
'day'], 1970 + $parsed[
'year'],
true),
2272 $this->
mktime(0, 0, 0, 1 + $month, 1 + $day, 1970 + $year,
true), $hour);
2274 #require_once 'Zend/Date/Exception.php'; 2281 if ($calc !=
'set') {
2287 return $this->_assign($calc, $this->
mktime($parsed[
'hour'], $parsed[
'minute'], $parsed[
'second'], $month, $day, $year,
true),
2288 $this->
mktime($hour, $minute, $second, $month, $day, $year,
true),
false);
2290 #require_once 'Zend/Date/Exception.php'; 2295 case self::TIME_FULL:
2299 if ($calc !=
'set') {
2305 if (!isset($parsed[
'second'])) {
2306 $parsed[
'second'] = 0;
2309 return $this->_assign($calc, $this->
mktime($parsed[
'hour'], $parsed[
'minute'], $parsed[
'second'], $month, $day, $year,
true),
2310 $this->
mktime($hour, $minute, $second, $month, $day, $year,
true),
false);
2312 #require_once 'Zend/Date/Exception.php'; 2317 case self::TIME_LONG:
2321 if ($calc !=
'set') {
2326 return $this->_assign($calc, $this->
mktime($parsed[
'hour'], $parsed[
'minute'], $parsed[
'second'], $month, $day, $year,
true),
2327 $this->
mktime($hour, $minute, $second, $month, $day, $year,
true),
false);
2329 #require_once 'Zend/Date/Exception.php'; 2334 case self::TIME_MEDIUM:
2338 if ($calc !=
'set') {
2343 return $this->_assign($calc, $this->
mktime($parsed[
'hour'], $parsed[
'minute'], $parsed[
'second'], $month, $day, $year,
true),
2344 $this->
mktime($hour, $minute, $second, $month, $day, $year,
true),
false);
2346 #require_once 'Zend/Date/Exception.php'; 2351 case self::TIME_SHORT:
2355 if ($calc !=
'set') {
2361 if (!isset($parsed[
'second'])) {
2362 $parsed[
'second'] = 0;
2365 return $this->_assign($calc, $this->
mktime($parsed[
'hour'], $parsed[
'minute'], $parsed[
'second'], $month, $day, $year,
true),
2366 $this->
mktime($hour, $minute, $second, $month, $day, $year,
true),
false);
2368 #require_once 'Zend/Date/Exception.php'; 2373 case self::DATETIME:
2376 if (($calc ==
'set') || ($calc ==
'cmp')) {
2381 $parsed[
'year'] -= 1970;
2384 return $this->_assign($calc, $this->
mktime($parsed[
'hour'], $parsed[
'minute'], $parsed[
'second'], 1 + $parsed[
'month'], 1 + $parsed[
'day'], 1970 + $parsed[
'year'],
true),
2385 $this->
mktime($hour, $minute, $second, 1 + $month, 1 + $day, 1970 + $year,
true), $hour);
2387 #require_once 'Zend/Date/Exception.php'; 2392 case self::DATETIME_FULL:
2397 if (($calc ==
'set') || ($calc ==
'cmp')) {
2402 $parsed[
'year'] -= 1970;
2406 if (!isset($parsed[
'second'])) {
2407 $parsed[
'second'] = 0;
2410 return $this->_assign($calc, $this->
mktime($parsed[
'hour'], $parsed[
'minute'], $parsed[
'second'], 1 + $parsed[
'month'], 1 + $parsed[
'day'], 1970 + $parsed[
'year'],
true),
2411 $this->
mktime($hour, $minute, $second, 1 + $month, 1 + $day, 1970 + $year,
true), $hour);
2413 #require_once 'Zend/Date/Exception.php'; 2418 case self::DATETIME_LONG:
2423 if (($calc ==
'set') || ($calc ==
'cmp')){
2428 $parsed[
'year'] -= 1970;
2431 return $this->_assign($calc, $this->
mktime($parsed[
'hour'], $parsed[
'minute'], $parsed[
'second'], 1 + $parsed[
'month'], 1 + $parsed[
'day'], 1970 + $parsed[
'year'],
true),
2432 $this->
mktime($hour, $minute, $second, 1 + $month, 1 + $day, 1970 + $year,
true), $hour);
2434 #require_once 'Zend/Date/Exception.php'; 2439 case self::DATETIME_MEDIUM:
2443 if (($calc ==
'set') || ($calc ==
'cmp')) {
2448 $parsed[
'year'] -= 1970;
2451 return $this->_assign($calc, $this->
mktime($parsed[
'hour'], $parsed[
'minute'], $parsed[
'second'], 1 + $parsed[
'month'], 1 + $parsed[
'day'], 1970 + $parsed[
'year'],
true),
2452 $this->
mktime($hour, $minute, $second, 1 + $month, 1 + $day, 1970 + $year,
true), $hour);
2454 #require_once 'Zend/Date/Exception.php'; 2459 case self::DATETIME_SHORT:
2464 $parsed[
'year'] = self::getFullYear($parsed[
'year']);
2466 if (($calc ==
'set') || ($calc ==
'cmp')) {
2471 $parsed[
'year'] -= 1970;
2475 if (!isset($parsed[
'second'])) {
2476 $parsed[
'second'] = 0;
2479 return $this->_assign($calc, $this->
mktime($parsed[
'hour'], $parsed[
'minute'], $parsed[
'second'], 1 + $parsed[
'month'], 1 + $parsed[
'day'], 1970 + $parsed[
'year'],
true),
2480 $this->
mktime($hour, $minute, $second, 1 + $month, 1 + $day, 1970 + $year,
true), $hour);
2482 #require_once 'Zend/Date/Exception.php'; 2489 case self::RFC_3339:
2490 $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);
2492 #require_once 'Zend/Date/Exception.php'; 2493 throw new Zend_Date_Exception(
"invalid date ($date) operand, ATOM format expected", 0,
null, $date);
2496 if (($calc ==
'set') || ($calc ==
'cmp')) {
2504 return $this->_assign($calc, $this->
mktime($match[4], $match[5], $match[6], 1 + $match[2], 1 + $match[3], 1970 + $match[1],
true),
2505 $this->
mktime($hour, $minute, $second, 1 + $month, 1 + $day, 1970 + $year,
true),
false);
2509 $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);
2511 #require_once 'Zend/Date/Exception.php'; 2512 throw new Zend_Date_Exception(
"invalid date ($date) operand, COOKIE format expected", 0,
null, $date);
2514 $matchStartPos = iconv_strpos($match[0],
' ', 0,
'UTF-8') + 1;
2515 $match[0] = iconv_substr($match[0],
2517 iconv_strlen($match[0],
'UTF-8') - $matchStartPos,
2520 $months = $this->_getDigitFromName($match[2]);
2521 $match[3] = self::getFullYear($match[3]);
2523 if (($calc ==
'set') || ($calc ==
'cmp')) {
2531 return $this->_assign($calc, $this->
mktime($match[4], $match[5], $match[6], 1 + $months, 1 + $match[1], 1970 + $match[3],
true),
2532 $this->
mktime($hour, $minute, $second, 1 + $month, 1 + $day, 1970 + $year,
true),
false);
2536 case self::RFC_1036:
2538 $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);
2540 #require_once 'Zend/Date/Exception.php'; 2541 throw new Zend_Date_Exception(
"invalid date ($date) operand, RFC 822 date format expected", 0,
null, $date);
2544 $months = $this->_getDigitFromName($match[2]);
2545 $match[3] = self::getFullYear($match[3]);
2547 if (($calc ==
'set') || ($calc ==
'cmp')) {
2555 return $this->_assign($calc, $this->
mktime($match[4], $match[5], $match[6], 1 + $months, 1 + $match[1], 1970 + $match[3],
false),
2556 $this->
mktime($hour, $minute, $second, 1 + $month, 1 + $day, 1970 + $year,
false),
false);
2560 $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);
2562 #require_once 'Zend/Date/Exception.php'; 2563 throw new Zend_Date_Exception(
"invalid date ($date) operand, RFC 850 date format expected", 0,
null, $date);
2566 $months = $this->_getDigitFromName($match[2]);
2567 $match[3] = self::getFullYear($match[3]);
2569 if (($calc ==
'set') || ($calc ==
'cmp')) {
2577 return $this->_assign($calc, $this->
mktime($match[4], $match[5], $match[6], 1 + $months, 1 + $match[1], 1970 + $match[3],
true),
2578 $this->
mktime($hour, $minute, $second, 1 + $month, 1 + $day, 1970 + $year,
true),
false);
2581 case self::RFC_1123:
2582 $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);
2584 #require_once 'Zend/Date/Exception.php'; 2585 throw new Zend_Date_Exception(
"invalid date ($date) operand, RFC 1123 date format expected", 0,
null, $date);
2588 $months = $this->_getDigitFromName($match[2]);
2590 if (($calc ==
'set') || ($calc ==
'cmp')) {
2598 return $this->_assign($calc, $this->
mktime($match[4], $match[5], $match[6], 1 + $months, 1 + $match[1], 1970 + $match[3],
true),
2599 $this->
mktime($hour, $minute, $second, 1 + $month, 1 + $day, 1970 + $year,
true),
false);
2603 $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);
2605 #require_once 'Zend/Date/Exception.php'; 2606 throw new Zend_Date_Exception(
"invalid date ($date) operand, RSS date format expected", 0,
null, $date);
2609 $months = $this->_getDigitFromName($match[2]);
2610 $match[3] = self::getFullYear($match[3]);
2612 if (($calc ==
'set') || ($calc ==
'cmp')) {
2620 return $this->_assign($calc, $this->
mktime($match[4], $match[5], $match[6], 1 + $months, 1 + $match[1], 1970 + $match[3],
true),
2621 $this->
mktime($hour, $minute, $second, 1 + $month, 1 + $day, 1970 + $year,
true),
false);
2625 $result = preg_match(
'/^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})[+-]{1}\d{2}:\d{2}$/', $date, $match);
2627 #require_once 'Zend/Date/Exception.php'; 2628 throw new Zend_Date_Exception(
"invalid date ($date) operand, W3C date format expected", 0,
null, $date);
2631 if (($calc ==
'set') || ($calc ==
'cmp')) {
2639 return $this->_assign($calc, $this->
mktime($match[4], $match[5], $match[6], 1 + $match[2], 1 + $match[3], 1970 + $match[1],
true),
2640 $this->
mktime($hour, $minute, $second, 1 + $month, 1 + $day, 1970 + $year,
true),
false);
2644 if (!is_numeric($date) || !empty($part)) {
2651 $parsed =
Zend_Locale_Format::getDate($date, array(
'date_format' => $part,
'locale' => $locale,
'fix_date' =>
true,
'format_type' =>
'iso'));
2652 if ((strpos(strtoupper($part),
'YY') !==
false) and (strpos(strtoupper($part),
'YYYY') ===
false)) {
2653 $parsed[
'year'] = self::getFullYear($parsed[
'year']);
2656 if (($calc ==
'set') || ($calc ==
'cmp')) {
2657 if (isset($parsed[
'month'])) {
2660 $parsed[
'month'] = 0;
2663 if (isset($parsed[
'day'])) {
2669 if (!isset($parsed[
'year'])) {
2670 $parsed[
'year'] = 1970;
2674 return $this->_assign($calc, $this->
mktime(
2675 isset($parsed[
'hour']) ? $parsed[
'hour'] : 0,
2676 isset($parsed[
'minute']) ? $parsed[
'minute'] : 0,
2677 isset($parsed[
'second']) ? $parsed[
'second'] : 0,
2678 isset($parsed[
'month']) ? (1 + $parsed[
'month']) : 1,
2679 isset($parsed[
'day']) ? (1 + $parsed[
'day']) : 1,
2683 if (!is_numeric($date)) {
2684 #require_once 'Zend/Date/Exception.php'; 2706 public function equals($date, $part = self::TIMESTAMP, $locale =
null)
2708 $result = $this->compare($date, $part, $locale);
2728 public function isEarlier($date, $part =
null, $locale =
null)
2730 $result = $this->compare($date, $part, $locale);
2751 public function isLater($date, $part =
null, $locale =
null)
2753 $result = $this->compare($date, $part, $locale);
2770 public function getTime($locale =
null)
2772 if (self::$_options[
'format_type'] ==
'php') {
2778 return $this->copyPart(
$format, $locale);
2791 private function _time($calc, $time,
$format, $locale)
2793 if ($time ===
null) {
2794 #require_once 'Zend/Date/Exception.php'; 2800 $time = $time->toString(
'HH:mm:ss',
'iso');
2802 if (is_array($time)) {
2803 if ((isset($time[
'hour']) ===
true) or (isset($time[
'minute']) ===
true) or
2804 (isset($time[
'second']) ===
true)) {
2807 #require_once 'Zend/Date/Exception.php'; 2811 if (self::$_options[
'format_type'] ==
'php') {
2815 if ($locale ===
null) {
2816 $locale = $this->getLocale();
2821 #require_once 'Zend/Date/Exception.php'; 2826 if (!array_key_exists(
'hour', $parsed)) {
2827 $parsed[
'hour'] = 0;
2830 if (!array_key_exists(
'minute', $parsed)) {
2831 $parsed[
'minute'] = 0;
2834 if (!array_key_exists(
'second', $parsed)) {
2835 $parsed[
'second'] = 0;
2838 $time = str_pad($parsed[
'hour'], 2,
'0', STR_PAD_LEFT) .
":";
2839 $time .= str_pad($parsed[
'minute'], 2,
'0', STR_PAD_LEFT) .
":";
2840 $time .= str_pad($parsed[
'second'], 2,
'0', STR_PAD_LEFT);
2843 $return = $this->_calcdetail($calc, $time, self::TIMES,
'de');
2844 if ($calc !=
'cmp') {
2864 public function setTime($time,
$format =
null, $locale =
null)
2866 return $this->_time(
'set', $time,
$format, $locale);
2882 public function addTime($time,
$format =
null, $locale =
null)
2884 return $this->_time(
'add', $time,
$format, $locale);
2900 public function subTime($time,
$format =
null, $locale =
null)
2902 return $this->_time(
'sub', $time,
$format, $locale);
2918 public function compareTime($time,
$format =
null, $locale =
null)
2920 return $this->_time(
'cmp', $time,
$format, $locale);
2929 public function getDate($locale =
null)
2931 $orig = self::$_options[
'format_type'];
2932 if (self::$_options[
'format_type'] ==
'php') {
2933 self::$_options[
'format_type'] =
'iso';
2936 $date = $this->copyPart(self::DATE_MEDIUM, $locale);
2938 self::$_options[
'format_type'] = $orig;
2953 private function _date($calc, $date,
$format, $locale)
2955 if ($date ===
null) {
2956 #require_once 'Zend/Date/Exception.php'; 2962 $date = $date->toString(
'd.M.y',
'iso');
2964 if (is_array($date)) {
2965 if ((isset($date[
'year']) ===
true) or (isset($date[
'month']) ===
true) or
2966 (isset($date[
'day']) ===
true)) {
2969 #require_once 'Zend/Date/Exception.php'; 2973 if ((self::$_options[
'format_type'] ==
'php') && !defined(
$format)) {
2977 if ($locale ===
null) {
2978 $locale = $this->getLocale();
2982 if ((strpos(strtoupper(
$format),
'YY') !==
false) and (strpos(strtoupper(
$format),
'YYYY') ===
false)) {
2983 $parsed[
'year'] = self::getFullYear($parsed[
'year']);
2986 #require_once 'Zend/Date/Exception.php'; 2991 if (!array_key_exists(
'day', $parsed)) {
2995 if (!array_key_exists(
'month', $parsed)) {
2996 $parsed[
'month'] = 1;
2999 if (!array_key_exists(
'year', $parsed)) {
3000 $parsed[
'year'] = 0;
3003 $date = $parsed[
'day'] .
"." . $parsed[
'month'] .
"." . $parsed[
'year'];
3006 $return = $this->_calcdetail($calc, $date, self::DATE_MEDIUM,
'de');
3007 if ($calc !=
'cmp') {
3026 public function setDate($date,
$format =
null, $locale =
null)
3028 return $this->_date(
'set', $date,
$format, $locale);
3044 public function addDate($date,
$format =
null, $locale =
null)
3046 return $this->_date(
'add', $date,
$format, $locale);
3063 public function subDate($date,
$format =
null, $locale =
null)
3065 return $this->_date(
'sub', $date,
$format, $locale);
3082 public function compareDate($date,
$format =
null, $locale =
null)
3084 return $this->_date(
'cmp', $date,
$format, $locale);
3097 public function getIso($locale =
null)
3099 return $this->toString(self::ISO_8601,
'iso', $locale);
3114 public function setIso($date, $locale =
null)
3116 return $this->_calcvalue(
'set', $date,
'iso', self::ISO_8601, $locale);
3131 public function addIso($date, $locale =
null)
3133 return $this->_calcvalue(
'add', $date,
'iso', self::ISO_8601, $locale);
3148 public function subIso($date, $locale =
null)
3150 return $this->_calcvalue(
'sub', $date,
'iso', self::ISO_8601, $locale);
3165 public function compareIso($date, $locale =
null)
3167 return $this->_calcvalue(
'cmp', $date,
'iso', self::ISO_8601, $locale);
3178 public function getArpa($locale =
null)
3180 if (self::$_options[
'format_type'] ==
'php') {
3181 $format =
'D\, d M y H\:i\:s O';
3186 return $this->toString(
$format,
'iso', $locale);
3201 public function setArpa($date, $locale =
null)
3203 return $this->_calcvalue(
'set', $date,
'arpa', self::RFC_822, $locale);
3219 public function addArpa($date, $locale =
null)
3221 return $this->_calcvalue(
'add', $date,
'arpa', self::RFC_822, $locale);
3237 public function subArpa($date, $locale =
null)
3239 return $this->_calcvalue(
'sub', $date,
'arpa', self::RFC_822, $locale);
3255 public function compareArpa($date, $locale =
null)
3257 return $this->_calcvalue(
'cmp', $date,
'arpa', self::RFC_822, $locale);
3267 private function _checkLocation($location)
3269 if (!isset($location[
'longitude']) or !isset($location[
'latitude'])) {
3270 #require_once 'Zend/Date/Exception.php'; 3271 throw new Zend_Date_Exception(
'Location must include \'longitude\' and \'latitude\'', 0,
null, $location);
3273 if (($location[
'longitude'] > 180) or ($location[
'longitude'] < -180)) {
3274 #require_once 'Zend/Date/Exception.php'; 3275 throw new Zend_Date_Exception(
'Longitude must be between -180 and 180', 0,
null, $location);
3277 if (($location[
'latitude'] > 90) or ($location[
'latitude'] < -90)) {
3278 #require_once 'Zend/Date/Exception.php'; 3282 if (!isset($location[
'horizon'])){
3283 $location[
'horizon'] =
'effective';
3286 switch ($location[
'horizon']) {
3314 public function getSunrise($location)
3316 $horizon = $this->_checkLocation($location);
3318 $result->set($this->
calcSun($location, $horizon,
true), self::TIMESTAMP);
3334 public function getSunset($location)
3336 $horizon = $this->_checkLocation($location);
3338 $result->set($this->
calcSun($location, $horizon,
false), self::TIMESTAMP);
3354 public function getSunInfo($location)
3357 for (
$i = 0;
$i < 4; ++
$i) {
3360 $location[
'horizon'] =
'effective';
3363 $location[
'horizon'] =
'civil';
3366 $location[
'horizon'] =
'nautic';
3369 $location[
'horizon'] =
'astronomic';
3372 $horizon = $this->_checkLocation($location);
3374 $result->set($this->
calcSun($location, $horizon,
true), self::TIMESTAMP);
3375 $suninfo[
'sunrise'][$location[
'horizon']] =
$result;
3377 $result->set($this->
calcSun($location, $horizon,
false), self::TIMESTAMP);
3378 $suninfo[
'sunset'][$location[
'horizon']] =
$result;
3390 public static function checkLeapYear($year)
3393 $year = (int) $year->toString(self::YEAR,
'iso');
3396 if (is_array($year)) {
3397 if (isset($year[
'year']) ===
true) {
3398 $year = $year[
'year'];
3400 #require_once 'Zend/Date/Exception.php'; 3405 if (!is_numeric($year)) {
3406 #require_once 'Zend/Date/Exception.php'; 3407 throw new Zend_Date_Exception(
"year ($year) has to be integer for checkLeapYear()", 0,
null, $year);
3410 return (
bool) parent::isYearLeapYear($year);
3419 public function isLeapYear()
3421 return self::checkLeapYear($this);
3430 public function isToday()
3434 return ($today == $day);
3443 public function isYesterday()
3445 list($year, $month, $day) = explode(
'-', $this->
date(
'Y-m-d', $this->
_getTime()));
3447 $yesterday = $this->
date(
'Ymd', $this->
mktime(0, 0, 0, $month, $day -1, $year));
3449 return $day == $yesterday;
3458 public function isTomorrow()
3460 list($year, $month, $day) = explode(
'-', $this->
date(
'Y-m-d', $this->
_getTime()));
3473 public static function now($locale =
null)
3488 private function _calcdetail($calc, $date,
$type, $locale)
3491 if (self::$_options[
'format_type'] ==
'php') {
3492 self::$_options[
'format_type'] =
'iso';
3498 $return = $this->
set($date,
$type, $locale);
3501 $return = $this->add($date,
$type, $locale);
3504 $return = $this->sub($date,
$type, $locale);
3507 $return = $this->compare($date,
$type, $locale);
3512 self::$_options[
'format_type'] =
'php';
3529 private function _calcvalue($calc,
$value,
$type, $parameter, $locale)
3532 #require_once 'Zend/Date/Exception.php'; 3536 if ($locale ===
null) {
3537 $locale = $this->getLocale();
3544 #require_once 'Zend/Date/Exception.php'; 3548 $return = $this->_calcdetail($calc,
$value, $parameter, $locale);
3549 if ($calc !=
'cmp') {
3563 public function getYear($locale =
null)
3565 if (self::$_options[
'format_type'] ==
'php') {
3571 return $this->copyPart(
$format, $locale);
3588 public function setYear($year, $locale =
null)
3590 return $this->_calcvalue(
'set', $year,
'year', self::YEAR, $locale);
3607 public function addYear($year, $locale =
null)
3609 return $this->_calcvalue(
'add', $year,
'year', self::YEAR, $locale);
3626 public function subYear($year, $locale =
null)
3628 return $this->_calcvalue(
'sub', $year,
'year', self::YEAR, $locale);
3642 public function compareYear($year, $locale =
null)
3644 return $this->_calcvalue(
'cmp', $year,
'year', self::YEAR, $locale);
3655 public function getMonth($locale =
null)
3657 if (self::$_options[
'format_type'] ==
'php') {
3663 return $this->copyPart(
$format, $locale);
3676 private function _month($calc, $month, $locale)
3678 if ($month ===
null) {
3679 #require_once 'Zend/Date/Exception.php'; 3683 if ($locale ===
null) {
3684 $locale = $this->getLocale();
3689 $found = $month->toString(self::MONTH_SHORT,
'iso', $locale);
3691 if (is_numeric($month)) {
3693 }
else if (is_array($month)) {
3694 if (isset($month[
'month']) ===
true) {
3695 $month = $month[
'month'];
3697 #require_once 'Zend/Date/Exception.php'; 3704 $monthlist = array_merge($monthlist, $monthlist2);
3707 foreach ($monthlist as $key =>
$value) {
3708 if (strtoupper(
$value) == strtoupper($month)) {
3709 $found = ($key % 12) + 1;
3715 foreach ($monthlist2 as $key =>
$value) {
3716 if (strtoupper(iconv_substr(
$value, 0, 1,
'UTF-8')) == strtoupper($month)) {
3724 #require_once 'Zend/Date/Exception.php'; 3729 $return = $this->_calcdetail($calc, $found, self::MONTH_SHORT, $locale);
3730 if ($calc !=
'cmp') {
3750 public function setMonth($month, $locale =
null)
3752 return $this->_month(
'set', $month, $locale);
3769 public function addMonth($month, $locale =
null)
3771 return $this->_month(
'add', $month, $locale);
3788 public function subMonth($month, $locale =
null)
3790 return $this->_month(
'sub', $month, $locale);
3804 public function compareMonth($month, $locale =
null)
3806 return $this->_month(
'cmp', $month, $locale);
3817 public function getDay($locale =
null)
3819 return $this->copyPart(self::DAY_SHORT, $locale);
3831 private function _day($calc, $day, $locale)
3833 if ($day ===
null) {
3834 #require_once 'Zend/Date/Exception.php'; 3838 if ($locale ===
null) {
3839 $locale = $this->getLocale();
3843 $day = $day->toString(self::DAY_SHORT,
'iso', $locale);
3846 if (is_numeric($day)) {
3847 $type = self::DAY_SHORT;
3848 }
else if (is_array($day)) {
3849 if (isset($day[
'day']) ===
true) {
3851 $type = self::WEEKDAY;
3853 #require_once 'Zend/Date/Exception.php'; 3857 switch (iconv_strlen($day,
'UTF-8')) {
3859 $type = self::WEEKDAY_NARROW;
3862 $type = self::WEEKDAY_NAME;
3865 $type = self::WEEKDAY_SHORT;
3868 $type = self::WEEKDAY;
3872 $return = $this->_calcdetail($calc, $day,
$type, $locale);
3873 if ($calc !=
'cmp') {
3894 public function setDay($day, $locale =
null)
3896 return $this->_day(
'set', $day, $locale);
3912 public function addDay($day, $locale =
null)
3914 return $this->_day(
'add', $day, $locale);
3930 public function subDay($day, $locale =
null)
3932 return $this->_day(
'sub', $day, $locale);
3946 public function compareDay($day, $locale =
null)
3948 return $this->_day(
'cmp', $day, $locale);
3960 public function getWeekday($locale =
null)
3962 if (self::$_options[
'format_type'] ==
'php') {
3968 return $this->copyPart(
$format, $locale);
3981 private function _weekday($calc, $weekday, $locale)
3983 if ($weekday ===
null) {
3984 #require_once 'Zend/Date/Exception.php'; 3988 if ($locale ===
null) {
3989 $locale = $this->getLocale();
3993 $weekday = $weekday->toString(self::WEEKDAY_8601,
'iso', $locale);
3996 if (is_numeric($weekday)) {
3997 $type = self::WEEKDAY_8601;
3998 }
else if (is_array($weekday)) {
3999 if (isset($weekday[
'weekday']) ===
true) {
4000 $weekday = $weekday[
'weekday'];
4001 $type = self::WEEKDAY;
4003 #require_once 'Zend/Date/Exception.php'; 4007 switch(iconv_strlen($weekday,
'UTF-8')) {
4009 $type = self::WEEKDAY_NARROW;
4012 $type = self::WEEKDAY_NAME;
4015 $type = self::WEEKDAY_SHORT;
4018 $type = self::WEEKDAY;
4022 $return = $this->_calcdetail($calc, $weekday,
$type, $locale);
4023 if ($calc !=
'cmp') {
4042 public function setWeekday($weekday, $locale =
null)
4044 return $this->_weekday(
'set', $weekday, $locale);
4062 public function addWeekday($weekday, $locale =
null)
4064 return $this->_weekday(
'add', $weekday, $locale);
4082 public function subWeekday($weekday, $locale =
null)
4084 return $this->_weekday(
'sub', $weekday, $locale);
4098 public function compareWeekday($weekday, $locale =
null)
4100 return $this->_weekday(
'cmp', $weekday, $locale);
4111 public function getDayOfYear($locale =
null)
4113 if (self::$_options[
'format_type'] ==
'php') {
4119 return $this->copyPart(
$format, $locale);
4134 public function setDayOfYear($day, $locale =
null)
4136 return $this->_calcvalue(
'set', $day,
'day of year', self::DAY_OF_YEAR, $locale);
4151 public function addDayOfYear($day, $locale =
null)
4153 return $this->_calcvalue(
'add', $day,
'day of year', self::DAY_OF_YEAR, $locale);
4168 public function subDayOfYear($day, $locale =
null)
4170 return $this->_calcvalue(
'sub', $day,
'day of year', self::DAY_OF_YEAR, $locale);
4184 public function compareDayOfYear($day, $locale =
null)
4186 return $this->_calcvalue(
'cmp', $day,
'day of year', self::DAY_OF_YEAR, $locale);
4197 public function getHour($locale =
null)
4199 return $this->copyPart(self::HOUR, $locale);
4214 public function setHour($hour, $locale =
null)
4216 return $this->_calcvalue(
'set', $hour,
'hour', self::HOUR_SHORT, $locale);
4231 public function addHour($hour, $locale =
null)
4233 return $this->_calcvalue(
'add', $hour,
'hour', self::HOUR_SHORT, $locale);
4248 public function subHour($hour, $locale =
null)
4250 return $this->_calcvalue(
'sub', $hour,
'hour', self::HOUR_SHORT, $locale);
4264 public function compareHour($hour, $locale =
null)
4266 return $this->_calcvalue(
'cmp', $hour,
'hour', self::HOUR_SHORT, $locale);
4277 public function getMinute($locale =
null)
4279 if (self::$_options[
'format_type'] ==
'php') {
4285 return $this->copyPart(
$format, $locale);
4300 public function setMinute($minute, $locale =
null)
4302 return $this->_calcvalue(
'set', $minute,
'minute', self::MINUTE_SHORT, $locale);
4317 public function addMinute($minute, $locale =
null)
4319 return $this->_calcvalue(
'add', $minute,
'minute', self::MINUTE_SHORT, $locale);
4334 public function subMinute($minute, $locale =
null)
4336 return $this->_calcvalue(
'sub', $minute,
'minute', self::MINUTE_SHORT, $locale);
4350 public function compareMinute($minute, $locale =
null)
4352 return $this->_calcvalue(
'cmp', $minute,
'minute', self::MINUTE_SHORT, $locale);
4363 public function getSecond($locale =
null)
4365 if (self::$_options[
'format_type'] ==
'php') {
4371 return $this->copyPart(
$format, $locale);
4386 public function setSecond($second, $locale =
null)
4388 return $this->_calcvalue(
'set', $second,
'second', self::SECOND_SHORT, $locale);
4403 public function addSecond($second, $locale =
null)
4405 return $this->_calcvalue(
'add', $second,
'second', self::SECOND_SHORT, $locale);
4420 public function subSecond($second, $locale =
null)
4422 return $this->_calcvalue(
'sub', $second,
'second', self::SECOND_SHORT, $locale);
4436 public function compareSecond($second, $locale =
null)
4438 return $this->_calcvalue(
'cmp', $second,
'second', self::SECOND_SHORT, $locale);
4447 public function getFractionalPrecision()
4449 return $this->_precision;
4460 public function setFractionalPrecision($precision)
4462 if (!intval($precision) or ($precision < 0) or ($precision > 9)) {
4463 #require_once 'Zend/Date/Exception.php'; 4464 throw new Zend_Date_Exception(
"precision ($precision) must be a positive integer less than 10", 0,
null, $precision);
4467 $this->_precision = (int) $precision;
4468 if ($this->_precision < strlen($this->_fractional)) {
4469 $this->_fractional = substr($this->_fractional, 0, $this->_precision);
4471 $this->_fractional = str_pad($this->_fractional, $this->_precision,
'0', STR_PAD_RIGHT);
4483 public function getMilliSecond()
4485 return $this->_fractional;
4497 public function setMilliSecond($milli =
null, $precision =
null)
4499 if ($milli ===
null) {
4500 list($milli, $time) = explode(
" ", microtime());
4501 $milli = intval($milli);
4503 }
else if (!is_numeric($milli)) {
4504 #require_once 'Zend/Date/Exception.php'; 4508 if ($precision ===
null) {
4509 $precision = $this->_precision;
4512 if (!is_int($precision) || $precision < 1 || $precision > 9) {
4513 #require_once 'Zend/Date/Exception.php'; 4514 throw new Zend_Date_Exception(
"precision ($precision) must be a positive integer less than 10", 0,
null, $precision);
4517 $this->_fractional = 0;
4518 $this->addMilliSecond($milli, $precision);
4530 public function addMilliSecond($milli =
null, $precision =
null)
4532 if ($milli ===
null) {
4533 list($milli, $time) = explode(
" ", microtime());
4534 $milli = intval($milli);
4535 }
else if (!is_numeric($milli)) {
4536 #require_once 'Zend/Date/Exception.php'; 4540 if ($precision ===
null) {
4545 $precision = $this->_precision;
4548 if (!is_int($precision) || $precision < 1 || $precision > 9) {
4549 #require_once 'Zend/Date/Exception.php'; 4551 "precision ($precision) must be a positive integer less than 10", 0,
null, $precision
4555 if ($this->_precision > $precision) {
4556 $milli = $milli * pow(10, $this->_precision - $precision);
4557 }
elseif ($this->_precision < $precision) {
4558 $milli = round($milli / pow(10, $precision - $this->_precision));
4561 $this->_fractional += $milli;
4564 $max = pow(10, $this->_precision);
4566 if ($this->_fractional >= $max) {
4567 while ($this->_fractional >= $max) {
4568 $this->addSecond(1);
4569 $this->_fractional -= $max;
4573 if ($this->_fractional < 0) {
4574 while ($this->_fractional < 0) {
4575 $this->subSecond(1);
4576 $this->_fractional += $max;
4580 if ($this->_precision > strlen($this->_fractional)) {
4581 $this->_fractional = str_pad($this->_fractional, $this->_precision,
'0', STR_PAD_LEFT);
4595 public function subMilliSecond($milli =
null, $precision =
null)
4597 $this->addMilliSecond(0 - $milli, $precision);
4609 public function compareMilliSecond($milli =
null, $precision =
null)
4611 if ($milli ===
null) {
4612 list($milli, $time) = explode(
" ", microtime());
4613 $milli = intval($milli);
4614 }
else if (is_numeric($milli) ===
false) {
4615 #require_once 'Zend/Date/Exception.php'; 4619 if ($precision ===
null) {
4620 $precision = strlen($milli);
4621 }
else if (!is_int($precision) || $precision < 1 || $precision > 9) {
4622 #require_once 'Zend/Date/Exception.php'; 4623 throw new Zend_Date_Exception(
"precision ($precision) must be a positive integer less than 10", 0,
null, $precision);
4626 if ($precision === 0) {
4627 #require_once 'Zend/Date/Exception.php'; 4631 if ($precision != $this->_precision) {
4632 if ($precision > $this->_precision) {
4633 $diff = $precision - $this->_precision;
4634 $milli = (int) ($milli / (10 * $diff));
4636 $diff = $this->_precision - $precision;
4637 $milli = (int) ($milli * (10 * $diff));
4641 $comp = $this->_fractional - $milli;
4644 }
else if ($comp > 0) {
4657 public function getWeek($locale =
null)
4659 if (self::$_options[
'format_type'] ==
'php') {
4665 return $this->copyPart(
$format, $locale);
4678 public function setWeek($week, $locale =
null)
4680 return $this->_calcvalue(
'set', $week,
'week', self::WEEK, $locale);
4693 public function addWeek($week, $locale =
null)
4695 return $this->_calcvalue(
'add', $week,
'week', self::WEEK, $locale);
4708 public function subWeek($week, $locale =
null)
4710 return $this->_calcvalue(
'sub', $week,
'week', self::WEEK, $locale);
4723 public function compareWeek($week, $locale =
null)
4725 return $this->_calcvalue(
'cmp', $week,
'week', self::WEEK, $locale);
4739 public function setLocale($locale =
null)
4744 #require_once 'Zend/Date/Exception.php'; 4756 public function getLocale()
4758 return $this->_locale;
4773 public static function isDate($date,
$format =
null, $locale =
null)
4775 if (!is_string($date) && !is_numeric($date) && !($date instanceof
Zend_Date) &&
4790 }
else if ((self::$_options[
'format_type'] ==
'php') && !defined(
$format)) {
4795 if (!is_array($date)) {
4798 'date_format' =>
$format,
'format_type' =>
'iso',
4799 'fix_date' =>
false));
4808 if (((strpos(
$format,
'Y') !==
false) or (strpos(
$format,
'y') !==
false)) and
4809 (!isset($parsed[
'year']))) {
4814 if ((strpos(
$format,
'M') !==
false) and (!isset($parsed[
'month']))) {
4819 if ((strpos(
$format,
'd') !==
false) and (!isset($parsed[
'day']))) {
4824 if (((strpos(
$format,
'H') !==
false) or (strpos(
$format,
'h') !==
false)) and
4825 (!isset($parsed[
'hour']))) {
4830 if ((strpos(
$format,
'm') !==
false) and (!isset($parsed[
'minute']))) {
4835 if ((strpos(
$format,
's') !==
false) and (!isset($parsed[
'second']))) {
4841 if (isset($parsed[
'hour']) ===
false) {
4842 $parsed[
'hour'] = 12;
4845 if (isset($parsed[
'minute']) ===
false) {
4846 $parsed[
'minute'] = 0;
4849 if (isset($parsed[
'second']) ===
false) {
4850 $parsed[
'second'] = 0;
4853 if (isset($parsed[
'month']) ===
false) {
4854 $parsed[
'month'] = 1;
4857 if (isset($parsed[
'day']) ===
false) {
4861 if (isset($parsed[
'year']) ===
false) {
4862 $parsed[
'year'] = 1970;
4865 if (self::isYearLeapYear($parsed[
'year'])) {
4866 $parsed[
'year'] = 1972;
4868 $parsed[
'year'] = 1971;
4871 $date =
new self($parsed,
null, $locale);
4872 $timestamp = $date->mktime($parsed[
'hour'], $parsed[
'minute'], $parsed[
'second'],
4873 $parsed[
'month'], $parsed[
'day'], $parsed[
'year']);
4875 if ($parsed[
'year'] != $date->date(
'Y', $timestamp)) {
4880 if ($parsed[
'month'] != $date->date(
'n', $timestamp)) {
4885 if ($parsed[
'day'] != $date->date(
'j', $timestamp)) {
4890 if ($parsed[
'hour'] != $date->date(
'G', $timestamp)) {
4895 if ($parsed[
'minute'] != $date->date(
'i', $timestamp)) {
4900 if ($parsed[
'second'] != $date->date(
's', $timestamp)) {
4915 protected static function _getLocalizedToken(
$token, $locale)
4918 case self::ISO_8601 :
4919 return "yyyy-MM-ddThh:mm:ss";
4921 case self::RFC_2822 :
4922 return "EEE, dd MMM yyyy HH:mm:ss";
4927 case self::DATE_FULL :
4930 case self::DATE_LONG :
4933 case self::DATE_MEDIUM :
4936 case self::DATE_SHORT :
4942 case self::TIME_FULL :
4945 case self::TIME_LONG :
4948 case self::TIME_MEDIUM :
4951 case self::TIME_SHORT :
4954 case self::DATETIME :
4957 case self::DATETIME_FULL :
4960 case self::DATETIME_LONG :
4963 case self::DATETIME_MEDIUM :
4966 case self::DATETIME_SHORT :
4970 case self::RFC_3339 :
4972 return "yyyy-MM-DD HH:mm:ss";
4975 case self::RFC_850 :
4976 return "EEEE, dd-MM-yyyy HH:mm:ss";
4978 case self::RFC_822 :
4979 case self::RFC_1036 :
4980 case self::RFC_1123 :
4982 return "EEE, dd MM yyyy HH:mm:ss";
5005 protected function mktime($hour, $minute, $second, $month, $day, $year, $gmt =
false)
5007 $day = intval($day);
5008 $month = intval($month);
5009 $year = intval($year);
5013 $overlap = floor($month / 12);
5015 $month -= $overlap * 12;
5017 $overlap = ceil((1 - $month) / 12);
5019 $month += $overlap * 12;
5022 if ($year > self::YEAR_MAX_VALUE || $year < self::YEAR_MIN_VALUE) {
5023 throw new Zend_Date_Exception(
'Invalid year, it must be between ' . self::YEAR_MIN_VALUE .
' and ' 5024 . self::YEAR_MAX_VALUE);
5027 return parent::mktime($hour, $minute, $second, $month, $day, $year, $gmt);
calcSun($location, $horizon, $rise=false)
date($format, $timestamp=null, $gmt=false)
mktime($hour, $minute, $second, $month, $day, $year, $gmt=false)
static getList($locale, $path, $value=false)
elseif(isset( $params[ 'redirect_parent']))
call_user_func($callable, $param)
static _getTagSupportForCache()
static getContent($locale, $path, $value=false)
setUnixTimestamp($timestamp=null)
static isLocale($locale, $strict=false, $compatible=true)
static findLocale($locale=null)
getDateParts($timestamp=null, $fast=null)
static setCache(Zend_Cache_Core $cache)
if(!isset($_GET['name'])) $name