Skip to content

Commit

Permalink
merged branch jturmel/patch-1 (PR #367)
Browse files Browse the repository at this point in the history
Commits
-------

6593761 Allow setting of timezone on twig_date_format_filter method

Discussion
----------

Allow setting of timezone on twig_date_format_filter method
  • Loading branch information
fabpot committed Jun 24, 2011
2 parents d03edac + 6593761 commit bbf55fe
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion lib/Twig/Extension/Core.php
Expand Up @@ -201,7 +201,7 @@ public function getName()
}
}

function twig_date_format_filter($date, $format = 'F j, Y H:i')
function twig_date_format_filter($date, $format = 'F j, Y H:i', $timezone = NULL)
{
if (!$date instanceof DateTime) {
if (ctype_digit((string) $date)) {
Expand All @@ -212,6 +212,14 @@ function twig_date_format_filter($date, $format = 'F j, Y H:i')
}
}

if ($timezone !== NULL) {
if (!$timezone instanceof DateTimeZone) {
$timezone = new DateTimeZone($timezone);
}

$date->setTimezone($timezone);
}

return $date->format($format);
}

Expand Down

0 comments on commit bbf55fe

Please sign in to comment.