From: fabien Date: Wed, 2 Dec 2009 21:41:57 +0000 (+0000) Subject: added support for DateTime instances for the date filter (closes #41) X-Git-Url: http://git.silmor.de/gitweb/?a=commitdiff_plain;h=dba457a702cadb296a9f974eb02dc2a5131e612c;p=konrad%2Ftwig.git added support for DateTime instances for the date filter (closes #41) git-svn-id: http://svn.twig-project.org/trunk@150 93ef8e89-cb99-4229-a87c-7fa0fa45744b --- diff --git a/doc/02-Twig-for-Template-Designers.markdown b/doc/02-Twig-for-Template-Designers.markdown index 014a2e5..2db8e95 100644 --- a/doc/02-Twig-for-Template-Designers.markdown +++ b/doc/02-Twig-for-Template-Designers.markdown @@ -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: diff --git a/lib/Twig/runtime.php b/lib/Twig/runtime.php index 3eaab71..4df8d41 100644 --- a/lib/Twig/runtime.php +++ b/lib/Twig/runtime.php @@ -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)