Skip to content

Commit

Permalink
Pass along the $timezone to the formatter
Browse files Browse the repository at this point in the history
Fixes #2926
  • Loading branch information
brandonkelly committed Jun 1, 2018
1 parent 802054d commit f3275d3
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG-v3.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
21 changes: 18 additions & 3 deletions src/web/twig/Extension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand Down Expand Up @@ -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;
}

/**
Expand All @@ -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;
}

/**
Expand Down

0 comments on commit f3275d3

Please sign in to comment.