Backward incompatibilities:
* The short notation of the `block` tag changed.
+ * changed the date filter to support any date format supported by DateTime
* added ignore_invalid_variables setting to throw an exception when an invalid variable is used in a template (disabled automatically when debug is true)
* added the lexer, parser, and compiler as arguments to the Twig_Environment constructor
* changed the cache option to only accepts an explicit path to a cache directory or false
[twig]
{{ post.published_at|date("m/d/Y") }}
-The `date` filter accepts both timestamps and `DateTime` instances.
+The `date` filter accepts any date format supported by
+[`DateTime`](http://www.php.net/manual/en/datetime.construct.php) and
+`DateTime` instances.
### `format`
}
}
-function twig_date_format_filter($timestamp, $format = 'F j, Y H:i')
+function twig_date_format_filter($date, $format = 'F j, Y H:i')
{
- return $timestamp instanceof DateTime ? $timestamp->format($format) : date($format, $timestamp);
+ if (!$date instanceof DateTime) {
+ $date = new DateTime((ctype_digit($date) ? '@' : '').$date);
+ }
+
+ return $date->format($format);
}
function twig_urlencode_filter($url, $raw = false)
{{ date1|date('d/m/Y') }}
{{ date2|date }}
{{ date2|date('d/m/Y') }}
+{{ date3|date }}
+{{ date3|date('d/m/Y') }}
+{{ date4|date }}
+{{ date4|date('d/m/Y') }}
--DATA--
-return array('date1' => mktime(13, 45, 0, 10, 4, 2010), 'date2' => new DateTime('2010-10-04 13:45'))
+date_default_timezone_set('UTC');
+return array('date1' => mktime(13, 45, 0, 10, 4, 2010), 'date2' => new DateTime('2010-10-04 13:45'), 'date3' => '2010-10-04 13:45', 'date4' => 1286199900)
--EXPECT--
October 4, 2010 13:45
04/10/2010
October 4, 2010 13:45
04/10/2010
+October 4, 2010 13:45
+04/10/2010
+October 4, 2010 13:45
+04/10/2010