mirror of
https://github.com/twigphp/Twig.git
synced 2026-09-17 04:46:49 +00:00
Make date_modify work with DateTimeImmutable
This commit is contained in:
committed by
Fabien Potencier
parent
b7f60e4db6
commit
a5fe46fce7
@@ -473,9 +473,16 @@ function twig_date_format_filter(Twig_Environment $env, $date, $format = null, $
|
|||||||
function twig_date_modify_filter(Twig_Environment $env, $date, $modifier)
|
function twig_date_modify_filter(Twig_Environment $env, $date, $modifier)
|
||||||
{
|
{
|
||||||
$date = twig_date_converter($env, $date, false);
|
$date = twig_date_converter($env, $date, false);
|
||||||
$date->modify($modifier);
|
$resultDate = $date->modify($modifier);
|
||||||
|
|
||||||
return $date;
|
// This is a hack to ensure PHP 5.2 support and support for DateTimeImmutable
|
||||||
|
// DateTime::modify does not return the modified DateTime object < 5.3.0
|
||||||
|
// and DateTimeImmutable does not modify $date.
|
||||||
|
if (null === $resultDate) {
|
||||||
|
return $date;
|
||||||
|
} else {
|
||||||
|
return $resultDate;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ version_compare(phpversion(), '5.5.0', '>=')
|
|||||||
{{ date1|date('d/m/Y H:i:s', 'Asia/Hong_Kong') }}
|
{{ date1|date('d/m/Y H:i:s', 'Asia/Hong_Kong') }}
|
||||||
{{ date1|date('d/m/Y H:i:s', timezone1) }}
|
{{ date1|date('d/m/Y H:i:s', timezone1) }}
|
||||||
{{ date1|date('d/m/Y H:i:s') }}
|
{{ date1|date('d/m/Y H:i:s') }}
|
||||||
|
{{ date1|date_modify('+1 hour')|date('d/m/Y H:i:s') }}
|
||||||
|
|
||||||
{{ date2|date('d/m/Y H:i:s P', 'Europe/Paris') }}
|
{{ date2|date('d/m/Y H:i:s P', 'Europe/Paris') }}
|
||||||
{{ date2|date('d/m/Y H:i:s P', 'Asia/Hong_Kong') }}
|
{{ date2|date('d/m/Y H:i:s P', 'Asia/Hong_Kong') }}
|
||||||
@@ -27,6 +28,7 @@ October 4, 2010 13:45
|
|||||||
04/10/2010 19:45:00
|
04/10/2010 19:45:00
|
||||||
04/10/2010 07:45:00
|
04/10/2010 07:45:00
|
||||||
04/10/2010 13:45:00
|
04/10/2010 13:45:00
|
||||||
|
04/10/2010 14:45:00
|
||||||
|
|
||||||
04/10/2010 19:45:00 +02:00
|
04/10/2010 19:45:00 +02:00
|
||||||
05/10/2010 01:45:00 +08:00
|
05/10/2010 01:45:00 +08:00
|
||||||
|
|||||||
Reference in New Issue
Block a user