TimeHelperTest.php 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623
  1. <?php
  2. /**
  3. * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
  4. * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
  5. *
  6. * Licensed under The MIT License
  7. * For full copyright and license information, please see the LICENSE.txt
  8. * Redistributions of files must retain the above copyright notice
  9. *
  10. * @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
  11. * @link http://cakephp.org CakePHP(tm) Project
  12. * @since 1.2.0
  13. * @license http://www.opensource.org/licenses/mit-license.php MIT License
  14. */
  15. namespace Cake\Test\TestCase\View\Helper;
  16. use Cake\Core\Configure;
  17. use Cake\I18n\I18n;
  18. use Cake\I18n\Time;
  19. use Cake\TestSuite\TestCase;
  20. use Cake\View\Helper\TimeHelper;
  21. use Cake\View\View;
  22. /**
  23. * TimeHelperTest class
  24. *
  25. */
  26. class TimeHelperTest extends TestCase
  27. {
  28. public $Time = null;
  29. /**
  30. * setUp method
  31. *
  32. * @return void
  33. */
  34. public function setUp()
  35. {
  36. parent::setUp();
  37. $this->View = new View();
  38. $this->Time = new TimeHelper($this->View);
  39. Time::$defaultLocale = 'en_US';
  40. $this->locale = I18n::locale();
  41. }
  42. /**
  43. * tearDown method
  44. *
  45. * @return void
  46. */
  47. public function tearDown()
  48. {
  49. parent::tearDown();
  50. Time::$defaultLocale = 'en_US';
  51. I18n::locale($this->locale);
  52. }
  53. /**
  54. * Test element wrapping in timeAgoInWords
  55. *
  56. * @return void
  57. */
  58. public function testTimeAgoInWords()
  59. {
  60. $Time = new TimeHelper($this->View);
  61. $timestamp = strtotime('+8 years, +4 months +2 weeks +3 days');
  62. $result = $Time->timeAgoInWords($timestamp, [
  63. 'end' => '1 years',
  64. 'element' => 'span'
  65. ]);
  66. $expected = [
  67. 'span' => [
  68. 'title' => $timestamp,
  69. 'class' => 'time-ago-in-words'
  70. ],
  71. 'on ' . date('n/j/y', $timestamp),
  72. '/span'
  73. ];
  74. $this->assertHtml($expected, $result);
  75. $result = $Time->timeAgoInWords($timestamp, [
  76. 'end' => '1 years',
  77. 'element' => [
  78. 'title' => 'testing',
  79. 'rel' => 'test'
  80. ]
  81. ]);
  82. $expected = [
  83. 'span' => [
  84. 'title' => 'testing',
  85. 'class' => 'time-ago-in-words',
  86. 'rel' => 'test'
  87. ],
  88. 'on ' . date('n/j/y', $timestamp),
  89. '/span'
  90. ];
  91. $this->assertHtml($expected, $result);
  92. $timestamp = strtotime('+2 weeks');
  93. $result = $Time->timeAgoInWords(
  94. $timestamp,
  95. ['end' => '1 years', 'element' => 'div']
  96. );
  97. $expected = [
  98. 'div' => [
  99. 'title' => $timestamp,
  100. 'class' => 'time-ago-in-words'
  101. ],
  102. '2 weeks',
  103. '/div'
  104. ];
  105. $this->assertHtml($expected, $result);
  106. }
  107. /**
  108. * Test output timezone with timeAgoInWords
  109. *
  110. * @return void
  111. */
  112. public function testTimeAgoInWordsOutputTimezone()
  113. {
  114. $Time = new TimeHelper($this->View, ['outputTimezone' => 'America/Vancouver']);
  115. $timestamp = new Time('+8 years, +4 months +2 weeks +3 days');
  116. $result = $Time->timeAgoInWords($timestamp, [
  117. 'end' => '1 years',
  118. 'element' => 'span'
  119. ]);
  120. $vancouver = clone $timestamp;
  121. $vancouver->timezone('America/Vancouver');
  122. $expected = [
  123. 'span' => [
  124. 'title' => $vancouver->__toString(),
  125. 'class' => 'time-ago-in-words'
  126. ],
  127. 'on ' . $vancouver->format('n/j/y'),
  128. '/span'
  129. ];
  130. $this->assertHtml($expected, $result);
  131. }
  132. /**
  133. * testToQuarter method
  134. *
  135. * @return void
  136. */
  137. public function testToQuarter()
  138. {
  139. $this->assertEquals(4, $this->Time->toQuarter('2007-12-25'));
  140. $this->assertEquals(['2007-10-01', '2007-12-31'], $this->Time->toQuarter('2007-12-25', true));
  141. }
  142. /**
  143. * testNice method
  144. *
  145. * @return void
  146. */
  147. public function testNice()
  148. {
  149. $time = '2014-04-20 20:00';
  150. $this->assertTimeFormat('Apr 20, 2014, 8:00 PM', $this->Time->nice($time));
  151. $result = $this->Time->nice($time, 'America/New_York');
  152. $this->assertTimeFormat('Apr 20, 2014, 4:00 PM', $result);
  153. }
  154. /**
  155. * test nice with outputTimezone
  156. *
  157. * @return void
  158. */
  159. public function testNiceOutputTimezone()
  160. {
  161. $this->Time->config('outputTimezone', 'America/Vancouver');
  162. $time = '2014-04-20 20:00';
  163. $this->assertTimeFormat('Apr 20, 2014, 1:00 PM', $this->Time->nice($time));
  164. }
  165. /**
  166. * testToUnix method
  167. *
  168. * @return void
  169. */
  170. public function testToUnix()
  171. {
  172. $this->assertEquals(1397980800, $this->Time->toUnix('2014-04-20 08:00:00'));
  173. }
  174. /**
  175. * testToAtom method
  176. *
  177. * @return void
  178. */
  179. public function testToAtom()
  180. {
  181. $dateTime = new \DateTime;
  182. $this->assertEquals($dateTime->format($dateTime::ATOM), $this->Time->toAtom($dateTime->getTimestamp()));
  183. }
  184. /**
  185. * testToAtom method
  186. *
  187. * @return void
  188. */
  189. public function testToAtomOutputTimezone()
  190. {
  191. $this->Time->config('outputTimezone', 'America/Vancouver');
  192. $dateTime = new Time;
  193. $vancouver = clone $dateTime;
  194. $vancouver->timezone('America/Vancouver');
  195. $this->assertEquals($vancouver->format(Time::ATOM), $this->Time->toAtom($vancouver));
  196. }
  197. /**
  198. * testToRss method
  199. *
  200. * @return void
  201. */
  202. public function testToRss()
  203. {
  204. $date = '2012-08-12 12:12:45';
  205. $time = strtotime($date);
  206. $this->assertEquals(date('r', $time), $this->Time->toRss($time));
  207. $timezones = ['Europe/London', 'Europe/Brussels', 'UTC', 'America/Denver', 'America/Caracas', 'Asia/Kathmandu'];
  208. foreach ($timezones as $timezone) {
  209. $yourTimezone = new \DateTimeZone($timezone);
  210. $yourTime = new \DateTime($date, $yourTimezone);
  211. $time = $yourTime->format('U');
  212. $this->assertEquals($yourTime->format('r'), $this->Time->toRss($time, $timezone), "Failed on $timezone");
  213. }
  214. }
  215. /**
  216. * test toRss with outputTimezone
  217. *
  218. * @return void
  219. */
  220. public function testToRssOutputTimezone()
  221. {
  222. $this->Time->config('outputTimezone', 'America/Vancouver');
  223. $dateTime = new Time;
  224. $vancouver = clone $dateTime;
  225. $vancouver->timezone('America/Vancouver');
  226. $this->assertEquals($vancouver->format('r'), $this->Time->toRss($vancouver));
  227. }
  228. /**
  229. * testOfGmt method
  230. *
  231. * @return void
  232. */
  233. public function testGmt()
  234. {
  235. $this->assertEquals(1397980800, $this->Time->gmt('2014-04-20 08:00:00'));
  236. }
  237. /**
  238. * testIsToday method
  239. *
  240. * @return void
  241. */
  242. public function testIsToday()
  243. {
  244. $result = $this->Time->isToday('+1 day');
  245. $this->assertFalse($result);
  246. $result = $this->Time->isToday('+1 days');
  247. $this->assertFalse($result);
  248. $result = $this->Time->isToday('+0 day');
  249. $this->assertTrue($result);
  250. $result = $this->Time->isToday('-1 day');
  251. $this->assertFalse($result);
  252. }
  253. /**
  254. * testIsFuture method
  255. *
  256. * @return void
  257. */
  258. public function testIsFuture()
  259. {
  260. $this->assertTrue($this->Time->isFuture('+1 month'));
  261. $this->assertTrue($this->Time->isFuture('+1 days'));
  262. $this->assertTrue($this->Time->isFuture('+1 minute'));
  263. $this->assertTrue($this->Time->isFuture('+1 second'));
  264. $this->assertFalse($this->Time->isFuture('-1 second'));
  265. $this->assertFalse($this->Time->isFuture('-1 day'));
  266. $this->assertFalse($this->Time->isFuture('-1 week'));
  267. $this->assertFalse($this->Time->isFuture('-1 month'));
  268. }
  269. /**
  270. * testIsPast method
  271. *
  272. * @return void
  273. */
  274. public function testIsPast()
  275. {
  276. $this->assertFalse($this->Time->isPast('+1 month'));
  277. $this->assertFalse($this->Time->isPast('+1 days'));
  278. $this->assertFalse($this->Time->isPast('+1 minute'));
  279. $this->assertFalse($this->Time->isPast('+1 second'));
  280. $this->assertTrue($this->Time->isPast('-1 second'));
  281. $this->assertTrue($this->Time->isPast('-1 day'));
  282. $this->assertTrue($this->Time->isPast('-1 week'));
  283. $this->assertTrue($this->Time->isPast('-1 month'));
  284. }
  285. /**
  286. * testIsThisWeek method
  287. *
  288. * @return void
  289. */
  290. public function testIsThisWeek()
  291. {
  292. // A map of days which goes from -1 day of week to +1 day of week
  293. $map = [
  294. 'Mon' => [-1, 7], 'Tue' => [-2, 6], 'Wed' => [-3, 5],
  295. 'Thu' => [-4, 4], 'Fri' => [-5, 3], 'Sat' => [-6, 2],
  296. 'Sun' => [-7, 1]
  297. ];
  298. $days = $map[date('D')];
  299. for ($day = $days[0] + 1; $day < $days[1]; $day++) {
  300. $this->assertTrue($this->Time->isThisWeek(($day > 0 ? '+' : '') . $day . ' days'));
  301. }
  302. $this->assertFalse($this->Time->isThisWeek($days[0] . ' days'));
  303. $this->assertFalse($this->Time->isThisWeek('+' . $days[1] . ' days'));
  304. }
  305. /**
  306. * testIsThisMonth method
  307. *
  308. * @return void
  309. */
  310. public function testIsThisMonth()
  311. {
  312. $result = $this->Time->isThisMonth('+0 day');
  313. $this->assertTrue($result);
  314. $result = $this->Time->isThisMonth($time = mktime(0, 0, 0, date('m'), mt_rand(1, 28), date('Y')));
  315. $this->assertTrue($result);
  316. $result = $this->Time->isThisMonth(mktime(0, 0, 0, date('m'), mt_rand(1, 28), date('Y') - mt_rand(1, 12)));
  317. $this->assertFalse($result);
  318. $result = $this->Time->isThisMonth(mktime(0, 0, 0, date('m'), mt_rand(1, 28), date('Y') + mt_rand(1, 12)));
  319. $this->assertFalse($result);
  320. }
  321. /**
  322. * testIsThisYear method
  323. *
  324. * @return void
  325. */
  326. public function testIsThisYear()
  327. {
  328. $result = $this->Time->isThisYear('+0 day');
  329. $this->assertTrue($result);
  330. $result = $this->Time->isThisYear(mktime(0, 0, 0, mt_rand(1, 12), mt_rand(1, 28), date('Y')));
  331. $this->assertTrue($result);
  332. }
  333. /**
  334. * testWasYesterday method
  335. *
  336. * @return void
  337. */
  338. public function testWasYesterday()
  339. {
  340. $result = $this->Time->wasYesterday('+1 day');
  341. $this->assertFalse($result);
  342. $result = $this->Time->wasYesterday('+1 days');
  343. $this->assertFalse($result);
  344. $result = $this->Time->wasYesterday('+0 day');
  345. $this->assertFalse($result);
  346. $result = $this->Time->wasYesterday('-1 day');
  347. $this->assertTrue($result);
  348. $result = $this->Time->wasYesterday('-1 days');
  349. $this->assertTrue($result);
  350. $result = $this->Time->wasYesterday('-2 days');
  351. $this->assertFalse($result);
  352. }
  353. /**
  354. * testIsTomorrow method
  355. *
  356. * @return void
  357. */
  358. public function testIsTomorrow()
  359. {
  360. $result = $this->Time->isTomorrow('+1 day');
  361. $this->assertTrue($result);
  362. $result = $this->Time->isTomorrow('+1 days');
  363. $this->assertTrue($result);
  364. $result = $this->Time->isTomorrow('+0 day');
  365. $this->assertFalse($result);
  366. $result = $this->Time->isTomorrow('-1 day');
  367. $this->assertFalse($result);
  368. }
  369. /**
  370. * testWasWithinLast method
  371. *
  372. * @return void
  373. */
  374. public function testWasWithinLast()
  375. {
  376. $this->assertTrue($this->Time->wasWithinLast('1 day', '-1 day'));
  377. $this->assertTrue($this->Time->wasWithinLast('1 week', '-1 week'));
  378. $this->assertTrue($this->Time->wasWithinLast('1 year', '-1 year'));
  379. $this->assertTrue($this->Time->wasWithinLast('1 second', '-1 second'));
  380. $this->assertTrue($this->Time->wasWithinLast('1 minute', '-1 minute'));
  381. $this->assertTrue($this->Time->wasWithinLast('1 year', '-1 year'));
  382. $this->assertTrue($this->Time->wasWithinLast('1 month', '-1 month'));
  383. $this->assertTrue($this->Time->wasWithinLast('1 day', '-1 day'));
  384. $this->assertTrue($this->Time->wasWithinLast('1 week', '-1 day'));
  385. $this->assertTrue($this->Time->wasWithinLast('2 week', '-1 week'));
  386. $this->assertFalse($this->Time->wasWithinLast('1 second', '-1 year'));
  387. $this->assertTrue($this->Time->wasWithinLast('10 minutes', '-1 second'));
  388. $this->assertTrue($this->Time->wasWithinLast('23 minutes', '-1 minute'));
  389. $this->assertFalse($this->Time->wasWithinLast('0 year', '-1 year'));
  390. $this->assertTrue($this->Time->wasWithinLast('13 month', '-1 month'));
  391. $this->assertTrue($this->Time->wasWithinLast('2 days', '-1 day'));
  392. $this->assertFalse($this->Time->wasWithinLast('1 week', '-2 weeks'));
  393. $this->assertFalse($this->Time->wasWithinLast('1 second', '-2 seconds'));
  394. $this->assertFalse($this->Time->wasWithinLast('1 day', '-2 days'));
  395. $this->assertFalse($this->Time->wasWithinLast('1 hour', '-2 hours'));
  396. $this->assertFalse($this->Time->wasWithinLast('1 month', '-2 months'));
  397. $this->assertFalse($this->Time->wasWithinLast('1 year', '-2 years'));
  398. $this->assertFalse($this->Time->wasWithinLast('1 day', '-2 weeks'));
  399. $this->assertFalse($this->Time->wasWithinLast('1 day', '-2 days'));
  400. $this->assertFalse($this->Time->wasWithinLast('0 days', '-2 days'));
  401. $this->assertTrue($this->Time->wasWithinLast('1 hour', '-20 seconds'));
  402. $this->assertTrue($this->Time->wasWithinLast('1 year', '-60 minutes -30 seconds'));
  403. $this->assertTrue($this->Time->wasWithinLast('3 years', '-2 months'));
  404. $this->assertTrue($this->Time->wasWithinLast('5 months', '-4 months'));
  405. $this->assertTrue($this->Time->wasWithinLast('5 ', '-3 days'));
  406. $this->assertTrue($this->Time->wasWithinLast('1 ', '-1 hour'));
  407. $this->assertTrue($this->Time->wasWithinLast('1 ', '-1 minute'));
  408. $this->assertTrue($this->Time->wasWithinLast('1 ', '-23 hours -59 minutes -59 seconds'));
  409. }
  410. /**
  411. * testWasWithinLast method
  412. *
  413. * @return void
  414. */
  415. public function testIsWithinNext()
  416. {
  417. $this->assertFalse($this->Time->isWithinNext('1 day', '-1 day'));
  418. $this->assertFalse($this->Time->isWithinNext('1 week', '-1 week'));
  419. $this->assertFalse($this->Time->isWithinNext('1 year', '-1 year'));
  420. $this->assertFalse($this->Time->isWithinNext('1 second', '-1 second'));
  421. $this->assertFalse($this->Time->isWithinNext('1 minute', '-1 minute'));
  422. $this->assertFalse($this->Time->isWithinNext('1 year', '-1 year'));
  423. $this->assertFalse($this->Time->isWithinNext('1 month', '-1 month'));
  424. $this->assertFalse($this->Time->isWithinNext('1 day', '-1 day'));
  425. $this->assertFalse($this->Time->isWithinNext('1 week', '-1 day'));
  426. $this->assertFalse($this->Time->isWithinNext('2 week', '-1 week'));
  427. $this->assertFalse($this->Time->isWithinNext('1 second', '-1 year'));
  428. $this->assertFalse($this->Time->isWithinNext('10 minutes', '-1 second'));
  429. $this->assertFalse($this->Time->isWithinNext('23 minutes', '-1 minute'));
  430. $this->assertFalse($this->Time->isWithinNext('0 year', '-1 year'));
  431. $this->assertFalse($this->Time->isWithinNext('13 month', '-1 month'));
  432. $this->assertFalse($this->Time->isWithinNext('2 days', '-1 day'));
  433. $this->assertFalse($this->Time->isWithinNext('1 week', '-2 weeks'));
  434. $this->assertFalse($this->Time->isWithinNext('1 second', '-2 seconds'));
  435. $this->assertFalse($this->Time->isWithinNext('1 day', '-2 days'));
  436. $this->assertFalse($this->Time->isWithinNext('1 hour', '-2 hours'));
  437. $this->assertFalse($this->Time->isWithinNext('1 month', '-2 months'));
  438. $this->assertFalse($this->Time->isWithinNext('1 year', '-2 years'));
  439. $this->assertFalse($this->Time->isWithinNext('1 day', '-2 weeks'));
  440. $this->assertFalse($this->Time->isWithinNext('1 day', '-2 days'));
  441. $this->assertFalse($this->Time->isWithinNext('0 days', '-2 days'));
  442. $this->assertFalse($this->Time->isWithinNext('1 hour', '-20 seconds'));
  443. $this->assertFalse($this->Time->isWithinNext('1 year', '-60 minutes -30 seconds'));
  444. $this->assertFalse($this->Time->isWithinNext('3 years', '-2 months'));
  445. $this->assertFalse($this->Time->isWithinNext('5 months', '-4 months'));
  446. $this->assertTrue($this->Time->isWithinNext('1 day', '+1 day'));
  447. $this->assertTrue($this->Time->isWithinNext('7 day', '+1 week'));
  448. $this->assertTrue($this->Time->isWithinNext('1 minute', '+1 second'));
  449. $this->assertTrue($this->Time->isWithinNext('1 month', '+1 month'));
  450. }
  451. /**
  452. * test formatting dates taking in account preferred i18n locale file
  453. *
  454. * @return void
  455. */
  456. public function testFormat()
  457. {
  458. $time = strtotime('Thu Jan 14 13:59:28 2010');
  459. $result = $this->Time->format($time);
  460. $expected = '1/14/10, 1:59 PM';
  461. $this->assertTimeFormat($expected, $result);
  462. $result = $this->Time->format($time, \IntlDateFormatter::FULL);
  463. $expected = 'Thursday, January 14, 2010 at 1:59:28 PM GMT';
  464. $this->assertTimeFormat($expected, $result);
  465. $result = $this->Time->format('invalid date', null, 'Date invalid');
  466. $expected = 'Date invalid';
  467. $this->assertEquals($expected, $result);
  468. I18n::locale('fr_FR');
  469. Time::$defaultLocale = 'fr_FR';
  470. $time = new \Cake\I18n\FrozenTime('Thu Jan 14 13:59:28 2010');
  471. $result = $this->Time->format($time, \IntlDateFormatter::FULL);
  472. $expected = 'jeudi 14 janvier 2010 13:59:28 UTC';
  473. $this->assertTimeFormat($expected, $result);
  474. }
  475. /**
  476. * test format with outputTimezone
  477. *
  478. * @return void
  479. */
  480. public function testFormatOutputTimezone()
  481. {
  482. $this->Time->config('outputTimezone', 'America/Vancouver');
  483. $time = strtotime('Thu Jan 14 8:59:28 2010 UTC');
  484. $result = $this->Time->format($time);
  485. $expected = '1/14/10, 12:59 AM';
  486. $this->assertTimeFormat($expected, $result);
  487. $time = new Time('Thu Jan 14 8:59:28 2010', 'UTC');
  488. $result = $this->Time->format($time);
  489. $expected = '1/14/10, 12:59 AM';
  490. $this->assertTimeFormat($expected, $result);
  491. }
  492. /**
  493. * test i18nFormat with outputTimezone
  494. *
  495. * @return void
  496. */
  497. public function testI18nFormatOutputTimezone()
  498. {
  499. $this->Time->config('outputTimezone', 'America/Vancouver');
  500. $time = strtotime('Thu Jan 14 8:59:28 2010 UTC');
  501. $result = $this->Time->i18nFormat($time, \IntlDateFormatter::SHORT);
  502. $expected = '1/14/10, 12:59:28 AM';
  503. $this->assertStringStartsWith($expected, $result);
  504. }
  505. /**
  506. * Test format() with a string.
  507. *
  508. * @return void
  509. */
  510. public function testFormatString()
  511. {
  512. $time = '2010-01-14 13:59:28';
  513. $result = $this->Time->format($time);
  514. $this->assertTimeFormat('1/14/10 1:59 PM', $result);
  515. $result = $this->Time->format($time, 'HH:mm', null, 'America/New_York');
  516. $this->assertTimeFormat('08:59', $result);
  517. }
  518. /**
  519. * Test format() with a Time instance.
  520. *
  521. * @return void
  522. */
  523. public function testFormatTimeInstance()
  524. {
  525. $time = new Time('2010-01-14 13:59:28', 'America/New_York');
  526. $result = $this->Time->format($time, 'HH:mm', null, 'America/New_York');
  527. $this->assertTimeFormat('13:59', $result);
  528. $time = new Time('2010-01-14 13:59:28', 'UTC');
  529. $result = $this->Time->format($time, 'HH:mm', null, 'America/New_York');
  530. $this->assertTimeFormat('08:59', $result);
  531. }
  532. /**
  533. * Custom assert to allow for variation in the version of the intl library, where
  534. * some translations contain a few extra commas.
  535. *
  536. * @param string $expected
  537. * @param string $result
  538. * @return void
  539. */
  540. public function assertTimeFormat($expected, $result)
  541. {
  542. return $this->assertEquals(
  543. str_replace([',', '(', ')', ' at', ' à'], '', $expected),
  544. str_replace([',', '(', ')', ' at', ' à'], '', $result)
  545. );
  546. }
  547. /**
  548. * Test formatting in case the $time parameter is not set
  549. *
  550. * @return void
  551. */
  552. public function testNullDateFormat()
  553. {
  554. $result = $this->Time->format(null);
  555. $this->assertSame(false, $result);
  556. $fallback = 'Date invalid or not set';
  557. $result = $this->Time->format(null, \IntlDateFormatter::FULL, $fallback);
  558. $this->assertEquals($fallback, $result);
  559. }
  560. }