diff --git a/CHANGELOG-v3.md b/CHANGELOG-v3.md index 3c1604c091c..ab89b53a6a0 100644 --- a/CHANGELOG-v3.md +++ b/CHANGELOG-v3.md @@ -29,6 +29,7 @@ - Fixed a bug where Craft could pick the wrong current site if the primary site had a root-relative or protocol-relative URL, and another site didn’t, but was otherwise an equal match. - Fixed a bug where Control Panel Ajax requests could cause some asset bundles and JavaScript files to be double-registered in the browser. - Fixed a bug where the “New entry” menu on the Entries index page was including sections that weren’t available in the selected site, and they weren’t linking to Edit Entry pages for the selected site. ([#2925](https://github.com/craftcms/cms/issues/2925)) +- Fixed a bug where the `|date`, `|time`, and `|datetime` filters weren’t respecting their `$timezone` arguments. ([#2926](https://github.com/craftcms/cms/issues/2926)) ## 3.0.9 - 2018-05-22 diff --git a/src/web/twig/Extension.php b/src/web/twig/Extension.php index 8dca7b0350f..9e79b2d31a7 100644 --- a/src/web/twig/Extension.php +++ b/src/web/twig/Extension.php @@ -467,7 +467,12 @@ public function dateFilter(\Twig_Environment $env, $date, string $format = null, } $date = \twig_date_converter($env, $date, $timezone); - return Craft::$app->getFormatter()->asDate($date, $format); + $formatter = Craft::$app->getFormatter(); + $fmtTimeZone = $formatter->timeZone; + $formatter->timeZone = $timezone ? $date->getTimezone()->getName() : $formatter->timeZone; + $formatted = $formatter->asDate($date, $format); + $formatter->timeZone = $fmtTimeZone; + return $formatted; } /** @@ -517,7 +522,12 @@ public function timeFilter(\Twig_Environment $env, $date, string $format = null, } $date = \twig_date_converter($env, $date, $timezone); - return Craft::$app->getFormatter()->asTime($date, $format); + $formatter = Craft::$app->getFormatter(); + $fmtTimeZone = $formatter->timeZone; + $formatter->timeZone = $timezone ? $date->getTimezone()->getName() : $formatter->timeZone; + $formatted = $formatter->asTime($date, $format); + $formatter->timeZone = $fmtTimeZone; + return $formatted; } /** @@ -541,7 +551,12 @@ public function datetimeFilter(\Twig_Environment $env, $date, string $format = n } $date = \twig_date_converter($env, $date, $timezone); - return Craft::$app->getFormatter()->asDatetime($date, $format); + $formatter = Craft::$app->getFormatter(); + $fmtTimeZone = $formatter->timeZone; + $formatter->timeZone = $timezone ? $date->getTimezone()->getName() : $formatter->timeZone; + $formatted = $formatter->asDatetime($date, $format); + $formatter->timeZone = $fmtTimeZone; + return $formatted; } /**