added support for DateTime instances for the date filter (closes #41)
authorfabien <fabien@93ef8e89-cb99-4229-a87c-7fa0fa45744b>
Wed, 2 Dec 2009 21:41:57 +0000 (21:41 +0000)
committerfabien <fabien@93ef8e89-cb99-4229-a87c-7fa0fa45744b>
Wed, 2 Dec 2009 21:41:57 +0000 (21:41 +0000)
git-svn-id: http://svn.twig-project.org/trunk@150 93ef8e89-cb99-4229-a87c-7fa0fa45744b

doc/02-Twig-for-Template-Designers.markdown
lib/Twig/runtime.php

index 014a2e5..2db8e95 100644 (file)
@@ -733,6 +733,8 @@ The `date` filter is able to format a date to a given format:
     [twig]
     {{ post.published_at|date("m/d/Y") }}
 
+The `date` filter accepts both timestamps and `DateTime` instances.
+
 ### `format`
 
 The `format` filter formats a given string by replacing the placeholders:
index 3eaab71..4df8d41 100644 (file)
@@ -12,7 +12,7 @@
 
 function twig_date_format_filter($timestamp, $format = 'F j, Y H:i')
 {
-  return date($format, $timestamp);
+  return $timestamp instanceof DateTime ? $timestamp->format($format) : date($format, $timestamp);
 }
 
 function twig_urlencode_filter($url, $raw = false)