TimeTest.php 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651
  1. <?php
  2. /**
  3. * TimeTest file
  4. *
  5. * CakePHP(tm) Tests <http://book.cakephp.org/2.0/en/development/testing.html>
  6. * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
  7. *
  8. * Licensed under The MIT License
  9. * For full copyright and license information, please see the LICENSE.txt
  10. * Redistributions of files must retain the above copyright notice
  11. *
  12. * @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
  13. * @link http://book.cakephp.org/2.0/en/development/testing.html CakePHP(tm) Tests
  14. * @since 1.2.0
  15. * @license http://www.opensource.org/licenses/mit-license.php MIT License
  16. */
  17. namespace Cake\Test\TestCase\Utility;
  18. use Cake\TestSuite\TestCase;
  19. use Cake\Utility\Time;
  20. /**
  21. * TimeTest class
  22. *
  23. */
  24. class TimeTest extends TestCase {
  25. /**
  26. * setUp method
  27. *
  28. * @return void
  29. */
  30. public function setUp() {
  31. parent::setUp();
  32. $this->now = Time::getTestNow();
  33. $this->locale = Time::$defaultLocale;
  34. Time::$defaultLocale = 'en_US';
  35. }
  36. /**
  37. * tearDown method
  38. *
  39. * @return void
  40. */
  41. public function tearDown() {
  42. parent::tearDown();
  43. Time::setTestNow($this->now);
  44. Time::$defaultLocale = $this->locale;
  45. Time::resetToStringFormat();
  46. }
  47. /**
  48. * Restored the original system timezone
  49. *
  50. * @return void
  51. */
  52. protected function _restoreSystemTimezone() {
  53. date_default_timezone_set($this->_systemTimezoneIdentifier);
  54. }
  55. /**
  56. * Provides values and expectations for the toQuarter method
  57. *
  58. * @return array
  59. */
  60. public function toQuarterProvider() {
  61. return [
  62. ['2007-12-25', 4],
  63. ['2007-9-25', 3],
  64. ['2007-3-25', 1],
  65. ['2007-3-25', ['2007-01-01', '2007-03-31'], true],
  66. ['2007-5-25', ['2007-04-01', '2007-06-30'], true],
  67. ['2007-8-25', ['2007-07-01', '2007-09-30'], true],
  68. ['2007-12-25', ['2007-10-01', '2007-12-31'], true],
  69. ];
  70. }
  71. /**
  72. * testToQuarter method
  73. *
  74. * @dataProvider toQuarterProvider
  75. * @return void
  76. */
  77. public function testToQuarter($date, $expected, $range = false) {
  78. $this->assertEquals($expected, (new Time($date))->toQuarter($range));
  79. }
  80. /**
  81. * provider for timeAgoInWords() tests
  82. *
  83. * @return array
  84. */
  85. public static function timeAgoProvider() {
  86. return array(
  87. array('-12 seconds', '12 seconds ago'),
  88. array('-12 minutes', '12 minutes ago'),
  89. array('-2 hours', '2 hours ago'),
  90. array('-1 day', '1 day ago'),
  91. array('-2 days', '2 days ago'),
  92. array('-2 days -3 hours', '2 days, 3 hours ago'),
  93. array('-1 week', '1 week ago'),
  94. array('-2 weeks -2 days', '2 weeks, 2 days ago'),
  95. array('+1 week', '1 week'),
  96. array('+1 week 1 day', '1 week, 1 day'),
  97. array('+2 weeks 2 day', '2 weeks, 2 days'),
  98. array('2007-9-24', 'on 24/9/07'),
  99. array('now', 'just now'),
  100. );
  101. }
  102. /**
  103. * testTimeAgoInWords method
  104. *
  105. * @dataProvider timeAgoProvider
  106. * @return void
  107. */
  108. public function testTimeAgoInWords($input, $expected) {
  109. $time = new Time($input);
  110. $result = $time->timeAgoInWords();
  111. $this->assertEquals($expected, $result);
  112. }
  113. /**
  114. * provider for timeAgo with an end date.
  115. *
  116. * @return void
  117. */
  118. public function timeAgoEndProvider() {
  119. return array(
  120. array(
  121. '+4 months +2 weeks +3 days',
  122. '4 months, 2 weeks, 3 days',
  123. '8 years'
  124. ),
  125. array(
  126. '+4 months +2 weeks +1 day',
  127. '4 months, 2 weeks, 1 day',
  128. '8 years'
  129. ),
  130. array(
  131. '+3 months +2 weeks',
  132. '3 months, 2 weeks',
  133. '8 years'
  134. ),
  135. array(
  136. '+3 months +2 weeks +1 day',
  137. '3 months, 2 weeks, 1 day',
  138. '8 years'
  139. ),
  140. array(
  141. '+1 months +1 week +1 day',
  142. '1 month, 1 week, 1 day',
  143. '8 years'
  144. ),
  145. array(
  146. '+2 months +2 days',
  147. '2 months, 2 days',
  148. '+2 months +2 days'
  149. ),
  150. array(
  151. '+2 months +12 days',
  152. '2 months, 1 week, 5 days',
  153. '3 months'
  154. ),
  155. );
  156. }
  157. /**
  158. * test the end option for timeAgoInWords
  159. *
  160. * @dataProvider timeAgoEndProvider
  161. * @return void
  162. */
  163. public function testTimeAgoInWordsEnd($input, $expected, $end) {
  164. $time = new Time($input);
  165. $result = $time->timeAgoInWords(array('end' => $end));
  166. $this->assertEquals($expected, $result);
  167. }
  168. /**
  169. * test the custom string options for timeAgoInWords
  170. *
  171. * @return void
  172. */
  173. public function testTimeAgoInWordsCustomStrings() {
  174. $time = new Time('-8 years -4 months -2 weeks -3 days');
  175. $result = $time->timeAgoInWords(array(
  176. 'relativeString' => 'at least %s ago',
  177. 'accuracy' => array('year' => 'year'),
  178. 'end' => '+10 years'
  179. ));
  180. $expected = 'at least 8 years ago';
  181. $this->assertEquals($expected, $result);
  182. $time = new Time('+4 months +2 weeks +3 days');
  183. $result = $time->timeAgoInWords(array(
  184. 'absoluteString' => 'exactly on %s',
  185. 'accuracy' => array('year' => 'year'),
  186. 'end' => '+2 months'
  187. ));
  188. $expected = 'exactly on ' . date('j/n/y', strtotime('+4 months +2 weeks +3 days'));
  189. $this->assertEquals($expected, $result);
  190. }
  191. /**
  192. * Test the accuracy option for timeAgoInWords()
  193. *
  194. * @return void
  195. */
  196. public function testTimeAgoInWordsAccuracy() {
  197. $time = new Time('+8 years +4 months +2 weeks +3 days');
  198. $result = $time->timeAgoInWords(array(
  199. 'accuracy' => array('year' => 'year'),
  200. 'end' => '+10 years'
  201. ));
  202. $expected = '8 years';
  203. $this->assertEquals($expected, $result);
  204. $time = new Time('+8 years +4 months +2 weeks +3 days');
  205. $result = $time->timeAgoInWords(array(
  206. 'accuracy' => array('year' => 'month'),
  207. 'end' => '+10 years'
  208. ));
  209. $expected = '8 years, 4 months';
  210. $this->assertEquals($expected, $result);
  211. $time = new Time('+8 years +4 months +2 weeks +3 days');
  212. $result = $time->timeAgoInWords(array(
  213. 'accuracy' => array('year' => 'week'),
  214. 'end' => '+10 years'
  215. ));
  216. $expected = '8 years, 4 months, 2 weeks';
  217. $this->assertEquals($expected, $result);
  218. $time = new Time('+8 years +4 months +2 weeks +3 days');
  219. $result = $time->timeAgoInWords(array(
  220. 'accuracy' => array('year' => 'day'),
  221. 'end' => '+10 years'
  222. ));
  223. $expected = '8 years, 4 months, 2 weeks, 3 days';
  224. $this->assertEquals($expected, $result);
  225. $time = new Time('+1 years +5 weeks');
  226. $result = $time->timeAgoInWords(array(
  227. 'accuracy' => array('year' => 'year'),
  228. 'end' => '+10 years'
  229. ));
  230. $expected = '1 year';
  231. $this->assertEquals($expected, $result);
  232. $time = new Time('+58 minutes');
  233. $result = $time->timeAgoInWords(array(
  234. 'accuracy' => 'hour'
  235. ));
  236. $expected = 'in about an hour';
  237. $this->assertEquals($expected, $result);
  238. $time = new Time('+23 hours');
  239. $result = $time->timeAgoInWords(array(
  240. 'accuracy' => 'day'
  241. ));
  242. $expected = 'in about a day';
  243. $this->assertEquals($expected, $result);
  244. }
  245. /**
  246. * Test the format option of timeAgoInWords()
  247. *
  248. * @return void
  249. */
  250. public function testTimeAgoInWordsWithFormat() {
  251. $time = new Time('2007-9-25');
  252. $result = $time->timeAgoInWords(array('format' => 'YYYY-MM-dd'));
  253. $this->assertEquals('on 2007-09-25', $result);
  254. $time = new Time('2007-9-25');
  255. $result = $time->timeAgoInWords(array('format' => 'YYYY-MM-dd'));
  256. $this->assertEquals('on 2007-09-25', $result);
  257. $time = new Time('+2 weeks +2 days');
  258. $result = $time->timeAgoInWords(array('format' => 'YYYY-MM-dd'));
  259. $this->assertRegExp('/^2 weeks, [1|2] day(s)?$/', $result);
  260. $time = new Time('+2 months +2 days');
  261. $result = $time->timeAgoInWords(array('end' => '1 month', 'format' => 'YYYY-MM-dd'));
  262. $this->assertEquals('on ' . date('Y-m-d', strtotime('+2 months +2 days')), $result);
  263. }
  264. /**
  265. * test timeAgoInWords() with negative values.
  266. *
  267. * @return void
  268. */
  269. public function testTimeAgoInWordsNegativeValues() {
  270. $time = new Time('-2 months -2 days');
  271. $result = $time->timeAgoInWords(array('end' => '3 month'));
  272. $this->assertEquals('2 months, 2 days ago', $result);
  273. $time = new Time('-2 months -2 days');
  274. $result = $time->timeAgoInWords(array('end' => '3 month'));
  275. $this->assertEquals('2 months, 2 days ago', $result);
  276. $time = new Time('-2 months -2 days');
  277. $result = $time->timeAgoInWords(array('end' => '1 month', 'format' => 'YYYY-MM-dd'));
  278. $this->assertEquals('on ' . date('Y-m-d', strtotime('-2 months -2 days')), $result);
  279. $time = new Time('-2 years -5 months -2 days');
  280. $result = $time->timeAgoInWords(array('end' => '3 years'));
  281. $this->assertEquals('2 years, 5 months, 2 days ago', $result);
  282. $time = new Time('-2 weeks -2 days');
  283. $result = $time->timeAgoInWords(array('format' => 'YYYY-MM-dd'));
  284. $this->assertEquals('2 weeks, 2 days ago', $result);
  285. $time = new Time('-3 years -12 months');
  286. $result = $time->timeAgoInWords();
  287. $expected = 'on ' . $time->format('j/n/y');
  288. $this->assertEquals($expected, $result);
  289. $time = new Time('-1 month -1 week -6 days');
  290. $result = $time->timeAgoInWords(
  291. array('end' => '1 year', 'accuracy' => array('month' => 'month'))
  292. );
  293. $this->assertEquals('1 month ago', $result);
  294. $time = new Time('-1 years -2 weeks -3 days');
  295. $result = $time->timeAgoInWords(
  296. array('accuracy' => array('year' => 'year'))
  297. );
  298. $expected = 'on ' . $time->format('j/n/y');
  299. $this->assertEquals($expected, $result);
  300. $time = new Time('-13 months -5 days');
  301. $result = $time->timeAgoInWords(array('end' => '2 years'));
  302. $this->assertEquals('1 year, 1 month, 5 days ago', $result);
  303. $time = new Time('-58 minutes');
  304. $result = $time->timeAgoInWords(array('accuracy' => 'hour'));
  305. $this->assertEquals('about an hour ago', $result);
  306. $time = new Time('-23 hours');
  307. $result = $time->timeAgoInWords(array('accuracy' => 'day'));
  308. $this->assertEquals('about a day ago', $result);
  309. }
  310. /**
  311. * testNice method
  312. *
  313. * @return void
  314. */
  315. public function testNice() {
  316. $time = new Time('2014-04-20 20:00', 'UTC');
  317. $this->assertTimeFormat('Apr 20, 2014, 8:00 PM', $time->nice());
  318. $result = $time->nice('America/New_York');
  319. $this->assertTimeFormat('Apr 20, 2014, 4:00 PM', $result);
  320. $this->assertEquals('UTC', $time->getTimezone()->getName());
  321. $this->assertTimeFormat('20 avr. 2014 20:00', $time->nice(null, 'fr-FR'));
  322. $this->assertTimeFormat('20 avr. 2014 16:00', $time->nice('America/New_York', 'fr-FR'));
  323. }
  324. /**
  325. * testToUnix method
  326. *
  327. * @return void
  328. */
  329. public function testToUnix() {
  330. $time = new Time('2014-04-20 08:00:00');
  331. $this->assertEquals('1397980800', $time->toUnixString());
  332. $time = new Time('2021-12-11 07:00:01');
  333. $this->assertEquals('1639206001', $time->toUnixString());
  334. }
  335. /**
  336. * testIsThisWeek method
  337. *
  338. * @return void
  339. */
  340. public function testIsThisWeek() {
  341. $time = new Time('this sunday');
  342. $this->assertTrue($time->isThisWeek());
  343. $this->assertTrue($time->modify('-1 day')->isThisWeek());
  344. $this->assertFalse($time->modify('-6 days')->isThisWeek());
  345. $time = new Time();
  346. $time->year = $time->year - 1;
  347. $this->assertFalse($time->isThisWeek());
  348. }
  349. /**
  350. * testIsThisMonth method
  351. *
  352. * @return void
  353. */
  354. public function testIsThisMonth() {
  355. $time = new Time();
  356. $this->assertTrue($time->isThisMonth());
  357. $time->year = $time->year + 1;
  358. $this->assertFalse($time->isThisMonth());
  359. $time = new Time();
  360. $this->assertFalse($time->modify('next month')->isThisMonth());
  361. }
  362. /**
  363. * testIsThisYear method
  364. *
  365. * @return void
  366. */
  367. public function testIsThisYear() {
  368. $time = new Time();
  369. $this->assertTrue($time->isThisYear());
  370. $time->year = $time->year + 1;
  371. $this->assertFalse($time->isThisYear());
  372. $thisYear = date('Y');
  373. $time = new Time("$thisYear-01-01 00:00", 'Australia/Sydney');
  374. $now = clone $time;
  375. $now->timezone('UTC');
  376. Time::setTestNow($now);
  377. $this->assertFalse($time->isThisYear());
  378. }
  379. /**
  380. * testWasWithinLast method
  381. *
  382. * @return void
  383. */
  384. public function testWasWithinLast() {
  385. $this->assertTrue((new Time('-1 day'))->wasWithinLast('1 day'));
  386. $this->assertTrue((new Time('-1 week'))->wasWithinLast('1 week'));
  387. $this->assertTrue((new Time('-1 year'))->wasWithinLast('1 year'));
  388. $this->assertTrue((new Time('-1 second'))->wasWithinLast('1 second'));
  389. $this->assertTrue((new Time('-1 day'))->wasWithinLast('1 week'));
  390. $this->assertTrue((new Time('-1 week'))->wasWithinLast('2 week'));
  391. $this->assertTrue((new Time('-1 second'))->wasWithinLast('10 minutes'));
  392. $this->assertTrue((new Time('-1 month'))->wasWithinLast('13 month'));
  393. $this->assertTrue((new Time('-1 seconds'))->wasWithinLast('1 hour'));
  394. $this->assertFalse((new Time('-1 year'))->wasWithinLast('1 second'));
  395. $this->assertFalse((new Time('-1 year'))->wasWithinLast('0 year'));
  396. $this->assertFalse((new Time('-1 weeks'))->wasWithinLast('1 day'));
  397. $this->assertTrue((new Time('-3 days'))->wasWithinLast('5'));
  398. }
  399. /**
  400. * testWasWithinLast method
  401. *
  402. * @return void
  403. */
  404. public function testIsWithinNext() {
  405. $this->assertFalse((new Time('-1 day'))->isWithinNext('1 day'));
  406. $this->assertFalse((new Time('-1 week'))->isWithinNext('1 week'));
  407. $this->assertFalse((new Time('-1 year'))->isWithinNext('1 year'));
  408. $this->assertFalse((new Time('-1 second'))->isWithinNext('1 second'));
  409. $this->assertFalse((new Time('-1 day'))->isWithinNext('1 week'));
  410. $this->assertFalse((new Time('-1 week'))->isWithinNext('2 week'));
  411. $this->assertFalse((new Time('-1 second'))->isWithinNext('10 minutes'));
  412. $this->assertFalse((new Time('-1 month'))->isWithinNext('13 month'));
  413. $this->assertFalse((new Time('-1 seconds'))->isWithinNext('1 hour'));
  414. $this->assertTrue((new Time('+1 day'))->isWithinNext('1 day'));
  415. $this->assertTrue((new Time('+1 week'))->isWithinNext('7 day'));
  416. $this->assertTrue((new Time('+1 second'))->isWithinNext('1 minute'));
  417. $this->assertTrue((new Time('+1 month'))->isWithinNext('1 month'));
  418. }
  419. /**
  420. * test formatting dates taking in account preferred i18n locale file
  421. *
  422. * @return void
  423. */
  424. public function testI18nFormat() {
  425. $time = new Time('Thu Jan 14 13:59:28 2010');
  426. $result = $time->i18nFormat();
  427. $expected = '1/14/10, 1:59 PM';
  428. $this->assertTimeFormat($expected, $result);
  429. $result = $time->i18nFormat(\IntlDateFormatter::FULL, null, 'es-ES');
  430. $expected = 'jueves, 14 de enero de 2010, 13:59:28 (GMT)';
  431. $this->assertTimeFormat($expected, $result);
  432. $format = [\IntlDateFormatter::NONE, \IntlDateFormatter::SHORT];
  433. $result = $time->i18nFormat($format);
  434. $expected = '1:59 PM';
  435. $this->assertTimeFormat($expected, $result);
  436. $result = $time->i18nFormat('HH:mm:ss', 'Australia/Sydney');
  437. $expected = '00:59:28';
  438. $this->assertTimeFormat($expected, $result);
  439. Time::$defaultLocale = 'fr-FR';
  440. $result = $time->i18nFormat(\IntlDateFormatter::FULL);
  441. $expected = 'jeudi 14 janvier 2010 13:59:28 UTC';
  442. $this->assertTimeFormat($expected, $result);
  443. $result = $time->i18nFormat(\IntlDateFormatter::FULL, null, 'es-ES');
  444. $expected = 'jueves, 14 de enero de 2010, 13:59:28 (GMT)';
  445. $this->assertTimeFormat($expected, $result, 'DEfault locale should not be used');
  446. }
  447. /**
  448. * testListTimezones
  449. *
  450. * @return void
  451. */
  452. public function testListTimezones() {
  453. $return = Time::listTimezones();
  454. $this->assertTrue(isset($return['Asia']['Asia/Bangkok']));
  455. $this->assertEquals('Bangkok', $return['Asia']['Asia/Bangkok']);
  456. $this->assertTrue(isset($return['America']['America/Argentina/Buenos_Aires']));
  457. $this->assertEquals('Argentina/Buenos_Aires', $return['America']['America/Argentina/Buenos_Aires']);
  458. $this->assertTrue(isset($return['UTC']['UTC']));
  459. $this->assertFalse(isset($return['Cuba']));
  460. $this->assertFalse(isset($return['US']));
  461. $return = Time::listTimezones('#^Asia/#');
  462. $this->assertTrue(isset($return['Asia']['Asia/Bangkok']));
  463. $this->assertFalse(isset($return['Pacific']));
  464. $return = Time::listTimezones('#^(America|Pacific)/#', null, false);
  465. $this->assertTrue(isset($return['America/Argentina/Buenos_Aires']));
  466. $this->assertTrue(isset($return['Pacific/Tahiti']));
  467. $return = Time::listTimezones(\DateTimeZone::ASIA);
  468. $this->assertTrue(isset($return['Asia']['Asia/Bangkok']));
  469. $this->assertFalse(isset($return['Pacific']));
  470. $return = Time::listTimezones(\DateTimeZone::PER_COUNTRY, 'US', false);
  471. $this->assertTrue(isset($return['Pacific/Honolulu']));
  472. $this->assertFalse(isset($return['Asia/Bangkok']));
  473. }
  474. /**
  475. * Tests that __toString uses the i18n formatter
  476. *
  477. * @return void
  478. */
  479. public function testToString() {
  480. $time = new Time('2014-04-20 22:10');
  481. Time::$defaultLocale = 'fr-FR';
  482. Time::setToStringFormat(\IntlDateFormatter::FULL);
  483. $this->assertTimeFormat('dimanche 20 avril 2014 22:10:00 UTC', (string)$time);
  484. }
  485. /**
  486. * Data provider for invalid values.
  487. *
  488. * @return array
  489. */
  490. public function invalidDataProvider() {
  491. return [
  492. [null],
  493. [false],
  494. [''],
  495. ];
  496. }
  497. /**
  498. * Test that invalid datetime values do not trigger errors.
  499. *
  500. * @dataProvider invalidDataProvider
  501. * @return void
  502. */
  503. public function testToStringInvalid($value) {
  504. $time = new Time($value);
  505. $this->assertInternalType('string', (string)$time);
  506. $this->assertNotEmpty((string)$time);
  507. }
  508. /**
  509. * These invalid values are not invalid on windows :(
  510. *
  511. * @return void
  512. */
  513. public function testToStringInvalidZeros() {
  514. $this->skipIf(DS === '\\', 'All zeros are valid on windows.');
  515. $time = new Time('0000-00-00');
  516. $this->assertInternalType('string', (string)$time);
  517. $this->assertNotEmpty((string)$time);
  518. $time = new Time('0000-00-00 00:00:00');
  519. $this->assertInternalType('string', (string)$time);
  520. $this->assertNotEmpty((string)$time);
  521. }
  522. /**
  523. * Tests diffForHumans
  524. *
  525. * @return void
  526. */
  527. public function testDiffForHumans() {
  528. $time = new Time('2014-04-20 10:10:10');
  529. $other = new Time('2014-04-27 10:10:10');
  530. $this->assertEquals('1 week ago', $time->diffForHumans($other));
  531. $other = new Time('2014-04-21 09:10:10');
  532. $this->assertEquals('23 hours ago', $time->diffForHumans($other));
  533. $other = new Time('2014-04-13 09:10:10');
  534. $this->assertEquals('1 week', $time->diffForHumans($other));
  535. }
  536. /**
  537. * Tests encoding a Time object as json
  538. *
  539. * @return void
  540. */
  541. public function testJsonEnconde() {
  542. $time = new Time('2014-04-20 10:10:10');
  543. $this->assertEquals('"2014-04-20T10:10:10+0000"', json_encode($time));
  544. }
  545. /**
  546. * Tests debugInfo
  547. *
  548. * @return void
  549. */
  550. public function testDebugInfo() {
  551. $time = new Time('2014-04-20 10:10:10');
  552. $expected = [
  553. 'time' => '2014-04-20T10:10:10+0000',
  554. 'timezone' => 'UTC',
  555. 'fixedNowTime' => Time::getTestNow()->toISO8601String()
  556. ];
  557. $this->assertEquals($expected, $time->__debugInfo());
  558. }
  559. /**
  560. * Cusotm assert to allow for variation in the version of the intl library, where
  561. * some translations contain a few extra commas.
  562. *
  563. * @param string $expected
  564. * @param string $result
  565. * @return void
  566. */
  567. public function assertTimeFormat($expected, $result) {
  568. return $this->assertEquals(
  569. str_replace([',', '(', ')', ' at'], '', $expected),
  570. str_replace([',', '(', ')', ' at'], '', $result)
  571. );
  572. }
  573. }