PageRenderTime 61ms CodeModel.GetById 27ms RepoModel.GetById 0ms app.codeStats 1ms

/standard/tags/release-1.5.0/library/Zend/Date.php

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

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