From dba457a702cadb296a9f974eb02dc2a5131e612c Mon Sep 17 00:00:00 2001 From: fabien Date: Wed, 2 Dec 2009 21:41:57 +0000 Subject: [PATCH] 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 --- doc/02-Twig-for-Template-Designers.markdown | 2 ++ lib/Twig/runtime.php | 2 +- 2 files changed, 3 insertions(+), 1 deletions(-) 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) -- 1.7.2.5