Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

fix Date Format filter: DateInterval does not provide setTimezone()

  • Loading branch information...
commit b2952743d19d40091c0bf82ce539651f72ba0867 1 parent fc85a16
@alefranz alefranz authored
Showing with 15 additions and 13 deletions.
  1. +15 −13 lib/Twig/Extension/Core.php
View
28 lib/Twig/Extension/Core.php
@@ -313,22 +313,24 @@ function twig_date_format_filter(Twig_Environment $env, $date, $format = null, $
$format = $env->getExtension('core')->getDateFormat();
}
- if (!$date instanceof DateTime && !$date instanceof DateInterval) {
- $asString = (string) $date;
- if (ctype_digit($asString) || (!empty($asString) && '-' === $asString[0] && ctype_digit(substr($asString, 1)))) {
- $date = new DateTime('@'.$date);
- $date->setTimezone(new DateTimeZone(date_default_timezone_get()));
- } else {
- $date = new DateTime($date);
+ if (!$date instanceof DateInterval) {
+ if (!$date instanceof DateTime) {
+ $asString = (string) $date;
+ if (ctype_digit($asString) || (!empty($asString) && '-' === $asString[0] && ctype_digit(substr($asString, 1)))) {
+ $date = new DateTime('@'.$date);
+ $date->setTimezone(new DateTimeZone(date_default_timezone_get()));
+ } else {
+ $date = new DateTime($date);
+ }
}
- }
- if (null !== $timezone) {
- if (!$timezone instanceof DateTimeZone) {
- $timezone = new DateTimeZone($timezone);
- }
+ if (null !== $timezone) {
+ if (!$timezone instanceof DateTimeZone) {
+ $timezone = new DateTimeZone($timezone);
+ }
- $date->setTimezone($timezone);
+ $date->setTimezone($timezone);
+ }
}
return $date->format($format);
Please sign in to comment.
Something went wrong with that request. Please try again.