PageRenderTime 64ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 1ms

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

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

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