Skip to content

Commit

Permalink
Relax types to fix string casting and format Chronos as well
Browse files Browse the repository at this point in the history
  • Loading branch information
markstory committed Jul 2, 2024
1 parent fe785ec commit 707e747
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/Twig/Extension/TimeExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

namespace Cake\TwigView\Twig\Extension;

use Cake\Chronos\Chronos;
use Cake\Chronos\ChronosDate;
use Cake\I18n\DateTime;
use DateInterval;

Check failure on line 24 in src/Twig/Extension/TimeExtension.php

View workflow job for this annotation

GitHub Actions / cs-stan / Coding Standard & Static Analysis

Type DateInterval is not used in this file.
Expand Down Expand Up @@ -70,12 +71,12 @@ public function getFunctions(): array
*
* Includes shims for \Chronos\ChronosDate as Twig doesn't.
*
* @param \Chronos\ChronosDate|\DateTimeInterface|\DateInterval|string $date The date to format.
* @param mixed $date The date to format.
* @param ?string $format The format to use, null to use the default.
* @param \DateTimeZone|string|false|null $timezone The target timezone, null to use system.
*/
public function formatDate(
ChronosDate|DateTimeInterface|DateInterval|string $date,
mixed $date,
?string $format = null,
DateTimeZone|string|false|null $timezone = null
): string {
Expand All @@ -85,6 +86,9 @@ public function formatDate(
if ($date instanceof ChronosDate) {
$date = $date->toDateString();
}
if ($date instanceof Chronos) {
$date = $date->toIso8601String();
}

return $this->coreExt->formatDate($date, $format, $timezone);
}
Expand Down

0 comments on commit 707e747

Please sign in to comment.