PageRenderTime 49ms CodeModel.GetById 29ms RepoModel.GetById 1ms app.codeStats 0ms

/tests/Zend/Date/DateTest.php

https://github.com/Knekkebjoern/zf2
PHP | 5695 lines | 5408 code | 119 blank | 168 comment | 9 complexity | aa9b829ef97778bfc3ddec0837e5d3b1 MD5 | raw file
Possible License(s): BSD-3-Clause
  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. * @subpackage UnitTests
  18. * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. */
  21. namespace ZendTest\Date;
  22. use Zend\Cache\StorageFactory as CacheFactory,
  23. Zend\Cache\Storage\Adapter\AdapterInterface as CacheAdapter,
  24. Zend\Date\Date,
  25. Zend\Date\Cities,
  26. Zend\Locale\Locale,
  27. Zend\Locale\Exception\ExceptionInterface as LocaleException,
  28. Zend\TimeSync\TimeSync,
  29. Zend\Registry;
  30. /**
  31. * These const values control some testing behavior.
  32. * They may be defined here or in TestConfiguration.php.
  33. */
  34. if (!defined('TESTS_ZEND_LOCALE_BCMATH_ENABLED')) {
  35. // Set to false to disable usage of bcmath extension by Zend_Date
  36. define('TESTS_ZEND_LOCALE_BCMATH_ENABLED', true);
  37. }
  38. if (!defined('TESTS_ZEND_I18N_EXTENDED_COVERAGE')) {
  39. // Set to true to run full Zend_Date unit tests.
  40. // Set to false to run a good subset of Zend_Date unit tests.
  41. define('TESTS_ZEND_I18N_EXTENDED_COVERAGE', true);
  42. }
  43. /**
  44. * @category Zend
  45. * @package Zend_Date
  46. * @subpackage UnitTests
  47. * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
  48. * @license http://framework.zend.com/license/new-bsd New BSD License
  49. * @group Zend_Date
  50. */
  51. class DateTest extends \PHPUnit_Framework_TestCase
  52. {
  53. private $_cache = null;
  54. private $_orig = array();
  55. /**
  56. * Stores the original set timezone
  57. * @var string
  58. */
  59. private $_originaltimezone;
  60. public function setUp()
  61. {
  62. $this->_originaltimezone = date_default_timezone_get();
  63. date_default_timezone_set('Indian/Maldives');
  64. $this->_orig = Date::setOptions();
  65. $this->_cache = CacheFactory::adapterFactory('memory', array('memory_limit' => 0));
  66. Date::setOptions(array('cache' => $this->_cache));
  67. Date::setOptions(array('fix_dst' => true));
  68. Date::setOptions(array('extend_month' => false));
  69. Date::setOptions(array('format_type' => 'iso'));
  70. }
  71. public function tearDown()
  72. {
  73. Date::setOptions($this->_orig);
  74. $this->_cache->clear(CacheAdapter::MATCH_ALL);
  75. date_default_timezone_set($this->_originaltimezone);
  76. }
  77. /**
  78. * Test for date object creation
  79. */
  80. public function testCreation()
  81. {
  82. // look if locale is detectable
  83. try {
  84. $locale = new Locale();
  85. } catch (LocaleException $e) {
  86. $this->markTestSkipped('Autodetection of locale failed');
  87. return;
  88. }
  89. $date = new Date(0);
  90. $this->assertTrue($date instanceof Date);
  91. }
  92. /**
  93. * Test for date object creation using default format for a locale
  94. */
  95. public function testCreationDefaultFormat()
  96. {
  97. // look if locale is detectable
  98. try {
  99. $locale = new Locale();
  100. } catch (LocaleException $e) {
  101. $this->markTestSkipped('Autodetection of locale failed');
  102. return;
  103. }
  104. $date = new Date('2006-01-01');
  105. $this->assertTrue($date instanceof Date);
  106. $this->assertSame('2006-01-01T00:00:00+05:00', $date->get(Date::ISO_8601));
  107. $date = new Date('2006-01-01', 'en_US');
  108. $this->assertTrue($date instanceof Date);
  109. $this->assertSame('2006-01-01T00:00:00+05:00', $date->get(Date::ISO_8601));
  110. }
  111. /**
  112. * Test for date object creation using default format for a locale
  113. */
  114. public function testCreationDefaultFormatConsistency()
  115. {
  116. // look if locale is detectable
  117. try {
  118. $locale = new Locale();
  119. } catch (LocaleException $e) {
  120. $this->markTestSkipped('Autodetection of locale failed');
  121. return;
  122. }
  123. date_default_timezone_set('America/New_York');
  124. $locale = 'en_US';
  125. //2006-01-01T00:00:00+05:00
  126. $date1 = new Date('2006-01-01 01:00:00', Date::ISO_8601, $locale);
  127. $date1string = $date1->get(Date::ISO_8601);
  128. // en_US defines AM/PM, hour 0 does not exist
  129. // ISO defines dates without AM, 0 exists instead of 12 PM
  130. // therefor hour is set to 1 to verify
  131. $date2 = new Date('2006-01-01', Date::DATES, $locale);
  132. $date2->setTime('01:00:00');
  133. $this->assertSame($date1string, $date2->get(Date::ISO_8601));
  134. $date2 = new Date('01-01-2006', Date::DATES, $locale);
  135. $date2->setTime('01:00:00');
  136. $this->assertSame($date1string, $date2->get(Date::ISO_8601));
  137. $date2 = new Date('2006-01-01', null, $locale);
  138. $date2->setTime('01:00:00');
  139. $this->assertSame($date1string, $date2->get(Date::ISO_8601));
  140. $date2 = new Date('2006-01-01');
  141. $date2->setTime('01:00:00');
  142. $this->assertSame($date1string, $date2->get(Date::ISO_8601));
  143. $date2 = new Date('2006-01-01 01:00:00');
  144. $this->assertSame($date1string, $date2->get(Date::ISO_8601));
  145. }
  146. /**
  147. * Test for creation with timestamp
  148. */
  149. public function testCreationTimestamp()
  150. {
  151. // look if locale is detectable
  152. try {
  153. $locale = new Locale();
  154. } catch (LocaleException $e) {
  155. $this->markTestSkipped('Autodetection of locale failed');
  156. return;
  157. }
  158. $date = new Date('12345678');
  159. $this->assertTrue($date instanceof Date);
  160. }
  161. /**
  162. * Test for creation but only part of date
  163. */
  164. public function testCreationDatePart()
  165. {
  166. // look if locale is detectable
  167. try {
  168. $locale = new Locale();
  169. } catch (LocaleException $e) {
  170. $this->markTestSkipped('Autodetection of locale failed');
  171. return;
  172. }
  173. $date = new Date('13',Date::HOUR);
  174. $this->assertTrue($date instanceof Date);
  175. $date = new Date('20070802', 'YYYYMMdd');
  176. $this->assertSame("2007-08-02T00:00:00+05:00", $date->getIso());
  177. }
  178. /**
  179. * Test for creation but only a defined locale
  180. */
  181. public function testCreationLocale()
  182. {
  183. $locale = new Locale('de_AT');
  184. $date = new Date('13',null,$locale);
  185. $this->assertTrue($date instanceof Date);
  186. }
  187. /**
  188. * Test for creation but only part of date with locale
  189. */
  190. public function testCreationLocalePart()
  191. {
  192. $locale = new Locale('de_AT');
  193. $date = new Date('13',Date::HOUR,$locale);
  194. $this->assertTrue($date instanceof Date);
  195. }
  196. /**
  197. * Test for date object creation using default format for a locale
  198. */
  199. public function testCreationDefaultLoose()
  200. {
  201. // look if locale is detectable
  202. try {
  203. $locale = new Locale();
  204. } catch (LocaleException $e) {
  205. $this->markTestSkipped('Autodetection of locale failed');
  206. return;
  207. }
  208. $locale = 'de_AT';
  209. $date = new Date();
  210. $date = $date->getTimestamp();
  211. $this->assertTrue(abs($date - time()) < 2);
  212. date_default_timezone_set('GMT');
  213. $date = new Date(Date::YEAR);
  214. $date = $date->getTimestamp();
  215. $reference = gmmktime(0,0,0,1,1,date('Y'));
  216. $this->assertTrue($reference == $date);
  217. $date = new Date('ar_EG');
  218. $this->assertSame('ar_EG', $date->getLocale());
  219. $date = $date->getTimestamp();
  220. $this->assertTrue(abs($date - time()) < 2);
  221. }
  222. /**
  223. * Test for getTimestamp
  224. */
  225. public function testGetTimestamp()
  226. {
  227. $locale = new Locale('de_AT');
  228. $date = new Date(10000000);
  229. $this->assertSame(10000000, $date->getTimestamp());
  230. }
  231. /**
  232. * Test for getUnixTimestamp
  233. */
  234. public function testgetUnixTimestamp2()
  235. {
  236. $locale = new Locale('de_AT');
  237. $date = new Date(-100000000);
  238. $this->assertSame(-100000000, $date->getTimestamp());
  239. }
  240. /**
  241. * Test for setTimestamp
  242. */
  243. public function testSetTimestamp()
  244. {
  245. $locale = new Locale('de_AT');
  246. $date = new Date(0,Date::TIMESTAMP,$locale);
  247. $result = $date->setTimestamp(10000000);
  248. $this->assertSame('10000000', (string)$result->getTimestamp());
  249. }
  250. /**
  251. * Test for setTimestamp
  252. */
  253. public function testSetTimestamp2()
  254. {
  255. try {
  256. $locale = new Locale('de_AT');
  257. $date = new Date(0,null,$locale);
  258. $result = $date->setTimestamp('notimestamp');
  259. $this->Fail("exception expected");
  260. } catch (\Zend\Date\Exception\ExceptionInterface $e) {
  261. // success
  262. }
  263. }
  264. /**
  265. * Test for addTimestamp
  266. */
  267. public function testAddTimestamp()
  268. {
  269. $locale = new Locale('de_AT');
  270. $date = new Date(0,null,$locale);
  271. $result = $date->addTimestamp(10000000);
  272. $this->assertSame('10000000', (string)$result->getTimestamp());
  273. $result = $date->addTimestamp(array('timestamp' => 1000));
  274. $this->assertSame('10001000', (string)$result->getTimestamp());
  275. try {
  276. $result = $date->addTimestamp(array('notimestamp' => 1000));
  277. $this->fail("exception expected");
  278. } catch (\Zend\Date\Exception\ExceptionInterface $e) {
  279. // success
  280. }
  281. }
  282. /**
  283. * Test for addTimestamp
  284. */
  285. public function testAddTimestamp2()
  286. {
  287. try {
  288. $locale = new Locale('de_AT');
  289. $date = new Date(0,null,$locale);
  290. $result = $date->addTimestamp('notimestamp');
  291. $this->fail("exception expected");
  292. } catch (\Zend\Date\Exception\ExceptionInterface $e) {
  293. // success
  294. }
  295. }
  296. /**
  297. * Test for subTimestamp
  298. */
  299. public function testSubTimestamp()
  300. {
  301. $locale = new Locale('de_AT');
  302. $date = new Date(0,null,$locale);
  303. $result = $date->subTimestamp(10000000);
  304. $this->assertSame('-10000000', (string)$result->getTimestamp());
  305. }
  306. /**
  307. * Test for subTimestamp
  308. */
  309. public function testSubTimestamp2()
  310. {
  311. try {
  312. $locale = new Locale('de_AT');
  313. $date = new Date(0,null,$locale);
  314. $result = $date->subTimestamp('notimestamp');
  315. $this->fail("exception expected");
  316. } catch (\Zend\Date\Exception\ExceptionInterface $e) {
  317. // success
  318. }
  319. }
  320. /**
  321. * Test for compareTimestamp
  322. */
  323. public function testCompareTimestamp()
  324. {
  325. $locale = new Locale('de_AT');
  326. $date1 = new Date(0,null,$locale);
  327. $date2 = new Date(0,null,$locale);
  328. $this->assertSame(0, $date1->compareTimestamp($date2));
  329. $date2 = new Date(100,null,$locale);
  330. $this->assertSame(-1, $date1->compareTimestamp($date2));
  331. $date2 = new Date(-100,null,$locale);
  332. $this->assertSame(1, $date1->compareTimestamp($date2));
  333. }
  334. /**
  335. * Test for __toString
  336. */
  337. public function test_ToString()
  338. {
  339. $locale = new Locale('de_AT');
  340. $date = new Date(0,null,$locale);
  341. $date->setTimezone(date_default_timezone_get());
  342. $this->assertSame('01.01.1970 05:00:00', $date->__toString());
  343. }
  344. /**
  345. * Test for toString
  346. */
  347. public function testToString()
  348. {
  349. $locale = new Locale('de_AT');
  350. $date = new Date(1234567890,null,$locale);
  351. $date->setTimezone(date_default_timezone_get());
  352. $this->assertSame('14.02.2009 04:31:30', $date->toString( ));
  353. $this->assertSame('Feb 14, 2009 4:31:30 AM', $date->toString('en_US' ));
  354. $this->assertSame('Feb 14, 2009 4:31:30 AM', $date->toString(null, 'en_US'));
  355. $this->assertSame('2009', $date->toString('yyy', null ));
  356. $this->assertSame('14.02.2009 04:31:30', $date->toString(null, null ));
  357. $date->setTimeZone('UTC');
  358. $this->assertSame('Feb 13, 2009 11:31:30 PM', $date->toString(null, 'en_US'));
  359. $date->setTimeZone('Indian/Maldives');
  360. $this->assertSame( "xxyy'yyxx", $date->toString("xx'yy''yy'xx"));
  361. $this->assertSame( 'n.', $date->toString("GGGGG"));
  362. $this->assertSame( 'n. Chr.', $date->toString( "GGGG"));
  363. $this->assertSame( 'n. Chr.', $date->toString( "GGG"));
  364. $this->assertSame( 'n. Chr.', $date->toString( "GG"));
  365. $this->assertSame( 'n. Chr.', $date->toString( "G"));
  366. $this->assertSame( '02009', $date->toString("yyyyy"));
  367. $this->assertSame( '2009', $date->toString( "yyyy"));
  368. $this->assertSame( '2009', $date->toString( "yyy"));
  369. $this->assertSame( '09', $date->toString( "yy"));
  370. $this->assertSame( '2009', $date->toString( "y"));
  371. $this->assertSame( '02009', $date->toString("YYYYY"));
  372. $this->assertSame( '2009', $date->toString( "YYYY"));
  373. $this->assertSame( '2009', $date->toString( "YYY"));
  374. $this->assertSame( '09', $date->toString( "YY"));
  375. $this->assertSame( '2009', $date->toString( "Y"));
  376. $this->assertSame( 'F', $date->toString("MMMMM"));
  377. $this->assertSame( 'Februar', $date->toString( "MMMM"));
  378. $this->assertSame( 'Feb', $date->toString( "MMM"));
  379. $this->assertSame( '02', $date->toString( "MM"));
  380. $this->assertSame( '2', $date->toString( "M"));
  381. $this->assertSame( '07', $date->toString( "ww"));
  382. $this->assertSame( '7', $date->toString( "w"));
  383. $this->assertSame( '14', $date->toString( "dd"));
  384. $this->assertSame( '14', $date->toString( "d"));
  385. $this->assertSame( '044', $date->toString( "DDD"));
  386. $this->assertSame( '44', $date->toString( "DD"));
  387. $this->assertSame( '44', $date->toString( "D"));
  388. $this->assertSame( 'S', $date->toString("EEEEE"));
  389. $this->assertSame( 'Samstag', $date->toString( "EEEE"));
  390. $this->assertSame( 'Sam', $date->toString( "EEE"));
  391. $this->assertSame( 'Sa.', $date->toString( "EE"));
  392. $this->assertSame( 'S', $date->toString( "E"));
  393. $this->assertSame( '06', $date->toString( "ee"));
  394. $this->assertSame( '6', $date->toString( "e"));
  395. $this->assertSame( 'vorm.', $date->toString( "a"));
  396. $this->assertSame( '04', $date->toString( "hh"));
  397. $this->assertSame( '4', $date->toString( "h"));
  398. $this->assertSame( '04', $date->toString( "HH"));
  399. $this->assertSame( '4', $date->toString( "H"));
  400. $this->assertSame( '31', $date->toString( "mm"));
  401. $this->assertSame( '31', $date->toString( "m"));
  402. $this->assertSame( '30', $date->toString( "ss"));
  403. $this->assertSame( '30', $date->toString( "s"));
  404. $this->assertSame( '0', $date->toString( "S"));
  405. $this->assertSame('Indian/Maldives', $date->toString( "zzzz"));
  406. $this->assertSame( 'MVT', $date->toString( "zzz"));
  407. $this->assertSame( 'MVT', $date->toString( "zz"));
  408. $this->assertSame( 'MVT', $date->toString( "z"));
  409. $this->assertSame( '+05:00', $date->toString( "ZZZZ"));
  410. $this->assertSame( '+0500', $date->toString( "ZZZ"));
  411. $this->assertSame( '+0500', $date->toString( "ZZ"));
  412. $this->assertSame( '+0500', $date->toString( "Z"));
  413. $this->assertSame( '16290000', $date->toString("AAAAA"));
  414. $this->assertSame( '16290000', $date->toString( "AAAA"));
  415. $this->assertSame( '16290000', $date->toString( "AAA"));
  416. $this->assertSame( '16290000', $date->toString( "AA"));
  417. $this->assertSame( '16290000', $date->toString( "A"));
  418. $date = new Date("1-1-01",null,$locale);
  419. $date->setTimezone(date_default_timezone_get());
  420. $this->assertSame('01', $date->toString("yy"));
  421. }
  422. /**
  423. * Test for toValue
  424. */
  425. public function testToValue()
  426. {
  427. $locale = new Locale('de_AT');
  428. $date = new Date(1234567890,null,$locale);
  429. $date->setTimezone(date_default_timezone_get());
  430. $this->assertSame(1234567890, $date->toValue() );
  431. $this->assertSame( 14, $date->toValue(Date::DAY));
  432. $date->setTimezone('UTC');
  433. $this->assertSame( 13, $date->toValue(Date::DAY ));
  434. $this->assertFalse( $date->toValue(Date::WEEKDAY_SHORT ));
  435. $this->assertSame( 13, $date->toValue(Date::DAY_SHORT ));
  436. $this->assertFalse( $date->toValue(Date::WEEKDAY ));
  437. $this->assertSame( 5, $date->toValue(Date::WEEKDAY_8601 ));
  438. $this->assertFalse( $date->toValue(Date::DAY_SUFFIX ));
  439. $this->assertSame( 5, $date->toValue(Date::WEEKDAY_DIGIT ));
  440. $this->assertSame( 43, $date->toValue(Date::DAY_OF_YEAR ));
  441. $this->assertFalse( $date->toValue(Date::WEEKDAY_NARROW ));
  442. $this->assertFalse( $date->toValue(Date::WEEKDAY_NAME ));
  443. $this->assertSame( 7, $date->toValue(Date::WEEK ));
  444. $this->assertFalse( $date->toValue(Date::MONTH_NAME ));
  445. $this->assertSame( 2, $date->toValue(Date::MONTH ));
  446. $this->assertFalse( $date->toValue(Date::MONTH_NAME_SHORT ));
  447. $this->assertSame( 2, $date->toValue(Date::MONTH_SHORT ));
  448. $this->assertSame( 28, $date->toValue(Date::MONTH_DAYS ));
  449. $this->assertFalse( $date->toValue(Date::MONTH_NAME_NARROW));
  450. $this->assertSame( 0, $date->toValue(Date::LEAPYEAR ));
  451. $this->assertSame( 2009, $date->toValue(Date::YEAR_8601 ));
  452. $this->assertSame( 2009, $date->toValue(Date::YEAR ));
  453. $this->assertSame( 9, $date->toValue(Date::YEAR_SHORT ));
  454. $this->assertSame( 9, $date->toValue(Date::YEAR_SHORT_8601 ));
  455. $this->assertFalse( $date->toValue(Date::MERIDIEM ));
  456. $this->assertSame( 21, $date->toValue(Date::SWATCH ));
  457. $this->assertSame( 11, $date->toValue(Date::HOUR_SHORT_AM ));
  458. $this->assertSame( 23, $date->toValue(Date::HOUR_SHORT ));
  459. $this->assertSame( 11, $date->toValue(Date::HOUR_AM ));
  460. $this->assertSame( 23, $date->toValue(Date::HOUR ));
  461. $this->assertSame( 31, $date->toValue(Date::MINUTE ));
  462. $this->assertSame( 30, $date->toValue(Date::SECOND ));
  463. $this->assertSame( 0, $date->toValue(Date::MILLISECOND ));
  464. $this->assertSame( 31, $date->toValue(Date::MINUTE_SHORT ));
  465. $this->assertSame( 30, $date->toValue(Date::SECOND_SHORT ));
  466. $this->assertFalse( $date->toValue(Date::TIMEZONE_NAME ));
  467. $this->assertSame( 0, $date->toValue(Date::DAYLIGHT ));
  468. $this->assertSame( 0, $date->toValue(Date::GMT_DIFF ));
  469. $this->assertFalse( $date->toValue(Date::GMT_DIFF_SEP ));
  470. $this->assertFalse( $date->toValue(Date::TIMEZONE ));
  471. $this->assertSame( 0, $date->toValue(Date::TIMEZONE_SECS ));
  472. $this->assertFalse( $date->toValue(Date::ISO_8601 ));
  473. $this->assertFalse( $date->toValue(Date::RFC_2822 ));
  474. $this->assertSame(1234567890, $date->toValue(Date::TIMESTAMP ));
  475. $this->assertFalse( $date->toValue(Date::ERA ));
  476. $this->assertFalse( $date->toValue(Date::ERA_NAME ));
  477. $this->assertFalse( $date->toValue(Date::DATES ));
  478. $this->assertFalse( $date->toValue(Date::DATE_FULL ));
  479. $this->assertFalse( $date->toValue(Date::DATE_LONG ));
  480. $this->assertFalse( $date->toValue(Date::DATE_MEDIUM ));
  481. $this->assertFalse( $date->toValue(Date::DATE_SHORT ));
  482. $this->assertFalse( $date->toValue(Date::TIMES ));
  483. $this->assertFalse( $date->toValue(Date::TIME_FULL ));
  484. $this->assertFalse( $date->toValue(Date::TIME_LONG ));
  485. $this->assertFalse( $date->toValue(Date::TIME_MEDIUM ));
  486. $this->assertFalse( $date->toValue(Date::TIME_SHORT ));
  487. $this->assertFalse( $date->toValue(Date::DATETIME ));
  488. $this->assertFalse( $date->toValue(Date::DATETIME_FULL ));
  489. $this->assertFalse( $date->toValue(Date::DATETIME_LONG ));
  490. $this->assertFalse( $date->toValue(Date::DATETIME_MEDIUM ));
  491. $this->assertFalse( $date->toValue(Date::DATETIME_SHORT ));
  492. $this->assertFalse( $date->toValue(Date::ATOM ));
  493. $this->assertFalse( $date->toValue(Date::COOKIE ));
  494. $this->assertFalse( $date->toValue(Date::RFC_822 ));
  495. $this->assertFalse( $date->toValue(Date::RFC_850 ));
  496. $this->assertFalse( $date->toValue(Date::RFC_1036 ));
  497. $this->assertFalse( $date->toValue(Date::RFC_1123 ));
  498. $this->assertFalse( $date->toValue(Date::RFC_3339 ));
  499. $this->assertFalse( $date->toValue(Date::RSS ));
  500. $this->assertFalse( $date->toValue(Date::W3C ));
  501. $date->setTimezone('Indian/Maldives');
  502. $this->assertFalse( $date->toValue(Date::WEEKDAY_SHORT ));
  503. $this->assertSame( 14, $date->toValue(Date::DAY_SHORT ));
  504. $this->assertFalse( $date->toValue(Date::WEEKDAY ));
  505. $this->assertSame( 6, $date->toValue(Date::WEEKDAY_8601 ));
  506. $this->assertFalse( $date->toValue(Date::DAY_SUFFIX ));
  507. $this->assertSame( 6, $date->toValue(Date::WEEKDAY_DIGIT ));
  508. $this->assertSame( 44, $date->toValue(Date::DAY_OF_YEAR ));
  509. $this->assertFalse( $date->toValue(Date::WEEKDAY_NARROW ));
  510. $this->assertFalse( $date->toValue(Date::WEEKDAY_NAME ));
  511. $this->assertSame( 7, $date->toValue(Date::WEEK ));
  512. $this->assertFalse( $date->toValue(Date::MONTH_NAME ));
  513. $this->assertSame( 2, $date->toValue(Date::MONTH ));
  514. $this->assertFalse( $date->toValue(Date::MONTH_NAME_SHORT ));
  515. $this->assertSame( 2, $date->toValue(Date::MONTH_SHORT ));
  516. $this->assertSame( 28, $date->toValue(Date::MONTH_DAYS ));
  517. $this->assertFalse( $date->toValue(Date::MONTH_NAME_NARROW));
  518. $this->assertSame( 0, $date->toValue(Date::LEAPYEAR ));
  519. $this->assertSame( 2009, $date->toValue(Date::YEAR_8601 ));
  520. $this->assertSame( 2009, $date->toValue(Date::YEAR ));
  521. $this->assertSame( 9, $date->toValue(Date::YEAR_SHORT ));
  522. $this->assertSame( 9, $date->toValue(Date::YEAR_SHORT_8601 ));
  523. $this->assertFalse( $date->toValue(Date::MERIDIEM ));
  524. $this->assertSame( 21, $date->toValue(Date::SWATCH ));
  525. $this->assertSame( 4, $date->toValue(Date::HOUR_SHORT_AM ));
  526. $this->assertSame( 4, $date->toValue(Date::HOUR_SHORT ));
  527. $this->assertSame( 4, $date->toValue(Date::HOUR_AM ));
  528. $this->assertSame( 4, $date->toValue(Date::HOUR ));
  529. $this->assertSame( 31, $date->toValue(Date::MINUTE ));
  530. $this->assertSame( 30, $date->toValue(Date::SECOND ));
  531. $this->assertSame( 0, $date->toValue(Date::MILLISECOND ));
  532. $this->assertSame( 31, $date->toValue(Date::MINUTE_SHORT ));
  533. $this->assertSame( 30, $date->toValue(Date::SECOND_SHORT ));
  534. $this->assertFalse( $date->toValue(Date::TIMEZONE_NAME ));
  535. $this->assertSame( 0, $date->toValue(Date::DAYLIGHT ));
  536. $this->assertSame( 500, $date->toValue(Date::GMT_DIFF ));
  537. $this->assertFalse( $date->toValue(Date::GMT_DIFF_SEP ));
  538. $this->assertFalse( $date->toValue(Date::TIMEZONE ));
  539. $this->assertSame( 18000, $date->toValue(Date::TIMEZONE_SECS ));
  540. $this->assertFalse( $date->toValue(Date::ISO_8601 ));
  541. $this->assertFalse( $date->toValue(Date::RFC_2822 ));
  542. $this->assertSame(1234567890, $date->toValue(Date::TIMESTAMP ));
  543. $this->assertFalse( $date->toValue(Date::ERA ));
  544. $this->assertFalse( $date->toValue(Date::ERA_NAME ));
  545. $this->assertFalse( $date->toValue(Date::DATES ));
  546. $this->assertFalse( $date->toValue(Date::DATE_FULL ));
  547. $this->assertFalse( $date->toValue(Date::DATE_LONG ));
  548. $this->assertFalse( $date->toValue(Date::DATE_MEDIUM ));
  549. $this->assertFalse( $date->toValue(Date::DATE_SHORT ));
  550. $this->assertFalse( $date->toValue(Date::TIMES ));
  551. $this->assertFalse( $date->toValue(Date::TIME_FULL ));
  552. $this->assertFalse( $date->toValue(Date::TIME_LONG ));
  553. $this->assertFalse( $date->toValue(Date::TIME_MEDIUM ));
  554. $this->assertFalse( $date->toValue(Date::TIME_SHORT ));
  555. $this->assertFalse( $date->toValue(Date::DATETIME ));
  556. $this->assertFalse( $date->toValue(Date::DATETIME_FULL ));
  557. $this->assertFalse( $date->toValue(Date::DATETIME_LONG ));
  558. $this->assertFalse( $date->toValue(Date::DATETIME_MEDIUM ));
  559. $this->assertFalse( $date->toValue(Date::DATETIME_SHORT ));
  560. $this->assertFalse( $date->toValue(Date::ATOM ));
  561. $this->assertFalse( $date->toValue(Date::COOKIE ));
  562. $this->assertFalse( $date->toValue(Date::RFC_822 ));
  563. $this->assertFalse( $date->toValue(Date::RFC_850 ));
  564. $this->assertFalse( $date->toValue(Date::RFC_1036 ));
  565. $this->assertFalse( $date->toValue(Date::RFC_1123 ));
  566. $this->assertFalse( $date->toValue(Date::RFC_3339 ));
  567. $this->assertFalse( $date->toValue(Date::RSS ));
  568. $this->assertFalse( $date->toValue(Date::W3C ));
  569. }
  570. /**
  571. * Test for toValue
  572. */
  573. public function testGet()
  574. {
  575. $locale = new Locale('de_AT');
  576. $date = new Date(1234567890,null,$locale);
  577. $date->setTimezone('UTC');
  578. $this->assertSame( '13', $date->get(Date::DAY ));
  579. $this->assertSame( 'Fre', $date->get(Date::WEEKDAY_SHORT ));
  580. $this->assertSame( '13', $date->get(Date::DAY_SHORT ));
  581. $this->assertSame( 'Freitag', $date->get(Date::WEEKDAY ));
  582. $this->assertSame( '5', $date->get(Date::WEEKDAY_8601 ));
  583. $this->assertSame( 'th', $date->get(Date::DAY_SUFFIX ));
  584. $this->assertSame( '5', $date->get(Date::WEEKDAY_DIGIT ));
  585. $this->assertSame( '43', $date->get(Date::DAY_OF_YEAR ));
  586. $this->assertSame( 'F', $date->get(Date::WEEKDAY_NARROW ));
  587. $this->assertSame( 'Fr.', $date->get(Date::WEEKDAY_NAME ));
  588. $this->assertSame( '07', $date->get(Date::WEEK ));
  589. $this->assertSame( 'Februar', $date->get(Date::MONTH_NAME ));
  590. $this->assertSame( '02', $date->get(Date::MONTH ));
  591. $this->assertSame( 'Feb', $date->get(Date::MONTH_NAME_SHORT ));
  592. $this->assertSame( '2', $date->get(Date::MONTH_SHORT ));
  593. $this->assertSame( '28', $date->get(Date::MONTH_DAYS ));
  594. $this->assertSame( 'F', $date->get(Date::MONTH_NAME_NARROW));
  595. $this->assertSame( '0', $date->get(Date::LEAPYEAR ));
  596. $this->assertSame( '2009', $date->get(Date::YEAR_8601 ));
  597. $this->assertSame( '2009', $date->get(Date::YEAR ));
  598. $this->assertSame( '09', $date->get(Date::YEAR_SHORT ));
  599. $this->assertSame( '09', $date->get(Date::YEAR_SHORT_8601 ));
  600. $this->assertSame( 'nachm.', $date->get(Date::MERIDIEM ));
  601. $this->assertSame( '021', $date->get(Date::SWATCH ));
  602. $this->assertSame( '11', $date->get(Date::HOUR_SHORT_AM ));
  603. $this->assertSame( '23', $date->get(Date::HOUR_SHORT ));
  604. $this->assertSame( '11', $date->get(Date::HOUR_AM ));
  605. $this->assertSame( '23', $date->get(Date::HOUR ));
  606. $this->assertSame( '31', $date->get(Date::MINUTE ));
  607. $this->assertSame( '30', $date->get(Date::SECOND ));
  608. $this->assertSame( '0', $date->get(Date::MILLISECOND ));
  609. $this->assertSame( '31', $date->get(Date::MINUTE_SHORT ));
  610. $this->assertSame( '30', $date->get(Date::SECOND_SHORT ));
  611. $this->assertSame( 'UTC', $date->get(Date::TIMEZONE_NAME ));
  612. $this->assertSame( '0', $date->get(Date::DAYLIGHT ));
  613. $this->assertSame( '+0000', $date->get(Date::GMT_DIFF ));
  614. $this->assertSame( '+00:00', $date->get(Date::GMT_DIFF_SEP ));
  615. $this->assertSame( 'UTC', $date->get(Date::TIMEZONE ));
  616. $this->assertSame( '0', $date->get(Date::TIMEZONE_SECS ));
  617. $this->assertSame( '2009-02-13T23:31:30+00:00', $date->get(Date::ISO_8601 ));
  618. $this->assertSame('Fri, 13 Feb 2009 23:31:30 +0000', $date->get(Date::RFC_2822 ));
  619. $this->assertSame( '1234567890', $date->get(Date::TIMESTAMP ));
  620. $this->assertSame( 'n. Chr.', $date->get(Date::ERA ));
  621. $this->assertSame( 'n. Chr.', $date->get(Date::ERA_NAME ));
  622. $this->assertSame( '13.02.2009', $date->get(Date::DATES ));
  623. $this->assertSame( 'Freitag, 13. Februar 2009', $date->get(Date::DATE_FULL ));
  624. $this->assertSame( '13. Februar 2009', $date->get(Date::DATE_LONG ));
  625. $this->assertSame( '13.02.2009', $date->get(Date::DATE_MEDIUM ));
  626. $this->assertSame( '13.02.09', $date->get(Date::DATE_SHORT ));
  627. $this->assertSame( '23:31:30', $date->get(Date::TIMES ));
  628. $this->assertSame( '23:31:30 UTC', $date->get(Date::TIME_FULL ));
  629. $this->assertSame( '23:31:30 UTC', $date->get(Date::TIME_LONG ));
  630. $this->assertSame( '23:31:30', $date->get(Date::TIME_MEDIUM ));
  631. $this->assertSame( '23:31', $date->get(Date::TIME_SHORT ));
  632. $this->assertSame( '13.02.2009 23:31:30', $date->get(Date::DATETIME ));
  633. $this->assertSame('Freitag, 13. Februar 2009 23:31:30 UTC', $date->get(Date::DATETIME_FULL ));
  634. $this->assertSame( '13. Februar 2009 23:31:30 UTC', $date->get(Date::DATETIME_LONG ));
  635. $this->assertSame( '13.02.2009 23:31:30', $date->get(Date::DATETIME_MEDIUM ));
  636. $this->assertSame( '13.02.09 23:31', $date->get(Date::DATETIME_SHORT ));
  637. $this->assertSame( '2009-02-13T23:31:30+00:00', $date->get(Date::ATOM ));
  638. $this->assertSame( 'Friday, 13-Feb-09 23:31:30 UTC', $date->get(Date::COOKIE ));
  639. $this->assertSame( 'Fri, 13 Feb 09 23:31:30 +0000', $date->get(Date::RFC_822 ));
  640. $this->assertSame( 'Friday, 13-Feb-09 23:31:30 UTC', $date->get(Date::RFC_850 ));
  641. $this->assertSame( 'Fri, 13 Feb 09 23:31:30 +0000', $date->get(Date::RFC_1036 ));
  642. $this->assertSame('Fri, 13 Feb 2009 23:31:30 +0000', $date->get(Date::RFC_1123 ));
  643. $this->assertSame( '2009-02-13T23:31:30+00:00', $date->get(Date::RFC_3339 ));
  644. $this->assertSame('Fri, 13 Feb 2009 23:31:30 +0000', $date->get(Date::RSS ));
  645. $this->assertSame( '2009-02-13T23:31:30+00:00', $date->get(Date::W3C ));
  646. $this->assertSame( '13', $date->get(Date::DAY, 'es'));
  647. $this->assertSame( 'vie', $date->get(Date::WEEKDAY_SHORT, 'es'));
  648. $this->assertSame( '13', $date->get(Date::DAY_SHORT, 'es'));
  649. $this->assertSame( 'viernes', $date->get(Date::WEEKDAY, 'es'));
  650. $this->assertSame( '5', $date->get(Date::WEEKDAY_8601, 'es'));
  651. $this->assertSame( 'th', $date->get(Date::DAY_SUFFIX, 'es'));
  652. $this->assertSame( '5', $date->get(Date::WEEKDAY_DIGIT, 'es'));
  653. $this->assertSame( '43', $date->get(Date::DAY_OF_YEAR, 'es'));
  654. $this->assertSame( 'v', $date->get(Date::WEEKDAY_NARROW, 'es'));
  655. $this->assertSame( 'vie', $date->get(Date::WEEKDAY_NAME, 'es'));
  656. $this->assertSame( '07', $date->get(Date::WEEK, 'es'));
  657. $this->assertSame( 'febrero', $date->get(Date::MONTH_NAME, 'es'));
  658. $this->assertSame( '02', $date->get(Date::MONTH, 'es'));
  659. $this->assertSame( 'feb', $date->get(Date::MONTH_NAME_SHORT, 'es'));
  660. $this->assertSame( '2', $date->get(Date::MONTH_SHORT, 'es'));
  661. $this->assertSame( '28', $date->get(Date::MONTH_DAYS, 'es'));
  662. $this->assertSame( 'f', $date->get(Date::MONTH_NAME_NARROW, 'es'));
  663. $this->assertSame( '0', $date->get(Date::LEAPYEAR, 'es'));
  664. $this->assertSame( '2009', $date->get(Date::YEAR_8601, 'es'));
  665. $this->assertSame( '2009', $date->get(Date::YEAR, 'es'));
  666. $this->assertSame( '09', $date->get(Date::YEAR_SHORT, 'es'));
  667. $this->assertSame( '09', $date->get(Date::YEAR_SHORT_8601, 'es'));
  668. $this->assertSame( 'p.m.', $date->get(Date::MERIDIEM, 'es'));
  669. $this->assertSame( '021', $date->get(Date::SWATCH, 'es'));
  670. $this->assertSame( '11', $date->get(Date::HOUR_SHORT_AM, 'es'));
  671. $this->assertSame( '23', $date->get(Date::HOUR_SHORT, 'es'));
  672. $this->assertSame( '11', $date->get(Date::HOUR_AM, 'es'));
  673. $this->assertSame( '23', $date->get(Date::HOUR, 'es'));
  674. $this->assertSame( '31', $date->get(Date::MINUTE, 'es'));
  675. $this->assertSame( '30', $date->get(Date::SECOND, 'es'));
  676. $this->assertSame( '0', $date->get(Date::MILLISECOND, 'es'));
  677. $this->assertSame( '31', $date->get(Date::MINUTE_SHORT, 'es'));
  678. $this->assertSame( '30', $date->get(Date::SECOND_SHORT, 'es'));
  679. $this->assertSame( 'UTC', $date->get(Date::TIMEZONE_NAME, 'es'));
  680. $this->assertSame( '0', $date->get(Date::DAYLIGHT, 'es'));
  681. $this->assertSame( '+0000', $date->get(Date::GMT_DIFF, 'es'));
  682. $this->assertSame( '+00:00', $date->get(Date::GMT_DIFF_SEP, 'es'));
  683. $this->assertSame( 'UTC', $date->get(Date::TIMEZONE, 'es'));
  684. $this->assertSame( '0', $date->get(Date::TIMEZONE_SECS, 'es'));
  685. $this->assertSame( '2009-02-13T23:31:30+00:00', $date->get(Date::ISO_8601, 'es'));
  686. $this->assertSame('Fri, 13 Feb 2009 23:31:30 +0000', $date->get(Date::RFC_2822, 'es'));
  687. $this->assertSame( '1234567890', $date->get(Date::TIMESTAMP, 'es'));
  688. $this->assertSame( 'd.C.', $date->get(Date::ERA, 'es'));
  689. $this->assertSame( 'anno Dómini', $date->get(Date::ERA_NAME, 'es'));
  690. $this->assertSame( '13/02/2009', $date->get(Date::DATES, 'es'));
  691. $this->assertSame( 'viernes 13 de febrero de 2009', $date->get(Date::DATE_FULL, 'es'));
  692. $this->assertSame( '13 de febrero de 2009', $date->get(Date::DATE_LONG, 'es'));
  693. $this->assertSame( '13/02/2009', $date->get(Date::DATE_MEDIUM, 'es'));
  694. $this->assertSame( '13/02/09', $date->get(Date::DATE_SHORT, 'es'));
  695. $this->assertSame( '23:31:30', $date->get(Date::TIMES, 'es'));
  696. $this->assertSame( '23:31:30 UTC', $date->get(Date::TIME_FULL, 'es'));
  697. $this->assertSame( '23:31:30 UTC', $date->get(Date::TIME_LONG, 'es'));
  698. $this->assertSame( '23:31:30', $date->get(Date::TIME_MEDIUM, 'es'));
  699. $this->assertSame( '23:31', $date->get(Date::TIME_SHORT, 'es'));
  700. $this->assertSame( '13/02/2009 23:31:30', $date->get(Date::DATETIME, 'es'));
  701. $this->assertSame('viernes 13 de febrero de 2009 23:31:30 UTC', $date->get(Date::DATETIME_FULL, 'es'));
  702. $this->assertSame('13 de febrero de 2009 23:31:30 UTC', $date->get(Date::DATETIME_LONG, 'es'));
  703. $this->assertSame( '13/02/2009 23:31:30', $date->get(Date::DATETIME_MEDIUM, 'es'));
  704. $this->assertSame( '13/02/09 23:31', $date->get(Date::DATETIME_SHORT, 'es'));
  705. $this->assertSame( '2009-02-13T23:31:30+00:00', $date->get(Date::ATOM, 'es'));
  706. $this->assertSame( 'Friday, 13-Feb-09 23:31:30 UTC', $date->get(Date::COOKIE, 'es'));
  707. $this->assertSame( 'Fri, 13 Feb 09 23:31:30 +0000', $date->get(Date::RFC_822, 'es'));
  708. $this->assertSame( 'Friday, 13-Feb-09 23:31:30 UTC', $date->get(Date::RFC_850, 'es'));
  709. $this->assertSame( 'Fri, 13 Feb 09 23:31:30 +0000', $date->get(Date::RFC_1036, 'es'));
  710. $this->assertSame('Fri, 13 Feb 2009 23:31:30 +0000', $date->get(Date::RFC_1123, 'es'));
  711. $this->assertSame( '2009-02-13T23:31:30+00:00', $date->get(Date::RFC_3339, 'es'));
  712. $this->assertSame('Fri, 13 Feb 2009 23:31:30 +0000', $date->get(Date::RSS, 'es'));
  713. $this->assertSame( '2009-02-13T23:31:30+00:00', $date->get(Date::W3C, 'es'));
  714. $date->setTimezone('Indian/Maldives');
  715. $this->assertSame( '1234567890', $date->get( ));
  716. $this->assertSame( '14', $date->get(Date::DAY ));
  717. $this->assertSame( 'Sam', $date->get(Date::WEEKDAY_SHORT ));
  718. $this->assertSame( '14', $date->get(Date::DAY_SHORT ));
  719. $this->assertSame( 'Samstag', $date->get(Date::WEEKDAY ));
  720. $this->assertSame( '6', $date->get(Date::WEEKDAY_8601 ));
  721. $this->assertSame( 'th', $date->get(Date::DAY_SUFFIX ));
  722. $this->assertSame( '6', $date->get(Date::WEEKDAY_DIGIT ));
  723. $this->assertSame( '44', $date->get(Date::DAY_OF_YEAR ));
  724. $this->assertSame( 'S', $date->get(Date::WEEKDAY_NARROW ));
  725. $this->assertSame( 'Sa.', $date->get(Date::WEEKDAY_NAME ));
  726. $this->assertSame( '07', $date->get(Date::WEEK ));
  727. $this->assertSame( 'Februar', $date->get(Date::MONTH_NAME ));
  728. $this->assertSame( '02', $date->get(Date::MONTH ));
  729. $this->assertSame( 'Feb', $date->get(Date::MONTH_NAME_SHORT ));
  730. $this->assertSame( '2', $date->get(Date::MONTH_SHORT ));
  731. $this->assertSame( '28', $date->get(Date::MONTH_DAYS ));
  732. $this->assertSame( 'F', $date->get(Date::MONTH_NAME_NARROW));
  733. $this->assertSame( '0', $date->get(Date::LEAPYEAR ));
  734. $this->assertSame( '2009', $date->get(Date::YEAR_8601 ));
  735. $this->assertSame( '2009', $date->get(Date::YEAR ));
  736. $this->assertSame( '09', $date->get(Date::YEAR_SHORT ));
  737. $this->assertSame( '09', $date->get(Date::YEAR_SHORT_8601 ));
  738. $this->assertSame( 'vorm.', $date->get(Date::MERIDIEM ));
  739. $this->assertSame( '021', $date->get(Date::SWATCH ));
  740. $this->assertSame( '4', $date->get(Date::HOUR_SHORT_AM ));
  741. $this->assertSame( '4', $date->get(Date::HOUR_SHORT ));
  742. $this->assertSame( '04', $date->get(Date::HOUR_AM ));
  743. $this->assertSame( '04', $date->get(Date::HOUR ));
  744. $this->assertSame( '31', $date->get(Date::MINUTE ));
  745. $this->assertSame( '30', $date->get(Date::SECOND ));
  746. $this->assertSame( '0', $date->get(Date::MILLISECOND ));
  747. $this->assertSame( '31', $date->get(Date::MINUTE_SHORT ));
  748. $this->assertSame( '30', $date->get(Date::SECOND_SHORT ));
  749. $this->assertSame( 'Indian/Maldives', $date->get(Date::TIMEZONE_NAME ));
  750. $this->assertSame( '0', $date->get(Date::DAYLIGHT ));
  751. $this->assertSame( '+0500', $date->get(Date::GMT_DIFF ));
  752. $this->assertSame( '+05:00', $date->get(Date::GMT_DIFF_SEP ));
  753. $this->assertSame( 'MVT', $date->get(Date::TIMEZONE ));
  754. $this->assertSame( '18000', $date->get(Date::TIMEZONE_SECS ));
  755. $this->assertSame( '2009-02-14T04:31:30+05:00', $date->get(Date::ISO_8601 ));
  756. $this->assertSame( 'Sat, 14 Feb 2009 04:31:30 +0500', $date->get(Date::RFC_2822 ));
  757. $this->assertSame( '1234567890', $date->get(Date::TIMESTAMP ));
  758. $this->assertSame( 'n. Chr.', $date->get(Date::ERA ));
  759. $this->assertSame( 'n. Chr.', $date->get(Date::ERA_NAME ));
  760. $this->assertSame( '14.02.2009', $date->get(Date::DATES ));
  761. $this->assertSame( 'Samstag, 14. Februar 2009', $date->get(Date::DATE_FULL ));
  762. $this->assertSame( '14. Februar 2009', $date->get(Date::DATE_LONG ));
  763. $this->assertSame( '14.02.2009', $date->get(Date::DATE_MEDIUM ));
  764. $this->assertSame( '14.02.09', $date->get(Date::DATE_SHORT ));
  765. $this->assertSame( '04:31:30', $date->get(Date::TIMES ));
  766. $this->assertSame( '04:31:30 Indian/Maldives', $date->get(Date::TIME_FULL ));
  767. $this->assertSame( '04:31:30 MVT', $date->get(Date::TIME_LONG ));
  768. $this->assertSame( '04:31:30', $date->get(Date::TIME_MEDIUM ));
  769. $this->assertSame( '04:31', $date->get(Date::TIME_SHORT ));
  770. $this->assertSame( '14.02.2009 04:31:30', $date->get(Date::DATETIME ));
  771. $this->assertSame('Samstag, 14. Februar 2009 04:31:30 Indian/Maldives', $date->get(Date::DATETIME_FULL ));
  772. $this->assertSame( '14. Februar 2009 04:31:30 MVT', $date->get(Date::DATETIME_LONG ));
  773. $this->assertSame( '14.02.2009 04:31:30', $date->get(Date::DATETIME_MEDIUM ));
  774. $this->assertSame( '14.02.09 04:31', $date->get(Date::DATETIME_SHORT ));
  775. $this->assertSame( '2009-02-14T04:31:30+05:00', $date->get(Date::ATOM ));
  776. $this->assertSame('Saturday, 14-Feb-09 04:31:30 Indian/Maldives', $date->get(Date::COOKIE ));
  777. $this->assertSame( 'Sat, 14 Feb 09 04:31:30 +0500', $date->get(Date::RFC_822 ));
  778. $this->assertSame('Saturday, 14-Feb-09 04:31:30 Indian/Maldives', $date->get(Date::RFC_850 ));
  779. $this->assertSame( 'Sat, 14 Feb 09 04:31:30 +0500', $date->get(Date::RFC_1036 ));
  780. $this->assertSame( 'Sat, 14 Feb 2009 04:31:30 +0500', $date->get(Date::RFC_1123 ));
  781. $this->assertSame( '2009-02-14T04:31:30+05:00', $date->get(Date::RFC_3339 ));
  782. $this->assertSame( 'Sat, 14 Feb 2009 04:31:30 +0500', $date->get(Date::RSS ));
  783. $this->assertSame( '2009-02-14T04:31:30+05:00', $date->get(Date::W3C ));
  784. // when get() receives a format string it responses like toString();
  785. $date->setTimezone('Indian/Maldives');
  786. $this->assertSame('2009', $date->get('Y'));
  787. }
  788. /**
  789. * Test for toValue
  790. */
  791. public function testGet2()
  792. {
  793. if (!defined('TESTS_ZEND_I18N_EXTENDED_COVERAGE') || TESTS_ZEND_I18N_EXTENDED_COVERAGE == false) {
  794. $this->markTestSkipped('Extended I18N test skipped');
  795. return;
  796. }
  797. $locale = new Locale('de_AT');
  798. $date = new Date(-62362925370,null,$locale);
  799. $this->assertSame('v. Chr.', $date->get(Date::ERA));
  800. $this->assertSame('v. Chr.', $date->get(Date::ERA_NAME));
  801. }
  802. /**
  803. * Test for set
  804. */
  805. public function testSet()
  806. {
  807. $locale = new Locale('de_AT');
  808. $date = new Date(0,null,$locale);
  809. $d2 = new Date(1010101010,null,$locale);
  810. $date->setTimezone(date_default_timezone_get());
  811. $d2->setTimezone(date_default_timezone_get());
  812. $retour = $date->set(1234567890);
  813. $this->assertSame('1234567890', $retour->getTimestamp());
  814. $this->assertSame('1010101010', $date->set($d2)->getTimestamp());
  815. $this->assertSame('1234567891', $date->set(1234567891)->getTimestamp());
  816. try {
  817. $date->set('noday', Date::DAY);
  818. $this->fail('exception expected');
  819. } catch (\Zend\Date\Exception\ExceptionInterface $e) {
  820. // success
  821. }
  822. $date->set($d2, Date::DAY);
  823. $this->assertSame('2009-02-04T04:31:31+05:00', $date->get(Date::W3C));
  824. $date->set( 10, Date::DAY);
  825. $this->assertSame('2009-02-10T04:31:31+05:00', $date->get(Date::W3C));
  826. $date->set( 40, Date::DAY);
  827. $this->assertSame('2009-03-12T04:31:31+05:00', $date->get(Date::W3C));
  828. $date->set(-10, Date::DAY);
  829. $this->assertSame('2009-02-18T04:31:31+05:00', $date->get(Date::W3C));
  830. $date->setTimezone('UTC');
  831. $date->set( 10, Date::DAY);
  832. $this->assertSame('2009-02-10T23:31:31+00:00', $date->get(Date::W3C));
  833. $date->setTimezone('Indian/Maldives');
  834. $date->set($d2, Date::DAY);
  835. $this->assertSame('2009-02-04T04:31:31+05:00', $date->get(Date::W3C));
  836. $date->setTimezone('UTC');
  837. $date->set( 10, Date::DAY, 'en_US');
  838. $this->assertSame('2009-02-10T23:31:31+00:00', $date->get(Date::W3C));
  839. $date->set($d2, Date::DAY, 'en_US');
  840. $this->assertSame('2009-02-04T04:31:31+05:00', $date->get(Date::W3C));
  841. $date->setTimezone('Indian/Maldives');
  842. $date->set(-20, Date::DAY, 'en_US');
  843. $this->assertSame('2009-01-11T04:31:31+05:00', $date->get(Date::W3C));
  844. $date->set($d2, Date::DAY, 'en_US');
  845. $this->assertSame('2009-01-04T04:31:31+05:00', $date->get(Date::W3C));
  846. $date->set('10.April.2007', 'dd.MMMM.YYYY');
  847. $this->assertSame('2007-04-10T00:00:00+05:00', $date->get(Date::W3C));
  848. }
  849. /**
  850. * Test for set
  851. */
  852. public function testSet2()
  853. {
  854. if (!defined('TESTS_ZEND_I18N_EXTENDED_COVERAGE') || TESTS_ZEND_I18N_EXTENDED_COVERAGE == false) {
  855. $this->markTestSkipped('Extended I18N test skipped');
  856. return;
  857. }
  858. $locale = new Locale('de_AT');
  859. $date = new Date(0,null,$locale);
  860. $d2 = new Date(1010101010,null,$locale);
  861. $date->setTimezone(date_default_timezone_get());
  862. $d2->setTimezone(date_default_timezone_get());
  863. $date->set(1234567890);
  864. try {
  865. $date->set('noday', Date::WEEKDAY_SHORT);
  866. $this->fail('exception expected');
  867. } catch (\Zend\Date\Exception\ExceptionInterface $e) {
  868. // success
  869. }
  870. $date->set($d2, Date::WEEKDAY_SHORT);
  871. $this->assertSame('2009-02-13T04:31:30+05:00', $date->get(Date::W3C));
  872. $date->set('Son', Date::WEEKDAY_SHORT);
  873. $this->assertSame('2009-02-08T04:31:30+05:00', $date->get(Date::W3C));
  874. $date->set('Mon', Date::WEEKDAY_SHORT);
  875. $this->assertSame('2009-02-09T04:31:30+05:00', $date->get(Date::W3C));
  876. $date->setTimezone('UTC');
  877. $date->set('Fre', Date::WEEKDAY_SHORT);
  878. $this->assertSame('2009-02-13T23:31:30+00:00', $date->get(Date::W3C));
  879. $date->set($d2, Date::WEEKDAY_SHORT);
  880. $this->assertSame('2009-02-13T04:31:30+05:00', $date->get(Date::W3C));
  881. $date->setTimezone('Indian/Maldives');
  882. $date->set('Thu', Date::WEEKDAY_SHORT, 'en_US');
  883. $this->assertSame('2009-02-12T04:31:30+05:00', $date->get(Date::W3C));
  884. $date->set($d2, Date::WEEKDAY_SHORT, 'en_US');
  885. $this->assertSame('2009-02-13T04:31:30+05:00', $date->get(Date::W3C));
  886. $date->setTimezone('UTC');
  887. $date->set('Wed', Date::WEEKDAY_SHORT , 'en_US');
  888. $this->assertSame('2009-02-11T23:31:30+00:00', $date->get(Date::W3C));
  889. $date->set($d2, Date::WEEKDAY_SHORT, 'en_US');
  890. $this->assertSame('2009-02-13T04:31:30+05:00', $date->get(Date::W3C));
  891. $date->setTimezone('Indian/Maldives');
  892. $date->set(1234567890);
  893. try {
  894. $date->set('xxx', Date::DAY_SHORT);
  895. $this->fail('exception expected');
  896. } catch (\Zend\Date\Exception\ExceptionInterface $e) {
  897. // success
  898. }
  899. $date->set($d2, Date::DAY_SHORT);
  900. $this->assertSame('2009-02-04T04:31:30+05:00', $date->get(Date::W3C));
  901. $date->set( 10, Date::DAY_SHORT);
  902. $this->assertSame('2009-02-10T04:31:30+05:00', $date->get(Date::W3C));
  903. $date->set( 40, Date::DAY_SHORT);
  904. $this->assertSame('2009-03-12T04:31:30+05:00', $date->get(Date::W3C));
  905. $date->set(-10, Date::DAY_SHORT);
  906. $this->assertSame('2009-02-18T04:31:30+05:00', $date->get(Date::W3C));
  907. $date->setTimeZone('UTC');
  908. $date->set( 10, Date::DAY_SHORT);
  909. $this->assertSame('2009-02-10T23:31:30+00:00', $date->get(Date::W3C));
  910. $date->set($d2, Date::DAY_SHORT);
  911. $this->assertSame('2009-02-04T04:31:30+05:00', $date->get(Date::W3C));
  912. $date->setTimezone('Indian/Maldives');
  913. $date->set( 10, Date::DAY_SHORT, 'en_US');
  914. $this->assertSame('2009-02-10T04:31:30+05:00', $date->get(Date::W3C));
  915. $date->set($d2, Date::DAY_SHORT, 'en_US');
  916. $this->assertSame('2009-02-04T04:31:30+05:00', $date->get(Date::W3C));
  917. $date->setTimeZone('UTC');
  918. $date->set(-20, Date::DAY_SHORT, 'en_US');
  919. $this->assertSame('2009-01-11T23:31:30+00:00', $date->get(Date::W3C));
  920. $date->set($d2, Date::DAY_SHORT, 'en_US');
  921. $this->assertSame('2009-01-04T04:31:30+05:00', $date->get(Date::W3C));
  922. $date->setTimezone('Indian/Maldives');
  923. $date->set(1234567890);
  924. try {
  925. $date->set('noday', Date::WEEKDAY);
  926. $this->fail('exception expected');
  927. } catch (\Zend\Date\Exception\ExceptionInterface $e) {
  928. // success
  929. }
  930. $date->set($d2, Date::WEEKDAY);
  931. $this->assertSame('2009-02-13T04:31:30+05:00', $date->get(Date::W3C));
  932. $date->set('Sonntag', Date::WEEKDAY);
  933. $this->assertSame('2009-02-08T04:31:30+05:00', $date->get(Date::W3C));
  934. $date->set('Montag', Date::WEEKDAY);
  935. $this->assertSame('2009-02-09T04:31:30+05:00', $date->get(Date::W3C));
  936. $date->setTimeZone('UTC');
  937. $date->set('Freitag', Date::WEEKDAY);
  938. $this->assertSame('2009-02-13T23:31:30+00:00', $date->get(Date::W3C));
  939. $date->set($d2, Date::WEEKDAY);
  940. $this->assertSame('2009-02-13T04:31:30+05:00', $date->get(Date::W3C));
  941. $date->setTimezone('Indian/Maldives');
  942. $date->set('Wednesday', Date::WEEKDAY, 'en_US');
  943. $this->assertSame('2009-02-11T04:31:30+05:00', $date->get(Date::W3C));
  944. $date->set($d2, Date::WEEKDAY, 'en_US');
  945. $this->assertSame('2009-02-13T04:31:30+05:00', $date->get(Date::W3C));
  946. $date->setTimeZone('UTC');
  947. $date->set('Thursday', Date::WEEKDAY, 'en_US');
  948. $this->assertSame('2009-02-12T23:31:30+00:00', $date->get(Date::W3C));
  949. $date->set($d2, Date::WEEKDAY, 'en_US');
  950. $this->assertSame('2009-02-13T04:31:30+05:00', $date->get(Date::W3C));
  951. $date->setTimezone('Indian/Maldives');
  952. $date->set(1234567890);
  953. try {
  954. $date->set(0, Date::WEEKDAY_8601);
  955. $this->fail('exception expected');
  956. } catch (\Zend\Date\Exception\ExceptionInterface $e) {
  957. // success
  958. }
  959. try {
  960. $date->set('noday', Date::WEEKDAY_8601);
  961. $this->fail('exception expected');
  962. } catch (\Zend\Date\Exception\ExceptionInterface $e) {
  963. // success
  964. }
  965. $date->set($d2, Date::WEEKDAY_8601);
  966. $this->assertSame('2009-02-13T04:31:30+05:00', $date->get(Date::W3C));
  967. $date->set(1, Date::WEEKDAY_8601);
  968. $this->assertSame('2009-02-09T04:31:30+05:00', $date->get(Date::W3C));
  969. $date->set(5, Date::WEEKDAY_8601);
  970. $this->assertSame('2009-02-13T04:31:30+05:00', $date->get(Date::W3C));
  971. $date->setTimeZone('UTC');
  972. $date->set(2, Date::WEEKDAY_8601);
  973. $this->assertSame('2009-02-10T23:31:30+00:00', $date->get(Date::W3C));
  974. $date->set($d2, Date::WEEKDAY_8601);
  975. $this->assertSame('2009-02-13T04:31:30+05:00', $date->get(Date::W3C));
  976. $date->setTimezone('Indian/Maldives');
  977. $date->set(4, Date::WEEKDAY_8601, 'en_US');
  978. $this->assertSame('2009-02-12T04:31:30+05:00', $date->get(Date::W3C));
  979. $date->set($d2, Date::WEEKDAY_8601, 'en_US');
  980. $this->assertSame('2009-02-13T04:31:30+05:00', $date->get(Date::W3C));
  981. $date->setTimeZone('UTC');
  982. $date->set(3, Date::WEEKDAY_8601, 'en_US');
  983. $this->assertSame('2009-02-11T23:31:30+00:00', $date->get(Date::W3C));
  984. $date->set($d2, Date::WEEKDAY_8601, 'en_US');
  985. $this->assertSame('2009-02-13T04:31:30+05:00', $date->get(Date::W3C));
  986. $date->setTimezone('Indian/Maldives');
  987. $date->set(1234567890);
  988. try {
  989. $date->set($d2, Date::DAY_SUFFIX);
  990. $this->fail('exception expected');
  991. } catch (\Zend\Date\Exception\ExceptionInterface $e) {
  992. // success
  993. }
  994. $date->set(1234567890);
  995. try {
  996. $date->set(7, Date::WEEKDAY_DIGIT);
  997. $this->fail();
  998. } catch (\Zend\Date\Exception\ExceptionInterface $e) {
  999. // success
  1000. }
  1001. try {
  1002. $date->set('noday', Date::WEEKDAY_DIGIT);
  1003. $this->fail();
  1004. } catch (\Zend\Date\Exception\ExceptionInterface $e) {
  1005. // success
  1006. }
  1007. $date->set($d2, Date::WEEKDAY_DIGIT);
  1008. $this->assertSame('2009-02-13T04:31:30+05:00', $date->get(Date::W3C));
  1009. $date->set(1, Date::WEEKDAY_DIGIT);
  1010. $this->assertSame('2009-02-09T04:31:30+05:00', $date->get(Date::W3C));
  1011. $date->set(5, Date::WEEKDAY_DIGIT);
  1012. $this->assertSame('2009-02-13T04:31:30+05:00', $date->get(Date::W3C));
  1013. $date->setTimeZone('UTC');
  1014. $date->set(2, Date::WEEKDAY_DIGIT);
  1015. $this->assertSame('2009-02-10T23:31:30+00:00', $date->get(Date::W3C));
  1016. $date->set($d2, Date::WEEKDAY_DIGIT);
  1017. $this->assertSame('2009-02-13T04:31:30+05:00', $date->get(Date::W3C));
  1018. $date->setTimezone('Indian/Maldives');
  1019. $date->set(4, Date::WEEKDAY_DIGIT, 'en_US');
  1020. $this->assertSame('2009-02-12T04:31:30+05:00', $date->get(Date::W3C));
  1021. $date->set($d2, Date::WEEKDAY_DIGIT, 'en_US');
  1022. $this->assertSame('2009-02-13T04:31:30+05:00', $date->get(Date::W3C));
  1023. $date->setTimeZone('UTC');
  1024. $date->set(3, Date::WEEKDAY_DIGIT, 'en_US');
  1025. $this->assertSame('2009-02-11T23:31:30+00:00', $date->get(Date::W3C));
  1026. $date->set($d2, Date::WEEKDAY_DIGIT, 'en_US');
  1027. $this->assertSame('2009-02-13T04:31:30+05:00', $date->get(Date::W3C));
  1028. $date->setTimezone('Indian/Maldives');
  1029. $date->set(1234567890);
  1030. try {
  1031. $date->set('noday', Date::DAY_OF_YEAR);
  1032. $this->fail();
  1033. } catch (\Zend\Date\Exception\ExceptionInterface $e) {
  1034. // success
  1035. }
  1036. $date->set($d2, Date::DAY_OF_YEAR);
  1037. $this->assertSame('2009-01-03T04:31:30+05:00', $date->get(Date::W3C));
  1038. $date->set( 124, Date::DAY_OF_YEAR);
  1039. $this->assertSame('2009-05-04T04:31:30+05:00', $date->get(Date::W3C));
  1040. $date->set( 524, Date::DAY_OF_YEAR);
  1041. $this->assertSame('2010-06-08T04:31:30+05:00', $date->get(Date::W3C));
  1042. $date->set(-135, Date::DAY_OF_YEAR);
  1043. $this->assertSame('2009-08-18T04:31:30+05:00', $date->get(Date::W3C));
  1044. $date->setTimeZone('UTC');
  1045. $date->set( 422, Date::DAY_OF_YEAR);
  1046. $this->assertSame('2010-02-26T23:31:30+00:00', $date->get(Date::W3C));
  1047. $date->set($d2, Date::DAY_OF_YEAR);
  1048. $this->assertSame('2010-01-03T04:31:30+05:00', $date->get(Date::W3C));
  1049. $date->setTimezone('Indian/Maldives');
  1050. $date->set( 12, Date::DAY_OF_YEAR, 'en_US');
  1051. $this->assertSame('2010-01-12T04:31:30+05:00', $date->get(Date::W3C));
  1052. $date->set($d2, Date::DAY_OF_YEAR, 'en_US');
  1053. $this->assertSame('2010-01-03T04:31:30+05:00', $date->get(Date::W3C));
  1054. $date->setTimeZone('UTC');
  1055. $date->set(-253, Date::DAY_OF_YEAR, 'en_US');
  1056. $this->assertSame('2009-04-22T23:31:30+00:00', $date->get(Date::W3C));
  1057. $date->set($d2, Date::DAY_OF_YEAR, 'en_US');
  1058. $this->assertSame('2009-01-03T04:31:30+05:00', $date->get(Date::W3C));
  1059. $date->setTimezone('Indian/Maldives');
  1060. $date->set(1234567890);
  1061. try {
  1062. $date->set('noday', Date::WEEKDAY_NARROW);
  1063. $this->fail('exception expected');
  1064. } catch (\Zend\Date\Exception\ExceptionInterface $e) {
  1065. // success
  1066. }
  1067. $date->set($d2, Date::WEEKDAY_NARROW);
  1068. $this->assertSame('2009-02-13T04:31:30+05:00', $date->get(Date::W3C));
  1069. $date->set('S', Date::WEEKDAY_NARROW);
  1070. $this->assertSame('2009-02-08T04:31:30+05:00', $date->get(Date::W3C));
  1071. $date->set('M', Date::WEEKDAY_NARROW);
  1072. $this->assertSame('2009-02-09T04:31:30+05:00', $date->get(Date::W3C));
  1073. $date->setTimeZone('UTC');
  1074. $date->set('F', Date::WEEKDAY_NARROW);
  1075. $this->assertSame('2009-02-13T23:31:30+00:00', $date->get(Date::W3C));
  1076. $date->set($d2, Date::WEEKDAY_NARROW);
  1077. $this->assertSame('2009-02-13T04:31:30+05:00', $date->get(Date::W3C));
  1078. $date->setTimezone('Indian/Maldives');
  1079. $date->set('W', Date::WEEKDAY_NARROW, 'en_US');
  1080. $this->assertSame('2009-02-11T04:31:30+05:00', $date->get(Date::W3C));
  1081. $date->set($d2, Date::WEEKDAY_NARROW, 'en_US');
  1082. $this->assertSame('2009-02-13T04:31:30+05:00', $date->get(Date::W3C));
  1083. $date->setTimeZone('UTC');
  1084. $date->set('W', Date::WEEKDAY_NARROW, 'en_US');
  1085. $this->assertSame('2009-02-11T23:31:30+00:00', $date->get(Date::W3C));
  1086. $date->set($d2, Date::WEEKDAY_NARROW, 'en_US');
  1087. $this->assertSame('2009-02-13T04:31:30+05:00', $date->get(Date::W3C));
  1088. $date->setTimezone('Indian/Maldives');
  1089. $date->set(1234567890);
  1090. try {
  1091. $date->set('noday', Date::WEEKDAY_NAME);
  1092. $this->fail();
  1093. } catch (\Zend\Date\Exception\ExceptionInterface $e) {
  1094. // success
  1095. }
  1096. $date->set($d2, Date::WEEKDAY_NAME);
  1097. $this->assertSame('2009-02-13T04:31:30+05:00', $date->get(Date::W3C));
  1098. $date->set('So.', Date::WEEKDAY_NAME);
  1099. $this->assertSame('2009-02-08T04:31:30+05:00', $date->get(Date::W3C));
  1100. $date->set('Mo.', Date::WEEKDAY_NAME);
  1101. $this->assertSame('2009-02-09T04:31:30+05:00', $date->get(Date::W3C));
  1102. $date->setTimeZone('UTC');
  1103. $date->set('Fr.', Date::WEEKDAY_NAME);
  1104. $this->assertSame('2009-02-13T23:31:30+00:00', $date->get(Date::W3C));
  1105. $date->set($d2, Date::WEEKDAY_NAME);
  1106. $this->assertSame('2009-02-13T04:31:30+05:00', $date->get(Date::W3C));
  1107. $date->setTimezone('Indian/Maldives');
  1108. $date->set('Thu', Date::WEEKDAY_NAME, 'en_US');
  1109. $this->assertSame('2009-02-12T04:31:30+05:00', $date->get(Date::W3C));
  1110. $date->set($d2, Date::WEEKDAY_NAME, 'en_US');
  1111. $this->assertSame('2009-02-13T04:31:30+05:00', $date->get(Date::W3C));
  1112. $date->setTimeZone('UTC');
  1113. $date->set('Wed', Date::WEEKDAY_NAME, 'en_US');
  1114. $this->assertSame('2009-02-11T23:31:30+00:00', $date->get(Date::W3C));
  1115. $date->set($d2, Date::WEEKDAY_NAME, 'en_US');
  1116. $this->assertSame('2009-02-13T04:31:30+05:00', $date->get(Date::W3C));
  1117. $date->setTimezone('Indian/Maldives');
  1118. $date->set(1234567890);
  1119. try {
  1120. $date->set('noday', Date::WEEK);
  1121. $this->fail();
  1122. } catch (\Zend\Date\Exception\ExceptionInterface $e) {
  1123. // success
  1124. }
  1125. $date->set($d2, Date::WEEK);
  1126. $this->assertSame('2009-01-03T04:31:30+05:00', $date->get(Date::W3C));
  1127. $date->set( 1, Date::WEEK);
  1128. $this->assertSame('2009-01-03T04:31:30+05:00', $date->get(Date::W3C));
  1129. $date->set( 55, Date::WEEK);
  1130. $this->assertSame('2010-01-16T04:31:30+05:00', $date->get(Date::W3C));
  1131. $date->set(-57, Date::WEEK);
  1132. $this->assertSame('2008-11-29T04:31:30+05:00', $date->get(Date::W3C));
  1133. $date->setTimeZone('UTC');
  1134. $date->set( 50, Date::WEEK);
  1135. $this->assertSame('2008-12-12T23:31:30+00:00', $date->get(Date::W3C));
  1136. $date->set($d2, Date::WEEK);
  1137. $this->assertSame('2008-01-05T04:31:30+05:00', $date->get(Date::W3C));
  1138. $date->setTimezone('Indian/Maldives');
  1139. $date->set( 10, Date::WEEK, 'en_US');
  1140. $this->assertSame('2008-03-08T04:31:30+05:00', $date->get(Date::W3C));
  1141. $date->set($d2, Date::WEEK, 'en_US');
  1142. $this->assertSame('2008-01-05T04:31:30+05:00', $date->get(Date::W3C));
  1143. $date->setTimeZone('UTC');
  1144. $date->set(-25, Date::WEEK, 'en_US');
  1145. $this->assertSame('2007-07-06T23:31:30+00:00', $date->get(Date::W3C));
  1146. $date->set($d2, Date::WEEK, 'en_US');
  1147. $this->assertSame('2007-01-06T04:31:30+05:00', $date->get(Date::W3C));
  1148. $date->setTimezone('Indian/Maldives');
  1149. $date->set(1234567890);
  1150. try {
  1151. $date->set('noday', Date::MONTH_NAME);
  1152. $this->fail('exception expected');
  1153. } catch (\Zend\Date\Exception\ExceptionInterface $e) {
  1154. // success
  1155. }
  1156. $date->set($d2, Date::MONTH_NAME);
  1157. $this->assertSame('2009-01-14T04:31:30+05:00', $date->get(Date::W3C));
  1158. $date->set('März', Date::MONTH_NAME);
  1159. $this->assertSame('2009-03-14T04:31:30+05:00', $date->get(Date::W3C));
  1160. $date->set('Dezember', Date::MONTH_NAME);
  1161. $this->assertSame('2009-12-14T04:31:30+05:00', $date->get(Date::W3C));
  1162. $date->setTimeZone('UTC');
  1163. $date->set('August', Date::MONTH_NAME);
  1164. $this->assertSame('2009-08-13T23:31:30+00:00', $date->get(Date::W3C));
  1165. $date->set($d2, Date::MONTH_NAME);
  1166. $this->assertSame('2009-01-14T04:31:30+05:00', $date->get(Date::W3C));
  1167. $date->setTimezone('Indian/Maldives');
  1168. $date->set('April', Date::MONTH_NAME, 'en_US');
  1169. $this->assertSame('2009-04-14T04:31:30+05:00', $date->get(Date::W3C));
  1170. $date->set($d2, Date::MONTH_NAME, 'en_US');
  1171. $this->assertSame('2009-01-14T04:31:30+05:00', $date->get(Date::W3C));
  1172. $date->setTimeZone('UTC');
  1173. $date->set('July', Date::MONTH_NAME, 'en_US');
  1174. $this->assertSame('2009-07-13T23:31:30+00:00', $date->get(Date::W3C));
  1175. $date->set($d2, Date::MONTH_NAME, 'en_US');
  1176. $this->assertSame('2009-01-14T04:31:30+05:00', $date->get(Date::W3C));
  1177. $date->setTimezone('Indian/Maldives');
  1178. $date->set(1234567890);
  1179. try {
  1180. $date->set('noday', Date::MONTH);
  1181. $this->fail();
  1182. } catch (\Zend\Date\Exception\ExceptionInterface $e) {
  1183. // success
  1184. }
  1185. $date->set($d2, Date::MONTH);
  1186. $this->assertSame('2009-01-14T04:31:30+05:00', $date->get(Date::W3C));
  1187. $date->set('03', Date::MONTH);
  1188. $this->assertSame('2009-03-14T04:31:30+05:00', $date->get(Date::W3C));
  1189. $date->set( 14, Date::MONTH);
  1190. $this->assertSame('2010-02-14T04:31:30+05:00', $date->get(Date::W3C));
  1191. $date->set(-6, Date::MONTH);
  1192. $this->assertSame('2009-06-14T04:31:30+05:00', $date->get(Date::W3C));
  1193. $date->setTimeZone('UTC');
  1194. $date->set( 10, Date::MONTH);
  1195. $this->assertSame('2009-10-13T23:31:30+00:00', $date->get(Date::W3C));
  1196. $date->set($d2, Date::MONTH);
  1197. $this->assertSame('2009-01-14T04:31:30+05:00', $date->get(Date::W3C));
  1198. $date->setTimezone('Indian/Maldives');
  1199. $date->set( 9, Date::MONTH, 'en_US');
  1200. $this->assertSame('2009-09-14T04:31:30+05:00', $date->get(Date::W3C));
  1201. $date->set($d2, Date::MONTH, 'en_US');
  1202. $this->assertSame('2009-01-14T04:31:30+05:00', $date->get(Date::W3C));
  1203. $date->setTimeZone('UTC');
  1204. $date->set(-20, Date::MONTH, 'en_US');
  1205. $this->assertSame('2007-04-13T23:31:30+00:00', $date->get(Date::W3C));
  1206. $date->set($d2, Date::MONTH, 'en_US');
  1207. $this->assertSame('2007-01-14T04:31:30+05:00', $date->get(Date::W3C));
  1208. $date->setTimezone('Indian/Maldives');
  1209. $date->set(1234567890);
  1210. try {
  1211. $date->set('noday', Date::MONTH_NAME_SHORT);
  1212. $this->fail('exception expected');
  1213. } catch (\Zend\Date\Exception\ExceptionInterface $e) {
  1214. // success
  1215. }
  1216. $date->set($d2, Date::MONTH_NAME_SHORT);
  1217. $this->assertSame('2009-01-14T04:31:30+05:00', $date->get(Date::W3C));
  1218. $date->set('Mär', Date::MONTH_NAME_SHORT);
  1219. $this->assertSame('2009-03-14T04:31:30+05:00', $date->get(Date::W3C));
  1220. $date->set('Dez', Date::MONTH_NAME_SHORT);
  1221. $this->assertSame('2009-12-14T04:31:30+05:00', $date->get(Date::W3C));
  1222. $date->setTimeZone('UTC');
  1223. $date->set('Aug', Date::MONTH_NAME_SHORT);
  1224. $this->assertSame('2009-08-13T23:31:30+00:00', $date->get(Date::W3C));
  1225. $date->set($d2, Date::MONTH_NAME_SHORT);
  1226. $this->assertSame('2009-01-14T04:31:30+05:00', $date->get(Date::W3C));
  1227. $date->setTimezone('Indian/Maldives');
  1228. $date->set('Apr', Date::MONTH_NAME_SHORT, 'en_US');
  1229. $this->assertSame('2009-04-14T04:31:30+05:00', $date->get(Date::W3C));
  1230. $date->set($d2, Date::MONTH_NAME_SHORT, 'en_US');
  1231. $this->assertSame('2009-01-14T04:31:30+05:00', $date->get(Date::W3C));
  1232. $date->setTimeZone('UTC');
  1233. $date->set('Jul', Date::MONTH_NAME_SHORT, 'en_US');
  1234. $this->assertSame('2009-07-13T23:31:30+00:00', $date->get(Date::W3C));
  1235. $date->set($d2, Date::MONTH_NAME_SHORT, 'en_US');
  1236. $this->assertSame('2009-01-14T04:31:30+05:00', $date->get(Date::W3C));
  1237. $date->setTimezone('Indian/Maldives');
  1238. $date->set(1234567890);
  1239. try {
  1240. $date->set('noday', Date::MONTH_SHORT);
  1241. $this->fail();
  1242. } catch (\Zend\Date\Exception\ExceptionInterface $e) {
  1243. // success
  1244. }
  1245. $date->set($d2, Date::MONTH_SHORT);
  1246. $this->assertSame('2009-01-14T04:31:30+05:00', $date->get(Date::W3C));
  1247. $date->set( 3, Date::MONTH_SHORT);
  1248. $this->assertSame('2009-03-14T04:31:30+05:00', $date->get(Date::W3C));
  1249. $date->set( 14, Date::MONTH_SHORT);
  1250. $this->assertSame('2010-02-14T04:31:30+05:00', $date->get(Date::W3C));
  1251. $date->set(-6, Date::MONTH_SHORT);
  1252. $this->assertSame('2009-06-14T04:31:30+05:00', $date->get(Date::W3C));
  1253. $date->setTimeZone('UTC');
  1254. $date->set( 10, Date::MONTH_SHORT);
  1255. $this->assertSame('2009-10-13T23:31:30+00:00', $date->get(Date::W3C));
  1256. $date->set($d2, Date::MONTH_SHORT);
  1257. $this->assertSame('2009-01-14T04:31:30+05:00', $date->get(Date::W3C));
  1258. $date->setTimezone('Indian/Maldives');
  1259. $date->set( 9, Date::MONTH_SHORT, 'en_US');
  1260. $this->assertSame('2009-09-14T04:31:30+05:00', $date->get(Date::W3C));
  1261. $date->set($d2, Date::MONTH_SHORT, 'en_US');
  1262. $this->assertSame('2009-01-14T04:31:30+05:00', $date->get(Date::W3C));
  1263. $date->setTimeZone('UTC');
  1264. $date->set(-20, Date::MONTH_SHORT, 'en_US');
  1265. $this->assertSame('2007-04-13T23:31:30+00:00', $date->get(Date::W3C));
  1266. $date->set($d2, Date::MONTH_SHORT, 'en_US');
  1267. $this->assertSame('2007-01-14T04:31:30+05:00', $date->get(Date::W3C));
  1268. $date->setTimezone('Indian/Maldives');
  1269. $date->set(1234567890);
  1270. try {
  1271. $date->set($d2, Date::MONTH_DAYS);
  1272. $this->fail('exception expected');
  1273. } catch (\Zend\Date\Exception\ExceptionInterface $e) {
  1274. // success
  1275. }
  1276. $date->set(1234567890);
  1277. try {
  1278. $date->set('xxday', Date::MONTH_NAME_NARROW);
  1279. $this->fail('exception expected');
  1280. } catch (\Zend\Date\Exception\ExceptionInterface $e) {
  1281. // success
  1282. }
  1283. $date->set($d2, Date::MONTH_NAME_NARROW);
  1284. $this->assertSame('2009-01-14T04:31:30+05:00', $date->get(Date::W3C));
  1285. $date->set('M', Date::MONTH_NAME_NARROW);
  1286. $this->assertSame('2009-03-14T04:31:30+05:00', $date->get(Date::W3C));
  1287. $date->set('D', Date::MONTH_NAME_NARROW);
  1288. $this->assertSame('2009-12-14T04:31:30+05:00', $date->get(Date::W3C));
  1289. $date->setTimeZone('UTC');
  1290. $date->set('A', Date::MONTH_NAME_NARROW);
  1291. $this->assertSame('2009-04-13T23:31:30+00:00', $date->get(Date::W3C));
  1292. $date->set($d2, Date::MONTH_NAME_NARROW);
  1293. $this->assertSame('2009-01-14T04:31:30+05:00', $date->get(Date::W3C));
  1294. $date->setTimezone('Indian/Maldives');
  1295. $date->set('A', Date::MONTH_NAME_NARROW, 'en_US');
  1296. $this->assertSame('2009-04-14T04:31:30+05:00', $date->get(Date::W3C));
  1297. $date->set($d2, Date::MONTH_NAME_NARROW, 'en_US');
  1298. $this->assertSame('2009-01-14T04:31:30+05:00', $date->get(Date::W3C));
  1299. $date->setTimeZone('UTC');
  1300. $date->set('J', Date::MONTH_NAME_NARROW, 'en_US');
  1301. $this->assertSame('2009-01-13T23:31:30+00:00', $date->get(Date::W3C));
  1302. $date->set($d2, Date::MONTH_NAME_NARROW, 'en_US');
  1303. $this->assertSame('2009-01-14T04:31:30+05:00', $date->get(Date::W3C));
  1304. $date->setTimezone('Indian/Maldives');
  1305. $date->set(1234567890);
  1306. try {
  1307. $date->set($d2, Date::LEAPYEAR);
  1308. $this->fail('exception expected');
  1309. } catch (\Zend\Date\Exception\ExceptionInterface $e) {
  1310. // success
  1311. }
  1312. $date->set(1234567890);
  1313. try {
  1314. $date->set('noday', Date::YEAR_8601);
  1315. $this->fail();
  1316. } catch (\Zend\Date\Exception\ExceptionInterface $e) {
  1317. // success
  1318. }
  1319. $date->set($d2, Date::YEAR_8601);
  1320. $this->assertSame('2002-02-14T04:31:30+05:00', $date->get(Date::W3C));
  1321. $date->set(1970, Date::YEAR_8601);
  1322. $this->assertSame('1970-02-14T04:31:30+05:00', $date->get(Date::W3C));
  1323. $date->set(2020, Date::YEAR_8601);
  1324. $this->assertSame('2020-02-14T04:31:30+05:00', $date->get(Date::W3C));
  1325. $date->set(2040, Date::YEAR_8601);
  1326. $this->assertSame('2040-02-14T04:31:30+05:00', $date->get(Date::W3C));
  1327. $date->setTimeZone('UTC');
  1328. $date->set(1900, Date::YEAR_8601);
  1329. $this->assertSame('1900-02-13T23:31:30+00:00', $date->get(Date::W3C));
  1330. $date->set($d2, Date::YEAR_8601);
  1331. $this->assertSame('2002-02-14T04:31:30+05:00', $date->get(Date::W3C));
  1332. $date->setTimezone('Indian/Maldives');
  1333. $date->set(2500, Date::YEAR_8601, 'en_US');
  1334. $this->assertSame('2500-02-14T04:31:30+05:00', $date->get(Date::W3C));
  1335. $date->set($d2, Date::YEAR_8601, 'en_US');
  1336. $this->assertSame('2002-02-14T04:31:30+05:00', $date->get(Date::W3C));
  1337. $date->setTimeZone('UTC');
  1338. $date->set(-20, Date::YEAR_8601, 'en_US');
  1339. $this->assertSame('-20-02-13T23:31:30+00:00', $date->get(Date::W3C));
  1340. $date->set($d2, Date::YEAR_8601, 'en_US');
  1341. $this->assertSame('2002-02-14T04:31:30+05:00', $date->get(Date::W3C));
  1342. $date->setTimezone('Indian/Maldives');
  1343. $date->set(1234567890);
  1344. try {
  1345. $date->set('noday', Date::YEAR);
  1346. $this->fail();
  1347. } catch (\Zend\Date\Exception\ExceptionInterface $e) {
  1348. // success
  1349. }
  1350. $date->set($d2, Date::YEAR);
  1351. $this->assertSame('2002-02-14T04:31:30+05:00', $date->get(Date::W3C));
  1352. $date->set(1970, Date::YEAR);
  1353. $this->assertSame('1970-02-14T04:31:30+05:00', $date->get(Date::W3C));
  1354. $date->set(2020, Date::YEAR);
  1355. $this->assertSame('2020-02-14T04:31:30+05:00', $date->get(Date::W3C));
  1356. $date->set(2040, Date::YEAR);
  1357. $this->assertSame('2040-02-14T04:31:30+05:00', $date->get(Date::W3C));
  1358. $date->setTimeZone('UTC');
  1359. $date->set(1900, Date::YEAR);
  1360. $this->assertSame('1900-02-13T23:31:30+00:00', $date->get(Date::W3C));
  1361. $date->set($d2, Date::YEAR);
  1362. $this->assertSame('2002-02-14T04:31:30+05:00', $date->get(Date::W3C));
  1363. $date->setTimezone('Indian/Maldives');
  1364. $date->set(2500, Date::YEAR, 'en_US');
  1365. $this->assertSame('2500-02-14T04:31:30+05:00', $date->get(Date::W3C));
  1366. $date->set($d2, Date::YEAR, 'en_US');
  1367. $this->assertSame('2002-02-14T04:31:30+05:00', $date->get(Date::W3C));
  1368. $date->setTimeZone('UTC');
  1369. $date->set(-20, Date::YEAR, 'en_US');
  1370. $this->assertSame('-20-02-13T23:31:30+00:00', $date->get(Date::W3C));
  1371. $date->set($d2, Date::YEAR, 'en_US');
  1372. $this->assertSame('2002-02-14T04:31:30+05:00', $date->get(Date::W3C));
  1373. $date->setTimezone('Indian/Maldives');
  1374. $date->set(1234567890);
  1375. try {
  1376. $date->set('noday', Date::YEAR_SHORT);
  1377. $this->fail();
  1378. } catch (\Zend\Date\Exception\ExceptionInterface $e) {
  1379. // success
  1380. }
  1381. $date->set($d2, Date::YEAR_SHORT);
  1382. $this->assertSame('2002-02-14T04:31:30+05:00', $date->get(Date::W3C));
  1383. $date->set(70, Date::YEAR_SHORT);
  1384. $this->assertSame('1970-02-14T04:31:30+05:00', $date->get(Date::W3C));
  1385. $date->set(20, Date::YEAR_SHORT);
  1386. $this->assertSame('2020-02-14T04:31:30+05:00', $date->get(Date::W3C));
  1387. $date->set(40, Date::YEAR_SHORT);
  1388. $this->assertSame('2040-02-14T04:31:30+05:00', $date->get(Date::W3C));
  1389. $date->setTimeZone('UTC');
  1390. $date->set(0, Date::YEAR_SHORT);
  1391. $this->assertSame('2000-02-13T23:31:30+00:00', $date->get(Date::W3C));
  1392. $date->set($d2, Date::YEAR_SHORT);
  1393. $date->setTimezone('Indian/Maldives');
  1394. $this->assertSame('2002-02-14T04:31:30+05:00', $date->get(Date::W3C));
  1395. $date->set(30, Date::YEAR_SHORT, 'en_US');
  1396. $this->assertSame('2030-02-14T04:31:30+05:00', $date->get(Date::W3C));
  1397. $date->set($d2, Date::YEAR_SHORT, 'en_US');
  1398. $this->assertSame('2002-02-14T04:31:30+05:00', $date->get(Date::W3C));
  1399. $date->setTimeZone('UTC');
  1400. $date->set(-20, Date::YEAR_SHORT, 'en_US');
  1401. $this->assertSame('-20-02-13T23:31:30+00:00', $date->get(Date::W3C));
  1402. $date->set($d2, Date::YEAR_SHORT, 'en_US');
  1403. $this->assertSame('2002-02-14T04:31:30+05:00', $date->get(Date::W3C));
  1404. $date->setTimezone('Indian/Maldives');
  1405. $date->set(1234567890);
  1406. try {
  1407. $date->set('noday', Date::YEAR_SHORT_8601);
  1408. $this->fail();
  1409. } catch (\Zend\Date\Exception\ExceptionInterface $e) {
  1410. // success
  1411. }
  1412. $date->set($d2, Date::YEAR_SHORT_8601);
  1413. $this->assertSame('2002-02-14T04:31:30+05:00', $date->get(Date::W3C));
  1414. $date->set(70, Date::YEAR_SHORT_8601);
  1415. $this->assertSame('1970-02-14T04:31:30+05:00', $date->get(Date::W3C));
  1416. $date->set(20, Date::YEAR_SHORT_8601);
  1417. $this->assertSame('2020-02-14T04:31:30+05:00', $date->get(Date::W3C));
  1418. $date->set(40, Date::YEAR_SHORT_8601);
  1419. $this->assertSame('2040-02-14T04:31:30+05:00', $date->get(Date::W3C));
  1420. $date->setTimeZone('UTC');
  1421. $date->set(0, Date::YEAR_SHORT_8601);
  1422. $this->assertSame('2000-02-13T23:31:30+00:00', $date->get(Date::W3C));
  1423. $date->set($d2, Date::YEAR_SHORT_8601);
  1424. $this->assertSame('2002-02-14T04:31:30+05:00', $date->get(Date::W3C));
  1425. $date->setTimezone('Indian/Maldives');
  1426. $date->set(30, Date::YEAR_SHORT_8601, 'en_US');
  1427. $this->assertSame('2030-02-14T04:31:30+05:00', $date->get(Date::W3C));
  1428. $date->set($d2, Date::YEAR_SHORT_8601, 'en_US');
  1429. $this->assertSame('2002-02-14T04:31:30+05:00', $date->get(Date::W3C));
  1430. $date->setTimeZone('UTC');
  1431. $date->set(-20, Date::YEAR_SHORT_8601, 'en_US');
  1432. $this->assertSame('-20-02-13T23:31:30+00:00', $date->get(Date::W3C));
  1433. $date->set($d2, Date::YEAR_SHORT_8601, 'en_US');
  1434. $this->assertSame('2002-02-14T04:31:30+05:00', $date->get(Date::W3C));
  1435. $date->setTimezone('Indian/Maldives');
  1436. $date->set(1234567890);
  1437. try {
  1438. $date->set('noday', Date::MERIDIEM);
  1439. $this->fail();
  1440. } catch (\Zend\Date\Exception\ExceptionInterface $e) {
  1441. // success
  1442. }
  1443. $date->set(1234567890);
  1444. try {
  1445. $date->set('noday', Date::SWATCH);
  1446. $this->fail();
  1447. } catch (\Zend\Date\Exception\ExceptionInterface $e) {
  1448. // success
  1449. }
  1450. $date->set($d2, Date::SWATCH);
  1451. $this->assertSame('2009-02-14T00:36:00+05:00', $date->get(Date::W3C));
  1452. $date->set(0, Date::SWATCH);
  1453. $this->assertSame('2009-02-14T00:00:00+05:00', $date->get(Date::W3C));
  1454. $date->set(600, Date::SWATCH);
  1455. $this->assertSame('2009-02-14T14:23:59+05:00', $date->get(Date::W3C));
  1456. $date->set(1700, Date::SWATCH);
  1457. $this->assertSame('2009-02-15T16:47:59+05:00', $date->get(Date::W3C));
  1458. $date->setTimeZone('UTC');
  1459. $date->set(1900, Date::SWATCH);
  1460. $this->assertSame('2009-02-16T21:36:00+00:00', $date->get(Date::W3C));
  1461. $date->set($d2, Date::SWATCH);
  1462. $this->assertSame('2009-02-17T00:36:00+05:00', $date->get(Date::W3C));
  1463. $date->setTimezone('Indian/Maldives');
  1464. $date->set(3700, Date::SWATCH, 'en_US');
  1465. $this->assertSame('2009-02-20T16:48:00+05:00', $date->get(Date::W3C));
  1466. $date->set($d2, Date::SWATCH, 'en_US');
  1467. $this->assertSame('2009-02-20T00:36:00+05:00', $date->get(Date::W3C));
  1468. $date->setTimeZone('UTC');
  1469. $date->set(-200, Date::SWATCH, 'en_US');
  1470. $this->assertSame('2009-02-18T19:12:00+00:00', $date->get(Date::W3C));
  1471. $date->set($d2, Date::SWATCH, 'en_US');
  1472. $this->assertSame('2009-02-19T00:36:00+05:00', $date->get(Date::W3C));
  1473. $date->setTimezone('Indian/Maldives');
  1474. $date->set(1234567890);
  1475. try {
  1476. $date->set('noday', Date::HOUR_SHORT_AM);
  1477. $this->fail();
  1478. } catch (\Zend\Date\Exception\ExceptionInterface $e) {
  1479. // success
  1480. }
  1481. $date->set($d2, Date::HOUR_SHORT_AM);
  1482. $this->assertSame('2009-02-14T04:31:30+05:00', $date->get(Date::W3C));
  1483. $date->set( 3, Date::HOUR_SHORT_AM);
  1484. $this->assertSame('2009-02-14T03:31:30+05:00', $date->get(Date::W3C));
  1485. $date->set( 14, Date::HOUR_SHORT_AM);
  1486. $this->assertSame('2009-02-14T14:31:30+05:00', $date->get(Date::W3C));
  1487. $date->set(-6, Date::HOUR_SHORT_AM);
  1488. $this->assertSame('2009-02-13T18:31:30+05:00', $date->get(Date::W3C));
  1489. $date->setTimeZone('UTC');
  1490. $date->set( 30, Date::HOUR_SHORT_AM);
  1491. $this->assertSame('2009-02-14T06:31:30+00:00', $date->get(Date::W3C));
  1492. $date->set($d2, Date::HOUR_SHORT_AM);
  1493. $this->assertSame('2009-02-14T04:31:30+05:00', $date->get(Date::W3C));
  1494. $date->setTimezone('Indian/Maldives');
  1495. $date->set( 9, Date::HOUR_SHORT_AM, 'en_US');
  1496. $this->assertSame('2009-02-14T09:31:30+05:00', $date->get(Date::W3C));
  1497. $date->set($d2, Date::HOUR_SHORT_AM, 'en_US');
  1498. $this->assertSame('2009-02-14T04:31:30+05:00', $date->get(Date::W3C));
  1499. $date->setTimeZone('UTC');
  1500. $date->set(-26, Date::HOUR_SHORT_AM, 'en_US');
  1501. $this->assertSame('2009-02-11T22:31:30+00:00', $date->get(Date::W3C));
  1502. $date->set($d2, Date::HOUR_SHORT_AM, 'en_US');
  1503. $this->assertSame('2009-02-12T04:31:30+05:00', $date->get(Date::W3C));
  1504. $date->setTimezone('Indian/Maldives');
  1505. $date->set(1234567890);
  1506. try {
  1507. $date->set('noday', Date::HOUR_SHORT);
  1508. $this->fail();
  1509. } catch (\Zend\Date\Exception\ExceptionInterface $e) {
  1510. // success
  1511. }
  1512. $date->set($d2, Date::HOUR_SHORT);
  1513. $this->assertSame('2009-02-14T04:31:30+05:00', $date->get(Date::W3C));
  1514. $date->set( 3, Date::HOUR_SHORT);
  1515. $this->assertSame('2009-02-14T03:31:30+05:00', $date->get(Date::W3C));
  1516. $date->set( 14, Date::HOUR_SHORT);
  1517. $this->assertSame('2009-02-14T14:31:30+05:00', $date->get(Date::W3C));
  1518. $date->set(-6, Date::HOUR_SHORT);
  1519. $this->assertSame('2009-02-13T18:31:30+05:00', $date->get(Date::W3C));
  1520. $date->setTimeZone('UTC');
  1521. $date->set( 30, Date::HOUR_SHORT);
  1522. $this->assertSame('2009-02-14T06:31:30+00:00', $date->get(Date::W3C));
  1523. $date->set($d2, Date::HOUR_SHORT);
  1524. $this->assertSame('2009-02-14T04:31:30+05:00', $date->get(Date::W3C));
  1525. $date->setTimezone('Indian/Maldives');
  1526. $date->set( 9, Date::HOUR_SHORT, 'en_US');
  1527. $this->assertSame('2009-02-14T09:31:30+05:00', $date->get(Date::W3C));
  1528. $date->set($d2, Date::HOUR_SHORT, 'en_US');
  1529. $this->assertSame('2009-02-14T04:31:30+05:00', $date->get(Date::W3C));
  1530. $date->setTimeZone('UTC');
  1531. $date->set(-26, Date::HOUR_SHORT, 'en_US');
  1532. $this->assertSame('2009-02-11T22:31:30+00:00', $date->get(Date::W3C));
  1533. $date->set($d2, Date::HOUR_SHORT, 'en_US');
  1534. $this->assertSame('2009-02-12T04:31:30+05:00', $date->get(Date::W3C));
  1535. $date->setTimezone('Indian/Maldives');
  1536. $date->set(1234567890);
  1537. try {
  1538. $date->set('noday', Date::HOUR_AM);
  1539. $this->fail();
  1540. } catch (\Zend\Date\Exception\ExceptionInterface $e) {
  1541. // success
  1542. }
  1543. $date->set($d2, Date::HOUR_AM);
  1544. $this->assertSame('2009-02-14T04:31:30+05:00', $date->get(Date::W3C));
  1545. $date->set( 3, Date::HOUR_AM);
  1546. $this->assertSame('2009-02-14T03:31:30+05:00', $date->get(Date::W3C));
  1547. $date->set( 14, Date::HOUR_AM);
  1548. $this->assertSame('2009-02-14T14:31:30+05:00', $date->get(Date::W3C));
  1549. $date->set(-6, Date::HOUR_AM);
  1550. $this->assertSame('2009-02-13T18:31:30+05:00', $date->get(Date::W3C));
  1551. $date->setTimeZone('UTC');
  1552. $date->set( 30, Date::HOUR_AM);
  1553. $this->assertSame('2009-02-14T06:31:30+00:00', $date->get(Date::W3C));
  1554. $date->set($d2, Date::HOUR_AM);
  1555. $this->assertSame('2009-02-14T04:31:30+05:00', $date->get(Date::W3C));
  1556. $date->setTimezone('Indian/Maldives');
  1557. $date->set( 9, Date::HOUR_AM, 'en_US');
  1558. $this->assertSame('2009-02-14T09:31:30+05:00', $date->get(Date::W3C));
  1559. $date->set($d2, Date::HOUR_AM, 'en_US');
  1560. $this->assertSame('2009-02-14T04:31:30+05:00', $date->get(Date::W3C));
  1561. $date->setTimeZone('UTC');
  1562. $date->set(-26, Date::HOUR_AM, 'en_US');
  1563. $this->assertSame('2009-02-11T22:31:30+00:00', $date->get(Date::W3C));
  1564. $date->set($d2, Date::HOUR_AM, 'en_US');
  1565. $this->assertSame('2009-02-12T04:31:30+05:00', $date->get(Date::W3C));
  1566. $date->setTimezone('Indian/Maldives');
  1567. $date->set(1234567890);
  1568. try {
  1569. $date->set('noday', Date::HOUR);
  1570. $this->fail();
  1571. } catch (\Zend\Date\Exception\ExceptionInterface $e) {
  1572. // success
  1573. }
  1574. $date->set($d2, Date::HOUR);
  1575. $this->assertSame('2009-02-14T04:31:30+05:00', $date->get(Date::W3C));
  1576. $date->set( 3, Date::HOUR);
  1577. $this->assertSame('2009-02-14T03:31:30+05:00', $date->get(Date::W3C));
  1578. $date->set( 14, Date::HOUR);
  1579. $this->assertSame('2009-02-14T14:31:30+05:00', $date->get(Date::W3C));
  1580. $date->set(-6, Date::HOUR);
  1581. $this->assertSame('2009-02-13T18:31:30+05:00', $date->get(Date::W3C));
  1582. $date->setTimeZone('UTC');
  1583. $date->set( 30, Date::HOUR);
  1584. $this->assertSame('2009-02-14T06:31:30+00:00', $date->get(Date::W3C));
  1585. $date->set($d2, Date::HOUR);
  1586. $this->assertSame('2009-02-14T04:31:30+05:00', $date->get(Date::W3C));
  1587. $date->setTimezone('Indian/Maldives');
  1588. $date->set( 9, Date::HOUR, 'en_US');
  1589. $this->assertSame('2009-02-14T09:31:30+05:00', $date->get(Date::W3C));
  1590. $date->set($d2, Date::HOUR, 'en_US');
  1591. $this->assertSame('2009-02-14T04:31:30+05:00', $date->get(Date::W3C));
  1592. $date->setTimeZone('UTC');
  1593. $date->set(-26, Date::HOUR, 'en_US');
  1594. $this->assertSame('2009-02-11T22:31:30+00:00', $date->get(Date::W3C));
  1595. $date->set($d2, Date::HOUR, 'en_US');
  1596. $this->assertSame('2009-02-12T04:31:30+05:00', $date->get(Date::W3C));
  1597. $date->setTimezone('Indian/Maldives');
  1598. $date->set(1234567890);
  1599. try {
  1600. $date->set('noday', Date::MINUTE);
  1601. $this->fail();
  1602. } catch (\Zend\Date\Exception\ExceptionInterface $e) {
  1603. // success
  1604. }
  1605. $date->set($d2, Date::MINUTE);
  1606. $this->assertSame('2009-02-14T04:36:30+05:00', $date->get(Date::W3C));
  1607. $date->set( 3, Date::MINUTE);
  1608. $this->assertSame('2009-02-14T04:03:30+05:00', $date->get(Date::W3C));
  1609. $date->set( 65, Date::MINUTE);
  1610. $this->assertSame('2009-02-14T05:05:30+05:00', $date->get(Date::W3C));
  1611. $date->set(-6, Date::MINUTE);
  1612. $this->assertSame('2009-02-14T04:54:30+05:00', $date->get(Date::W3C));
  1613. $date->setTimeZone('UTC');
  1614. $date->set( 30, Date::MINUTE);
  1615. $this->assertSame('2009-02-13T23:30:30+00:00', $date->get(Date::W3C));
  1616. $date->set($d2, Date::MINUTE);
  1617. $this->assertSame('2009-02-14T04:36:30+05:00', $date->get(Date::W3C));
  1618. $date->setTimezone('Indian/Maldives');
  1619. $date->set( 9, Date::MINUTE, 'en_US');
  1620. $this->assertSame('2009-02-14T04:09:30+05:00', $date->get(Date::W3C));
  1621. $date->set($d2, Date::MINUTE, 'en_US');
  1622. $this->assertSame('2009-02-14T04:36:30+05:00', $date->get(Date::W3C));
  1623. $date->setTimeZone('UTC');
  1624. $date->set(-65, Date::MINUTE, 'en_US');
  1625. $this->assertSame('2009-02-13T21:55:30+00:00', $date->get(Date::W3C));
  1626. $date->set($d2, Date::MINUTE, 'en_US');
  1627. $this->assertSame('2009-02-14T02:36:30+05:00', $date->get(Date::W3C));
  1628. $date->setTimezone('Indian/Maldives');
  1629. $date->set(1234567890);
  1630. try {
  1631. $date->set('noday', Date::MINUTE_SHORT);
  1632. $this->fail();
  1633. } catch (\Zend\Date\Exception\ExceptionInterface $e) {
  1634. // success
  1635. }
  1636. $date->set($d2, Date::MINUTE_SHORT);
  1637. $this->assertSame('2009-02-14T04:36:30+05:00', $date->get(Date::W3C));
  1638. $date->set( 3, Date::MINUTE_SHORT);
  1639. $this->assertSame('2009-02-14T04:03:30+05:00', $date->get(Date::W3C));
  1640. $date->set( 65, Date::MINUTE_SHORT);
  1641. $this->assertSame('2009-02-14T05:05:30+05:00', $date->get(Date::W3C));
  1642. $date->set(-6, Date::MINUTE_SHORT);
  1643. $this->assertSame('2009-02-14T04:54:30+05:00', $date->get(Date::W3C));
  1644. $date->setTimeZone('UTC');
  1645. $date->set( 30, Date::MINUTE_SHORT);
  1646. $this->assertSame('2009-02-13T23:30:30+00:00', $date->get(Date::W3C));
  1647. $date->set($d2, Date::MINUTE_SHORT);
  1648. $this->assertSame('2009-02-14T04:36:30+05:00', $date->get(Date::W3C));
  1649. $date->setTimezone('Indian/Maldives');
  1650. $date->set( 9, Date::MINUTE_SHORT, 'en_US');
  1651. $this->assertSame('2009-02-14T04:09:30+05:00', $date->get(Date::W3C));
  1652. $date->set($d2, Date::MINUTE_SHORT, 'en_US');
  1653. $this->assertSame('2009-02-14T04:36:30+05:00', $date->get(Date::W3C));
  1654. $date->setTimeZone('UTC');
  1655. $date->set(-65, Date::MINUTE_SHORT, 'en_US');
  1656. $this->assertSame('2009-02-13T21:55:30+00:00', $date->get(Date::W3C));
  1657. $date->set($d2, Date::MINUTE_SHORT, 'en_US');
  1658. $this->assertSame('2009-02-14T02:36:30+05:00', $date->get(Date::W3C));
  1659. $date->setTimezone('Indian/Maldives');
  1660. $date->set(1234567890);
  1661. try {
  1662. $date->set('noday', Date::SECOND);
  1663. $this->fail();
  1664. } catch (\Zend\Date\Exception\ExceptionInterface $e) {
  1665. // success
  1666. }
  1667. $date->set($d2, Date::SECOND);
  1668. $this->assertSame('2009-02-14T04:31:50+05:00', $date->get(Date::W3C));
  1669. $date->set( 3, Date::SECOND);
  1670. $this->assertSame('2009-02-14T04:31:03+05:00', $date->get(Date::W3C));
  1671. $date->set( 65, Date::SECOND);
  1672. $this->assertSame('2009-02-14T04:32:05+05:00', $date->get(Date::W3C));
  1673. $date->set(-6, Date::SECOND);
  1674. $this->assertSame('2009-02-14T04:31:54+05:00', $date->get(Date::W3C));
  1675. $date->setTimeZone('UTC');
  1676. $date->set( 30, Date::SECOND);
  1677. $this->assertSame('2009-02-13T23:31:30+00:00', $date->get(Date::W3C));
  1678. $date->set($d2, Date::SECOND);
  1679. $this->assertSame('2009-02-14T04:31:50+05:00', $date->get(Date::W3C));
  1680. $date->setTimezone('Indian/Maldives');
  1681. $date->set( 9, Date::SECOND, 'en_US');
  1682. $this->assertSame('2009-02-14T04:31:09+05:00', $date->get(Date::W3C));
  1683. $date->set($d2, Date::SECOND, 'en_US');
  1684. $this->assertSame('2009-02-14T04:31:50+05:00', $date->get(Date::W3C));
  1685. $date->setTimeZone('UTC');
  1686. $date->set(-65, Date::SECOND, 'en_US');
  1687. $this->assertSame('2009-02-13T23:29:55+00:00', $date->get(Date::W3C));
  1688. $date->set($d2, Date::SECOND, 'en_US');
  1689. $this->assertSame('2009-02-14T04:29:50+05:00', $date->get(Date::W3C));
  1690. $date->setTimezone('Indian/Maldives');
  1691. $date->set(1234567890);
  1692. try {
  1693. $date->set('noday', Date::SECOND_SHORT);
  1694. $this->fail();
  1695. } catch (\Zend\Date\Exception\ExceptionInterface $e) {
  1696. // success
  1697. }
  1698. $date->set($d2, Date::SECOND_SHORT);
  1699. $this->assertSame('2009-02-14T04:31:50+05:00', $date->get(Date::W3C));
  1700. $date->set( 3, Date::SECOND_SHORT);
  1701. $this->assertSame('2009-02-14T04:31:03+05:00', $date->get(Date::W3C));
  1702. $date->set( 65, Date::SECOND_SHORT);
  1703. $this->assertSame('2009-02-14T04:32:05+05:00', $date->get(Date::W3C));
  1704. $date->set(-6, Date::SECOND_SHORT);
  1705. $this->assertSame('2009-02-14T04:31:54+05:00', $date->get(Date::W3C));
  1706. $date->setTimeZone('UTC');
  1707. $date->set( 30, Date::SECOND_SHORT);
  1708. $this->assertSame('2009-02-13T23:31:30+00:00', $date->get(Date::W3C));
  1709. $date->set($d2, Date::SECOND_SHORT);
  1710. $this->assertSame('2009-02-14T04:31:50+05:00', $date->get(Date::W3C));
  1711. $date->setTimezone('Indian/Maldives');
  1712. $date->set( 9, Date::SECOND_SHORT, 'en_US');
  1713. $this->assertSame('2009-02-14T04:31:09+05:00', $date->get(Date::W3C));
  1714. $date->set($d2, Date::SECOND_SHORT, 'en_US');
  1715. $this->assertSame('2009-02-14T04:31:50+05:00', $date->get(Date::W3C));
  1716. $date->setTimeZone('UTC');
  1717. $date->set(-65, Date::SECOND_SHORT, 'en_US');
  1718. $this->assertSame('2009-02-13T23:29:55+00:00', $date->get(Date::W3C));
  1719. $date->set($d2, Date::SECOND_SHORT, 'en_US');
  1720. $this->assertSame('2009-02-14T04:29:50+05:00', $date->get(Date::W3C));
  1721. $date->setTimezone('Indian/Maldives');
  1722. $date->set(1234567890);
  1723. try {
  1724. $date->set('noday', Date::MILLISECOND);
  1725. $this->fail();
  1726. } catch (\Zend\Date\Exception\ExceptionInterface $e) {
  1727. // success
  1728. }
  1729. $date->set($d2, Date::MILLISECOND);
  1730. $this->assertSame('000', $date->get(Date::MILLISECOND));
  1731. $date->set( 3, Date::MILLISECOND);
  1732. $this->assertSame('003', $date->get(Date::MILLISECOND));
  1733. $date->set( 1065, Date::MILLISECOND);
  1734. $this->assertSame('065', $date->get(Date::MILLISECOND));
  1735. $date->set(-6, Date::MILLISECOND);
  1736. $this->assertSame('994', $date->get(Date::MILLISECOND));
  1737. $date->set( 30, Date::MILLISECOND, true);
  1738. $this->assertSame('030', $date->get(Date::MILLISECOND));
  1739. $date->set($d2, Date::MILLISECOND, true);
  1740. $this->assertSame('000', $date->get(Date::MILLISECOND));
  1741. $date->set( 9, Date::MILLISECOND, false, 'en_US');
  1742. $this->assertSame('009', $date->get(Date::MILLISECOND));
  1743. $date->set($d2, Date::MILLISECOND, false, 'en_US');
  1744. $this->assertSame('000', $date->get(Date::MILLISECOND));
  1745. $date->set(-65, Date::MILLISECOND, true , 'en_US');
  1746. $this->assertSame('935', $date->get(Date::MILLISECOND));
  1747. $date->set($d2, Date::MILLISECOND, true , 'en_US');
  1748. $this->assertSame('000', $date->get(Date::MILLISECOND));
  1749. $date->set(1234567890);
  1750. try {
  1751. $date->set('noday', Date::TIMEZONE_NAME);
  1752. $this->fail();
  1753. } catch (\Zend\Date\Exception\ExceptionInterface $e) {
  1754. // success
  1755. }
  1756. $date->set(1234567890);
  1757. try {
  1758. $date->set('noday', Date::DAYLIGHT);
  1759. $this->fail();
  1760. } catch (\Zend\Date\Exception\ExceptionInterface $e) {
  1761. // success
  1762. }
  1763. $date->set(1234567890);
  1764. try {
  1765. $date->set('noday', Date::GMT_DIFF);
  1766. $this->fail();
  1767. } catch (\Zend\Date\Exception\ExceptionInterface $e) {
  1768. // success
  1769. }
  1770. $date->set(1234567890);
  1771. try {
  1772. $date->set('noday', Date::GMT_DIFF_SEP);
  1773. $this->fail();
  1774. } catch (\Zend\Date\Exception\ExceptionInterface $e) {
  1775. // success
  1776. }
  1777. $date->set(1234567890);
  1778. try {
  1779. $date->set('noday', Date::TIMEZONE);
  1780. $this->fail();
  1781. } catch (\Zend\Date\Exception\ExceptionInterface $e) {
  1782. // success
  1783. }
  1784. $date->set(1234567890);
  1785. try {
  1786. $date->set('noday', Date::TIMEZONE_SECS);
  1787. $this->fail();
  1788. } catch (\Zend\Date\Exception\ExceptionInterface $e) {
  1789. // success
  1790. }
  1791. $date->set(1234567890);
  1792. try {
  1793. $date->set('noday', Date::ISO_8601);
  1794. $this->fail();
  1795. } catch (\Zend\Date\Exception\ExceptionInterface $e) {
  1796. // success
  1797. }
  1798. $date->set($d2, Date::ISO_8601);
  1799. $this->assertSame('2002-01-04T04:36:50+05:00', $date->get(Date::W3C));
  1800. $date->set(1234567890);
  1801. $date->set('2007-10-20 20:10:30', Date::ISO_8601);
  1802. $this->assertSame('2007-10-20T20:10:30+05:00', $date->get(Date::W3C));
  1803. $date->set(1234567890);
  1804. $date->set('2007-10-20 201030', Date::ISO_8601);
  1805. $this->assertSame('2007-10-20T20:10:30+05:00', $date->get(Date::W3C));
  1806. $date->set(1234567890);
  1807. $date->set('07-10-20 20:10:30', Date::ISO_8601);
  1808. $this->assertSame('2007-10-20T20:10:30+05:00', $date->get(Date::W3C));
  1809. $date->set(1234567890);
  1810. $date->set('80-10-20 20:10:30', Date::ISO_8601);
  1811. $this->assertSame('1980-10-20T20:10:30+05:00', $date->get(Date::W3C));
  1812. $date->set(1234567890);
  1813. $date->set('-2007-10-20 20:10:30', Date::ISO_8601);
  1814. $this->assertSame('-2007-10-20T20:10:30+05:00', $date->get(Date::W3C));
  1815. $date->set(1234567890);
  1816. $date->set('-07-10-20 20:10:30', Date::ISO_8601);
  1817. $this->assertSame('-7-10-20T20:10:30+05:00', $date->get(Date::W3C));
  1818. $date->set(1234567890);
  1819. $date->set('2007-10-20T20:10:30', Date::ISO_8601);
  1820. $this->assertSame('2007-10-20T20:10:30+05:00', $date->get(Date::W3C));
  1821. $date->set(1234567890);
  1822. $date->set('2007-10-20T201030', Date::ISO_8601);
  1823. $this->assertSame('2007-10-20T20:10:30+05:00', $date->get(Date::W3C));
  1824. $date->set(1234567890);
  1825. $date->set('20-10-20T20:10:30', Date::ISO_8601);
  1826. $this->assertSame('2020-10-20T20:10:30+05:00', $date->get(Date::W3C));
  1827. $date->set(1234567890);
  1828. $date->set('80-10-20T20:10:30', Date::ISO_8601);
  1829. $this->assertSame('1980-10-20T20:10:30+05:00', $date->get(Date::W3C));
  1830. $date->set(1234567890);
  1831. $date->set('-2007-10-20T20:10:30', Date::ISO_8601);
  1832. $this->assertSame('-2007-10-20T20:10:30+05:00', $date->get(Date::W3C));
  1833. $date->set(1234567890);
  1834. $date->set('-07-10-20T20:10:30', Date::ISO_8601);
  1835. $this->assertSame('-7-10-20T20:10:30+05:00', $date->get(Date::W3C));
  1836. $date->set(1234567890);
  1837. $date->set('20071020 20:10:30', Date::ISO_8601);
  1838. $this->assertSame('2007-10-20T20:10:30+05:00', $date->get(Date::W3C));
  1839. $date->set(1234567890);
  1840. $date->set('201020 20:10:30', Date::ISO_8601);
  1841. $this->assertSame('2020-10-20T20:10:30+05:00', $date->get(Date::W3C));
  1842. $date->set(1234567890);
  1843. $date->set('801020 20:10:30', Date::ISO_8601);
  1844. $this->assertSame('1980-10-20T20:10:30+05:00', $date->get(Date::W3C));
  1845. $date->set(1234567890);
  1846. $date->set('-071020 20:10:30', Date::ISO_8601);
  1847. $this->assertSame('-7-10-20T20:10:30-07:00', $date->get(Date::W3C));
  1848. $date->set(1234567890);
  1849. $date->set('-00071020 20:10:30', Date::ISO_8601);
  1850. $this->assertSame('-7-10-20T20:10:30+00:00', $date->get(Date::W3C));
  1851. $date->setTimezone('Indian/Maldives');
  1852. $date->set(1234567890);
  1853. $date->set('20071020T20:10:30', Date::ISO_8601);
  1854. $this->assertSame('2007-10-20T20:10:30+05:00', $date->get(Date::W3C));
  1855. $date->set(1234567890);
  1856. $date->set('-00071020T20:10:30', Date::ISO_8601);
  1857. $this->assertSame('-7-10-20T20:10:30+00:00', $date->get(Date::W3C));
  1858. $date->setTimezone('Indian/Maldives');
  1859. $date->set(1234567890);
  1860. $date->set('2007-10-20', Date::ISO_8601);
  1861. $this->assertSame('2007-10-20T00:00:00+05:00', $date->get(Date::W3C));
  1862. $date->set(1234567890);
  1863. $date->set('20071020', Date::ISO_8601);
  1864. $this->assertSame('2007-10-20T00:00:00+05:00', $date->get(Date::W3C));
  1865. $date->set(1234567890);
  1866. $date->set('20071020122030', Date::ISO_8601);
  1867. $this->assertSame('2007-10-20T12:20:30+05:00', $date->get(Date::W3C));
  1868. $date->set(1234567890);
  1869. $date->set('071020', Date::ISO_8601);
  1870. $this->assertSame('2007-10-20T00:00:00+05:00', $date->get(Date::W3C));
  1871. $date->set(1234567890);
  1872. $date->set('07:10:20', Date::ISO_8601);
  1873. $this->assertSame('1970-01-01T07:10:20+05:00', $date->get(Date::W3C));
  1874. $date->set(1234567890);
  1875. try {
  1876. $date->set('noday', Date::RFC_2822);
  1877. $this->fail();
  1878. } catch (\Zend\Date\Exception\ExceptionInterface $e) {
  1879. // success
  1880. }
  1881. $date->set($d2, Date::RFC_2822);
  1882. $this->assertSame('2002-01-04T04:36:50+05:00', $date->get(Date::W3C));
  1883. $date->set(1234567890);
  1884. $date->set('Thu, 05 Jan 2009 01:31:30 +0500', Date::RFC_2822);
  1885. $this->assertSame('2009-01-05T01:31:30+05:00', $date->get(Date::W3C));
  1886. $date->set(1234567890);
  1887. $date->set('Thu, 05 Feb 2009 01:31:30 +0500', Date::RFC_2822);
  1888. $this->assertSame('2009-02-05T01:31:30+05:00', $date->get(Date::W3C));
  1889. $date->set(1234567890);
  1890. $date->set('Thu, 05 Mar 2009 01:31:30 +0500', Date::RFC_2822);
  1891. $this->assertSame('2009-03-05T01:31:30+05:00', $date->get(Date::W3C));
  1892. $date->set(1234567890);
  1893. $date->set('Thu, 05 Apr 2009 01:31:30 +0500', Date::RFC_2822);
  1894. $this->assertSame('2009-04-05T01:31:30+05:00', $date->get(Date::W3C));
  1895. $date->set(1234567890);
  1896. $date->set('Thu, 05 May 2009 01:31:30 +0500', Date::RFC_2822);
  1897. $this->assertSame('2009-05-05T01:31:30+05:00', $date->get(Date::W3C));
  1898. $date->set(1234567890);
  1899. $date->set('Thu, 05 Jun 2009 01:31:30 +0500', Date::RFC_2822);
  1900. $this->assertSame('2009-06-05T01:31:30+05:00', $date->get(Date::W3C));
  1901. $date->set(1234567890);
  1902. $date->set('Thu, 05 Jul 2009 01:31:30 +0500', Date::RFC_2822);
  1903. $this->assertSame('2009-07-05T01:31:30+05:00', $date->get(Date::W3C));
  1904. $date->set(1234567890);
  1905. $date->set('Thu, 05 Aug 2009 01:31:30 +0500', Date::RFC_2822);
  1906. $this->assertSame('2009-08-05T01:31:30+05:00', $date->get(Date::W3C));
  1907. $date->set(1234567890);
  1908. $date->set('Thu, 05 Sep 2009 01:31:30 +0500', Date::RFC_2822);
  1909. $this->assertSame('2009-09-05T01:31:30+05:00', $date->get(Date::W3C));
  1910. $date->set(1234567890);
  1911. $date->set('Thu, 05 Oct 2009 01:31:30 +0500', Date::RFC_2822);
  1912. $this->assertSame('2009-10-05T01:31:30+05:00', $date->get(Date::W3C));
  1913. $date->set(1234567890);
  1914. $date->set('Thu, 05 Nov 2009 01:31:30 +0500', Date::RFC_2822);
  1915. $this->assertSame('2009-11-05T01:31:30+05:00', $date->get(Date::W3C));
  1916. $date->set(1234567890);
  1917. $date->set('Thu, 05 Dec 2009 01:31:30 +0500', Date::RFC_2822);
  1918. $this->assertSame('2009-12-05T01:31:30+05:00', $date->get(Date::W3C));
  1919. $date->set(1234567890);
  1920. try {
  1921. $date->set('Thu, 05 Fxx 2009 01:31:30 +0500', Date::RFC_2822);
  1922. $this->fail();
  1923. } catch (\Zend\Date\Exception\ExceptionInterface $e) {
  1924. // success
  1925. }
  1926. $date->set(1234567890);
  1927. try {
  1928. $date->set('noday', Date::TIMESTAMP);
  1929. $this->fail();
  1930. } catch (\Zend\Date\Exception\ExceptionInterface $e) {
  1931. // success
  1932. }
  1933. $date->set($d2, Date::TIMESTAMP);
  1934. $this->assertSame('2002-01-04T04:36:50+05:00', $date->get(Date::W3C));
  1935. $date->set(1234567890);
  1936. $date->set('1010101099', Date::TIMESTAMP);
  1937. $this->assertSame('2002-01-04T04:38:19+05:00', $date->get(Date::W3C));
  1938. $date->set(1234567890);
  1939. try {
  1940. $date->set('noday', Date::ERA);
  1941. $this->fail();
  1942. } catch (\Zend\Date\Exception\ExceptionInterface $e) {
  1943. // success
  1944. }
  1945. $date->set(1234567890);
  1946. try {
  1947. $date->set('noday', Date::ERA_NAME);
  1948. $this->fail();
  1949. } catch (\Zend\Date\Exception\ExceptionInterface $e) {
  1950. // success
  1951. }
  1952. $date->set(1234567890);
  1953. try {
  1954. $date->set('noday', Date::DATES);
  1955. $this->fail();
  1956. } catch (\Zend\Date\Exception\ExceptionInterface $e) {
  1957. // success
  1958. }
  1959. $date->set($d2, Date::DATES);
  1960. $this->assertSame('2002-01-04T04:31:30+05:00', $date->get(Date::W3C));
  1961. $date->set(1234567890);
  1962. $date->set('14.02.2009', Date::DATES);
  1963. $this->assertSame('2009-02-14T04:31:30+05:00', $date->get(Date::W3C));
  1964. $date->set(1234567890);
  1965. try {
  1966. $date->set('noday', Date::DATE_FULL);
  1967. $this->fail();
  1968. } catch (\Zend\Date\Exception\ExceptionInterface $e) {
  1969. // success
  1970. }
  1971. $date->set($d2, Date::DATE_FULL);
  1972. $this->assertSame('2002-01-04T04:31:30+05:00', $date->get(Date::W3C));
  1973. $date->set(1234567890);
  1974. $date->set('Samstag, 14. Februar 2009', Date::DATE_FULL);
  1975. $this->assertSame('2009-02-14T04:31:30+05:00', $date->get(Date::W3C));
  1976. $date->set(1234567890);
  1977. try {
  1978. $date->set('noday', Date::DATE_LONG);
  1979. $this->fail();
  1980. } catch (\Zend\Date\Exception\ExceptionInterface $e) {
  1981. // success
  1982. }
  1983. $date->set($d2, Date::DATE_LONG);
  1984. $this->assertSame('2002-01-04T04:31:30+05:00', $date->get(Date::W3C));
  1985. $date->set(1234567890);
  1986. $date->set('14. Februar 2009', Date::DATE_LONG);
  1987. $this->assertSame('2009-02-14T04:31:30+05:00', $date->get(Date::W3C));
  1988. $date->set(1234567890);
  1989. try {
  1990. $date->set('noday', Date::DATE_MEDIUM);
  1991. $this->fail();
  1992. } catch (\Zend\Date\Exception\ExceptionInterface $e) {
  1993. // success
  1994. }
  1995. $date->set($d2, Date::DATE_MEDIUM);
  1996. $this->assertSame('2002-01-04T04:31:30+05:00', $date->get(Date::W3C));
  1997. $date->set(1234567890);
  1998. $date->set('14.02.2009', Date::DATE_MEDIUM);
  1999. $this->assertSame('2009-02-14T04:31:30+05:00', $date->get(Date::W3C));
  2000. $date->set(1234567890);
  2001. try {
  2002. $date->set('noday', Date::DATE_SHORT);
  2003. $this->fail();
  2004. } catch (\Zend\Date\Exception\ExceptionInterface $e) {
  2005. // success
  2006. }
  2007. $date->set($d2, Date::DATE_SHORT);
  2008. $this->assertSame('2002-01-04T04:31:30+05:00', $date->get(Date::W3C));
  2009. $date->set(1234567890);
  2010. $date->set('14.02.09', Date::DATE_SHORT);
  2011. $this->assertSame('2009-02-14T04:31:30+05:00', $date->get(Date::W3C));
  2012. $date->set(1234567890);
  2013. try {
  2014. $date->set('noday', Date::TIMES);
  2015. $this->fail();
  2016. } catch (\Zend\Date\Exception\ExceptionInterface $e) {
  2017. // success
  2018. }
  2019. $date->set($d2, Date::TIMES);
  2020. $this->assertSame('2009-02-14T04:36:50+05:00', $date->get(Date::W3C));
  2021. $date->set(1234567890);
  2022. $date->set('15:26:40', Date::TIMES);
  2023. $this->assertSame('2009-02-14T15:26:40+05:00', $date->get(Date::W3C));
  2024. $date->set(1234567890);
  2025. try {
  2026. $date->set('noday', Date::TIME_FULL);
  2027. $this->fail();
  2028. } catch (\Zend\Date\Exception\ExceptionInterface $e) {
  2029. // success
  2030. }
  2031. $date->set($d2, Date::TIME_FULL);
  2032. $this->assertSame('2009-02-14T04:36:50+05:00', $date->get(Date::W3C));
  2033. $date->set(1234567890);
  2034. $date->set('15:26 Uhr CET', Date::TIME_FULL);
  2035. $this->assertSame('2009-02-14T15:26:00+01:00', $date->get(Date::W3C));
  2036. $date->set(1234567890);
  2037. try {
  2038. $date->set('noday', Date::TIME_LONG);
  2039. $this->fail();
  2040. } catch (\Zend\Date\Exception\ExceptionInterface $e) {
  2041. // success
  2042. }
  2043. $date->set($d2, Date::TIME_LONG);
  2044. $this->assertSame('2009-02-14T04:36:50+05:00', $date->get(Date::W3C));
  2045. $date->set(1234567890);
  2046. $date->set('15:26:40 CET', Date::TIME_LONG);
  2047. $this->assertSame('2009-02-14T15:26:40+01:00', $date->get(Date::W3C));
  2048. $date->setTimezone('Indian/Maldives');
  2049. $date->set(1234567890);
  2050. try {
  2051. $date->set('noday', Date::TIME_MEDIUM);
  2052. $this->fail();
  2053. } catch (\Zend\Date\Exception\ExceptionInterface $e) {
  2054. // success
  2055. }
  2056. $date->set($d2, Date::TIME_MEDIUM);
  2057. $this->assertSame('2009-02-14T04:36:50+05:00', $date->get(Date::W3C));
  2058. $date->set(1234567890);
  2059. $date->set('15:26:40', Date::TIME_MEDIUM);
  2060. $this->assertSame('2009-02-14T15:26:40+05:00', $date->get(Date::W3C));
  2061. $date->set(1234567890);
  2062. try {
  2063. $date->set('noday', Date::TIME_SHORT);
  2064. $this->fail();
  2065. } catch (\Zend\Date\Exception\ExceptionInterface $e) {
  2066. // success
  2067. }
  2068. $date->set($d2, Date::TIME_SHORT);
  2069. $this->assertSame('2009-02-14T04:36:00+05:00', $date->get(Date::W3C));
  2070. $date->set(1234567890);
  2071. $date->set('15:26', Date::TIME_SHORT);
  2072. $this->assertSame('2009-02-14T15:26:00+05:00', $date->get(Date::W3C));
  2073. $date->set(1234567890);
  2074. try {
  2075. $date->set('noday', Date::DATETIME);
  2076. $this->fail();
  2077. } catch (\Zend\Date\Exception\ExceptionInterface $e) {
  2078. // success
  2079. }
  2080. $date->set($d2, Date::DATETIME);
  2081. $this->assertSame('2002-01-04T04:36:50+05:00', $date->get(Date::W3C));
  2082. $date->set(1234567890);
  2083. $date->set('14.02.2009 15:26:03', Date::DATETIME);
  2084. $this->assertSame('2009-02-14T15:26:03+05:00', $date->get(Date::W3C));
  2085. $date->set(1234567890);
  2086. try {
  2087. $date->set('noday', Date::DATETIME_FULL);
  2088. $this->fail();
  2089. } catch (\Zend\Date\Exception\ExceptionInterface $e) {
  2090. // success
  2091. }
  2092. $date->set($d2, Date::DATETIME_FULL);
  2093. $this->assertSame('2002-01-04T04:36:50+05:00', $date->get(Date::W3C));
  2094. $date->set(1234567890);
  2095. $date->set('Samstag, 14. Februar 2009 15:26 Uhr CET', Date::DATETIME_FULL);
  2096. $this->assertSame('2009-02-14T15:26:00+01:00', $date->get(Date::W3C));
  2097. $date->set(1234567890);
  2098. try {
  2099. $date->set('noday', Date::DATETIME_LONG);
  2100. $this->fail();
  2101. } catch (\Zend\Date\Exception\ExceptionInterface $e) {
  2102. // success
  2103. }
  2104. $date->set($d2, Date::DATETIME_LONG);
  2105. $this->assertSame('2002-01-04T04:36:50+05:00', $date->get(Date::W3C));
  2106. $date->set(1234567890);
  2107. $date->set('14. Februar 2009 15:26:03 CET', Date::DATETIME_LONG);
  2108. $this->assertSame('2009-02-14T15:26:03+01:00', $date->get(Date::W3C));
  2109. $date->set(1234567890);
  2110. try {
  2111. $date->set('noday', Date::DATETIME_MEDIUM);
  2112. $this->fail();
  2113. } catch (\Zend\Date\Exception\ExceptionInterface $e) {
  2114. // success
  2115. }
  2116. $date->set($d2, Date::DATETIME_MEDIUM);
  2117. $this->assertSame('2002-01-04T04:36:50+05:00', $date->get(Date::W3C));
  2118. $date->set(1234567890);
  2119. $date->set('14.02.2009 15:26:31', Date::DATETIME_MEDIUM);
  2120. $this->assertSame('2009-02-14T15:26:31+05:00', $date->get(Date::W3C));
  2121. $date->set(1234567890);
  2122. try {
  2123. $date->set('noday', Date::DATETIME_SHORT);
  2124. $this->fail();
  2125. } catch (\Zend\Date\Exception\ExceptionInterface $e) {
  2126. // success
  2127. }
  2128. $date->set($d2, Date::DATETIME_SHORT);
  2129. $this->assertSame('2002-01-04T04:36:00+05:00', $date->get(Date::W3C));
  2130. $date->set(1234567890);
  2131. $date->set('14.02.09 15:26', Date::DATETIME_SHORT);
  2132. $this->assertSame('2009-02-14T15:26:00+05:00', $date->get(Date::W3C));
  2133. $date->set(1234567890);
  2134. try {
  2135. $date->set('noday', Date::ATOM);
  2136. $this->fail();
  2137. } catch (\Zend\Date\Exception\ExceptionInterface $e) {
  2138. // success
  2139. }
  2140. $date->set($d2, Date::ATOM);
  2141. $this->assertSame('2002-01-04T04:36:50+05:00', $date->get(Date::W3C));
  2142. $date->set(1234567890);
  2143. $date->set('2009-02-14T00:31:30+05:00', Date::ATOM);
  2144. $this->assertSame('2009-02-14T00:31:30+05:00', $date->get(Date::W3C));
  2145. $date->set(1234567890);
  2146. try {
  2147. $date->set('noday', Date::COOKIE);
  2148. $this->fail();
  2149. } catch (\Zend\Date\Exception\ExceptionInterface $e) {
  2150. // success
  2151. }
  2152. $date->set($d2, Date::COOKIE);
  2153. $this->assertSame('2002-01-04T04:36:50+05:00', $date->get(Date::W3C));
  2154. $date->set(1234567890);
  2155. $date->set('Saturday, 14-Feb-09 00:31:30 Europe/Vienna', Date::COOKIE);
  2156. $this->assertSame('2009-02-14T00:31:30+01:00', $date->get(Date::W3C));
  2157. $date->set(1234567890);
  2158. try {
  2159. $date->set('noday', Date::RFC_822);
  2160. $this->fail();
  2161. } catch (\Zend\Date\Exception\ExceptionInterface $e) {
  2162. // success
  2163. }
  2164. $date->set($d2, Date::RFC_822);
  2165. $this->assertSame('2002-01-04T04:36:50+05:00', $date->get(Date::W3C));
  2166. $date->set(1234567890);
  2167. $date->set('Sat, 14 Feb 09 00:31:30 +0500', Date::RFC_822);
  2168. $this->assertSame('2009-02-14T00:31:30+05:00', $date->get(Date::W3C));
  2169. $date->set(1234567890);
  2170. try {
  2171. $date->set('noday', Date::RFC_850);
  2172. $this->fail();
  2173. } catch (\Zend\Date\Exception\ExceptionInterface $e) {
  2174. // success
  2175. }
  2176. $date->set($d2, Date::RFC_850);
  2177. $this->assertSame('2002-01-04T04:36:50+05:00', $date->get(Date::W3C));
  2178. $date->set(1234567890);
  2179. $date->set('Saturday, 14-Feb-09 00:31:30 Europe/Vienna', Date::RFC_850);
  2180. $this->assertSame('2009-02-14T00:31:30+01:00', $date->get(Date::W3C));
  2181. $date->set(1234567890);
  2182. try {
  2183. $date->set('noday', Date::RFC_1036);
  2184. $this->fail();
  2185. } catch (\Zend\Date\Exception\ExceptionInterface $e) {
  2186. // success
  2187. }
  2188. $date->set($d2, Date::RFC_1036);
  2189. $this->assertSame('2002-01-04T04:36:50+05:00', $date->get(Date::W3C));
  2190. $date->set(1234567890);
  2191. $date->set('Sat, 14 Feb 09 00:31:30 +0500', Date::RFC_1036);
  2192. $this->assertSame('2009-02-14T00:31:30+05:00', $date->get(Date::W3C));
  2193. $date->set(1234567890);
  2194. try {
  2195. $date->set('noday', Date::RFC_1123);
  2196. $this->fail();
  2197. } catch (\Zend\Date\Exception\ExceptionInterface $e) {
  2198. // success
  2199. }
  2200. $date->set($d2, Date::RFC_1123);
  2201. $this->assertSame('2002-01-04T04:36:50+05:00', $date->get(Date::W3C));
  2202. $date->set(1234567890);
  2203. $date->set('Sat, 14 Feb 2009 00:31:30 +0500', Date::RFC_1123);
  2204. $this->assertSame('2009-02-14T00:31:30+05:00', $date->get(Date::W3C));
  2205. $date->set(1234567890);
  2206. try {
  2207. $date->set('noday', Date::RFC_3339);
  2208. $this->fail();
  2209. } catch (\Zend\Date\Exception\ExceptionInterface $e) {
  2210. // success
  2211. }
  2212. $date->set($d2, Date::RFC_3339);
  2213. $this->assertSame('2002-01-04T04:36:50+05:00', $date->get(Date::W3C));
  2214. $date->set(1234567890);
  2215. $date->set('2009-02-14T00:31:30+05:00', Date::RFC_3339);
  2216. $this->assertSame('2009-02-14T00:31:30+05:00', $date->get(Date::W3C));
  2217. $date->set(1234567890);
  2218. try {
  2219. $date->set('noday', Date::RSS);
  2220. $this->fail();
  2221. } catch (\Zend\Date\Exception\ExceptionInterface $e) {
  2222. // success
  2223. }
  2224. $date->set($d2, Date::RSS);
  2225. $this->assertSame('2002-01-04T04:36:50+05:00', $date->get(Date::W3C));
  2226. $date->set(1234567890);
  2227. $date->set('Sat, 14 Feb 2009 00:31:30 +0500', Date::RSS);
  2228. $this->assertSame('2009-02-14T00:31:30+05:00', $date->get(Date::W3C));
  2229. $date->set('Sat, 14 Feb 2009 00:31:30 GMT', Date::RSS);
  2230. $this->assertSame('2009-02-14T00:31:30+00:00', $date->get(Date::W3C));
  2231. $date->set('Sat, 14 Feb 09 00:31:30 GMT', Date::RSS);
  2232. $this->assertSame('2009-02-14T00:31:30+00:00', $date->get(Date::W3C));
  2233. $date->set('Sat, 14 Feb 09 00:31:30 +0500', Date::RSS);
  2234. $this->assertSame('2009-02-14T00:31:30+05:00', $date->get(Date::W3C));
  2235. $date->set(1234567890);
  2236. try {
  2237. $date->set('noday', Date::W3C);
  2238. $this->fail();
  2239. } catch (\Zend\Date\Exception\ExceptionInterface $e) {
  2240. // success
  2241. }
  2242. $date->set($d2, Date::W3C);
  2243. $this->assertSame('2002-01-04T04:36:50+05:00', $date->get(Date::W3C));
  2244. $date->set(1234567890);
  2245. $date->set('2009-02-14T00:31:30+05:00', Date::W3C);
  2246. $this->assertSame('2009-02-14T00:31:30+05:00', $date->get(Date::W3C));
  2247. $date->set('2009-02-14T00:31:30-05:00', Date::W3C);
  2248. $this->assertSame('2009-02-14T00:31:30-05:00', $date->get(Date::W3C));
  2249. $date->setTimezone('Indian/Maldives');
  2250. $date->set(1234567890);
  2251. try {
  2252. $date->set('noday', 'xx');
  2253. $this->fail();
  2254. } catch (\Zend\Date\Exception\ExceptionInterface $e) {
  2255. // success
  2256. }
  2257. try {
  2258. $date->set($d2, 'xx');
  2259. $this->fail();
  2260. } catch (\Zend\Date\Exception\ExceptionInterface $e) {
  2261. // success
  2262. }
  2263. $date->set(1234567890);
  2264. $date->set('1000', 'xx');
  2265. $this->assertSame('1970-01-01T05:16:40+05:00', $date->get(Date::W3C));
  2266. }
  2267. /**
  2268. * Test for add
  2269. */
  2270. public function testAdd()
  2271. {
  2272. $locale = new Locale('de_AT');
  2273. $date = new Date(0,null,$locale);
  2274. $d2 = new Date(1010101010,null,$locale);
  2275. $retour = $date->set(1234567890);
  2276. $this->assertSame($retour->getTimestamp(),'1234567890');
  2277. $this->assertSame($date->add(10)->getTimestamp(),'1234567900');
  2278. $this->assertSame($date->add(-10)->getTimestamp(),'1234567890');
  2279. $this->assertSame($date->add(0)->getTimestamp(),'1234567890');
  2280. $date->set($d2);
  2281. $date->add(10, Date::DAY);
  2282. $this->assertSame('2002-01-14T04:36:50+05:00', $date->get(Date::W3C));
  2283. $date->add(-10, Date::DAY);
  2284. $this->assertSame('2002-01-04T04:36:50+05:00', $date->get(Date::W3C));
  2285. $date->set($d2);
  2286. $date->add('Mon', Date::WEEKDAY_SHORT);
  2287. $this->assertSame('2002-01-05T04:36:50+05:00', $date->get(Date::W3C));
  2288. $date->set($d2);
  2289. $date->add(10, Date::DAY_SHORT);
  2290. $this->assertSame('2002-01-14T04:36:50+05:00', $date->get(Date::W3C));
  2291. $date->add(-10, Date::DAY_SHORT);
  2292. $this->assertSame('2002-01-04T04:36:50+05:00', $date->get(Date::W3C));
  2293. $date->set($d2);
  2294. $date->add('Montag', Date::WEEKDAY);
  2295. $this->assertSame('2002-01-05T04:36:50+05:00', $date->get(Date::W3C));
  2296. $date->set($d2);
  2297. $date->add(1, Date::WEEKDAY_8601);
  2298. $this->assertSame('2002-01-05T04:36:50+05:00', $date->get(Date::W3C));
  2299. $date->set($d2);
  2300. try {
  2301. $date->add($d2, Date::DAY_SUFFIX);
  2302. $this->fail('exception expected');
  2303. } catch (\Zend\Date\Exception\ExceptionInterface $e) {
  2304. // success
  2305. }
  2306. }
  2307. /**
  2308. * Test for add
  2309. */
  2310. public function testAdd2()
  2311. {
  2312. if (!defined('TESTS_ZEND_I18N_EXTENDED_COVERAGE') || TESTS_ZEND_I18N_EXTENDED_COVERAGE == false) {
  2313. $this->markTestSkipped('Extended I18N test skipped');
  2314. return;
  2315. }
  2316. $locale = new Locale('de_AT');
  2317. $date = new Date(0,null,$locale);
  2318. $d2 = new Date(1010101010,null,$locale);
  2319. $date->set($d2);
  2320. $date->add(1, Date::WEEKDAY_DIGIT);
  2321. $this->assertSame('2002-01-05T04:36:50+05:00', $date->get(Date::W3C));
  2322. $date->set($d2);
  2323. $date->add(10, Date::DAY_OF_YEAR);
  2324. $this->assertSame('2002-01-14T04:36:50+05:00', $date->get(Date::W3C));
  2325. $date->add(-10, Date::DAY_OF_YEAR);
  2326. $this->assertSame('2002-01-04T04:36:50+05:00', $date->get(Date::W3C));
  2327. $date->set($d2);
  2328. $date->add('M', Date::WEEKDAY_NARROW);
  2329. $this->assertSame('2002-01-05T04:36:50+05:00', $date->get(Date::W3C));
  2330. $date->set($d2);
  2331. $date->add('Mo.', Date::WEEKDAY_NAME);
  2332. $this->assertSame('2002-01-05T04:36:50+05:00', $date->get(Date::W3C));
  2333. $date->set($d2);
  2334. $date->add(10, Date::WEEK);
  2335. $this->assertSame('2002-03-15T04:36:50+05:00', $date->get(Date::W3C));
  2336. $date->add(-10, Date::WEEK);
  2337. $this->assertSame('2002-01-04T04:36:50+05:00', $date->get(Date::W3C));
  2338. $date->set($d2);
  2339. $date->add('April', Date::MONTH_NAME);
  2340. $this->assertSame('2002-08-04T04:36:50+05:00', $date->get(Date::W3C));
  2341. $date->set($d2);
  2342. $date->add(10, Date::MONTH);
  2343. $this->assertSame('2002-11-04T04:36:50+05:00', $date->get(Date::W3C));
  2344. $date->add(-10, Date::MONTH);
  2345. $this->assertSame('2002-01-04T04:36:50+05:00', $date->get(Date::W3C));
  2346. $date->set($d2);
  2347. $date->add('Apr', Date::MONTH_NAME_SHORT);
  2348. $this->assertSame('2002-08-04T04:36:50+05:00', $date->get(Date::W3C));
  2349. $date->set($d2);
  2350. $date->add(10, Date::MONTH_SHORT);
  2351. $this->assertSame('2002-11-04T04:36:50+05:00', $date->get(Date::W3C));
  2352. $date->add(-10, Date::MONTH_SHORT);
  2353. $this->assertSame('2002-01-04T04:36:50+05:00', $date->get(Date::W3C));
  2354. $date->set($d2);
  2355. try {
  2356. $date->add($d2, Date::MONTH_DAYS);
  2357. $this->fail('exception expected');
  2358. } catch (\Zend\Date\Exception\ExceptionInterface $e) {
  2359. // success
  2360. }
  2361. $date->set($d2);
  2362. $date->add('M', Date::MONTH_NAME_NARROW);
  2363. $this->assertSame('2002-06-04T04:36:50+05:00', $date->get(Date::W3C));
  2364. $date->set($d2);
  2365. try {
  2366. $date->add($d2, Date::LEAPYEAR);
  2367. $this->fail('exception expected');
  2368. } catch (\Zend\Date\Exception\ExceptionInterface $e) {
  2369. // success
  2370. }
  2371. $date->set($d2);
  2372. $date->add(10, Date::YEAR_8601);
  2373. $this->assertSame('2012-01-04T04:36:50+05:00', $date->get(Date::W3C));
  2374. $date->add(-10, Date::YEAR_8601);
  2375. $this->assertSame('2002-01-04T04:36:50+05:00', $date->get(Date::W3C));
  2376. $date->set($d2);
  2377. $date->add(10, Date::YEAR);
  2378. $this->assertSame('2012-01-04T04:36:50+05:00', $date->get(Date::W3C));
  2379. $date->add(-10, Date::YEAR);
  2380. $this->assertSame('2002-01-04T04:36:50+05:00', $date->get(Date::W3C));
  2381. $date->set($d2);
  2382. $date->add(10, Date::YEAR_SHORT);
  2383. $this->assertSame('2012-01-04T04:36:50+05:00', $date->get(Date::W3C));
  2384. $date->add(-10, Date::YEAR_SHORT);
  2385. $this->assertSame('2002-01-04T04:36:50+05:00', $date->get(Date::W3C));
  2386. $date->set($d2);
  2387. $date->add(10, Date::YEAR_SHORT_8601);
  2388. $this->assertSame('2012-01-04T04:36:50+05:00', $date->get(Date::W3C));
  2389. $date->add(-10, Date::YEAR_SHORT_8601);
  2390. $this->assertSame('2002-01-04T04:36:50+05:00', $date->get(Date::W3C));
  2391. $date->set($d2);
  2392. try {
  2393. $date->add('noday', Date::MERIDIEM);
  2394. $this->fail();
  2395. } catch (\Zend\Date\Exception\ExceptionInterface $e) {
  2396. // success
  2397. }
  2398. $date->set($d2);
  2399. $date->add(10, Date::SWATCH);
  2400. $this->assertSame('2002-01-04T04:51:14+05:00', $date->get(Date::W3C));
  2401. $date->add(-10, Date::SWATCH);
  2402. $this->assertSame('2002-01-04T04:36:49+05:00', $date->get(Date::W3C));
  2403. $date->set($d2);
  2404. $date->add(10, Date::HOUR_SHORT_AM);
  2405. $this->assertSame('2002-01-04T14:36:50+05:00', $date->get(Date::W3C));
  2406. $date->add(-10, Date::HOUR_SHORT_AM);
  2407. $this->assertSame('2002-01-04T04:36:50+05:00', $date->get(Date::W3C));
  2408. $date->set($d2);
  2409. $date->add(10, Date::HOUR_SHORT);
  2410. $this->assertSame('2002-01-04T14:36:50+05:00', $date->get(Date::W3C));
  2411. $date->add(-10, Date::HOUR_SHORT);
  2412. $this->assertSame('2002-01-04T04:36:50+05:00', $date->get(Date::W3C));
  2413. $date->set($d2);
  2414. $date->add(10, Date::HOUR_AM);
  2415. $this->assertSame('2002-01-04T14:36:50+05:00', $date->get(Date::W3C));
  2416. $date->add(-10, Date::HOUR_AM);
  2417. $this->assertSame('2002-01-04T04:36:50+05:00', $date->get(Date::W3C));
  2418. $date->set($d2);
  2419. $date->add(10, Date::HOUR);
  2420. $this->assertSame('2002-01-04T14:36:50+05:00', $date->get(Date::W3C));
  2421. $date->add(-10, Date::HOUR);
  2422. $this->assertSame('2002-01-04T04:36:50+05:00', $date->get(Date::W3C));
  2423. $date->set($d2);
  2424. $date->add(10, Date::MINUTE);
  2425. $this->assertSame('2002-01-04T04:46:50+05:00', $date->get(Date::W3C));
  2426. $date->add(-10, Date::MINUTE);
  2427. $this->assertSame('2002-01-04T04:36:50+05:00', $date->get(Date::W3C));
  2428. $date->set($d2);
  2429. $date->add(10, Date::MINUTE_SHORT);
  2430. $this->assertSame('2002-01-04T04:46:50+05:00', $date->get(Date::W3C));
  2431. $date->add(-10, Date::MINUTE_SHORT);
  2432. $this->assertSame('2002-01-04T04:36:50+05:00', $date->get(Date::W3C));
  2433. $date->set($d2);
  2434. $date->add(10, Date::SECOND);
  2435. $this->assertSame('2002-01-04T04:37:00+05:00', $date->get(Date::W3C));
  2436. $date->add(-10, Date::SECOND);
  2437. $this->assertSame('2002-01-04T04:36:50+05:00', $date->get(Date::W3C));
  2438. $date->set($d2);
  2439. $date->add(10, Date::SECOND_SHORT);
  2440. $this->assertSame('2002-01-04T04:37:00+05:00', $date->get(Date::W3C));
  2441. $date->add(-10, Date::SECOND_SHORT);
  2442. $this->assertSame('2002-01-04T04:36:50+05:00', $date->get(Date::W3C));
  2443. $date->set($d2);
  2444. $date->add(10, Date::MILLISECOND);
  2445. $this->assertSame('010', $date->get(Date::MILLISECOND));
  2446. $date->add(-10, Date::MILLISECOND);
  2447. $this->assertSame( '000', $date->get(Date::MILLISECOND));
  2448. $date->set($d2);
  2449. try {
  2450. $date->add('noday', Date::TIMEZONE_NAME);
  2451. $this->fail();
  2452. } catch (\Zend\Date\Exception\ExceptionInterface $e) {
  2453. // success
  2454. }
  2455. $date->set($d2);
  2456. try {
  2457. $date->add('noday', Date::DAYLIGHT);
  2458. $this->fail();
  2459. } catch (\Zend\Date\Exception\ExceptionInterface $e) {
  2460. // success
  2461. }
  2462. $date->set($d2);
  2463. try {
  2464. $date->add('noday', Date::GMT_DIFF);
  2465. $this->fail();
  2466. } catch (\Zend\Date\Exception\ExceptionInterface $e) {
  2467. // success
  2468. }
  2469. $date->set($d2);
  2470. try {
  2471. $date->add('noday', Date::GMT_DIFF_SEP);
  2472. $this->fail();
  2473. } catch (\Zend\Date\Exception\ExceptionInterface $e) {
  2474. // success
  2475. }
  2476. $date->set($d2);
  2477. try {
  2478. $date->add('noday', Date::TIMEZONE);
  2479. $this->fail();
  2480. } catch (\Zend\Date\Exception\ExceptionInterface $e) {
  2481. // success
  2482. }
  2483. $date->set($d2);
  2484. try {
  2485. $date->add('noday', Date::TIMEZONE_SECS);
  2486. $this->fail();
  2487. } catch (\Zend\Date\Exception\ExceptionInterface $e) {
  2488. // success
  2489. }
  2490. $date->set($d2);
  2491. $date->add('1000-01-02 20:05:12', Date::ISO_8601);
  2492. $this->assertSame('3002-02-07T19:42:02+05:00', $date->get(Date::W3C));
  2493. $date->set($d2);
  2494. $date->add('Thu, 02 Jan 1000 20:05:12 +0500', Date::RFC_2822);
  2495. $this->assertSame('3002-02-07T19:42:02+05:00', $date->get(Date::W3C));
  2496. $date->set($d2);
  2497. $date->add(10, Date::TIMESTAMP);
  2498. $this->assertSame('2002-01-04T04:37:00+05:00', $date->get(Date::W3C));
  2499. $date->set($d2);
  2500. try {
  2501. $date->add('noday', Date::ERA);
  2502. $this->fail();
  2503. } catch (\Zend\Date\Exception\ExceptionInterface $e) {
  2504. // success
  2505. }
  2506. $date->set($d2);
  2507. try {
  2508. $date->add('noday', Date::ERA_NAME);
  2509. $this->fail();
  2510. } catch (\Zend\Date\Exception\ExceptionInterface $e) {
  2511. // success
  2512. }
  2513. $date->set($d2);
  2514. $date->add('10.02.0005', Date::DATES);
  2515. $this->assertSame('2007-03-14T04:36:50+05:00', $date->get(Date::W3C));
  2516. $date->set($d2);
  2517. $date->add('Samstag, 10. Februar 0005', Date::DATE_FULL);
  2518. $this->assertSame('2007-03-14T04:36:50+05:00', $date->get(Date::W3C));
  2519. $date->set($d2);
  2520. $date->add('10. Februar 0005', Date::DATE_LONG);
  2521. $this->assertSame('2007-03-14T04:36:50+05:00', $date->get(Date::W3C));
  2522. $date->set($d2);
  2523. $date->add('10.02.0005', Date::DATE_MEDIUM);
  2524. $this->assertSame('2007-03-14T04:36:50+05:00', $date->get(Date::W3C));
  2525. $date->set($d2);
  2526. $date->add('10.02.05', Date::DATE_SHORT);
  2527. $this->assertSame('4007-03-14T04:36:50+05:00', $date->get(Date::W3C));
  2528. $date->set($d2);
  2529. $date->add('10:05:05', Date::TIMES);
  2530. $this->assertSame('2002-01-04T14:41:55+05:00', $date->get(Date::W3C));
  2531. $date->set($d2);
  2532. $date->add('10:05 Uhr CET', Date::TIME_FULL);
  2533. $this->assertSame('2002-01-04T14:41:50+05:00', $date->get(Date::W3C));
  2534. $date->set($d2);
  2535. $date->add('10:05:05 CET', Date::TIME_LONG);
  2536. $this->assertSame('2002-01-04T14:41:55+05:00', $date->get(Date::W3C));
  2537. $date->set($d2);
  2538. $date->add('10:05:05', Date::TIME_MEDIUM);
  2539. $this->assertSame('2002-01-04T14:41:55+05:00', $date->get(Date::W3C));
  2540. $date->set($d2);
  2541. $date->add('10:05', Date::TIME_SHORT);
  2542. $this->assertSame('2002-01-04T14:41:50+05:00', $date->get(Date::W3C));
  2543. $date->set($d2);
  2544. $date->add('10.02.0005 10:05:05', Date::DATETIME);
  2545. $this->assertSame('2007-03-14T14:41:55+05:00', $date->get(Date::W3C));
  2546. $date->set($d2);
  2547. $date->add('Samstag, 10. Februar 0005 10:05 Uhr CET', Date::DATETIME_FULL);
  2548. $this->assertSame('2007-03-14T14:41:50+05:00', $date->get(Date::W3C));
  2549. $date->set($d2);
  2550. $date->add('10. Februar 0005 10:05:05 CET', Date::DATETIME_LONG);
  2551. $this->assertSame('2007-03-14T14:41:55+05:00', $date->get(Date::W3C));
  2552. $date->set($d2);
  2553. $date->add('10.02.0005 10:05:05', Date::DATETIME_MEDIUM);
  2554. $this->assertSame('2007-03-14T14:41:55+05:00', $date->get(Date::W3C));
  2555. $date->set($d2);
  2556. $date->add('10.02.05 10:05', Date::DATETIME_SHORT);
  2557. $this->assertSame('4007-03-14T14:41:50+05:00', $date->get(Date::W3C));
  2558. $date->set($d2);
  2559. $date->add('1000-01-02T20:05:12+05:00', Date::ATOM);
  2560. $this->assertSame('3002-02-08T00:42:02+05:00', $date->get(Date::W3C));
  2561. $date->set($d2);
  2562. $date->add('Saturday, 02-Jan-00 20:05:12 Europe/Vienna', Date::COOKIE);
  2563. $this->assertSame('4002-02-07T00:42:02+05:00', $date->get(Date::W3C));
  2564. $date->set($d2);
  2565. $date->add('Sat, 02 Jan 00 20:05:12 +0500', Date::RFC_822);
  2566. $this->assertSame('4002-02-06T19:42:02+05:00', $date->get(Date::W3C));
  2567. $date->set($d2);
  2568. $date->add('Saturday, 02-Jan-00 20:05:12 Europe/Vienna', Date::RFC_850);
  2569. $this->assertSame('4002-02-07T00:42:02+05:00', $date->get(Date::W3C));
  2570. $date->set($d2);
  2571. $date->add('Sat, 02 Jan 00 20:05:12 +0500', Date::RFC_1036);
  2572. $this->assertSame('4002-02-06T19:42:02+05:00', $date->get(Date::W3C));
  2573. $date->set($d2);
  2574. $date->add('Sat, 02 Jan 1000 20:05:12 +0500', Date::RFC_1123);
  2575. $this->assertSame('3002-02-08T00:42:02+05:00', $date->get(Date::W3C));
  2576. $date->set($d2);
  2577. $date->add('1000-01-02T20:05:12+05:00', Date::RFC_3339);
  2578. $this->assertSame('3002-02-08T00:42:02+05:00', $date->get(Date::W3C));
  2579. $date->set($d2);
  2580. $date->add('Sat, 02 Jan 1000 20:05:12 +0500', Date::RSS);
  2581. $this->assertSame('3002-02-08T00:42:02+05:00', $date->get(Date::W3C));
  2582. $date->set($d2);
  2583. $date->add('1000-01-02T20:05:12+05:00', Date::W3C);
  2584. $this->assertSame('3002-02-08T00:42:02+05:00', $date->get(Date::W3C));
  2585. $date->set($d2);
  2586. $date->add('1000', 'xx');
  2587. $this->assertSame('2002-01-04T04:53:30+05:00', $date->get(Date::W3C));
  2588. }
  2589. /**
  2590. * Test for sub
  2591. */
  2592. public function testSub()
  2593. {
  2594. $locale = new Locale('de_AT');
  2595. $date = new Date(0,null,$locale);
  2596. $d2 = new Date(1010101010,null,$locale);
  2597. $retour = $date->set(1234567890);
  2598. $this->assertSame('1234567890', $retour->getTimestamp());
  2599. $this->assertSame('1234567900', $date->sub(-10)->getTimestamp());
  2600. $this->assertSame('1234567890', $date->sub( 10)->getTimestamp());
  2601. $this->assertSame('1234567890', $date->sub( 0)->getTimestamp());
  2602. $date->set($d2);
  2603. $date->sub(-10, Date::DAY);
  2604. $this->assertSame('2002-01-14T04:36:50+05:00', $date->get(Date::W3C));
  2605. $date->sub(10, Date::DAY);
  2606. $this->assertSame('2002-01-04T04:36:50+05:00', $date->get(Date::W3C));
  2607. }
  2608. /**
  2609. * Test for sub
  2610. */
  2611. public function testSub2()
  2612. {
  2613. if (!defined('TESTS_ZEND_I18N_EXTENDED_COVERAGE') || TESTS_ZEND_I18N_EXTENDED_COVERAGE == false) {
  2614. $this->markTestSkipped('Extended I18N test skipped');
  2615. return;
  2616. }
  2617. $locale = new Locale('de_AT');
  2618. $date = new Date(0,null,$locale);
  2619. $d2 = new Date(1010101010,null,$locale);
  2620. $date->set($d2);
  2621. $date->sub('Mon', Date::WEEKDAY_SHORT);
  2622. $this->assertSame('2002-01-03T04:36:50+05:00', $date->get(Date::W3C));
  2623. $date->set($d2);
  2624. $date->sub(-10, Date::DAY_SHORT);
  2625. $this->assertSame('2002-01-14T04:36:50+05:00', $date->get(Date::W3C));
  2626. $date->sub(10, Date::DAY_SHORT);
  2627. $this->assertSame('2002-01-04T04:36:50+05:00', $date->get(Date::W3C));
  2628. $date->set($d2);
  2629. $date->sub('Montag', Date::WEEKDAY);
  2630. $this->assertSame('2002-01-03T04:36:50+05:00', $date->get(Date::W3C));
  2631. $date->set($d2);
  2632. $date->sub(1, Date::WEEKDAY_8601);
  2633. $this->assertSame('2002-01-03T04:36:50+05:00', $date->get(Date::W3C));
  2634. $date->set($d2);
  2635. try {
  2636. $date->sub($d2, Date::DAY_SUFFIX);
  2637. $this->fail('exception expected');
  2638. } catch (\Zend\Date\Exception\ExceptionInterface $e) {
  2639. // success
  2640. }
  2641. $date->set($d2);
  2642. $date->sub(1, Date::WEEKDAY_DIGIT);
  2643. $this->assertSame('2002-01-03T04:36:50+05:00', $date->get(Date::W3C));
  2644. $date->set($d2);
  2645. $date->sub(-10, Date::DAY_OF_YEAR);
  2646. $this->assertSame('2002-01-14T04:36:50+05:00', $date->get(Date::W3C));
  2647. $date->sub(10, Date::DAY_OF_YEAR);
  2648. $this->assertSame('2002-01-04T04:36:50+05:00', $date->get(Date::W3C));
  2649. $date->set($d2);
  2650. $date->sub('M', Date::WEEKDAY_NARROW);
  2651. $this->assertSame('2002-01-03T04:36:50+05:00', $date->get(Date::W3C));
  2652. $date->set($d2);
  2653. $date->sub('Mo.', Date::WEEKDAY_NAME);
  2654. $this->assertSame('2002-01-03T04:36:50+05:00', $date->get(Date::W3C));
  2655. $date->set($d2);
  2656. $date->sub(-10, Date::WEEK);
  2657. $this->assertSame('2002-03-15T04:36:50+05:00', $date->get(Date::W3C));
  2658. $date->sub(10, Date::WEEK);
  2659. $this->assertSame('2002-01-04T04:36:50+05:00', $date->get(Date::W3C));
  2660. $date->set($d2);
  2661. $date->sub('April', Date::MONTH_NAME);
  2662. $this->assertSame('2001-09-04T04:36:50+05:00', $date->get(Date::W3C));
  2663. $date->set($d2);
  2664. $date->sub(-10, Date::MONTH);
  2665. $this->assertSame('2002-11-04T04:36:50+05:00', $date->get(Date::W3C));
  2666. $date->sub(10, Date::MONTH);
  2667. $this->assertSame('2002-01-04T04:36:50+05:00', $date->get(Date::W3C));
  2668. $date->set($d2);
  2669. $date->sub('Apr', Date::MONTH_NAME_SHORT);
  2670. $this->assertSame('2001-09-04T04:36:50+05:00', $date->get(Date::W3C));
  2671. $date->set($d2);
  2672. $date->sub(-10, Date::MONTH_SHORT);
  2673. $this->assertSame('2002-11-04T04:36:50+05:00', $date->get(Date::W3C));
  2674. $date->sub(10, Date::MONTH_SHORT);
  2675. $this->assertSame('2002-01-04T04:36:50+05:00', $date->get(Date::W3C));
  2676. $date->set($d2);
  2677. try {
  2678. $date->sub($d2, Date::MONTH_DAYS);
  2679. $this->fail('exception expected');
  2680. } catch (\Zend\Date\Exception\ExceptionInterface $e) {
  2681. // success
  2682. }
  2683. $date->set($d2);
  2684. $date->sub('M', Date::MONTH_NAME_NARROW);
  2685. $this->assertSame('2001-10-04T04:36:50+05:00', $date->get(Date::W3C));
  2686. $date->set($d2);
  2687. try {
  2688. $date->sub($d2, Date::LEAPYEAR);
  2689. $this->fail('exception expected');
  2690. } catch (\Zend\Date\Exception\ExceptionInterface $e) {
  2691. // success
  2692. }
  2693. $date->set($d2);
  2694. $date->sub(-10, Date::YEAR_8601);
  2695. $this->assertSame('2012-01-04T04:36:50+05:00', $date->get(Date::W3C));
  2696. $date->sub(10, Date::YEAR_8601);
  2697. $this->assertSame('2002-01-04T04:36:50+05:00', $date->get(Date::W3C));
  2698. $date->set($d2);
  2699. $date->sub(-10, Date::YEAR);
  2700. $this->assertSame('2012-01-04T04:36:50+05:00', $date->get(Date::W3C));
  2701. $date->sub(10, Date::YEAR);
  2702. $this->assertSame('2002-01-04T04:36:50+05:00', $date->get(Date::W3C));
  2703. $date->set($d2);
  2704. $date->sub(10, Date::YEAR_SHORT);
  2705. $this->assertSame('1992-01-04T04:36:50+05:00', $date->get(Date::W3C));
  2706. $date->sub(-10, Date::YEAR_SHORT);
  2707. $this->assertSame('2002-01-04T04:36:50+05:00', $date->get(Date::W3C));
  2708. $date->set($d2);
  2709. $date->sub(10, Date::YEAR_SHORT_8601);
  2710. $this->assertSame('1992-01-04T04:36:50+05:00', $date->get(Date::W3C));
  2711. $date->sub(-10, Date::YEAR_SHORT_8601);
  2712. $this->assertSame('2002-01-04T04:36:50+05:00', $date->get(Date::W3C));
  2713. $date->set($d2);
  2714. try {
  2715. $date->sub('noday', Date::MERIDIEM);
  2716. $this->fail();
  2717. } catch (\Zend\Date\Exception\ExceptionInterface $e) {
  2718. // success
  2719. }
  2720. $date->set($d2);
  2721. $date->sub(-10, Date::SWATCH);
  2722. $this->assertSame('2002-01-04T04:51:15+05:00', $date->get(Date::W3C));
  2723. $date->sub(10, Date::SWATCH);
  2724. $this->assertSame('2002-01-04T04:36:51+05:00', $date->get(Date::W3C));
  2725. $date->set($d2);
  2726. $date->sub(-10, Date::HOUR_SHORT_AM);
  2727. $this->assertSame('2002-01-04T14:36:50+05:00', $date->get(Date::W3C));
  2728. $date->sub(10, Date::HOUR_SHORT_AM);
  2729. $this->assertSame('2002-01-04T04:36:50+05:00', $date->get(Date::W3C));
  2730. $date->set($d2);
  2731. $date->sub(-10, Date::HOUR_SHORT);
  2732. $this->assertSame('2002-01-04T14:36:50+05:00', $date->get(Date::W3C));
  2733. $date->sub(10, Date::HOUR_SHORT);
  2734. $this->assertSame('2002-01-04T04:36:50+05:00', $date->get(Date::W3C));
  2735. $date->set($d2);
  2736. $date->sub(-10, Date::HOUR_AM);
  2737. $this->assertSame('2002-01-04T14:36:50+05:00', $date->get(Date::W3C));
  2738. $date->sub(10, Date::HOUR_AM);
  2739. $this->assertSame('2002-01-04T04:36:50+05:00', $date->get(Date::W3C));
  2740. $date->set($d2);
  2741. $date->sub(-10, Date::HOUR);
  2742. $this->assertSame('2002-01-04T14:36:50+05:00', $date->get(Date::W3C));
  2743. $date->sub(10, Date::HOUR);
  2744. $this->assertSame('2002-01-04T04:36:50+05:00', $date->get(Date::W3C));
  2745. $date->set($d2);
  2746. $date->sub(-10, Date::MINUTE);
  2747. $this->assertSame('2002-01-04T04:46:50+05:00', $date->get(Date::W3C));
  2748. $date->sub(10, Date::MINUTE);
  2749. $this->assertSame('2002-01-04T04:36:50+05:00', $date->get(Date::W3C));
  2750. $date->set($d2);
  2751. $date->sub(-10, Date::MINUTE_SHORT);
  2752. $this->assertSame('2002-01-04T04:46:50+05:00', $date->get(Date::W3C));
  2753. $date->sub(10, Date::MINUTE_SHORT);
  2754. $this->assertSame('2002-01-04T04:36:50+05:00', $date->get(Date::W3C));
  2755. $date->set($d2);
  2756. $date->sub(-10, Date::SECOND);
  2757. $this->assertSame('2002-01-04T04:37:00+05:00', $date->get(Date::W3C));
  2758. $date->sub(10, Date::SECOND);
  2759. $this->assertSame('2002-01-04T04:36:50+05:00', $date->get(Date::W3C));
  2760. $date->set($d2);
  2761. $date->sub(-10, Date::SECOND_SHORT);
  2762. $this->assertSame('2002-01-04T04:37:00+05:00', $date->get(Date::W3C));
  2763. $date->sub(10, Date::SECOND_SHORT);
  2764. $this->assertSame('2002-01-04T04:36:50+05:00', $date->get(Date::W3C));
  2765. $date->set($d2);
  2766. $date->sub(-10, Date::MILLISECOND);
  2767. $this->assertSame('010', $date->get(Date::MILLISECOND));
  2768. $date->sub(10, Date::MILLISECOND);
  2769. $this->assertSame( '000', $date->get(Date::MILLISECOND));
  2770. $date->set($d2);
  2771. try {
  2772. $date->sub('noday', Date::TIMEZONE_NAME);
  2773. $this->fail();
  2774. } catch (\Zend\Date\Exception\ExceptionInterface $e) {
  2775. // success
  2776. }
  2777. $date->set($d2);
  2778. try {
  2779. $date->sub('noday', Date::DAYLIGHT);
  2780. $this->fail();
  2781. } catch (\Zend\Date\Exception\ExceptionInterface $e) {
  2782. // success
  2783. }
  2784. $date->set($d2);
  2785. try {
  2786. $date->sub('noday', Date::GMT_DIFF);
  2787. $this->fail();
  2788. } catch (\Zend\Date\Exception\ExceptionInterface $e) {
  2789. // success
  2790. }
  2791. $date->set($d2);
  2792. try {
  2793. $date->sub('noday', Date::GMT_DIFF_SEP);
  2794. $this->fail();
  2795. } catch (\Zend\Date\Exception\ExceptionInterface $e) {
  2796. // success
  2797. }
  2798. $date->set($d2);
  2799. try {
  2800. $date->sub('noday', Date::TIMEZONE);
  2801. $this->fail();
  2802. } catch (\Zend\Date\Exception\ExceptionInterface $e) {
  2803. // success
  2804. }
  2805. $date->set($d2);
  2806. try {
  2807. $date->sub('noday', Date::TIMEZONE_SECS);
  2808. $this->fail();
  2809. } catch (\Zend\Date\Exception\ExceptionInterface $e) {
  2810. // success
  2811. }
  2812. $date->set($d2);
  2813. $date->sub('1000-01-02 20:05:12', Date::ISO_8601);
  2814. $this->assertSame('1001-11-25T13:31:38+05:00', $date->get(Date::W3C));
  2815. $date->set($d2);
  2816. $date->sub('1000-01-02T20:05:12+05:00', Date::ISO_8601);
  2817. $this->assertSame('1001-11-25T13:31:38+05:00', $date->get(Date::W3C));
  2818. $date->set($d2);
  2819. $date->sub('Thu, 02 Jan 1000 20:05:12 +0500', Date::RFC_2822);
  2820. $this->assertSame('1001-11-25T13:31:38+05:00', $date->get(Date::W3C));
  2821. $date->set($d2);
  2822. $date->sub(-10, Date::TIMESTAMP);
  2823. $this->assertSame('2002-01-04T04:37:00+05:00', $date->get(Date::W3C));
  2824. $date->set($d2);
  2825. try {
  2826. $date->sub('noday', Date::ERA);
  2827. $this->fail();
  2828. } catch (\Zend\Date\Exception\ExceptionInterface $e) {
  2829. // success
  2830. }
  2831. $date->set($d2);
  2832. try {
  2833. $date->sub('noday', Date::ERA_NAME);
  2834. $this->fail();
  2835. } catch (\Zend\Date\Exception\ExceptionInterface $e) {
  2836. // success
  2837. }
  2838. $date->set($d2);
  2839. $date->sub('10.02.0005', Date::DATES);
  2840. $this->assertSame('1996-10-27T04:36:50+05:00', $date->get(Date::W3C));
  2841. $date->set($d2);
  2842. $date->sub('Samstag, 10. Februar 0005', Date::DATE_FULL);
  2843. $this->assertSame('1996-10-27T04:36:50+05:00', $date->get(Date::W3C));
  2844. $date->set($d2);
  2845. $date->sub('10. Februar 0005', Date::DATE_LONG);
  2846. $this->assertSame('1996-10-27T04:36:50+05:00', $date->get(Date::W3C));
  2847. $date->set($d2);
  2848. $date->sub('10.02.0005', Date::DATE_MEDIUM);
  2849. $this->assertSame('1996-10-27T04:36:50+05:00', $date->get(Date::W3C));
  2850. $date->set($d2);
  2851. $date->sub('10.02.05', Date::DATE_SHORT);
  2852. $this->assertSame('-4-10-29T04:36:50+05:00', $date->get(Date::W3C));
  2853. $date->set($d2);
  2854. $date->sub('10:05:05', Date::TIMES);
  2855. $this->assertSame('2002-01-03T18:31:45+05:00', $date->get(Date::W3C));
  2856. $date->set($d2);
  2857. $date->sub('10:05 Uhr CET', Date::TIME_FULL);
  2858. $this->assertSame('2002-01-03T18:31:50+05:00', $date->get(Date::W3C));
  2859. $date->set($d2);
  2860. $date->sub('10:05:05 CET', Date::TIME_LONG);
  2861. $this->assertSame('2002-01-03T18:31:45+05:00', $date->get(Date::W3C));
  2862. $date->set($d2);
  2863. $date->sub('10:05:05', Date::TIME_MEDIUM);
  2864. $this->assertSame('2002-01-03T18:31:45+05:00', $date->get(Date::W3C));
  2865. $date->set($d2);
  2866. $date->sub('10:05', Date::TIME_SHORT);
  2867. $this->assertSame('2002-01-03T18:31:50+05:00', $date->get(Date::W3C));
  2868. $date->set($d2);
  2869. $date->sub('10.02.0005 10:05:05', Date::DATETIME);
  2870. $this->assertSame('1996-10-26T18:31:45+05:00', $date->get(Date::W3C));
  2871. $date->set($d2);
  2872. $date->sub('Samstag, 10. Februar 0005 10:05 Uhr CET', Date::DATETIME_FULL);
  2873. $this->assertSame('1996-10-26T18:31:50+05:00', $date->get(Date::W3C));
  2874. $date->set($d2);
  2875. $date->sub('10. Februar 0005 10:05:05 CET', Date::DATETIME_LONG);
  2876. $this->assertSame('1996-10-26T18:31:45+05:00', $date->get(Date::W3C));
  2877. $date->set($d2);
  2878. $date->sub('10.02.0005 10:05:05', Date::DATETIME_MEDIUM);
  2879. $this->assertSame('1996-10-26T18:31:45+05:00', $date->get(Date::W3C));
  2880. $date->set($d2);
  2881. $date->sub('10.02.05 10:05', Date::DATETIME_SHORT);
  2882. $this->assertSame('-4-10-28T18:31:50+05:00', $date->get(Date::W3C));
  2883. $date->set($d2);
  2884. $date->sub('1000-01-02T20:05:12+05:00', Date::ATOM);
  2885. $this->assertSame('1001-11-25T08:31:38+05:00', $date->get(Date::W3C));
  2886. $date->set($d2);
  2887. $date->sub('Saturday, 02-Jan-00 20:05:12 Europe/Vienna', Date::COOKIE);
  2888. $this->assertSame('1-12-03T08:31:38+05:00', $date->get(Date::W3C) );
  2889. $date->set($d2);
  2890. $date->sub('Sat, 02 Jan 00 20:05:12 +0500', Date::RFC_822);
  2891. $this->assertSame('1-12-03T13:31:38+05:00', $date->get(Date::W3C));
  2892. $date->set($d2);
  2893. $date->sub('Saturday, 02-Jan-00 20:05:12 Europe/Vienna', Date::RFC_850);
  2894. $this->assertSame('1-12-03T08:31:38+05:00', $date->get(Date::W3C));
  2895. $date->set($d2);
  2896. $date->sub('Sat, 02 Jan 00 20:05:12 +0500', Date::RFC_1036);
  2897. $this->assertSame('1-12-03T13:31:38+05:00', $date->get(Date::W3C));
  2898. $date->set($d2);
  2899. $date->sub('Sat, 02 Jan 1000 20:05:12 +0500', Date::RFC_1123);
  2900. $this->assertSame('1001-11-25T08:31:38+05:00', $date->get(Date::W3C));
  2901. $date->set($d2);
  2902. $date->sub('1000-01-02T20:05:12+05:00', Date::RFC_3339);
  2903. $this->assertSame('1001-11-25T08:31:38+05:00', $date->get(Date::W3C));
  2904. $date->set($d2);
  2905. $date->sub('Sat, 02 Jan 1000 20:05:12 +0500', Date::RSS);
  2906. $this->assertSame('1001-11-25T08:31:38+05:00', $date->get(Date::W3C));
  2907. $date->set($d2);
  2908. $date->sub('1000-01-02T20:05:12+05:00', Date::W3C);
  2909. $this->assertSame('1001-11-25T08:31:38+05:00', $date->get(Date::W3C));
  2910. $date->set($d2);
  2911. $date->sub('1000', 'xx');
  2912. $this->assertSame('2002-01-04T04:20:10+05:00', $date->get(Date::W3C));
  2913. }
  2914. /**
  2915. * Test for compare
  2916. */
  2917. public function testCompare()
  2918. {
  2919. $locale = new Locale('de_AT');
  2920. $date = new Date(0,null,$locale);
  2921. $d2 = new Date(1010101010,null,$locale);//03.01.2002 15:36:50
  2922. $retour = $date->set(1234567890); //13.02.2009 15:31:30
  2923. $this->assertSame('1234567890', $retour->getTimestamp());
  2924. $this->assertSame( 0, $date->compare(1234567890));
  2925. $this->assertSame( 1, $date->compare(1234567800));
  2926. $this->assertSame(-1, $date->compare(1234567899));
  2927. $date->set($d2);//03.01.2002 15:36:50
  2928. $this->assertSame( 1, $date->compare(3,Date::DAY));
  2929. $this->assertSame( 0, $date->compare(4,Date::DAY));
  2930. $this->assertSame(-1, $date->compare(5,Date::DAY));
  2931. $this->assertSame( 1, $date->compare('Mon',Date::WEEKDAY_SHORT));
  2932. $this->assertSame(-1, $date->compare('Sam',Date::WEEKDAY_SHORT));
  2933. $date->set($d2);//03.01.2002 15:36:50
  2934. $this->assertSame(0, $date->compare(0,Date::MILLISECOND));
  2935. }
  2936. /**
  2937. * Test for copy
  2938. */
  2939. public function testCopy()
  2940. {
  2941. $locale = new Locale('de_AT');
  2942. $date = new Date(0,null,$locale);
  2943. $d2 = new Date(1010101010,null,$locale);
  2944. $date->set(1234567890);
  2945. $newdate = clone $date;
  2946. $this->assertSame($date->get(),$newdate->get());
  2947. $date->set($d2);
  2948. $newdate = $date->copyPart(Date::DAY);
  2949. $this->assertSame('2002-01-04T04:36:50+05:00', $date->get(Date::W3C ));
  2950. $this->assertSame('1970-01-04T05:00:00+05:00', $newdate->get(Date::W3C));
  2951. }
  2952. /**
  2953. * Test for equals
  2954. */
  2955. public function testEquals()
  2956. {
  2957. $locale = new Locale('de_AT');
  2958. $date = new Date(0,null,$locale);
  2959. $d2 = new Date(1010101010,null,$locale);
  2960. $retour = $date->set(1234567890);
  2961. $this->assertSame('1234567890', $retour->getTimestamp());
  2962. $this->assertTrue( $date->equals(1234567890));
  2963. $this->assertFalse($date->equals(1234567800));
  2964. $date->set($d2);
  2965. $this->assertFalse($date->equals(3,Date::DAY));
  2966. $this->assertTrue( $date->equals(4,Date::DAY));
  2967. }
  2968. /**
  2969. * Test for isEarlier
  2970. */
  2971. public function testIsEarlier()
  2972. {
  2973. $locale = new Locale('de_AT');
  2974. $date = new Date(0,null,$locale);
  2975. $d2 = new Date(1010101010,null,$locale);
  2976. $retour = $date->set(1234567890);
  2977. $this->assertSame('1234567890', $retour->getTimestamp());
  2978. $this->assertFalse($date->isEarlier(1234567890));
  2979. $this->assertFalse($date->isEarlier(1234567800));
  2980. $this->assertTrue( $date->isEarlier(1234567899));
  2981. $date->set($d2);
  2982. $this->assertFalse($date->isEarlier(3,Date::DAY));
  2983. $this->assertFalse($date->isEarlier(4,Date::DAY));
  2984. $this->assertTrue( $date->isEarlier(5,Date::DAY));
  2985. }
  2986. /**
  2987. * Test for isLater
  2988. */
  2989. public function testIsLater()
  2990. {
  2991. $locale = new Locale('de_AT');
  2992. $date = new Date(0,null,$locale);
  2993. $d2 = new Date(1010101010,null,$locale);
  2994. $retour = $date->set(1234567890);
  2995. $this->assertSame('1234567890', $retour->getTimestamp());
  2996. $this->assertFalse($date->isLater(1234567890));
  2997. $this->assertTrue( $date->isLater(1234567800));
  2998. $this->assertFalse($date->isLater(1234567899));
  2999. $date->set($d2);
  3000. $this->assertTrue( $date->isLater(3,Date::DAY));
  3001. $this->assertFalse($date->isLater(4,Date::DAY));
  3002. $this->assertFalse($date->isLater(5,Date::DAY));
  3003. }
  3004. /**
  3005. * Test for getTime
  3006. */
  3007. public function testGetTime()
  3008. {
  3009. $locale = new Locale('de_AT');
  3010. $date = new Date(1010101010,null,$locale);
  3011. $d2 = new Date(1010101010,null,$locale);
  3012. $result = $date->getTime();
  3013. $this->assertSame('1970-01-01T04:36:50+05:00', $result->get(Date::W3C));
  3014. }
  3015. /**
  3016. * Test for setTime
  3017. */
  3018. public function testSetTime()
  3019. {
  3020. $locale = new Locale('de_AT');
  3021. $date = new Date(1234567890,null,$locale);
  3022. $d2 = new Date(1234567899,null,$locale);
  3023. $result = $date->setTime(Date::now());
  3024. $this->assertTrue($result instanceof Date);
  3025. $result = $date->setTime('10:20:30');
  3026. $this->assertSame('2009-02-14T10:20:30+05:00', $result->get(Date::W3C));
  3027. $this->assertSame('2009-02-14T10:20:30+05:00', $date->get(Date::W3C));
  3028. $date->setTime('30-20-10','ss:mm:HH');
  3029. $this->assertSame('2009-02-14T10:20:30+05:00', $date->get(Date::W3C));
  3030. $date->setTime($d2);
  3031. $this->assertSame('2009-02-14T04:31:39+05:00', $date->get(Date::W3C));
  3032. $date = new Date(Date::now(), $locale);
  3033. $t1 = $date->get(Date::TIMESTAMP);
  3034. $date->setTime(Date::now());
  3035. $t2 = $date->get(Date::TIMESTAMP);
  3036. $diff = abs($t2 - $t1);
  3037. $this->assertTrue($diff < 2, "Instance of Zend_Date has a significantly different time than returned by setTime(): $diff seconds");
  3038. }
  3039. /**
  3040. * Test for addTime
  3041. */
  3042. public function testAddTime()
  3043. {
  3044. $locale = new Locale('de_AT');
  3045. $date = new Date(1234567890,null,$locale);
  3046. $d2 = new Date(1234567899,null,$locale);
  3047. $result = $date->addTime(Date::now());
  3048. $this->assertTrue($result instanceof Date);
  3049. $date = new Date(1234567890,null,$locale);
  3050. $result = $date->addTime('10:20:30');
  3051. $this->assertSame('2009-02-14T14:52:00+05:00', $result->get(Date::W3C));
  3052. $this->assertSame('2009-02-14T14:52:00+05:00', $date->get(Date::W3C));
  3053. $date = new Date(1234567890,null,$locale);
  3054. $date->addTime('30:20:10','ss:mm:HH');
  3055. $this->assertSame('2009-02-14T14:52:00+05:00', $date->get(Date::W3C));
  3056. $date = new Date(1234567890,null,$locale);
  3057. $date->addTime($d2);
  3058. $this->assertSame('2009-02-14T09:03:09+05:00', $date->get(Date::W3C));
  3059. }
  3060. /**
  3061. * Test for subTime
  3062. */
  3063. public function testSubTime()
  3064. {
  3065. $locale = new Locale('de_AT');
  3066. $date = new Date(1234567890,null,$locale);
  3067. $d2 = new Date(1234567899,null,$locale);
  3068. $result = $date->subTime(Date::now());
  3069. $this->assertTrue($result instanceof Date);
  3070. $date = new Date(1234567890,null,$locale);
  3071. $result = $date->subTime('10:20:30');
  3072. $this->assertSame('2009-02-13T18:11:00+05:00', $result->get(Date::W3C));
  3073. $this->assertSame('2009-02-13T18:11:00+05:00', $date->get(Date::W3C));
  3074. $date = new Date(1234567890,null,$locale);
  3075. $date->subTime('30-20-10','ss:mm:HH');
  3076. $this->assertSame('2009-02-13T18:11:00+05:00', $date->get(Date::W3C));
  3077. $date = new Date(1234567890,null,$locale);
  3078. $date->subTime($d2);
  3079. $this->assertSame('2009-02-13T23:59:51+05:00', $date->get(Date::W3C));
  3080. }
  3081. /**
  3082. * Test for compareTime
  3083. */
  3084. public function testCompareTime()
  3085. {
  3086. $locale = new Locale('de_AT');
  3087. $date = new Date(1234567890,null,$locale);
  3088. $d2 = new Date(1234567899,null,$locale);
  3089. $date = new Date(1234567890,null,$locale);
  3090. $this->assertSame(-1, $date->compareTime('10:20:30'));
  3091. $this->assertSame( 0, $date->compareTime('04:31:30'));
  3092. $this->assertSame( 1, $date->compareTime('04:00:30'));
  3093. $this->assertSame(-1, $date->compareTime($d2 ));
  3094. }
  3095. /**
  3096. * Test for setTime
  3097. */
  3098. public function testSetHour()
  3099. {
  3100. $locale = new Locale('de_AT');
  3101. $date = new Date(1234567890,null,$locale);
  3102. $this->assertSame('2009-02-14T04:31:30+05:00', $date->get(Date::W3C));
  3103. for($i=23; $i >= 0; $i--) {
  3104. $date->setHour($i);
  3105. $hour = $i;
  3106. if ($i < 10) {
  3107. $hour = '0' . $hour;
  3108. }
  3109. $this->assertSame("2009-02-14T$hour:31:30+05:00", $date->get(Date::W3C));
  3110. }
  3111. }
  3112. /**
  3113. * Test for getDate
  3114. */
  3115. public function testGetDate()
  3116. {
  3117. $locale = new Locale('de_AT');
  3118. $date = new Date(1010101010,null,$locale);
  3119. $d2 = new Date(1010101010,null,$locale);
  3120. $result = $date->getDate();
  3121. $this->assertSame('2002-01-04T00:00:00+05:00', $result->get(Date::W3C));
  3122. }
  3123. /**
  3124. * Test for setDate
  3125. */
  3126. public function testSetDate()
  3127. {
  3128. $locale = new Locale('de_AT');
  3129. $date = new Date(1234567890,null,$locale);
  3130. $d2 = new Date(1234567899,null,$locale);
  3131. $result = $date->setDate(Date::now());
  3132. $this->assertTrue($result instanceof Date);
  3133. $result = $date->setDate('11.05.2008');
  3134. // Hint: the hour changes from 0 to 1 because of DST...
  3135. // An hour is added by winter->summertime change
  3136. $this->assertSame('2008-05-11T04:31:30+05:00', $result->get(Date::W3C));
  3137. $this->assertSame('2008-05-11T04:31:30+05:00', $date->get(Date::W3C));
  3138. $date->setDate('2008-05-11','YYYY-MM-dd');
  3139. $this->assertSame('2008-05-11T04:31:30+05:00', $date->get(Date::W3C));
  3140. $date->setDate($d2);
  3141. $this->assertSame('2009-02-14T04:31:30+05:00', $date->get(Date::W3C));
  3142. }
  3143. /**
  3144. * Test for addDate
  3145. */
  3146. public function testAddDate()
  3147. {
  3148. if (!defined('TESTS_ZEND_I18N_EXTENDED_COVERAGE') || TESTS_ZEND_I18N_EXTENDED_COVERAGE == false) {
  3149. $this->markTestSkipped('Extended I18N test skipped');
  3150. return;
  3151. }
  3152. $locale = new Locale('de_AT');
  3153. $date = new Date(1234567890,null,$locale);
  3154. $d2 = new Date(1234567899,null,$locale);
  3155. $result = $date->addDate(Date::now());
  3156. $this->assertTrue($result instanceof Date);
  3157. $date = new Date(1234567890,null,$locale);
  3158. $result = $date->addDate('02-03-05');
  3159. $this->assertSame('4014-05-17T04:31:30+05:00', $result->get(Date::W3C));
  3160. $this->assertSame('4014-05-17T04:31:30+05:00', $date->get(Date::W3C));
  3161. $date = new Date(1234567890,null,$locale);
  3162. $date->addDate('05-03-02','YY-MM-dd');
  3163. $this->assertSame('4014-05-17T04:31:30+05:00', $date->get(Date::W3C));
  3164. $date = new Date(1234567890,null,$locale);
  3165. $date->addDate($d2);
  3166. $this->assertSame('4018-04-28T04:31:30+05:00', $date->get(Date::W3C));
  3167. }
  3168. /**
  3169. * Test for subDate
  3170. */
  3171. public function testSubDate()
  3172. {
  3173. if (!defined('TESTS_ZEND_I18N_EXTENDED_COVERAGE') || TESTS_ZEND_I18N_EXTENDED_COVERAGE == false) {
  3174. $this->markTestSkipped('Extended I18N test skipped');
  3175. return;
  3176. }
  3177. $locale = new Locale('de_AT');
  3178. $date = new Date(1234567890,null,$locale);
  3179. $d2 = new Date(1234567899,null,$locale);
  3180. $result = $date->subDate(Date::now());
  3181. $this->assertTrue($result instanceof Date);
  3182. $date = new Date(1234567890,null,$locale);
  3183. $result = $date->subDate('03-05-1001');
  3184. $this->assertSame('1007-09-08T04:31:30+05:00', $result->get(Date::W3C));
  3185. $this->assertSame('1007-09-08T04:31:30+05:00', $date->get(Date::W3C));
  3186. $date = new Date(1234567890,null,$locale);
  3187. $date->subDate('1001-05-03','YYYY-MM-dd');
  3188. $this->assertSame('1007-09-08T04:31:30+05:00', $date->get(Date::W3C));
  3189. $date = new Date(1234567890,null,$locale);
  3190. $date->subDate($d2);
  3191. $this->assertSame('-1-12-06T04:31:30+05:00', $date->get(Date::W3C));
  3192. }
  3193. /**
  3194. * Test for compareDate
  3195. */
  3196. public function testCompareDate()
  3197. {
  3198. if (!defined('TESTS_ZEND_I18N_EXTENDED_COVERAGE') || TESTS_ZEND_I18N_EXTENDED_COVERAGE == false) {
  3199. $this->markTestSkipped('Extended I18N test skipped');
  3200. return;
  3201. }
  3202. $locale = new Locale('de_AT');
  3203. $date = new Date(1234567890,$locale);
  3204. $d2 = new Date(1234567899,$locale);
  3205. $date = new Date(1234567890,$locale);
  3206. $this->assertSame( 1, $date->compareDate('10.01.2009'));
  3207. $this->assertSame( 0, $date->compareDate('14.02.2009'));
  3208. $this->assertSame(-1, $date->compareDate('15.02.2009'));
  3209. $this->assertSame( 0, $date->compareDate($d2 ));
  3210. }
  3211. /**
  3212. * Test for getIso
  3213. */
  3214. public function testGetIso()
  3215. {
  3216. $locale = new Locale('de_AT');
  3217. $date = new Date(1010101010,null,$locale);
  3218. $d2 = new Date(1010101010,null,$locale);
  3219. $result = $date->getIso();
  3220. $this->assertTrue(is_string($result));
  3221. $this->assertSame('2002-01-04T04:36:50+05:00', $result);
  3222. }
  3223. /**
  3224. * Test for setIso
  3225. */
  3226. public function testSetIso()
  3227. {
  3228. $locale = new Locale('de_AT');
  3229. $date = new Date(1234567890,null,$locale);
  3230. $d2 = new Date(1234567899,null,$locale);
  3231. $result = $date->setIso(Date::now());
  3232. $this->assertTrue($result instanceof Date);
  3233. $result = $date->setIso('2002-01-04T00:00:00+0000');
  3234. $this->assertSame('2002-01-04T00:00:00+00:00', $result->get(Date::W3C));
  3235. $this->assertSame('2002-01-04T00:00:00+00:00', $date->get(Date::W3C));
  3236. $date->setIso($d2);
  3237. $this->assertSame('2009-02-14T04:31:39+05:00', $date->get(Date::W3C));
  3238. }
  3239. /**
  3240. * Test for addIso
  3241. */
  3242. public function testAddIso()
  3243. {
  3244. $locale = new Locale('de_AT');
  3245. $date = new Date(1234567890,$locale);
  3246. $d2 = new Date(1234567899,$locale);
  3247. $result = $date->addIso(Date::now());
  3248. $this->assertTrue($result instanceof Date);
  3249. }
  3250. /**
  3251. * Test for addIso
  3252. */
  3253. public function testAddIso2()
  3254. {
  3255. if (!defined('TESTS_ZEND_I18N_EXTENDED_COVERAGE') || TESTS_ZEND_I18N_EXTENDED_COVERAGE == false) {
  3256. $this->markTestSkipped('Extended I18N test skipped');
  3257. return;
  3258. }
  3259. $locale = new Locale('de_AT');
  3260. $date = new Date(1234567890,$locale);
  3261. $d2 = new Date(1234567899,$locale);
  3262. $result = $date->setIso('2002-01-04T01:00:00+0500');
  3263. $result = $date->addIso('0000-00-00T01:00:00+0500');
  3264. $this->assertSame('2002-01-03T21:00:00+05:00', $result->get(Date::W3C));
  3265. $this->assertSame('2002-01-03T21:00:00+05:00', $date->get(Date::W3C));
  3266. $date->addIso('0001-01-01T01:01:01+0500');
  3267. $this->assertSame('2003-02-04T17:01:01+05:00', $date->get(Date::W3C));
  3268. $date = new Date(1234567890,$locale);
  3269. $date->addIso($d2);
  3270. $this->assertSame('4018-04-28T04:03:09+05:00', $date->get(Date::W3C));
  3271. }
  3272. /**
  3273. * Test for subIso
  3274. */
  3275. public function testSubIso()
  3276. {
  3277. $locale = new Locale('de_AT');
  3278. $date = new Date(1234567890,null,$locale);
  3279. $d2 = new Date(1234567899,null,$locale);
  3280. $result = $date->subIso(Date::now());
  3281. $this->assertTrue($result instanceof Date);
  3282. }
  3283. /**
  3284. * Test for subIso
  3285. */
  3286. public function testSubIso2()
  3287. {
  3288. if (!defined('TESTS_ZEND_I18N_EXTENDED_COVERAGE') || TESTS_ZEND_I18N_EXTENDED_COVERAGE == false) {
  3289. $this->markTestSkipped('Extended I18N test skipped');
  3290. return;
  3291. }
  3292. $locale = new Locale('de_AT');
  3293. $date = new Date(1234567890,null,$locale);
  3294. $d2 = new Date(1234567899,null,$locale);
  3295. $result = $date->subIso('0000-00-00T01:00:00+0500');
  3296. $this->assertSame('2009-02-14T08:31:30+05:00', $result->get(Date::W3C));
  3297. $this->assertSame('2009-02-14T08:31:30+05:00', $date->get(Date::W3C));
  3298. $result = $date->subIso('0001-01-01T01:01:01+0500');
  3299. $this->assertSame('2008-01-14T12:30:29+05:00', $date->get(Date::W3C));
  3300. $date = new Date(1234567890,null,$locale);
  3301. $date->subIso($d2);
  3302. $this->assertSame('-1-12-06T04:59:51+05:00', $date->get(Date::W3C));
  3303. }
  3304. /**
  3305. * Test for compareIso
  3306. */
  3307. public function testCompareIso()
  3308. {
  3309. if (!defined('TESTS_ZEND_I18N_EXTENDED_COVERAGE') || TESTS_ZEND_I18N_EXTENDED_COVERAGE == false) {
  3310. $this->markTestSkipped('Extended I18N test skipped');
  3311. return;
  3312. }
  3313. $locale = new Locale('de_AT');
  3314. $date = new Date(1234567890,null,$locale);
  3315. $d2 = new Date(1234567899,null,$locale);
  3316. $date = new Date(1234567890,null,$locale);
  3317. $this->assertSame( 1, $date->compareIso('2002-01-04T04:00:00+0500'));
  3318. $this->assertSame( 0, $date->compareIso('2009-02-14T04:31:30+0500'));
  3319. $this->assertSame(-1, $date->compareIso('2010-01-04T05:00:00+0500'));
  3320. $this->assertSame(-1, $date->compareIso($d2 ));
  3321. }
  3322. /**
  3323. * Test for getArpa
  3324. */
  3325. public function testGetArpa()
  3326. {
  3327. $locale = new Locale('de_AT');
  3328. $date = new Date(1010101010,null,$locale);
  3329. $result = $date->getArpa();
  3330. $this->assertTrue(is_string($result));
  3331. $this->assertSame('Fri, 04 Jan 02 04:36:50 +0500', $result);
  3332. }
  3333. /**
  3334. * Test for setArpa
  3335. */
  3336. public function testSetArpa()
  3337. {
  3338. $locale = new Locale('de_AT');
  3339. $date = new Date(1234567890,$locale);
  3340. $d2 = new Date(1234567899,$locale);
  3341. $date->setTimezone('Indian/Maldives');
  3342. $result = $date->setArpa(Date::now());
  3343. $this->assertTrue($result instanceof Date);
  3344. $result = $date->setArpa('Sat, 03 May 01 00:00:00 +0500');
  3345. $this->assertSame('Thu, 03 May 01 00:00:00 +0500', $result->get(Date::RFC_822));
  3346. $this->assertSame('2001-05-03T00:00:00+05:00', $date->get(Date::W3C));
  3347. $date->setArpa($d2);
  3348. $this->assertSame('2009-02-14T04:31:39+05:00', $date->get(Date::W3C));
  3349. }
  3350. /**
  3351. * Test for addArpa
  3352. */
  3353. public function testAddArpa()
  3354. {
  3355. if (!defined('TESTS_ZEND_I18N_EXTENDED_COVERAGE') || TESTS_ZEND_I18N_EXTENDED_COVERAGE == false) {
  3356. $this->markTestSkipped('Extended I18N test skipped');
  3357. return;
  3358. }
  3359. $locale = new Locale('de_AT');
  3360. $date = new Date(1234567890,$locale);
  3361. $d2 = new Date(1234567899,$locale);
  3362. $result = $date->addArpa(Date::now());
  3363. $this->assertTrue($result instanceof Date);
  3364. $date = new Date(1234567890,$locale);
  3365. $result = $date->addArpa('Sat, 03 May 01 00:00:00 +0500');
  3366. $this->assertSame('Sat, 17 Jul 10 23:31:30 +0500', $result->get(Date::RFC_822));
  3367. $this->assertSame('4010-07-17T23:31:30+05:00', $date->get(Date::W3C));
  3368. $date = new Date(1234567890,$locale);
  3369. $date->addArpa($d2);
  3370. $this->assertSame('4018-04-28T04:03:09+05:00', $date->get(Date::W3C));
  3371. $result = $date->setArpa('Fri, 05 Jan 07 03:35:53 +0500');
  3372. $arpa = $result->getArpa();
  3373. $this->assertSame('Fri, 05 Jan 07 03:35:53 +0500', $arpa);
  3374. }
  3375. /**
  3376. * Test for subArpa
  3377. */
  3378. public function testSubArpa()
  3379. {
  3380. if (!defined('TESTS_ZEND_I18N_EXTENDED_COVERAGE') || TESTS_ZEND_I18N_EXTENDED_COVERAGE == false) {
  3381. $this->markTestSkipped('Extended I18N test skipped');
  3382. return;
  3383. }
  3384. $locale = new Locale('de_AT');
  3385. $date = new Date(1234567890,$locale);
  3386. $d2 = new Date(1234567899,$locale);
  3387. $result = $date->subArpa(Date::now());
  3388. $this->assertTrue($result instanceof Date);
  3389. $date = new Date(1234567890,null,$locale);
  3390. $result = $date->subArpa('Sat, 03 May 01 00:00:00 +0500');
  3391. $this->assertSame('Wed, 16 Sep 7 09:31:30 +0500', $result->get(Date::RFC_822));
  3392. $this->assertSame('7-09-16T09:31:30+05:00', $date->get(Date::W3C));
  3393. $date = new Date(1234567890,$locale);
  3394. $date->subArpa($d2);
  3395. $this->assertSame('-1-12-06T04:59:51+05:00', $date->get(Date::W3C));
  3396. }
  3397. /**
  3398. * Test for compareArpa
  3399. */
  3400. public function testCompareArpa()
  3401. {
  3402. if (!defined('TESTS_ZEND_I18N_EXTENDED_COVERAGE') || TESTS_ZEND_I18N_EXTENDED_COVERAGE == false) {
  3403. $this->markTestSkipped('Extended I18N test skipped');
  3404. return;
  3405. }
  3406. $locale = new Locale('de_AT');
  3407. $date = new Date(1234567890,$locale);
  3408. $d2 = new Date(1234567899,$locale);
  3409. $date = new Date(1234567890,$locale);
  3410. $this->assertSame(-1, $date->compareArpa('Sat, 14 Feb 09 05:31:30 +0500'));
  3411. $this->assertSame( 0, $date->compareArpa('Sat, 14 Feb 09 04:31:30 +0500'));
  3412. $this->assertSame( 1, $date->compareArpa('Sat, 13 Feb 09 04:31:30 +0500'));
  3413. $this->assertSame(-1, $date->compareArpa($d2 ));
  3414. }
  3415. /**
  3416. * Test for false locale setting
  3417. */
  3418. public function testReducedParams()
  3419. {
  3420. $locale = new Locale('de_AT');
  3421. $date = new Date(1010101010,$locale);
  3422. $date->setArpa('Sat, 03 May 01 00:00:00 +0500',$locale);
  3423. $this->assertSame('Thu, 03 May 01 00:00:00 +0500', $date->get(Date::RFC_822));
  3424. }
  3425. /**
  3426. * Test for SunFunc
  3427. */
  3428. public function testSunFunc()
  3429. {
  3430. $locale = new Locale('de_AT');
  3431. $date = new Date(1010101010,$locale);
  3432. $date->setTimezone(date_default_timezone_get());
  3433. $result = Cities::City('vienna');
  3434. $this->assertTrue(is_array($result));
  3435. $result = $date->getSunset($result);
  3436. $this->assertSame('2002-01-04T20:09:59+05:00', $result->get(Date::W3C));
  3437. unset($result);
  3438. $result = Cities::City('vienna', 'civil');
  3439. $this->assertTrue(is_array($result));
  3440. $result = $date->getSunset($result);
  3441. $this->assertSame('2002-01-04T20:09:20+05:00', $result->get(Date::W3C));
  3442. unset($result);
  3443. $result = Cities::City('vienna', 'nautic');
  3444. $this->assertTrue(is_array($result));
  3445. $result = $date->getSunset($result);
  3446. $this->assertSame('2002-01-04T20:08:34+05:00', $result->get(Date::W3C));
  3447. unset($result);
  3448. $result = Cities::City('vienna', 'astronomic');
  3449. $this->assertTrue(is_array($result));
  3450. $result = $date->getSunset($result);
  3451. $this->assertSame('2002-01-04T20:07:49+05:00', $result->get(Date::W3C));
  3452. unset($result);
  3453. $result = Cities::City('BERLIN');
  3454. $this->assertTrue(is_array($result));
  3455. $result = $date->getSunrise($result);
  3456. $this->assertSame('2002-01-04T12:21:21+05:00', $result->get(Date::W3C));
  3457. unset($result);
  3458. $result = Cities::City('London');
  3459. $this->assertTrue(is_array($result));
  3460. $result = $date->getSunInfo($result);
  3461. $this->assertSame('2002-01-04T13:10:10+05:00', $result['sunrise']['effective']->get(Date::W3C ));
  3462. $this->assertSame('2002-01-04T13:10:54+05:00', $result['sunrise']['civil']->get(Date::W3C ));
  3463. $this->assertSame('2002-01-04T13:11:45+05:00', $result['sunrise']['nautic']->get(Date::W3C ));
  3464. $this->assertSame('2002-01-04T13:12:35+05:00', $result['sunrise']['astronomic']->get(Date::W3C));
  3465. $this->assertSame('2002-01-04T21:00:52+05:00', $result['sunset']['effective']->get(Date::W3C ));
  3466. $this->assertSame('2002-01-04T21:00:08+05:00', $result['sunset']['civil']->get(Date::W3C ));
  3467. $this->assertSame('2002-01-04T20:59:18+05:00', $result['sunset']['nautic']->get(Date::W3C ));
  3468. $this->assertSame('2002-01-04T20:58:28+05:00', $result['sunset']['astronomic']->get(Date::W3C ));
  3469. unset($result);
  3470. $result = array('longitude' => 0);
  3471. try {
  3472. $result = $date->getSunrise($result);
  3473. $this->fail();
  3474. } catch (\Zend\Date\Exception\ExceptionInterface $e) {
  3475. // success
  3476. }
  3477. unset($result);
  3478. $result = array('latitude' => 0);
  3479. try {
  3480. $result = $date->getSunrise($result);
  3481. $this->fail();
  3482. } catch (\Zend\Date\Exception\ExceptionInterface $e) {
  3483. // success
  3484. }
  3485. unset($result);
  3486. $result = array('longitude' => 180.1, 'latitude' => 0);
  3487. try {
  3488. $result = $date->getSunrise($result);
  3489. $this->fail();
  3490. } catch (\Zend\Date\Exception\ExceptionInterface $e) {
  3491. // success
  3492. }
  3493. unset($result);
  3494. $result = array('longitude' => -180.1, 'latitude' => 0);
  3495. try {
  3496. $result = $date->getSunrise($result);
  3497. $this->fail();
  3498. } catch (\Zend\Date\Exception\ExceptionInterface $e) {
  3499. // success
  3500. }
  3501. unset($result);
  3502. $result = array('longitude' => 0, 'latitude' => 90.1);
  3503. try {
  3504. $result = $date->getSunrise($result);
  3505. $this->fail();
  3506. } catch (\Zend\Date\Exception\ExceptionInterface $e) {
  3507. // success
  3508. }
  3509. unset($result);
  3510. $result = array('longitude' => 0, 'latitude' => -90.1);
  3511. try {
  3512. $result = $date->getSunrise($result);
  3513. $this->fail();
  3514. } catch (\Zend\Date\Exception\ExceptionInterface $e) {
  3515. // success
  3516. }
  3517. unset($result);
  3518. $result = array('latitude' => 0, 'longitude' => 0);
  3519. $result = $date->getSunInfo($result);
  3520. $this->assertTrue(is_array($result));
  3521. unset($result);
  3522. $result = array('latitude' => 0, 'longitude' => 0);
  3523. $result = $date->getSunrise($result);
  3524. $this->assertTrue($result instanceof Date);
  3525. }
  3526. /**
  3527. * Test for Timezone
  3528. */
  3529. public function testTimezone()
  3530. {
  3531. $locale = new Locale('de_AT');
  3532. $date = new Date(1010101010,$locale);
  3533. $date->setTimezone(date_default_timezone_get());
  3534. $result = $date->getTimezone();
  3535. $this->assertSame('Indian/Maldives', $result);
  3536. try {
  3537. $result = $date->setTimezone('unknown');
  3538. // if function timezone_identifiers_list is not available false should be returned
  3539. $this->assertFalse($result);
  3540. } catch (\Zend\Date\Exception\ExceptionInterface $e) {
  3541. // success
  3542. }
  3543. $result = $date->getTimezone();
  3544. $this->assertSame('Indian/Maldives', $result);
  3545. $result = $date->setTimezone('America/Chicago');
  3546. $this->assertTrue($result instanceof Date);
  3547. $result = $date->getTimezone();
  3548. $this->assertSame('America/Chicago', $result);
  3549. $date = new Date('01.01.2000T00:00:00Z',Date::ISO_8601);
  3550. $result = $date->getTimezone();
  3551. $this->assertSame('Etc/UTC', $result);
  3552. }
  3553. /**
  3554. * Test for LeapYear
  3555. */
  3556. public function testLeapYear()
  3557. {
  3558. $locale = new Locale('de_AT');
  3559. $date = new Date('01.01.2006', Date::DATES, $locale);
  3560. $this->assertFalse($date->isLeapYear());
  3561. unset($date);
  3562. $date = new Date('01.01.2004', Date::DATES, $locale);
  3563. $this->assertTrue($date->isLeapYear());
  3564. try {
  3565. $result = Date::checkLeapYear('noyear');
  3566. $this->fail('exception expected');
  3567. } catch (\Zend\Date\Exception\ExceptionInterface $e) {
  3568. // succeed
  3569. }
  3570. }
  3571. /**
  3572. * Test for Today
  3573. */
  3574. public function testToday()
  3575. {
  3576. $locale = new Locale('de_AT');
  3577. $date = new Date(Date::now());
  3578. $d2 = new Date(1010101010,$locale);
  3579. $this->assertFalse($d2->isToday());
  3580. $this->assertTrue($date->isToday());
  3581. }
  3582. /**
  3583. * Test for Yesterday
  3584. */
  3585. public function testYesterday()
  3586. {
  3587. $locale = new Locale('de_AT');
  3588. $date = new Date(Date::now());
  3589. $d2 = new Date(1010101010,$locale);
  3590. $date->subDay(1);
  3591. $this->assertFalse($d2->isYesterday());
  3592. $this->assertTrue($date->isYesterday());
  3593. }
  3594. /**
  3595. * Test for Tomorrow
  3596. */
  3597. public function testTomorrow()
  3598. {
  3599. $locale = new Locale('de_AT');
  3600. $date = new Date(Date::now());
  3601. $d2 = new Date(1010101010,$locale);
  3602. $date->addDay(1);
  3603. $this->assertFalse($d2->isTomorrow());
  3604. $this->assertTrue($date->isTomorrow());
  3605. }
  3606. /**
  3607. * test isToday(), isTomorrow(), and isYesterday() for cases other than time() = "now"
  3608. */
  3609. public function testIsDay()
  3610. {
  3611. date_default_timezone_set('Europe/Vienna'); // should have DST
  3612. $locale = new Locale('de_AT');
  3613. $date = new TestHelper('01.01.2006', Date::DATES, $locale);
  3614. $date->_setTime($date->mktime(0, 0, 0, 1, 1, 2006));
  3615. $this->assertTrue($date->isToday());
  3616. $this->assertFalse($date->isTomorrow());
  3617. $date->_setTime($date->mktime(0, 0, 0, 1, 1, 2006));
  3618. $this->assertFalse($date->isYesterday());
  3619. $date->_setTime($date->mktime(0, 0, 0, 12, 31, 2005));
  3620. $this->assertTrue($date->isTomorrow());
  3621. $date->_setTime($date->mktime(0, 0, 0, 12, 31, 2005));
  3622. $this->assertFalse($date->isYesterday());
  3623. $date->_setTime($date->mktime(0, 0, 0, 12, 31, 2006));
  3624. $this->assertFalse($date->isTomorrow());
  3625. $date->_setTime($date->mktime(0, 0, 0, 12, 31, 2006));
  3626. $this->assertFalse($date->isYesterday());
  3627. $date->_setTime($date->mktime(0, 0, 0, 1, 0, 2006));
  3628. $this->assertTrue($date->isTomorrow());
  3629. $date->_setTime($date->mktime(0, 0, 0, 1, 0, 2006));
  3630. $this->assertFalse($date->isYesterday());
  3631. $date->_setTime($date->mktime(0, 0, 0, 1, 2, 2006));
  3632. $this->assertFalse($date->isTomorrow());
  3633. $date->_setTime($date->mktime(0, 0, 0, 1, 2, 2006));
  3634. $this->assertTrue($date->isYesterday());
  3635. }
  3636. /**
  3637. * Test for Now
  3638. */
  3639. public function testNow()
  3640. {
  3641. $locale = new Locale('de_AT');
  3642. $date = Date::now();
  3643. $reference = date('U');
  3644. $this->assertTrue(($reference - $date->get(Date::TIMESTAMP)) < 2);
  3645. }
  3646. /**
  3647. * Test for getYear
  3648. */
  3649. public function testGetYear()
  3650. {
  3651. $locale = new Locale('de_AT');
  3652. $date = new Date(1234567890,$locale);
  3653. $d2 = new Date(1610101010,$locale);
  3654. $date->setTimeZone(date_default_timezone_get());
  3655. $d2->setTimeZone(date_default_timezone_get());
  3656. $result = $date->getYear();
  3657. $this->assertTrue($result instanceof Date);
  3658. $this->assertSame('01.01.2009 05:00:00', $result->toString());
  3659. $this->assertSame('01.01.2021 05:00:00', $d2->getYear()->toString());
  3660. }
  3661. /**
  3662. * Test for setYear
  3663. */
  3664. public function testSetYear()
  3665. {
  3666. $locale = new Locale('de_AT');
  3667. $date = new Date(1577833200,$locale);
  3668. $date2 = new Date(2006, Date::YEAR);
  3669. $date->setTimeZone(date_default_timezone_get());
  3670. $date->setYear(2000);
  3671. $this->assertSame('2000-01-01T04:00:00+05:00', $date->get(Date::W3C));
  3672. $date->setYear(1800);
  3673. $this->assertSame('1800-01-01T04:00:00+05:00', $date->get(Date::W3C));
  3674. $date->setYear(2100);
  3675. $this->assertSame('2100-01-01T04:00:00+05:00', $date->get(Date::W3C));
  3676. $date->setYear($date2);
  3677. $this->assertSame('2006-01-01T04:00:00+05:00', $date->get(Date::W3C));
  3678. try {
  3679. $date->setYear('noyear');
  3680. $this->fail();
  3681. } catch (\Zend\Date\Exception\ExceptionInterface $e) {
  3682. // success
  3683. }
  3684. }
  3685. /**
  3686. * Test for addYear
  3687. */
  3688. public function testAddYear()
  3689. {
  3690. if (!defined('TESTS_ZEND_I18N_EXTENDED_COVERAGE') || TESTS_ZEND_I18N_EXTENDED_COVERAGE == false) {
  3691. $this->markTestSkipped('Extended I18N test skipped');
  3692. return;
  3693. }
  3694. $locale = new Locale('de_AT');
  3695. $date = new Date(1577833200,$locale);
  3696. $date->setTimeZone(date_default_timezone_get());
  3697. $date->addYear(1);
  3698. $this->assertSame('2021-01-01T04:00:00+05:00', $date->get(Date::W3C));
  3699. $date->addYear(1);
  3700. $this->assertSame('2022-01-01T04:00:00+05:00', $date->get(Date::W3C));
  3701. $date->addYear(1);
  3702. $this->assertSame('2023-01-01T04:00:00+05:00', $date->get(Date::W3C));
  3703. $date->addYear(1);
  3704. $this->assertSame('2024-01-01T04:00:00+05:00', $date->get(Date::W3C));
  3705. $date->addYear(1);
  3706. $this->assertSame('2025-01-01T04:00:00+05:00', $date->get(Date::W3C));
  3707. $date->setYear(1500);
  3708. $this->assertSame('1500-01-01T04:00:00+05:00', $date->get(Date::W3C));
  3709. $date->addYear(20);
  3710. $this->assertSame('1520-01-01T04:00:00+05:00', $date->get(Date::W3C));
  3711. $date->setYear(2100);
  3712. $this->assertSame('2100-01-01T04:00:00+05:00', $date->get(Date::W3C));
  3713. $date->addYear(20);
  3714. $this->assertSame('2120-01-01T04:00:00+05:00', $date->get(Date::W3C));
  3715. $date->setDay(4);
  3716. $date->setMonth(4);
  3717. $date->setYear(2020);
  3718. $this->assertSame('2020-04-04T04:00:00+05:00', $date->get(Date::W3C));
  3719. $date->addYear(1);
  3720. $this->assertSame('2021-04-04T04:00:00+05:00', $date->get(Date::W3C));
  3721. $date->addYear(1);
  3722. $this->assertSame('2022-04-04T04:00:00+05:00', $date->get(Date::W3C));
  3723. $date->addYear(1);
  3724. $this->assertSame('2023-04-04T04:00:00+05:00', $date->get(Date::W3C));
  3725. $date->addYear(1);
  3726. $this->assertSame('2024-04-04T04:00:00+05:00', $date->get(Date::W3C));
  3727. $date->addYear(1);
  3728. $this->assertSame('2025-04-04T04:00:00+05:00', $date->get(Date::W3C));
  3729. $date->setYear(1500);
  3730. $this->assertSame('1500-04-04T04:00:00+05:00', $date->get(Date::W3C));
  3731. $date->addYear(20);
  3732. $this->assertSame('1520-04-04T04:00:00+05:00', $date->get(Date::W3C));
  3733. $date->setYear(2100);
  3734. $this->assertSame('2100-04-04T04:00:00+05:00', $date->get(Date::W3C));
  3735. $date->addYear(20);
  3736. $this->assertSame('2120-04-04T04:00:00+05:00', $date->get(Date::W3C));
  3737. }
  3738. /**
  3739. * Test for subYear
  3740. */
  3741. public function testSubYear()
  3742. {
  3743. if (!defined('TESTS_ZEND_I18N_EXTENDED_COVERAGE') || TESTS_ZEND_I18N_EXTENDED_COVERAGE == false) {
  3744. $this->markTestSkipped('Extended I18N test skipped');
  3745. return;
  3746. }
  3747. $locale = new Locale('de_AT');
  3748. $date = new Date(1577833200,$locale);
  3749. $date->setTimeZone(date_default_timezone_get());
  3750. $date->subYear(1);
  3751. $this->assertSame('2019-01-01T04:00:00+05:00', $date->get(Date::W3C));
  3752. $date->subYear(1);
  3753. $this->assertSame('2018-01-01T04:00:00+05:00', $date->get(Date::W3C));
  3754. $date->subYear(1);
  3755. $this->assertSame('2017-01-01T04:00:00+05:00', $date->get(Date::W3C));
  3756. $date->subYear(1);
  3757. $this->assertSame('2016-01-01T04:00:00+05:00', $date->get(Date::W3C));
  3758. $date->subYear(1);
  3759. $this->assertSame('2015-01-01T04:00:00+05:00', $date->get(Date::W3C));
  3760. $date->setYear(1500);
  3761. $this->assertSame('1500-01-01T04:00:00+05:00', $date->get(Date::W3C));
  3762. $date->subYear(20);
  3763. $this->assertSame('1480-01-01T04:00:00+05:00', $date->get(Date::W3C));
  3764. $date->setYear(2100);
  3765. $this->assertSame('2100-01-01T04:00:00+05:00', $date->get(Date::W3C));
  3766. $date->subYear(20);
  3767. $this->assertSame('2080-01-01T04:00:00+05:00', $date->get(Date::W3C));
  3768. }
  3769. /**
  3770. * Test for compareYear
  3771. */
  3772. public function testCompareYear()
  3773. {
  3774. $locale = new Locale('de_AT');
  3775. $date = new Date(1234567890,$locale);
  3776. $d2 = new Date(1234567899,$locale);
  3777. $date = new Date(1234567890,$locale);
  3778. $this->assertSame(-1, $date->compareYear(2010));
  3779. $this->assertSame( 0, $date->compareYear(2009));
  3780. $this->assertSame( 1, $date->compareYear(2008));
  3781. $this->assertSame( 0, $date->compareYear($d2 ));
  3782. }
  3783. /**
  3784. * Test for getMonth
  3785. */
  3786. public function testGetMonth()
  3787. {
  3788. $locale = new Locale('de_AT');
  3789. $date = new Date(1234567890,$locale);
  3790. $d2 = new Date(1610101010,$locale);
  3791. $date->setTimeZone(date_default_timezone_get());
  3792. $d2->setTimeZone(date_default_timezone_get());
  3793. $result = $date->getMonth();
  3794. $this->assertTrue($result instanceof Date);
  3795. $this->assertSame('01.02.1970 05:00:00', $result->toString( ));
  3796. $this->assertSame('01.02.1970 05:00:00', $date->getMonth()->toString());
  3797. }
  3798. /**
  3799. * Test for setMonth
  3800. */
  3801. public function testSetMonth()
  3802. {
  3803. $locale = new Locale('de_AT');
  3804. $date = new Date(1577833200,$locale);
  3805. $date2 = new Date(2006, Date::YEAR);
  3806. $date->setTimeZone(date_default_timezone_get());
  3807. $date->setMonth(3);
  3808. $this->assertSame('2020-03-01T04:00:00+05:00', $date->get(Date::W3C));
  3809. $date->setMonth(-3);
  3810. $this->assertSame('2019-09-01T04:00:00+05:00', $date->get(Date::W3C));
  3811. $date->setMonth('March', 'en');
  3812. $this->assertSame('2019-03-01T04:00:00+05:00', $date->get(Date::W3C));
  3813. $date->setMonth($date2);
  3814. $this->assertSame('2019-01-01T04:00:00+05:00', $date->get(Date::W3C));
  3815. try {
  3816. $date->setMonth('nomonth');
  3817. $this->fail();
  3818. } catch (\Zend\Date\Exception\ExceptionInterface $e) {
  3819. // success
  3820. }
  3821. }
  3822. /**
  3823. * Test for addMonth
  3824. */
  3825. public function testAddMonth()
  3826. {
  3827. date_default_timezone_set('Europe/Vienna');
  3828. $locale = new Locale('de_AT');
  3829. $date = new Date(1577833200,$locale);
  3830. $date->setTimeZone(date_default_timezone_get());
  3831. $date->addMonth(1);
  3832. $this->assertSame('2020-02-01T00:00:00+01:00', $date->get(Date::W3C));
  3833. $date->addMonth(1);
  3834. $this->assertSame('2020-03-01T00:00:00+01:00', $date->get(Date::W3C));
  3835. $date->addMonth(1);
  3836. $this->assertSame('2020-04-01T00:00:00+02:00', $date->get(Date::W3C));
  3837. $date->addMonth(1);
  3838. $this->assertSame('2020-05-01T00:00:00+02:00', $date->get(Date::W3C));
  3839. $date->addMonth(1);
  3840. $this->assertSame('2020-06-01T00:00:00+02:00', $date->get(Date::W3C));
  3841. $date->addMonth(5);
  3842. $this->assertSame('2020-11-01T00:00:00+01:00', $date->get(Date::W3C));
  3843. Date::setOptions(array('fix_dst' => true));
  3844. $date = new Date('2007-10-01 00:00:00', Date::ISO_8601);
  3845. $this->assertSame('2007-10-01 00:00:00', $date->toString('yyyy-MM-dd HH:mm:ss'));
  3846. $date->addMonth(1);
  3847. $this->assertSame('2007-11-01 00:00:00', $date->toString('yyyy-MM-dd HH:mm:ss'));
  3848. $date = new Date('2007-10-01 23:00:00', Date::ISO_8601);
  3849. $this->assertSame('2007-10-01 23:00:00', $date->toString('yyyy-MM-dd HH:mm:ss'));
  3850. $date->addMonth(1);
  3851. $this->assertSame('2007-11-01 23:00:00', $date->toString('yyyy-MM-dd HH:mm:ss'));
  3852. $date = new Date('2007-03-01 00:00:00', Date::ISO_8601);
  3853. $this->assertSame('2007-03-01 00:00:00', $date->toString('yyyy-MM-dd HH:mm:ss'));
  3854. $date->addMonth(1);
  3855. $this->assertSame('2007-04-01 00:00:00', $date->toString('yyyy-MM-dd HH:mm:ss'));
  3856. $date = new Date('2007-03-01 23:00:00', Date::ISO_8601);
  3857. $this->assertSame('2007-03-01 23:00:00', $date->toString('yyyy-MM-dd HH:mm:ss'));
  3858. $date->addMonth(1);
  3859. $this->assertSame('2007-04-01 23:00:00', $date->toString('yyyy-MM-dd HH:mm:ss'));
  3860. Date::setOptions(array('fix_dst' => false));
  3861. $date = new Date('2007-10-01 00:00:00', Date::ISO_8601);
  3862. $this->assertSame('2007-10-01 00:00:00', $date->toString('yyyy-MM-dd HH:mm:ss'));
  3863. $date->addMonth(1);
  3864. $this->assertSame('2007-10-31 23:00:00', $date->toString('yyyy-MM-dd HH:mm:ss'));
  3865. $date = new Date('2007-10-01 23:00:00', Date::ISO_8601);
  3866. $this->assertSame('2007-10-01 23:00:00', $date->toString('yyyy-MM-dd HH:mm:ss'));
  3867. $date->addMonth(1);
  3868. $this->assertSame('2007-11-01 22:00:00', $date->toString('yyyy-MM-dd HH:mm:ss'));
  3869. $date = new Date('2007-03-01 00:00:00', Date::ISO_8601);
  3870. $this->assertSame('2007-03-01 00:00:00', $date->toString('yyyy-MM-dd HH:mm:ss'));
  3871. $date->addMonth(1);
  3872. $this->assertSame('2007-04-01 01:00:00', $date->toString('yyyy-MM-dd HH:mm:ss'));
  3873. $date = new Date('2007-03-01 23:00:00', Date::ISO_8601);
  3874. $this->assertSame('2007-03-01 23:00:00', $date->toString('yyyy-MM-dd HH:mm:ss'));
  3875. $date->addMonth(1);
  3876. $this->assertSame('2007-04-02 00:00:00', $date->toString('yyyy-MM-dd HH:mm:ss'));
  3877. $date = new Date('2007-01-31 00:00:00', Date::ISO_8601);
  3878. $this->assertSame('2007-01-31 00:00:00', $date->toString('yyyy-MM-dd HH:mm:ss'));
  3879. $date->addMonth(1);
  3880. $this->assertSame('2007-02-28 00:00:00', $date->toString('yyyy-MM-dd HH:mm:ss'));
  3881. $date = new Date('2007-01-31 00:00:00', Date::ISO_8601);
  3882. $this->assertSame('2007-01-31 00:00:00', $date->toString('yyyy-MM-dd HH:mm:ss'));
  3883. Date::setOptions(array('extend_month' => true));
  3884. $date->addMonth(1);
  3885. $this->assertSame('2007-03-03 00:00:00', $date->toString('yyyy-MM-dd HH:mm:ss'));
  3886. date_default_timezone_set('America/Chicago');
  3887. $date = new Date(1577858400,$locale);
  3888. $date->setTimeZone(date_default_timezone_get());
  3889. $this->assertSame('2020-01-01T00:00:00-06:00', $date->get(Date::ISO_8601));
  3890. $date->addMonth(12);
  3891. $this->assertSame('2021-01-01T00:00:00-06:00', $date->get(Date::ISO_8601));
  3892. }
  3893. /**
  3894. * Test for subMonth
  3895. */
  3896. public function testSubMonth()
  3897. {
  3898. $locale = new Locale('de_AT');
  3899. $date = new Date(1577833200,$locale);
  3900. $date->setTimeZone(date_default_timezone_get());
  3901. $date->subMonth(1);
  3902. $this->assertSame('2019-12-01T04:00:00+05:00', $date->get(Date::W3C));
  3903. $date->subMonth(12);
  3904. $this->assertSame('2018-12-01T04:00:00+05:00', $date->get(Date::W3C));
  3905. }
  3906. /**
  3907. * Test for compareMonth
  3908. */
  3909. public function testCompareMonth()
  3910. {
  3911. $locale = new Locale('de_AT');
  3912. $date = new Date(1234567890,$locale);
  3913. $d2 = new Date(1234567899,$locale);
  3914. $date = new Date(1234567890,$locale);
  3915. $this->assertSame( 1, $date->compareMonth( 1));
  3916. $this->assertSame( 0, $date->compareMonth( 2));
  3917. $this->assertSame(-1, $date->compareMonth( 3));
  3918. $this->assertSame( 0, $date->compareYear($d2));
  3919. }
  3920. /**
  3921. * Test accessors for _Locale member property of Zend_Date
  3922. */
  3923. public function testLocale()
  3924. {
  3925. $date = new Date(Date::now());
  3926. $locale = new Locale('en_US');
  3927. $date->setLocale($locale);
  3928. $this->assertSame('en_US', $date->getLocale());
  3929. }
  3930. /**
  3931. * test for getWeek
  3932. */
  3933. public function testGetWeek()
  3934. {
  3935. $locale = new Locale('de_AT');
  3936. $date = new Date(1168293600, $locale);
  3937. //Tuesday
  3938. $date->addDay(1);
  3939. $this->assertSame('08.01.1970 05:00:00', $date->getWeek()->toString());
  3940. //Wednesday
  3941. $date->addDay(1);
  3942. $this->assertSame('08.01.1970 05:00:00', $date->getWeek()->toString());
  3943. //Thursday
  3944. $date->addDay(1);
  3945. $this->assertSame('08.01.1970 05:00:00', $date->getWeek()->toString());
  3946. //Friday
  3947. $date->addDay(1);
  3948. $this->assertSame('08.01.1970 05:00:00', $date->getWeek()->toString());
  3949. //Friday 05:30 am
  3950. $date->addTime('05:30:00');
  3951. $this->assertSame('08.01.1970 05:00:00', $date->getWeek()->toString());
  3952. //Saturday
  3953. $date->addDay(1);
  3954. $this->assertSame('08.01.1970 05:00:00', $date->getWeek()->toString());
  3955. //Saturday [ar_EG]
  3956. // The right value for AM/PM has to be set in arabic letters
  3957. $this->assertSame('08‏/01‏/1970 5:00:00 ص', $date->getWeek('ar_EG')->toString());
  3958. $date->setTimeZone('UTC');
  3959. $this->assertSame('08‏/01‏/1970 12:00:00 ص', $date->getWeek('ar_EG')->toString());
  3960. $date->setTimeZone('Indian/Maldives');
  3961. $this->assertSame('08‏/01‏/1970 5:00:00 ص', $date->getWeek('ar_EG')->toString());
  3962. //Sunday [start of a new week as defined per ISO 8601]
  3963. $date->addDay(1);
  3964. $this->assertSame('15.01.1970 05:00:00', $date->getWeek()->toString());
  3965. //Monday
  3966. $date->addDay(1);
  3967. $this->assertSame('15.01.1970 05:00:00', $date->getWeek()->toString());
  3968. //Monday 03:45 pm
  3969. $date->addTime('15:45:00');
  3970. $this->assertSame('15.01.1970 05:00:00', $date->getWeek()->toString());
  3971. }
  3972. /**
  3973. * test setting dates to specify weekdays
  3974. */
  3975. public function testDay()
  3976. {
  3977. // all tests and calculations below are in GMT (that is intention for this test)
  3978. $date = new Date(0, 'de_AT');
  3979. $date->setTimeZone('UTC');
  3980. $dw = $date->getDay();
  3981. $this->assertSame('01.01.1970 00:00:00', $dw->toString());
  3982. for($day = 1; $day < 31; $day++) {
  3983. $date->setDay($day);
  3984. $dw = $date->getDay();
  3985. $weekday = str_pad($day, 2, '0', STR_PAD_LEFT);
  3986. $this->assertSame("$weekday.01.1970 00:00:00", $dw->toString());
  3987. }
  3988. }
  3989. /**
  3990. * @group ZF-8332
  3991. */
  3992. public function testSetDayOnThirtyFirstGivesThirtyOne()
  3993. {
  3994. $locale = new Locale('en_US');
  3995. $date = new Date();
  3996. $date->setYear(2009, $locale)
  3997. ->setMonth(5, $locale)
  3998. ->setDay(31, $locale);
  3999. $this->assertSame('5/31/09', $date->get(Date::DATE_SHORT, $locale));
  4000. }
  4001. /**
  4002. * test setWeekday
  4003. */
  4004. public function testSetWeekday()
  4005. {
  4006. $date = new Date('2006-01-01','YYYY-MM-dd', 'en');
  4007. $date->setWeekday(1);
  4008. $this->assertSame('2005-12-26T00:00:00+05:00', $date->getIso());
  4009. $date->set('2006-01-02', 'YYYY-MM-dd');
  4010. $date->setWeekday(1);
  4011. $this->assertSame('2006-01-02T00:00:00+05:00', $date->getIso());
  4012. }
  4013. /**
  4014. * test setLocale/getLocale
  4015. */
  4016. public function testSetLocale()
  4017. {
  4018. $date = new Date(0, 'de');
  4019. $this->assertSame('de', $date->getLocale());
  4020. $date->setLocale('en');
  4021. $this->assertSame('en', $date->getLocale());
  4022. $date->setLocale('en_XX');
  4023. $this->assertSame('en', $date->getLocale());
  4024. $date->setLocale('de_AT');
  4025. $this->assertSame('de_AT', $date->getLocale());
  4026. $locale = new Locale('ar');
  4027. $date->setLocale($locale);
  4028. $this->assertSame('ar', $date->getLocale());
  4029. try {
  4030. $date->setLocale('xx_XX');
  4031. $this->fail();
  4032. } catch (\Zend\Date\Exception\ExceptionInterface $e) {
  4033. // success
  4034. }
  4035. }
  4036. /**
  4037. * test looseBehaviour
  4038. */
  4039. public function testLoose()
  4040. {
  4041. $date = new Date(0, 'de_DE');
  4042. try {
  4043. $date->set(null, Date::YEAR);
  4044. $this->fail();
  4045. } catch (\Zend\Date\Exception\ExceptionInterface $e) {
  4046. // success
  4047. }
  4048. $date->set(10, 'de_DE');
  4049. $this->assertEquals(10, $date->getTimestamp());
  4050. try {
  4051. $date->add(null, Date::YEAR);
  4052. $this->fail();
  4053. } catch (\Zend\Date\Exception\ExceptionInterface $e) {
  4054. // success
  4055. }
  4056. $date->add(10, 'de_DE');
  4057. $this->assertEquals(20, $date->getTimestamp());
  4058. try {
  4059. $date->sub(null, Date::YEAR);
  4060. $this->fail();
  4061. } catch (\Zend\Date\Exception\ExceptionInterface $e) {
  4062. // success
  4063. }
  4064. $date->sub(10, 'de_DE');
  4065. $this->assertEquals(10, $date->getTimestamp());
  4066. try {
  4067. $date->compare(null, Date::YEAR);
  4068. $this->fail();
  4069. } catch (\Zend\Date\Exception\ExceptionInterface $e) {
  4070. // success
  4071. }
  4072. try {
  4073. $date->equals(null, Date::YEAR);
  4074. $this->fail();
  4075. } catch (\Zend\Date\Exception\ExceptionInterface $e) {
  4076. // success
  4077. }
  4078. try {
  4079. $date->isEarlier(null, Date::YEAR);
  4080. $this->fail();
  4081. } catch (\Zend\Date\Exception\ExceptionInterface $e) {
  4082. // success
  4083. }
  4084. try {
  4085. $date->isLater(null, Date::YEAR);
  4086. $this->fail();
  4087. } catch (\Zend\Date\Exception\ExceptionInterface $e) {
  4088. // success
  4089. }
  4090. try {
  4091. $date->setTime(null);
  4092. $this->fail();
  4093. } catch (\Zend\Date\Exception\ExceptionInterface $e) {
  4094. // success
  4095. }
  4096. try {
  4097. $date->addTime(null);
  4098. $this->fail();
  4099. } catch (\Zend\Date\Exception\ExceptionInterface $e) {
  4100. // success
  4101. }
  4102. try {
  4103. $date->subTime(null);
  4104. $this->fail();
  4105. } catch (\Zend\Date\Exception\ExceptionInterface $e) {
  4106. // success
  4107. }
  4108. try {
  4109. $date->compareTime(null);
  4110. $this->fail();
  4111. } catch (\Zend\Date\Exception\ExceptionInterface $e) {
  4112. // success
  4113. }
  4114. try {
  4115. $date->setDate(null);
  4116. $this->fail();
  4117. } catch (\Zend\Date\Exception\ExceptionInterface $e) {
  4118. // success
  4119. }
  4120. try {
  4121. $date->addDate(null);
  4122. $this->fail();
  4123. } catch (\Zend\Date\Exception\ExceptionInterface $e) {
  4124. // success
  4125. }
  4126. try {
  4127. $date->subDate(null);
  4128. $this->fail();
  4129. } catch (\Zend\Date\Exception\ExceptionInterface $e) {
  4130. // success
  4131. }
  4132. try {
  4133. $date->compareDate(null);
  4134. $this->fail();
  4135. } catch (\Zend\Date\Exception\ExceptionInterface $e) {
  4136. // success
  4137. }
  4138. try {
  4139. $date->setIso(null);
  4140. $this->fail();
  4141. } catch (\Zend\Date\Exception\ExceptionInterface $e) {
  4142. // success
  4143. }
  4144. try {
  4145. $date->addIso(null);
  4146. $this->fail();
  4147. } catch (\Zend\Date\Exception\ExceptionInterface $e) {
  4148. // success
  4149. }
  4150. try {
  4151. $date->subIso(null);
  4152. $this->fail();
  4153. } catch (\Zend\Date\Exception\ExceptionInterface $e) {
  4154. // success
  4155. }
  4156. try {
  4157. $date->compareIso(null);
  4158. $this->fail();
  4159. } catch (\Zend\Date\Exception\ExceptionInterface $e) {
  4160. // success
  4161. }
  4162. try {
  4163. $date->setArpa(null);
  4164. $this->fail();
  4165. } catch (\Zend\Date\Exception\ExceptionInterface $e) {
  4166. // success
  4167. }
  4168. try {
  4169. $date->addArpa(null);
  4170. $this->fail();
  4171. } catch (\Zend\Date\Exception\ExceptionInterface $e) {
  4172. // success
  4173. }
  4174. try {
  4175. $date->subArpa(null);
  4176. $this->fail();
  4177. } catch (\Zend\Date\Exception\ExceptionInterface $e) {
  4178. // success
  4179. }
  4180. try {
  4181. $date->compareArpa(null);
  4182. $this->fail();
  4183. } catch (\Zend\Date\Exception\ExceptionInterface $e) {
  4184. // success
  4185. }
  4186. try {
  4187. $date->setYear(null);
  4188. $this->fail();
  4189. } catch (\Zend\Date\Exception\ExceptionInterface $e) {
  4190. // success
  4191. }
  4192. try {
  4193. $date->addYear(null);
  4194. $this->fail();
  4195. } catch (\Zend\Date\Exception\ExceptionInterface $e) {
  4196. // success
  4197. }
  4198. try {
  4199. $date->subYear(null);
  4200. $this->fail();
  4201. } catch (\Zend\Date\Exception\ExceptionInterface $e) {
  4202. // success
  4203. }
  4204. try {
  4205. $date->compareYear(null);
  4206. $this->fail();
  4207. } catch (\Zend\Date\Exception\ExceptionInterface $e) {
  4208. // success
  4209. }
  4210. try {
  4211. $date->setMonth(null);
  4212. $this->fail();
  4213. } catch (\Zend\Date\Exception\ExceptionInterface $e) {
  4214. // success
  4215. }
  4216. try {
  4217. $date->addMonth(null);
  4218. $this->fail();
  4219. } catch (\Zend\Date\Exception\ExceptionInterface $e) {
  4220. // success
  4221. }
  4222. try {
  4223. $date->subMonth(null);
  4224. $this->fail();
  4225. } catch (\Zend\Date\Exception\ExceptionInterface $e) {
  4226. // success
  4227. }
  4228. try {
  4229. $date->compareMonth(null);
  4230. $this->fail();
  4231. } catch (\Zend\Date\Exception\ExceptionInterface $e) {
  4232. // success
  4233. }
  4234. try {
  4235. $date->setDay(null);
  4236. $this->fail();
  4237. } catch (\Zend\Date\Exception\ExceptionInterface $e) {
  4238. // success
  4239. }
  4240. try {
  4241. $date->addDay(null);
  4242. $this->fail();
  4243. } catch (\Zend\Date\Exception\ExceptionInterface $e) {
  4244. // success
  4245. }
  4246. try {
  4247. $date->subDay(null);
  4248. $this->fail();
  4249. } catch (\Zend\Date\Exception\ExceptionInterface $e) {
  4250. // success
  4251. }
  4252. try {
  4253. $date->compareDay(null);
  4254. $this->fail();
  4255. } catch (\Zend\Date\Exception\ExceptionInterface $e) {
  4256. // success
  4257. }
  4258. try {
  4259. $date->setWeekday(null);
  4260. $this->fail();
  4261. } catch (\Zend\Date\Exception\ExceptionInterface $e) {
  4262. // success
  4263. }
  4264. try {
  4265. $date->addWeekday(null);
  4266. $this->fail();
  4267. } catch (\Zend\Date\Exception\ExceptionInterface $e) {
  4268. // success
  4269. }
  4270. try {
  4271. $date->subWeekday(null);
  4272. $this->fail();
  4273. } catch (\Zend\Date\Exception\ExceptionInterface $e) {
  4274. // success
  4275. }
  4276. try {
  4277. $date->compareWeekday(null);
  4278. $this->fail();
  4279. } catch (\Zend\Date\Exception\ExceptionInterface $e) {
  4280. // success
  4281. }
  4282. try {
  4283. $date->setDayOfYear(null);
  4284. $this->fail();
  4285. } catch (\Zend\Date\Exception\ExceptionInterface $e) {
  4286. // success
  4287. }
  4288. try {
  4289. $date->addDayOfYear(null);
  4290. $this->fail();
  4291. } catch (\Zend\Date\Exception\ExceptionInterface $e) {
  4292. // success
  4293. }
  4294. try {
  4295. $date->subDayOfYear(null);
  4296. $this->fail();
  4297. } catch (\Zend\Date\Exception\ExceptionInterface $e) {
  4298. // success
  4299. }
  4300. try {
  4301. $date->compareDayOfYear(null);
  4302. $this->fail();
  4303. } catch (\Zend\Date\Exception\ExceptionInterface $e) {
  4304. // success
  4305. }
  4306. try {
  4307. $date->setHour(null);
  4308. $this->fail();
  4309. } catch (\Zend\Date\Exception\ExceptionInterface $e) {
  4310. // success
  4311. }
  4312. try {
  4313. $date->addHour(null);
  4314. $this->fail();
  4315. } catch (\Zend\Date\Exception\ExceptionInterface $e) {
  4316. // success
  4317. }
  4318. try {
  4319. $date->subHour(null);
  4320. $this->fail();
  4321. } catch (\Zend\Date\Exception\ExceptionInterface $e) {
  4322. // success
  4323. }
  4324. try {
  4325. $date->compareHour(null);
  4326. $this->fail();
  4327. } catch (\Zend\Date\Exception\ExceptionInterface $e) {
  4328. // success
  4329. }
  4330. try {
  4331. $date->setMinute(null);
  4332. $this->fail();
  4333. } catch (\Zend\Date\Exception\ExceptionInterface $e) {
  4334. // success
  4335. }
  4336. try {
  4337. $date->addMinute(null);
  4338. $this->fail();
  4339. } catch (\Zend\Date\Exception\ExceptionInterface $e) {
  4340. // success
  4341. }
  4342. try {
  4343. $date->subMinute(null);
  4344. $this->fail();
  4345. } catch (\Zend\Date\Exception\ExceptionInterface $e) {
  4346. // success
  4347. }
  4348. try {
  4349. $date->compareMinute(null);
  4350. $this->fail();
  4351. } catch (\Zend\Date\Exception\ExceptionInterface $e) {
  4352. // success
  4353. }
  4354. try {
  4355. $date->setSecond(null);
  4356. $this->fail();
  4357. } catch (\Zend\Date\Exception\ExceptionInterface $e) {
  4358. // success
  4359. }
  4360. try {
  4361. $date->addSecond(null);
  4362. $this->fail();
  4363. } catch (\Zend\Date\Exception\ExceptionInterface $e) {
  4364. // success
  4365. }
  4366. try {
  4367. $date->subSecond(null);
  4368. $this->fail();
  4369. } catch (\Zend\Date\Exception\ExceptionInterface $e) {
  4370. // success
  4371. }
  4372. try {
  4373. $date->compareSecond(null);
  4374. $this->fail();
  4375. } catch (\Zend\Date\Exception\ExceptionInterface $e) {
  4376. // success
  4377. }
  4378. try {
  4379. $date->setWeek(null);
  4380. $this->fail();
  4381. } catch (\Zend\Date\Exception\ExceptionInterface $e) {
  4382. // success
  4383. }
  4384. try {
  4385. $date->addWeek(null);
  4386. $this->fail();
  4387. } catch (\Zend\Date\Exception\ExceptionInterface $e) {
  4388. // success
  4389. }
  4390. try {
  4391. $date->subWeek(null);
  4392. $this->fail();
  4393. } catch (\Zend\Date\Exception\ExceptionInterface $e) {
  4394. // success
  4395. }
  4396. try {
  4397. $date->compareWeek(null);
  4398. $this->fail();
  4399. } catch (\Zend\Date\Exception\ExceptionInterface $e) {
  4400. // success
  4401. }
  4402. }
  4403. public function testTimesync()
  4404. {
  4405. try {
  4406. $server = new TimeSync('ntp://pool.ntp.org', 'alias');
  4407. $date1 = $server->getDate();
  4408. // need to use the proxy class to simulate time() returning wrong value
  4409. $date2 = new TestHelper(time());
  4410. $info = $server->getInfo();
  4411. if (($info['offset'] >= 1) || ($info['offset'] <= -1)) {
  4412. $this->assertFalse($date1->getTimestamp() == $date2->getTimestamp());
  4413. } else {
  4414. $this->assertEquals($date1->getTimestamp(), $date2->getTimestamp());
  4415. }
  4416. } catch (\Zend\TimeSync\Exception $e) {
  4417. $this->markTestIncomplete('NTP timeserver not available.');
  4418. }
  4419. }
  4420. public function testUsePhpDateFormat()
  4421. {
  4422. Date::setOptions(array('format_type' => 'iso'));
  4423. // PHP date() format specifier tests
  4424. $date1 = new Date('2006-01-02 23:58:59', Date::ISO_8601, 'en_US');
  4425. $date2 = new Date('2006-01-02 23:58:59', 'YYYY-MM-dd HH:mm:ss', 'en_US');
  4426. $this->assertSame($date1->getTimestamp(), $date2->getTimestamp());
  4427. date_default_timezone_set('GMT');
  4428. $date = new Date(0); // 1970-01-01 is a Thursday (should be 4 for 'w' format specifier)
  4429. $this->assertSame(gmdate('w',$date->getTimestamp()), $date->toString( 'eee'));
  4430. $this->assertSame(gmdate('d',$date->getTimestamp()), $date->toString( 'dd'));
  4431. $this->assertSame(gmdate('D',$date->getTimestamp()), $date->toString( 'EEE', 'en'));
  4432. $this->assertSame(gmdate('j',$date->getTimestamp()), $date->toString( 'd'));
  4433. $this->assertSame(gmdate('l',$date->getTimestamp()), $date->toString( 'EEEE', 'en'));
  4434. $this->assertSame(gmdate('N',$date->getTimestamp()), $date->toString( 'e'));
  4435. $this->assertSame(gmdate('S',$date->getTimestamp()), $date->toString( 'SS'));
  4436. $this->assertSame(gmdate('z',$date->getTimestamp()), $date->toString( 'D'));
  4437. $this->assertSame(gmdate('W',$date->getTimestamp()), $date->toString( 'ww'));
  4438. $this->assertSame(gmdate('F',$date->getTimestamp()), $date->toString( 'MMMM', 'en'));
  4439. $this->assertSame(gmdate('m',$date->getTimestamp()), $date->toString( 'MM'));
  4440. $this->assertSame(gmdate('M',$date->getTimestamp()), $date->toString( 'MMM', 'en'));
  4441. $this->assertSame(gmdate('n',$date->getTimestamp()), $date->toString( 'M'));
  4442. $this->assertSame(gmdate('t',$date->getTimestamp()), $date->toString( 'ddd'));
  4443. $this->assertSame(gmdate('L',$date->getTimestamp()), $date->toString( 'l'));
  4444. $this->assertSame(gmdate('o',$date->getTimestamp()), $date->toString( 'YYYY'));
  4445. $this->assertSame(gmdate('Y',$date->getTimestamp()), $date->toString( 'yyyy'));
  4446. $this->assertSame(gmdate('y',$date->getTimestamp()), $date->toString( 'yy'));
  4447. $this->assertSame(gmdate('a',$date->getTimestamp()), strtolower($date->toString( 'a', 'en')));
  4448. $this->assertSame(gmdate('A',$date->getTimestamp()), strtoupper($date->toString( 'a', 'en')));
  4449. $this->assertSame(gmdate('B',$date->getTimestamp()), $date->toString( 'B'));
  4450. $this->assertSame(gmdate('g',$date->getTimestamp()), $date->toString( 'h'));
  4451. $this->assertSame(gmdate('G',$date->getTimestamp()), $date->toString( 'H'));
  4452. $this->assertSame(gmdate('h',$date->getTimestamp()), $date->toString( 'hh'));
  4453. $this->assertSame(gmdate('H',$date->getTimestamp()), $date->toString( 'HH'));
  4454. $this->assertSame(gmdate('i',$date->getTimestamp()), $date->toString( 'mm'));
  4455. $this->assertSame(gmdate('s',$date->getTimestamp()), $date->toString( 'ss'));
  4456. $this->assertSame( date('e',$date->getTimestamp()), $date->toString( 'zzzz'));
  4457. $this->assertSame(gmdate('I',$date->getTimestamp()), $date->toString( 'I'));
  4458. $this->assertSame(gmdate('O',$date->getTimestamp()), $date->toString( 'Z'));
  4459. $this->assertSame(gmdate('P',$date->getTimestamp()), $date->toString( 'ZZZZ'));
  4460. $this->assertSame(gmdate('T',$date->getTimestamp()), $date->toString( 'z'));
  4461. $this->assertSame(gmdate('Z',$date->getTimestamp()), $date->toString( 'X'));
  4462. $this->assertSame(gmdate('c',$date->getTimestamp()), $date->toString('yyyy-MM-ddTHH:mm:ssZZZZ'));
  4463. $this->assertSame(gmdate('r',$date->getTimestamp()), $date->toString( 'r'));
  4464. $this->assertSame(gmdate('U',$date->getTimestamp()), $date->toString( 'U'));
  4465. // PHP date() format specifier tests
  4466. $date1 = new Date('2006-01-02 23:58:59', Date::ISO_8601, 'en_US');
  4467. Date::setOptions(array('format_type' => 'php'));
  4468. $date2 = new Date('2006-01-02 23:58:59', 'Y-m-d H:i:s', 'en_US');
  4469. $this->assertSame($date1->getTimestamp(), $date2->getTimestamp());
  4470. date_default_timezone_set('GMT');
  4471. $date = new Date(0); // 1970-01-01 is a Thursday (should be 4 for 'w' format specifier)
  4472. $this->assertSame(gmdate('w',$date->getTimestamp()), $date->toString( 'w'));
  4473. $this->assertSame(gmdate('d',$date->getTimestamp()), $date->toString( 'd'));
  4474. $this->assertSame(gmdate('D',$date->getTimestamp()), $date->toString('D', 'en'));
  4475. $this->assertSame(gmdate('j',$date->getTimestamp()), $date->toString( 'j'));
  4476. $this->assertSame(gmdate('l',$date->getTimestamp()), $date->toString('l', 'en'));
  4477. $this->assertSame(gmdate('N',$date->getTimestamp()), $date->toString( 'N'));
  4478. $this->assertSame(gmdate('S',$date->getTimestamp()), $date->toString( 'S'));
  4479. $this->assertSame(gmdate('z',$date->getTimestamp()), $date->toString( 'z'));
  4480. $this->assertSame(gmdate('W',$date->getTimestamp()), $date->toString( 'W'));
  4481. $this->assertSame(gmdate('F',$date->getTimestamp()), $date->toString('F', 'en'));
  4482. $this->assertSame(gmdate('m',$date->getTimestamp()), $date->toString( 'm'));
  4483. $this->assertSame(gmdate('M',$date->getTimestamp()), $date->toString('M', 'en'));
  4484. $this->assertSame(gmdate('n',$date->getTimestamp()), $date->toString( 'n'));
  4485. $this->assertSame(gmdate('t',$date->getTimestamp()), $date->toString( 't'));
  4486. $this->assertSame(gmdate('L',$date->getTimestamp()), $date->toString( 'L'));
  4487. $this->assertSame(gmdate('o',$date->getTimestamp()), $date->toString( 'o'));
  4488. $this->assertSame(gmdate('Y',$date->getTimestamp()), $date->toString( 'Y'));
  4489. $this->assertSame(gmdate('y',$date->getTimestamp()), $date->toString( 'y'));
  4490. $this->assertSame(gmdate('a',$date->getTimestamp()), strtolower($date->toString('a', 'en')));
  4491. $this->assertSame(gmdate('A',$date->getTimestamp()), strtoupper($date->toString('A', 'en')));
  4492. $this->assertSame(gmdate('B',$date->getTimestamp()), $date->toString( 'B'));
  4493. $this->assertSame(gmdate('g',$date->getTimestamp()), $date->toString( 'g'));
  4494. $this->assertSame(gmdate('G',$date->getTimestamp()), $date->toString( 'G'));
  4495. $this->assertSame(gmdate('h',$date->getTimestamp()), $date->toString( 'h'));
  4496. $this->assertSame(gmdate('H',$date->getTimestamp()), $date->toString( 'H'));
  4497. $this->assertSame(gmdate('i',$date->getTimestamp()), $date->toString( 'i'));
  4498. $this->assertSame(gmdate('s',$date->getTimestamp()), $date->toString( 's'));
  4499. $this->assertSame( date('e',$date->getTimestamp()), $date->toString( 'e'));
  4500. $this->assertSame(gmdate('I',$date->getTimestamp()), $date->toString( 'I'));
  4501. $this->assertSame(gmdate('O',$date->getTimestamp()), $date->toString( 'O'));
  4502. $this->assertSame(gmdate('P',$date->getTimestamp()), $date->toString( 'P'));
  4503. $this->assertSame(gmdate('T',$date->getTimestamp()), $date->toString( 'T'));
  4504. $this->assertSame(gmdate('Z',$date->getTimestamp()), $date->toString( 'Z'));
  4505. $this->assertSame(gmdate('c',$date->getTimestamp()), $date->toString( 'c'));
  4506. $this->assertSame(gmdate('r',$date->getTimestamp()), $date->toString( 'r'));
  4507. $this->assertSame(gmdate('U',$date->getTimestamp()), $date->toString( 'U'));
  4508. date_default_timezone_set('GMT');
  4509. $date = new Date(mktime(20,10,0,10,10,2000)); // 1970-01-01 is a Thursday (should be 4 for 'w' format specifier)
  4510. $this->assertSame(gmdate('w',$date->getTimestamp()), $date->toString( 'w'));
  4511. $this->assertSame(gmdate('d',$date->getTimestamp()), $date->toString( 'd'));
  4512. $this->assertSame(gmdate('D',$date->getTimestamp()), $date->toString('D', 'en'));
  4513. $this->assertSame(gmdate('j',$date->getTimestamp()), $date->toString( 'j'));
  4514. $this->assertSame(gmdate('l',$date->getTimestamp()), $date->toString('l', 'en'));
  4515. $this->assertSame(gmdate('N',$date->getTimestamp()), $date->toString( 'N'));
  4516. $this->assertSame(gmdate('S',$date->getTimestamp()), $date->toString( 'S'));
  4517. $this->assertSame(gmdate('z',$date->getTimestamp()), $date->toString( 'z'));
  4518. $this->assertSame(gmdate('W',$date->getTimestamp()), $date->toString( 'W'));
  4519. $this->assertSame(gmdate('F',$date->getTimestamp()), $date->toString('F', 'en'));
  4520. $this->assertSame(gmdate('m',$date->getTimestamp()), $date->toString( 'm'));
  4521. $this->assertSame(gmdate('M',$date->getTimestamp()), $date->toString('M', 'en'));
  4522. $this->assertSame(gmdate('n',$date->getTimestamp()), $date->toString( 'n'));
  4523. $this->assertSame(gmdate('t',$date->getTimestamp()), $date->toString( 't'));
  4524. $this->assertSame(gmdate('L',$date->getTimestamp()), $date->toString( 'L'));
  4525. $this->assertSame(gmdate('o',$date->getTimestamp()), $date->toString( 'o'));
  4526. $this->assertSame(gmdate('Y',$date->getTimestamp()), $date->toString( 'Y'));
  4527. $this->assertSame(gmdate('y',$date->getTimestamp()), $date->toString( 'y'));
  4528. $this->assertSame(gmdate('a',$date->getTimestamp()), strtolower($date->toString('a', 'en')));
  4529. $this->assertSame(gmdate('A',$date->getTimestamp()), strtoupper($date->toString('A', 'en')));
  4530. $this->assertSame(gmdate('B',$date->getTimestamp()), $date->toString( 'B'));
  4531. $this->assertSame(gmdate('g',$date->getTimestamp()), $date->toString( 'g'));
  4532. $this->assertSame(gmdate('G',$date->getTimestamp()), $date->toString( 'G'));
  4533. $this->assertSame(gmdate('h',$date->getTimestamp()), $date->toString( 'h'));
  4534. $this->assertSame(gmdate('H',$date->getTimestamp()), $date->toString( 'H'));
  4535. $this->assertSame(gmdate('i',$date->getTimestamp()), $date->toString( 'i'));
  4536. $this->assertSame(gmdate('s',$date->getTimestamp()), $date->toString( 's'));
  4537. $this->assertSame( date('e',$date->getTimestamp()), $date->toString( 'e'));
  4538. $this->assertSame(gmdate('I',$date->getTimestamp()), $date->toString( 'I'));
  4539. $this->assertSame(gmdate('O',$date->getTimestamp()), $date->toString( 'O'));
  4540. $this->assertSame(gmdate('P',$date->getTimestamp()), $date->toString( 'P'));
  4541. $this->assertSame(gmdate('T',$date->getTimestamp()), $date->toString( 'T'));
  4542. $this->assertSame(gmdate('Z',$date->getTimestamp()), $date->toString( 'Z'));
  4543. $this->assertSame(gmdate('c',$date->getTimestamp()), $date->toString( 'c'));
  4544. $this->assertSame(gmdate('r',$date->getTimestamp()), $date->toString( 'r'));
  4545. $this->assertSame(gmdate('U',$date->getTimestamp()), $date->toString( 'U'));
  4546. date_default_timezone_set('Indian/Maldives');
  4547. $date = new Date(0); // 1970-01-01 is a Thursday (should be 4 for 'w' format specifier)
  4548. $this->assertSame(date('w',$date->getTimestamp()), $date->toString( 'w'));
  4549. $this->assertSame(date('d',$date->getTimestamp()), $date->toString( 'd'));
  4550. $this->assertSame(date('D',$date->getTimestamp()), $date->toString('D', 'en'));
  4551. $this->assertSame(date('j',$date->getTimestamp()), $date->toString( 'j'));
  4552. $this->assertSame(date('l',$date->getTimestamp()), $date->toString('l', 'en'));
  4553. $this->assertSame(date('N',$date->getTimestamp()), $date->toString( 'N'));
  4554. $this->assertSame(date('S',$date->getTimestamp()), $date->toString( 'S'));
  4555. $this->assertSame(date('z',$date->getTimestamp()), $date->toString( 'z'));
  4556. $this->assertSame(date('W',$date->getTimestamp()), $date->toString( 'W'));
  4557. $this->assertSame(date('F',$date->getTimestamp()), $date->toString('F', 'en'));
  4558. $this->assertSame(date('m',$date->getTimestamp()), $date->toString( 'm'));
  4559. $this->assertSame(date('M',$date->getTimestamp()), $date->toString('M', 'en'));
  4560. $this->assertSame(date('n',$date->getTimestamp()), $date->toString( 'n'));
  4561. $this->assertSame(date('t',$date->getTimestamp()), $date->toString( 't'));
  4562. $this->assertSame(date('L',$date->getTimestamp()), $date->toString( 'L'));
  4563. $this->assertSame(date('o',$date->getTimestamp()), $date->toString( 'o'));
  4564. $this->assertSame(date('Y',$date->getTimestamp()), $date->toString( 'Y'));
  4565. $this->assertSame(date('y',$date->getTimestamp()), $date->toString( 'y'));
  4566. $this->assertSame(date('a',$date->getTimestamp()), strtolower($date->toString('a', 'en')));
  4567. $this->assertSame(date('A',$date->getTimestamp()), strtoupper($date->toString('A', 'en')));
  4568. $this->assertSame(date('B',$date->getTimestamp()), $date->toString( 'B'));
  4569. $this->assertSame(date('g',$date->getTimestamp()), $date->toString( 'g'));
  4570. $this->assertSame(date('G',$date->getTimestamp()), $date->toString( 'G'));
  4571. $this->assertSame(date('h',$date->getTimestamp()), $date->toString( 'h'));
  4572. $this->assertSame(date('H',$date->getTimestamp()), $date->toString( 'H'));
  4573. $this->assertSame(date('i',$date->getTimestamp()), $date->toString( 'i'));
  4574. $this->assertSame(date('s',$date->getTimestamp()), $date->toString( 's'));
  4575. $this->assertSame(date('e',$date->getTimestamp()), $date->toString( 'e'));
  4576. $this->assertSame(date('I',$date->getTimestamp()), $date->toString( 'I'));
  4577. $this->assertSame(date('O',$date->getTimestamp()), $date->toString( 'O'));
  4578. $this->assertSame(date('P',$date->getTimestamp()), $date->toString( 'P'));
  4579. $this->assertSame(date('T',$date->getTimestamp()), $date->toString( 'T'));
  4580. $this->assertSame(date('Z',$date->getTimestamp()), $date->toString( 'Z'));
  4581. $this->assertSame(date('c',$date->getTimestamp()), $date->toString( 'c'));
  4582. $this->assertSame(date('r',$date->getTimestamp()), $date->toString( 'r'));
  4583. $this->assertSame(date('U',$date->getTimestamp()), $date->toString( 'U'));
  4584. date_default_timezone_set('Indian/Maldives');
  4585. $date = new Date(mktime(20,10,0,10,10,2000)); // 1970-01-01 is a Thursday (should be 4 for 'w' format specifier)
  4586. $this->assertSame(date('w',$date->getTimestamp()), $date->toString( 'w'));
  4587. $this->assertSame(date('d',$date->getTimestamp()), $date->toString( 'd'));
  4588. $this->assertSame(date('D',$date->getTimestamp()), $date->toString('D', 'en'));
  4589. $this->assertSame(date('j',$date->getTimestamp()), $date->toString( 'j'));
  4590. $this->assertSame(date('l',$date->getTimestamp()), $date->toString('l', 'en'));
  4591. $this->assertSame(date('N',$date->getTimestamp()), $date->toString( 'N'));
  4592. $this->assertSame(date('S',$date->getTimestamp()), $date->toString( 'S'));
  4593. $this->assertSame(date('z',$date->getTimestamp()), $date->toString( 'z'));
  4594. $this->assertSame(date('W',$date->getTimestamp()), $date->toString( 'W'));
  4595. $this->assertSame(date('F',$date->getTimestamp()), $date->toString('F', 'en'));
  4596. $this->assertSame(date('m',$date->getTimestamp()), $date->toString( 'm'));
  4597. $this->assertSame(date('M',$date->getTimestamp()), $date->toString('M', 'en'));
  4598. $this->assertSame(date('n',$date->getTimestamp()), $date->toString( 'n'));
  4599. $this->assertSame(date('t',$date->getTimestamp()), $date->toString( 't'));
  4600. $this->assertSame(date('L',$date->getTimestamp()), $date->toString( 'L'));
  4601. $this->assertSame(date('o',$date->getTimestamp()), $date->toString( 'o'));
  4602. $this->assertSame(date('Y',$date->getTimestamp()), $date->toString( 'Y'));
  4603. $this->assertSame(date('y',$date->getTimestamp()), $date->toString( 'y'));
  4604. $this->assertSame(date('a',$date->getTimestamp()), strtolower($date->toString('a', 'en')));
  4605. $this->assertSame(date('A',$date->getTimestamp()), strtoupper($date->toString('A', 'en')));
  4606. $this->assertSame(date('B',$date->getTimestamp()), $date->toString( 'B'));
  4607. $this->assertSame(date('g',$date->getTimestamp()), $date->toString( 'g'));
  4608. $this->assertSame(date('G',$date->getTimestamp()), $date->toString( 'G'));
  4609. $this->assertSame(date('h',$date->getTimestamp()), $date->toString( 'h'));
  4610. $this->assertSame(date('H',$date->getTimestamp()), $date->toString( 'H'));
  4611. $this->assertSame(date('i',$date->getTimestamp()), $date->toString( 'i'));
  4612. $this->assertSame(date('s',$date->getTimestamp()), $date->toString( 's'));
  4613. $this->assertSame(date('e',$date->getTimestamp()), $date->toString( 'e'));
  4614. $this->assertSame(date('I',$date->getTimestamp()), $date->toString( 'I'));
  4615. $this->assertSame(date('O',$date->getTimestamp()), $date->toString( 'O'));
  4616. $this->assertSame(date('P',$date->getTimestamp()), $date->toString( 'P'));
  4617. $this->assertSame(date('T',$date->getTimestamp()), $date->toString( 'T'));
  4618. $this->assertSame(date('Z',$date->getTimestamp()), $date->toString( 'Z'));
  4619. $this->assertSame(date('c',$date->getTimestamp()), $date->toString( 'c'));
  4620. $this->assertSame(date('r',$date->getTimestamp()), $date->toString( 'r'));
  4621. $this->assertSame(date('U',$date->getTimestamp()), $date->toString( 'U'));
  4622. Date::setOptions(array('format_type' => 'iso'));
  4623. }
  4624. public function testDaylightsaving()
  4625. {
  4626. $date = new Date('2007.03.25', Date::DATES);
  4627. $date->set('16:00:00', Date::TIMES);
  4628. $this->assertEquals('2007-03-25T16:00:00+05:00', $date->get(Date::W3C));
  4629. $date->set('01:00:00', Date::TIMES);
  4630. $this->assertEquals('2007-03-25T01:00:00+05:00', $date->get(Date::W3C));
  4631. }
  4632. public function testSetOptions()
  4633. {
  4634. $options = Date::setOptions();
  4635. $this->assertTrue(is_array($options));
  4636. $this->assertEquals('iso', $options['format_type']);
  4637. Date::setOptions(array('format_type' => 'php'));
  4638. $options = Date::setOptions();
  4639. $this->assertEquals('php', $options['format_type']);
  4640. try {
  4641. Date::setOptions(array('format_type' => 'non'));
  4642. $this->fail();
  4643. } catch (\Zend\Date\Exception\ExceptionInterface $e) {
  4644. // success
  4645. }
  4646. try {
  4647. Date::setOptions(array('unknown' => 'non'));
  4648. $this->fail();
  4649. } catch (\Zend\Date\Exception\ExceptionInterface $e) {
  4650. // success
  4651. }
  4652. try {
  4653. Date::setOptions(array('fix_dst' => 2));
  4654. $this->fail();
  4655. } catch (\Zend\Date\Exception\ExceptionInterface $e) {
  4656. // success
  4657. }
  4658. try {
  4659. Date::setOptions(array('fix_dst' => 2));
  4660. $this->fail();
  4661. } catch (\Zend\Date\Exception\ExceptionInterface $e) {
  4662. // success
  4663. }
  4664. $cache = CacheFactory::adapterFactory('memory', array('memory_limit' => 0));
  4665. Date::setOptions(array('cache' => $cache));
  4666. }
  4667. public function testIsDate()
  4668. {
  4669. $this->assertTrue(Date::isDate('25.03.2007', 'de_AT'));
  4670. $this->assertTrue(Date::isDate('2007.03.25', 'YYYY.MM.dd'));
  4671. $this->assertTrue(Date::isDate('25.Mai.2007', 'dd.MMMM.YYYY', 'de_AT'));
  4672. $this->assertTrue(Date::isDate('25.Mai.2007 10:00:00', 'dd.MMMM.YYYY', 'de_AT'));
  4673. $this->assertFalse(Date::isDate('32.Mai.2007 10:00:00', 'dd.MMMM.YYYY', 'de_AT'));
  4674. $this->assertFalse(Date::isDate('30.Februar.2007 10:00:00', 'dd.MMMM.YYYY', 'de_AT'));
  4675. $this->assertFalse(Date::isDate('30.Februar.2007 30:00:00', 'dd.MMMM.YYYY HH:mm:ss', 'de_AT'));
  4676. $this->assertFalse(Date::isDate(3.01));
  4677. }
  4678. public function testToArray()
  4679. {
  4680. $date = new Date('2006-01-02 23:58:59', Date::ISO_8601, 'en_US');
  4681. $return = $date->toArray();
  4682. $orig = array('day' => 02, 'month' => 01, 'year' => 2006, 'hour' => 23, 'minute' => 58,
  4683. 'second' => 59, 'timezone' => 'MVT', 'timestamp' => 1136228339, 'weekday' => 1,
  4684. 'dayofyear' => 1, 'week' => '01', 'gmtsecs' => 18000);
  4685. $this->assertEquals($orig, $return);
  4686. }
  4687. public function testFromArray()
  4688. {
  4689. $date = new Date(array('day' => 04, 'month' => 12, 'year' => 2006, 'hour' => 10,
  4690. 'minute' => 56, 'second' => 30), 'en_US');
  4691. $this->assertSame('2006-12-04T10:56:30+05:00', $date->getIso());
  4692. }
  4693. public function testTimezoneArray()
  4694. {
  4695. date_default_timezone_set('UTC');
  4696. $date = new Date(array('year' => 2007, 'month' => 1, 'day' => 1,
  4697. 'hour' => 20, 'minute' => 45, 'second' => 37, 'en_US'));
  4698. $this->assertSame('2007-01-01T20:45:37+00:00', $date->getIso());
  4699. date_default_timezone_set('CET');
  4700. $date = new Date(array('year' => 2007, 'month' => 1, 'day' => 1,
  4701. 'hour' => 1, 'minute' => 45, 'second' => 37, 'en_US'));
  4702. $this->assertSame('2007-01-01T01:45:37+01:00', $date->getIso());
  4703. $date = new Date(array('year' => 2006, 'month' => 4, 'day' => 18,
  4704. 'hour' => 12, 'minute' => 3, 'second' => 10, 'de_AT'));
  4705. $this->assertSame('2006-04-18T12:03:10+02:00', $date->getIso());
  4706. $date = new Date(array('year' => 2009, 'month' => 1, 'day' => 28,
  4707. 'hour' => 23, 'minute' => 30, 'second' => 00, 'de'));
  4708. $this->assertSame('2009-01-28T23:30:00+01:00', $date->getIso());
  4709. $date = new Date(array('year' => 2009, 'month' => 8, 'day' => 28,
  4710. 'hour' => 22, 'minute' => 00, 'second' => 00, 'de'));
  4711. $this->assertSame('2009-08-28T22:00:00+02:00', $date->getIso());
  4712. }
  4713. public function testExtendedDst()
  4714. {
  4715. Date::setOptions(array('format_type' => 'iso'));
  4716. $date = new Date();
  4717. $date->setTimezone('UTC');
  4718. $date->set('25-05-2050 12:00:00');
  4719. $this->assertSame('2050-05-25 12:00:00', $date->get('YYYY-MM-dd HH:mm:ss'));
  4720. $date->setTimezone('Europe/Warsaw');
  4721. $this->assertSame('2050-05-25 14:00:00', $date->get('YYYY-MM-dd HH:mm:ss'));
  4722. $date->setTimezone('UTC');
  4723. $date->set('25-05-2020 12:00:00');
  4724. $this->assertSame('2020-05-25 12:00:00', $date->get('YYYY-MM-dd HH:mm:ss'));
  4725. $date->setTimezone('Europe/Warsaw');
  4726. $this->assertSame('2020-05-25 14:00:00', $date->get('YYYY-MM-dd HH:mm:ss'));
  4727. }
  4728. public function testGetFullYear()
  4729. {
  4730. $this->assertSame(1970, Date::getFullYear(70));
  4731. $this->assertSame(1999, Date::getFullYear(99));
  4732. $this->assertSame(2000, Date::getFullYear(0));
  4733. $this->assertSame(2037, Date::getFullYear(37));
  4734. $this->assertSame(2069, Date::getFullYear(69));
  4735. $this->assertSame(-4, Date::getFullYear(-4));
  4736. $this->assertSame(100, Date::getFullYear(100));
  4737. }
  4738. /**
  4739. * Test for ZF-3677
  4740. */
  4741. public function testZF3677()
  4742. {
  4743. $locale = new Locale('de_AT');
  4744. Registry::set('Zend_Locale', $locale);
  4745. $date = new Date('13',null,$locale);
  4746. $this->assertSame($date->getLocale(), $locale->toString());
  4747. }
  4748. /**
  4749. * Test for ZF-4867
  4750. */
  4751. public function testZF4867()
  4752. {
  4753. date_default_timezone_set('America/New_York');
  4754. $date1 = new Date('2006-01-01 01:00:00 Europe/Paris', Date::ISO_8601);
  4755. $this->assertEquals('Europe/Paris', $date1->getTimezone());
  4756. }
  4757. /**
  4758. * Test for ZF-5203
  4759. */
  4760. public function testMultiByteWeekdaysShouldNotBeTruncated()
  4761. {
  4762. $date1 = new Date('pl');
  4763. $date1->setWeekday(3);
  4764. $this->assertEquals('ś', $date1->get(Date::WEEKDAY_NARROW));
  4765. }
  4766. /**
  4767. * Test for False Month Addition
  4768. */
  4769. public function testAddingMonthWhenChangingTimezone()
  4770. {
  4771. $date = new Date(mktime(22, 59, 59, 1, 10, 2009));
  4772. $this->assertEquals(10, $date->toString('d'));
  4773. $this->assertEquals( 1, $date->toString('M'));
  4774. $date->setTimezone('Europe/Berlin');
  4775. $date->addMonth(1);
  4776. $this->assertEquals(10, $date->toString('d'));
  4777. $this->assertEquals( 2, $date->toString('M'));
  4778. }
  4779. /**
  4780. * Test for False Month Addition
  4781. */
  4782. public function testGmtOffsetValues()
  4783. {
  4784. date_default_timezone_set('Pacific/Auckland');
  4785. $time = time();
  4786. $date = new Date($time);
  4787. $stamp = $date->getGmtOffset();
  4788. $localtime = localtime($time, true);
  4789. $offset = mktime($localtime['tm_hour'],
  4790. $localtime['tm_min'],
  4791. $localtime['tm_sec'],
  4792. $localtime['tm_mon'] + 1,
  4793. $localtime['tm_mday'],
  4794. $localtime['tm_year'] + 1900)
  4795. - gmmktime($localtime['tm_hour'],
  4796. $localtime['tm_min'],
  4797. $localtime['tm_sec'],
  4798. $localtime['tm_mon'] + 1,
  4799. $localtime['tm_mday'],
  4800. $localtime['tm_year'] + 1900);
  4801. $this->assertEquals($stamp, $offset);
  4802. $date->addMonth(6);
  4803. $stamp = $date->getGmtOffset();
  4804. $localtime = localtime($time, true);
  4805. $offset = mktime($localtime['tm_hour'],
  4806. $localtime['tm_min'],
  4807. $localtime['tm_sec'],
  4808. $localtime['tm_mon'] + 7,
  4809. $localtime['tm_mday'],
  4810. $localtime['tm_year'] + 1900)
  4811. - gmmktime($localtime['tm_hour'],
  4812. $localtime['tm_min'],
  4813. $localtime['tm_sec'],
  4814. $localtime['tm_mon'] + 7,
  4815. $localtime['tm_mday'],
  4816. $localtime['tm_year'] + 1900);
  4817. $this->assertEquals($stamp, $offset);
  4818. }
  4819. public function testIsDateWithConstants()
  4820. {
  4821. $this->assertTrue(Date::isDate('2009-02-13T23:31:30+00:00', Date::W3C, 'de_AT'));
  4822. $date = new Date();
  4823. $string = $date->toString(Date::DATES);
  4824. $this->assertTrue(Date::isDate($string, Date::DATES));
  4825. }
  4826. /**
  4827. * @ZF-7154
  4828. */
  4829. public function testZF7154()
  4830. {
  4831. $locale = new Locale('de_AT');
  4832. $date = new Date(1577833200,$locale);
  4833. $date2 = new Date(2006, Date::YEAR);
  4834. $date->setTimeZone(date_default_timezone_get());
  4835. $date->setYear(2000);
  4836. $date->setMonth('Apr');
  4837. $this->assertSame('2000-04-01T04:00:00+05:00', $date->get(Date::W3C));
  4838. $date->setYear(2004);
  4839. $date->setMonth('Februar');
  4840. $this->assertSame('2004-02-01T04:00:00+05:00', $date->get(Date::W3C));
  4841. }
  4842. /**
  4843. * @ZF-7202
  4844. */
  4845. public function testZF7202()
  4846. {
  4847. $date = new Date();
  4848. $timezone = $date->getTimezoneFromString('03:58:09 Jul 06, 2009 Indian/Reunion');
  4849. $this->assertSame('Indian/Reunion', $timezone);
  4850. }
  4851. /**
  4852. * @ZF-7589
  4853. */
  4854. public function testSetDateWithArray()
  4855. {
  4856. $date = new Date(1234567890);
  4857. $result = $date->setDate(array('year' => 2009, 'month' => 8, 'day' => 14));
  4858. $this->assertSame('2009-08-14T04:31:30+05:00', $result->get(Date::W3C));
  4859. }
  4860. /**
  4861. * @ZF-7454
  4862. */
  4863. public function testSetWithoutHourAtDSTChange()
  4864. {
  4865. $this->assertTrue(Date::isDate("23/05/2010", "dd/MM/yyyy", "it_IT"));
  4866. $this->assertTrue(Date::isDate("24/05/2010", "dd/MM/yyyy", "it_IT"));
  4867. }
  4868. /**
  4869. * @ZF-7456
  4870. */
  4871. public function testSetArrayDateWithoutHour()
  4872. {
  4873. $date = new Date(array(
  4874. 'year'=>2008,
  4875. 'month'=>3,
  4876. 'day'=>1)
  4877. );
  4878. $this->assertEquals('2008-03-01T00:00:00+05:00', $date->getIso());
  4879. }
  4880. /**
  4881. * @ZF-7745
  4882. *
  4883. */
  4884. public function testSetFirstDayOfLeapYear()
  4885. {
  4886. $date = new Date(2008, Date::YEAR);
  4887. $date->setDayOfYear(1);
  4888. $this->assertEquals('2008-01-01T00:00:00+05:00', $date->getIso());
  4889. $date->setDayOfYear(61);
  4890. $this->assertEquals('2008-03-01T00:00:00+05:00', $date->getIso());
  4891. $date->setDayOfYear(62);
  4892. $this->assertEquals('2008-03-02T00:00:00+05:00', $date->getIso());
  4893. }
  4894. /**
  4895. * @ZF-7913
  4896. */
  4897. public function testUsePhpNFormat()
  4898. {
  4899. Date::setOptions(array('format_type' => 'php'));
  4900. date_default_timezone_set('GMT');
  4901. $date = new Date(mktime(20,10,0,09,20,2009));
  4902. $this->assertSame(gmdate('w',$date->getTimestamp()), $date->toString( 'w'));
  4903. $this->assertSame(gmdate('d',$date->getTimestamp()), $date->toString( 'd'));
  4904. $this->assertSame(gmdate('D',$date->getTimestamp()), $date->toString('D', 'en'));
  4905. $this->assertSame(gmdate('j',$date->getTimestamp()), $date->toString( 'j'));
  4906. $this->assertSame(gmdate('l',$date->getTimestamp()), $date->toString('l', 'en'));
  4907. $this->assertSame(gmdate('N',$date->getTimestamp()), $date->toString( 'N'));
  4908. $this->assertSame(gmdate('S',$date->getTimestamp()), $date->toString( 'S'));
  4909. $this->assertSame(gmdate('z',$date->getTimestamp()), $date->toString( 'z'));
  4910. $this->assertSame(gmdate('W',$date->getTimestamp()), $date->toString( 'W'));
  4911. $this->assertSame(gmdate('F',$date->getTimestamp()), $date->toString('F', 'en'));
  4912. $this->assertSame(gmdate('m',$date->getTimestamp()), $date->toString( 'm'));
  4913. $this->assertSame(gmdate('M',$date->getTimestamp()), $date->toString('M', 'en'));
  4914. $this->assertSame(gmdate('n',$date->getTimestamp()), $date->toString( 'n'));
  4915. $this->assertSame(gmdate('t',$date->getTimestamp()), $date->toString( 't'));
  4916. $this->assertSame(gmdate('L',$date->getTimestamp()), $date->toString( 'L'));
  4917. $this->assertSame(gmdate('o',$date->getTimestamp()), $date->toString( 'o'));
  4918. $this->assertSame(gmdate('Y',$date->getTimestamp()), $date->toString( 'Y'));
  4919. $this->assertSame(gmdate('y',$date->getTimestamp()), $date->toString( 'y'));
  4920. $this->assertSame(gmdate('a',$date->getTimestamp()), strtolower($date->toString('a', 'en')));
  4921. $this->assertSame(gmdate('A',$date->getTimestamp()), strtoupper($date->toString('A', 'en')));
  4922. $this->assertSame(gmdate('B',$date->getTimestamp()), $date->toString( 'B'));
  4923. $this->assertSame(gmdate('g',$date->getTimestamp()), $date->toString( 'g'));
  4924. $this->assertSame(gmdate('G',$date->getTimestamp()), $date->toString( 'G'));
  4925. $this->assertSame(gmdate('h',$date->getTimestamp()), $date->toString( 'h'));
  4926. $this->assertSame(gmdate('H',$date->getTimestamp()), $date->toString( 'H'));
  4927. $this->assertSame(gmdate('i',$date->getTimestamp()), $date->toString( 'i'));
  4928. $this->assertSame(gmdate('s',$date->getTimestamp()), $date->toString( 's'));
  4929. $this->assertSame( date('e',$date->getTimestamp()), $date->toString( 'e'));
  4930. $this->assertSame(gmdate('I',$date->getTimestamp()), $date->toString( 'I'));
  4931. $this->assertSame(gmdate('O',$date->getTimestamp()), $date->toString( 'O'));
  4932. $this->assertSame(gmdate('P',$date->getTimestamp()), $date->toString( 'P'));
  4933. $this->assertSame(gmdate('T',$date->getTimestamp()), $date->toString( 'T'));
  4934. $this->assertSame(gmdate('Z',$date->getTimestamp()), $date->toString( 'Z'));
  4935. $this->assertSame(gmdate('c',$date->getTimestamp()), $date->toString( 'c'));
  4936. $this->assertSame(gmdate('r',$date->getTimestamp()), $date->toString( 'r'));
  4937. $this->assertSame(gmdate('U',$date->getTimestamp()), $date->toString( 'U'));
  4938. date_default_timezone_set('Indian/Maldives');
  4939. $date = new Date(mktime(20,10,0,09,20,2009));
  4940. $this->assertSame(date('w',$date->getTimestamp()), $date->toString( 'w'));
  4941. $this->assertSame(date('d',$date->getTimestamp()), $date->toString( 'd'));
  4942. $this->assertSame(date('D',$date->getTimestamp()), $date->toString('D', 'en'));
  4943. $this->assertSame(date('j',$date->getTimestamp()), $date->toString( 'j'));
  4944. $this->assertSame(date('l',$date->getTimestamp()), $date->toString('l', 'en'));
  4945. $this->assertSame(date('N',$date->getTimestamp()), $date->toString( 'N'));
  4946. $this->assertSame(date('S',$date->getTimestamp()), $date->toString( 'S'));
  4947. $this->assertSame(date('z',$date->getTimestamp()), $date->toString( 'z'));
  4948. $this->assertSame(date('W',$date->getTimestamp()), $date->toString( 'W'));
  4949. $this->assertSame(date('F',$date->getTimestamp()), $date->toString('F', 'en'));
  4950. $this->assertSame(date('m',$date->getTimestamp()), $date->toString( 'm'));
  4951. $this->assertSame(date('M',$date->getTimestamp()), $date->toString('M', 'en'));
  4952. $this->assertSame(date('n',$date->getTimestamp()), $date->toString( 'n'));
  4953. $this->assertSame(date('t',$date->getTimestamp()), $date->toString( 't'));
  4954. $this->assertSame(date('L',$date->getTimestamp()), $date->toString( 'L'));
  4955. $this->assertSame(date('o',$date->getTimestamp()), $date->toString( 'o'));
  4956. $this->assertSame(date('Y',$date->getTimestamp()), $date->toString( 'Y'));
  4957. $this->assertSame(date('y',$date->getTimestamp()), $date->toString( 'y'));
  4958. $this->assertSame(date('a',$date->getTimestamp()), strtolower($date->toString('a', 'en')));
  4959. $this->assertSame(date('A',$date->getTimestamp()), strtoupper($date->toString('A', 'en')));
  4960. $this->assertSame(date('B',$date->getTimestamp()), $date->toString( 'B'));
  4961. $this->assertSame(date('g',$date->getTimestamp()), $date->toString( 'g'));
  4962. $this->assertSame(date('G',$date->getTimestamp()), $date->toString( 'G'));
  4963. $this->assertSame(date('h',$date->getTimestamp()), $date->toString( 'h'));
  4964. $this->assertSame(date('H',$date->getTimestamp()), $date->toString( 'H'));
  4965. $this->assertSame(date('i',$date->getTimestamp()), $date->toString( 'i'));
  4966. $this->assertSame(date('s',$date->getTimestamp()), $date->toString( 's'));
  4967. $this->assertSame(date('e',$date->getTimestamp()), $date->toString( 'e'));
  4968. $this->assertSame(date('I',$date->getTimestamp()), $date->toString( 'I'));
  4969. $this->assertSame(date('O',$date->getTimestamp()), $date->toString( 'O'));
  4970. $this->assertSame(date('P',$date->getTimestamp()), $date->toString( 'P'));
  4971. $this->assertSame(date('T',$date->getTimestamp()), $date->toString( 'T'));
  4972. $this->assertSame(date('Z',$date->getTimestamp()), $date->toString( 'Z'));
  4973. $this->assertSame(date('c',$date->getTimestamp()), $date->toString( 'c'));
  4974. $this->assertSame(date('r',$date->getTimestamp()), $date->toString( 'r'));
  4975. $this->assertSame(date('U',$date->getTimestamp()), $date->toString( 'U'));
  4976. Date::setOptions(array('format_type' => 'iso'));
  4977. }
  4978. /**
  4979. * @ZF-7912
  4980. */
  4981. public function testPhpFormatWithIsEmpty()
  4982. {
  4983. Date::setOptions(array('format_type' => 'php'));
  4984. $date1 = new Date();
  4985. $date2 = clone $date1;
  4986. $date2->add(1, 'd');
  4987. $this->assertTrue($date1->isEarlier($date2, 'd.M.y'));
  4988. $this->assertFalse($date2->isEarlier($date1, 'd.M.y'));
  4989. $this->assertFalse($date1->isLater($date2, 'd.M.y'));
  4990. $this->assertTrue($date2->isLater($date1, 'd.M.y'));
  4991. }
  4992. public function testPhpFormatWithToString()
  4993. {
  4994. Date::setOptions(array('format_type' => 'php'));
  4995. $date = new Date('10.10.2009 10:10:10');
  4996. $this->assertEquals('10.10.2009 10:10:10', $date->toString("d.m.Y H:i:s"));
  4997. $date->setTime("23:59:59");
  4998. $this->assertEquals('10.10.2009 23:59:59', $date->toString("d.m.Y H:i:s"));
  4999. }
  5000. /**
  5001. * @ZF-8650
  5002. */
  5003. public function testFractionalPrecision()
  5004. {
  5005. $date = new Date();
  5006. $date->set('012345', Date::MILLISECOND);
  5007. $this->assertEquals(3, $date->getFractionalPrecision());
  5008. $this->assertEquals('345', $date->toString('S'));
  5009. $date->setFractionalPrecision(6);
  5010. $this->assertEquals(6, $date->getFractionalPrecision());
  5011. $this->assertEquals('345000', $date->toString('S'));
  5012. $date->add(200, Date::MILLISECOND);
  5013. $this->assertEquals(6, $date->getFractionalPrecision());
  5014. $this->assertEquals('345200', $date->toString('S'));
  5015. }
  5016. /**
  5017. * @ZF-9085
  5018. */
  5019. public function testGettingMonthWhenUsingGNU()
  5020. {
  5021. Date::setOptions(array('format_type' => 'php'));
  5022. $date = new Date(array('day' => 1, 'month' => 4, 'year' => 2008));
  5023. $date2 = $date->getMonth();
  5024. $result = $date2->toArray();
  5025. $this->assertEquals(1970, $result['year']);
  5026. }
  5027. /**
  5028. * @ZF-9891
  5029. */
  5030. public function testComparingDatesWithoutOption()
  5031. {
  5032. $date = new Date(strtotime('Sat, 07 Mar 2009 08:03:50 +0000'));
  5033. $date2 = new Date();
  5034. $date2->set('Sat, 07 Mar 2009 08:03:50 +0000', Date::RFC_2822);
  5035. $this->assertTrue($date2->equals($date));
  5036. }
  5037. /**
  5038. * @ZF-10150
  5039. */
  5040. public function testChineseFullDates()
  5041. {
  5042. $date = new Date(array('year' => 2008, 'month' => 10, 'day' => 12));
  5043. $this->assertEquals('2008年10月12日', $date->get(Date::DATE_LONG, 'zh'));
  5044. }
  5045. }
  5046. class TestHelper extends Date
  5047. {
  5048. public function _setTime($timestamp)
  5049. {
  5050. $this->_getTime($timestamp);
  5051. }
  5052. protected function _getTime($timestamp = null)
  5053. {
  5054. static $_timestamp = null;
  5055. if ($timestamp !== null) {
  5056. $_timestamp = $timestamp;
  5057. }
  5058. if ($_timestamp !== null) {
  5059. return $_timestamp;
  5060. }
  5061. return time();
  5062. }
  5063. public function mktime($hour, $minute, $second, $month, $day, $year, $dst= -1, $gmt = false)
  5064. {
  5065. return parent::mktime($hour, $minute, $second, $month, $day, $year, $dst, $gmt);
  5066. }
  5067. }