I found something that might help you: override the inline branch date filter
Creates a new branch extension for what you want :)
PS: At the end, it returns a PHP DateTime
<?php namespace My\Twig\Extension; use Twig_Extension; use Twig_SimpleFilter; use Twig_SimpleFunction; use DateTime; use DateTimeInterface; use DateTimeImmutable; class DateExtension extends Twig_Extension { public function getName() { return 'my_date'; } public function getFilters() { return array( new Twig_SimpleFilter('date', [$this, 'dateFilter'], ['needs_environment' => true]), new Twig_SimpleFilter('date_modify', [$this, 'modifyFilter'], ['needs_environment' => true]), ); } public function getFunctions() { return array( new Twig_SimpleFunction('date', [$this, 'dateFromString'], ['needs_environment' => true]), ); } public function dateFilter($env, $date, $format = null, $timezone = null) { if (null === $format) { $formats = $env->getExtension('core')->getDateFormat(); $format = $date instanceof DateInterval ? $formats[1] : $formats[0]; } if ($date instanceof DateInterval) { return $date->format($format); } return $this->dateFromString($env, $date, $timezone)->format($format); } public function modifyFilter($env, $date, $format = null, $timezone = null) { $date = $this->dateFromString($env, $date, false); $date->modify($modifier); return $date; } public function dateFromString($env, $date, $timezone) {
This class simply registers a new date, date_modify filters and a new one to replace them in the Twig kernel, and then is a direct copy of the twig_date_format_filter, twig_date_modify_filter and twig_date_converter functions with remote functionality.
I also needed to register this extension with Twig_Environment with:
$env->addExtension(new \My\Twig\Extension\DateExtension());
and i finished.
{{ "20141216"|date('jS F Y') }} {{ "20141216"|date('jS F Y') }}
now correctly issues: December 16, 2014 December 16, 2014
So far, ashamed, I cannot just override twig_date_converter , I am glad that I can reregister relevant Twig filters and functions.