PageRenderTime 56ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 1ms

/app/code/core/Zend/Date.php

https://bitbucket.org/kdms/sh-magento
PHP | 5008 lines | 3092 code | 509 blank | 1407 comment | 647 complexity | df6de8ff9dfdb044fe51cdf32e0af534 MD5 | raw file

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

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

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