From e27af340a64ded6f8a184a9562c43448c9c7da8f Mon Sep 17 00:00:00 2001 From: David mattei Date: Mon, 9 Dec 2024 16:37:07 +0100 Subject: [PATCH] feat(common/twig): new filter ems_date (#1102) --- EMS/common-bundle/src/Twig/CommonExtension.php | 2 ++ docs/dev/common-bundle/twig.md | 11 +++++++++++ 2 files changed, 13 insertions(+) diff --git a/EMS/common-bundle/src/Twig/CommonExtension.php b/EMS/common-bundle/src/Twig/CommonExtension.php index 74b5021b0..39ab9a02a 100644 --- a/EMS/common-bundle/src/Twig/CommonExtension.php +++ b/EMS/common-bundle/src/Twig/CommonExtension.php @@ -7,6 +7,7 @@ use EMS\CommonBundle\Common\Standard\Base64; use EMS\CommonBundle\Helper\Text\Encoder; use EMS\Helpers\Standard\Color; +use EMS\Helpers\Standard\DateTime; use EMS\Helpers\Standard\UuidGenerator; use Twig\Extension\AbstractExtension; use Twig\TwigFilter; @@ -68,6 +69,7 @@ public function getFilters(): array new TwigFilter('ems_link', fn ($emsLink) => EMSLink::fromText($emsLink)), new TwigFilter('ems_valid_mail', [TextRuntime::class, 'isValidEmail']), new TwigFilter('ems_uuid', [UuidGenerator::class, 'fromValue']), + new TwigFilter('ems_date', DateTime::createFromFormat(...)), ]; } diff --git a/docs/dev/common-bundle/twig.md b/docs/dev/common-bundle/twig.md index a99a4c50c..acd596ebc 100644 --- a/docs/dev/common-bundle/twig.md +++ b/docs/dev/common-bundle/twig.md @@ -25,6 +25,7 @@ * [ems_link](#ems_link) * [ems_valid_mail](#ems_valid_mail) * [ems_uuid](#ems_uuid-1) + * [ems_date](#ems_date) # Twig Functions @@ -421,4 +422,14 @@ Generate a version 5 UUID from a value. [More info](https://uuid.ramsey.dev/en/s {{ 'my_unique_id_value'|ems_uuid }} ``` +## ems_date + +Generate a \DateTimeImmutable object from a value. + +```twig +{% set date = '31/12/1998 0:00:00'|ems_date('j/m/Y H:i:s') %} + +{{ date.format('d-m-Y') }} +{{ date.timezone }} +```