Skip to content

Commit

Permalink
dev: Refactor the _date helper function
Browse files Browse the repository at this point in the history
  • Loading branch information
marienfressinaud committed Mar 25, 2024
1 parent 63609b1 commit 28620cb
Showing 1 changed file with 2 additions and 23 deletions.
25 changes: 2 additions & 23 deletions src/utils/view_helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,36 +9,15 @@
*/

/**
* Format a datetime.
* Format a datetime in the current locale.
*
* @see https://www.php.net/manual/class.intldateformatter.php
* @see https://unicode-org.github.io/icu/userguide/format_parse/datetime/#datetime-format-syntax
*
* @throws \Exception
* If the date cannot be formatted
*/
function _date(\DateTimeInterface $date, string $format): string
{
$current_locale = \flusio\utils\Locale::currentLocale();
$formatter = new IntlDateFormatter(
$current_locale,
IntlDateFormatter::FULL,
IntlDateFormatter::FULL,
null,
null,
$format
);

$formatted_date = $formatter->format($date);

if ($formatted_date === false) {
throw new \Exception(
$formatter->getErrorMessage(),
$formatter->getErrorCode()
);
}

return $formatted_date;
return \Minz\Output\ViewHelpers::formatDate($date, $format, $current_locale);
}

/**
Expand Down

0 comments on commit 28620cb

Please sign in to comment.