Permalink
Browse files

merged branch alefranz/patch-2 (PR #575)

Commits
-------

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

Discussion
----------

fix Date Format filter: DateInterval does not provide setTimezone()
  • Loading branch information...
2 parents fc85a16 + b295274 commit bd0807221b3c45bc6b846f0d60748959c9781f46 @fabpot committed Dec 30, 2011
Showing with 15 additions and 13 deletions.
  1. +15 −13 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);

0 comments on commit bd08072

Please sign in to comment.