From: Fabien Potencier Date: Mon, 21 Nov 2011 08:02:49 +0000 (+0100) Subject: fixed previous merge and added some unit tests X-Git-Url: http://git.silmor.de/gitweb/?a=commitdiff_plain;h=9d2272efbf3340f79e447cbd249fe2ad6714663f;p=web%2Fkonrad%2Ftwig.git fixed previous merge and added some unit tests --- diff --git a/CHANGELOG b/CHANGELOG index 6f400cc..421fa70 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,7 @@ +* 1.4.0-RC2 + + * added negative timestamp support to the date filter + * 1.4.0-RC1 (2011-11-20) * optimized variable access when using PHP 5.4 diff --git a/lib/Twig/Extension/Core.php b/lib/Twig/Extension/Core.php index 215ec6f..40cf292 100644 --- a/lib/Twig/Extension/Core.php +++ b/lib/Twig/Extension/Core.php @@ -237,11 +237,8 @@ function twig_cycle($values, $i) function twig_date_format_filter($date, $format = 'F j, Y H:i', $timezone = null) { if (!$date instanceof DateTime && !$date instanceof DateInterval) { - if (ctype_digit((string) $date) - || (!empty($date) - && ('-' === $date[0]) - && ctype_digit(substr($date, 1))) - ) { + $asString = (string) $date; + if (ctype_digit($asString) || (!empty($asString) && '-' === $asString[0] && ctype_digit(substr($asString, 1)))) { $date = new DateTime('@'.$date); $date->setTimezone(new DateTimeZone(date_default_timezone_get())); } else { diff --git a/test/Twig/Tests/Fixtures/filters/date.test b/test/Twig/Tests/Fixtures/filters/date.test index 21b57ba..deb52b2 100644 --- a/test/Twig/Tests/Fixtures/filters/date.test +++ b/test/Twig/Tests/Fixtures/filters/date.test @@ -9,9 +9,17 @@ {{ date3|date('d/m/Y') }} {{ date4|date }} {{ date4|date('d/m/Y') }} +{{ date5|date }} +{{ date5|date('d/m/Y') }} --DATA-- 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) +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, + 'date5' => -86410, +) --EXPECT-- October 4, 2010 13:45 04/10/2010 @@ -21,3 +29,5 @@ October 4, 2010 13:45 04/10/2010 October 4, 2010 13:45 04/10/2010 +December 30, 1969 23:59 +30/12/1969