Permalink
Browse files

Merge remote-tracking branch 'blaugueux/master'

* blaugueux/master:
  Improved localizeddate extension with dynamic DateTimeZone.

Conflicts:
	lib/Twig/Extensions/Extension/Intl.php
  • Loading branch information...
2 parents dcdff02 + 0a8496c commit 91336a6ca014a9772ae281cae5e30390a1f3fbaf @fabpot fabpot committed Dec 15, 2012
Showing with 5 additions and 12 deletions.
  1. +5 −12 lib/Twig/Extensions/Extension/Intl.php
@@ -26,7 +26,7 @@ public function __construct()
public function getFilters()
{
return array(
- 'localizeddate' => new Twig_Filter_Function('twig_localized_date_filter'),
+ 'localizeddate' => new Twig_Filter_Function('twig_localized_date_filter', array('needs_environment' => true)),
);
}
@@ -41,8 +41,10 @@ public function getName()
}
}
-function twig_localized_date_filter($date, $dateFormat = 'medium', $timeFormat = 'medium', $locale = null)
+function twig_localized_date_filter(Twig_Environment $env, $date, $dateFormat = 'medium', $timeFormat = 'medium', $locale = null, $timezone = null)
{
+ $date = twig_date_converter($env, $date, $timezone);
+
$formatValues = array(
'none' => IntlDateFormatter::NONE,
'short' => IntlDateFormatter::SHORT,
@@ -55,17 +57,8 @@ function twig_localized_date_filter($date, $dateFormat = 'medium', $timeFormat =
$locale !== null ? $locale : Locale::getDefault(),
$formatValues[$dateFormat],
$formatValues[$timeFormat],
- date_default_timezone_get()
+ $date->getTimezone()->getName()
);
- if (!$date instanceof DateTime) {
- if (ctype_digit((string) $date)) {
- $date = new DateTime('@'.$date);
- $date->setTimezone(new DateTimeZone(date_default_timezone_get()));
- } else {
- $date = new DateTime($date);
- }
- }
-
return $formatter->format($date->getTimestamp());
}

0 comments on commit 91336a6

Please sign in to comment.