Browse Source

Modify TimeHelper::format to accept arrays for the parameter

Mauro Brandoni 2 years ago
parent
commit
7786003bfc
2 changed files with 6 additions and 2 deletions
  1. 2 2
      src/View/Helper/TimeHelper.php
  2. 4 0
      tests/TestCase/View/Helper/TimeHelperTest.php

+ 2 - 2
src/View/Helper/TimeHelper.php

@@ -395,7 +395,7 @@ class TimeHelper extends Helper
      *
      * @param \Cake\Chronos\ChronosDate|\DateTimeInterface|string|int|null $date UNIX timestamp, strtotime() valid string
      *   or DateTime object (or a date format string).
-     * @param string|int|null $format date format string (or a UNIX timestamp,
+     * @param array<int>|string|int|null $format date format string (or a UNIX timestamp,
      *   `strtotime()` valid string or DateTime object).
      * @param string|false $invalid Default value to display on invalid dates
      * @param \DateTimeZone|string|null $timezone User's timezone string or DateTimeZone object
@@ -404,7 +404,7 @@ class TimeHelper extends Helper
      */
     public function format(
         ChronosDate|DateTimeInterface|string|int|null $date,
-        string|int|null $format = null,
+        array|string|int|null $format = null,
         string|false $invalid = false,
         DateTimeZone|string|null $timezone = null
     ): string|int|false {

+ 4 - 0
tests/TestCase/View/Helper/TimeHelperTest.php

@@ -473,6 +473,10 @@ class TimeHelperTest extends TestCase
         $result = preg_replace('/[\pZ\pC]/u', ' ', $result);
         $this->assertStringStartsWith('Thursday, January 14, 2010 at 1:59:28 PM', $result);
 
+        $result = $this->Time->format($time, [IntlDateFormatter::SHORT, IntlDateFormatter::MEDIUM]);
+        $result = preg_replace('/[\pZ\pC]/u', ' ', $result);
+        $this->assertSame('1/14/10, 1:59:28 PM', $result);
+
         $result = $this->Time->format('invalid date', null, 'Date invalid');
         $expected = 'Date invalid';
         $this->assertSame($expected, $result);