Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

improved error message if date/time formatting fails

  • Loading branch information...
commit 0c5a6c1cd123da75e6622f6639304d3f7b1b752d 1 parent 2371be5
Christian Raue authored
Showing with 4 additions and 3 deletions.
  1. +4 −3 Twig/Extension/FormatDateTimeExtension.php
7 Twig/Extension/FormatDateTimeExtension.php
View
@@ -146,17 +146,18 @@ protected function getFormattedDateTime($value, $locale, $datetype, $timetype) {
}
$valueToUse = $value;
- $localeToUse = !empty($locale) ? $locale : $this->getLocale();
- $formatter = new \IntlDateFormatter($localeToUse, $datetype, $timetype, date_default_timezone_get());
// IntlDateFormatter#format() doesn't support \DateTime objects prior to PHP 5.3.4 (http://php.net/manual/intldateformatter.format.php)
if ($valueToUse instanceof \DateTime) {
$valueToUse = $valueToUse->getTimestamp();
}
+ $localeToUse = !empty($locale) ? $locale : $this->getLocale();
+ $formatter = new \IntlDateFormatter($localeToUse, $datetype, $timetype, date_default_timezone_get());
+
$result = $formatter->format($valueToUse);
if ($result === false) {
- throw new \InvalidArgumentException(sprintf('The value "%s" of type %s cannot be formatted.', $value, gettype($value)));
+ throw new \InvalidArgumentException(sprintf('The value "%s" of type %s cannot be formatted. Error: "%s".', $value, gettype($value), $formatter->getErrorMessage()));
}
return $result;
Please sign in to comment.
Something went wrong with that request. Please try again.