Permalink
Browse files

improved error message if date/time formatting fails

  • Loading branch information...
1 parent 2371be5 commit 0c5a6c1cd123da75e6622f6639304d3f7b1b752d @craue committed Jan 12, 2012
Showing with 4 additions and 3 deletions.
  1. +4 −3 Twig/Extension/FormatDateTimeExtension.php
@@ -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;

0 comments on commit 0c5a6c1

Please sign in to comment.