TimeHelperTest.php 21 KB

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