PageRenderTime 82ms CodeModel.GetById 32ms RepoModel.GetById 1ms app.codeStats 1ms

/inc/app/sitesearch/lib/Zend/Date.php

https://github.com/lux/siteforge
PHP | 4549 lines | 2667 code | 594 blank | 1288 comment | 495 complexity | 77edaa570d0ddd5948ba9d4e04808826 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1, Apache-2.0

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

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