From: Fabien Potencier Date: Fri, 8 Feb 2013 20:59:58 +0000 (+0100) Subject: added some unit tests for previous merge X-Git-Url: http://git.silmor.de/gitweb/?a=commitdiff_plain;h=b5438c274581b2ab2e5045b531d70ba55eccd99d;p=web%2Fkonrad%2Ftwig.git added some unit tests for previous merge --- diff --git a/lib/Twig/Extension/Core.php b/lib/Twig/Extension/Core.php index 3ff740a..6a2e142 100644 --- a/lib/Twig/Extension/Core.php +++ b/lib/Twig/Extension/Core.php @@ -469,14 +469,14 @@ function twig_date_converter(Twig_Environment $env, $date = null, $timezone = nu $asString = (string) $date; if (ctype_digit($asString) || (!empty($asString) && '-' === $asString[0] && ctype_digit(substr($asString, 1)))) { - $date = new DateTime('@'.$date); - $date->setTimezone($defaultTimezone); - - return $date; + $date = '@'.$date; } $date = new DateTime($date, $defaultTimezone); - $date->setTimezone($defaultTimezone); + if (false !== $timezone) { + $date->setTimezone($defaultTimezone); + } + return $date; } diff --git a/test/Twig/Tests/Fixtures/filters/date.test b/test/Twig/Tests/Fixtures/filters/date.test index f40f4cb..d40bb04 100644 --- a/test/Twig/Tests/Fixtures/filters/date.test +++ b/test/Twig/Tests/Fixtures/filters/date.test @@ -3,59 +3,74 @@ --TEMPLATE-- {{ date1|date }} {{ date1|date('d/m/Y') }} -{{ date1|date('d/m/Y H:i:s', 'Europe/Paris') }} -{{ date1|date('d/m/Y H:i:s P', 'Europe/Paris') }} +{{ date1|date('d/m/Y H:i:s', 'Asia/Hong_Kong') }} +{{ date1|date('d/m/Y H:i:s P', 'Asia/Hong_Kong') }} {{ date1|date('d/m/Y H:i:s P', 'America/Chicago') }} {{ date1|date('e') }} {{ date1|date('d/m/Y H:i:s') }} + {{ date2|date }} {{ date2|date('d/m/Y') }} -{{ date2|date('d/m/Y H:i:s', 'Europe/Paris') }} +{{ date2|date('d/m/Y H:i:s', 'Asia/Hong_Kong') }} {{ date2|date('d/m/Y H:i:s', timezone1) }} {{ date2|date('d/m/Y H:i:s') }} + {{ date3|date }} {{ date3|date('d/m/Y') }} + {{ date4|date }} {{ date4|date('d/m/Y') }} + {{ date5|date }} {{ date5|date('d/m/Y') }} + {{ date6|date('d/m/Y H:i:s P', 'Europe/Paris') }} {{ date6|date('d/m/Y H:i:s P', 'Asia/Hong_Kong') }} {{ date6|date('d/m/Y H:i:s P', false) }} {{ date6|date('e', 'Europe/Paris') }} {{ date6|date('e', false) }} + +{{ date7|date }} --DATA-- -date_default_timezone_set('UTC'); +date_default_timezone_set('Europe/Paris'); 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, + 'date4' => 1286199900, // DateTime::createFromFormat('Y-m-d H:i', '2010-10-04 13:45', new DateTimeZone('UTC'))->getTimestamp() -- A unixtimestamp is always GMT + 'date5' => -189291360, // DateTime::createFromFormat('Y-m-d H:i', '1964-01-02 03:04', new DateTimeZone('UTC'))->getTimestamp(), 'date6' => new DateTime('2010-10-04 13:45', new DateTimeZone('America/New_York')), + 'date7' => '2010-01-28T15:00:00+05:00', 'timezone1' => new DateTimeZone('America/New_York'), ) --EXPECT-- October 4, 2010 13:45 04/10/2010 -04/10/2010 15:45:00 -04/10/2010 15:45:00 +02:00 -04/10/2010 08:45:00 -05:00 -UTC +04/10/2010 19:45:00 +04/10/2010 19:45:00 +08:00 +04/10/2010 06:45:00 -05:00 +Europe/Paris 04/10/2010 13:45:00 + October 4, 2010 13:45 04/10/2010 -04/10/2010 15:45:00 -04/10/2010 09:45:00 +04/10/2010 19:45:00 +04/10/2010 07:45:00 04/10/2010 13:45:00 + October 4, 2010 13:45 04/10/2010 -October 4, 2010 13:45 + +October 4, 2010 15:45 04/10/2010 -December 30, 1969 23:59 -30/12/1969 + +January 2, 1964 04:04 +02/01/1964 + 04/10/2010 19:45:00 +02:00 05/10/2010 01:45:00 +08:00 04/10/2010 13:45:00 -04:00 Europe/Paris America/New_York + +January 28, 2010 11:00