Browse code

fixed the date filter when a DateTime instance is passed with a specific timezone (closes #660)

Fabien Potencier authored on 15/03/2012 16:24:51
Showing 3 changed files
... ...
@@ -1,5 +1,6 @@
1 1
 * 1.7.0 (2012-XX-XX)
2 2
 
3
+ * fixed the date filter when a DateTime instance is passed with a specific timezone
3 4
  * added a trim filter
4 5
 
5 6
 * 1.6.1 (2012-02-29)
... ...
@@ -380,6 +380,10 @@ function twig_date_format_filter(Twig_Environment $env, $date, $format = null, $
380 380
     }
381 381
 
382 382
     if ($date instanceof DateInterval || $date instanceof DateTime) {
383
+        if (null !== $timezone) {
384
+            $date->setTimezone($timezone instanceof DateTimeZone ? $timezone : new DateTimeZone($timezone));
385
+        }
386
+
383 387
         return $date->format($format);
384 388
     }
385 389
 
... ...
@@ -3,8 +3,10 @@
3 3
 --TEMPLATE--
4 4
 {{ date1|date }}
5 5
 {{ date1|date('d/m/Y') }}
6
+{{ date1|date('d/m/Y H:i:s', 'Europe/Paris') }}
6 7
 {{ date2|date }}
7 8
 {{ date2|date('d/m/Y') }}
9
+{{ date2|date('d/m/Y H:i:s', 'Europe/Paris') }}
8 10
 {{ date3|date }}
9 11
 {{ date3|date('d/m/Y') }}
10 12
 {{ date4|date }}
... ...
@@ -23,8 +25,10 @@ return array(
23 25
 --EXPECT--
24 26
 October 4, 2010 13:45
25 27
 04/10/2010
28
+04/10/2010 15:45:00
26 29
 October 4, 2010 13:45
27 30
 04/10/2010
31
+04/10/2010 15:45:00
28 32
 October 4, 2010 13:45
29 33
 04/10/2010
30 34
 October 4, 2010 13:45