From 9ca40378b57885d37a588201fc056b9c9694d080 Mon Sep 17 00:00:00 2001 From: Georgios Andrianakis Date: Tue, 24 Jan 2023 16:18:08 +0200 Subject: [PATCH] Fix formatting of dates in Qute templates Fixes: #7 --- .../org/quarkus/samples/petclinic/Temporals.java | 15 +++++++++++++++ .../templates/createOrUpdateVisitForm.html | 4 ++-- src/main/resources/templates/ownerDetails.html | 4 ++-- 3 files changed, 19 insertions(+), 4 deletions(-) create mode 100644 src/main/java/org/quarkus/samples/petclinic/Temporals.java diff --git a/src/main/java/org/quarkus/samples/petclinic/Temporals.java b/src/main/java/org/quarkus/samples/petclinic/Temporals.java new file mode 100644 index 0000000..0967cfc --- /dev/null +++ b/src/main/java/org/quarkus/samples/petclinic/Temporals.java @@ -0,0 +1,15 @@ +package org.quarkus.samples.petclinic; + +import io.quarkus.qute.TemplateExtension; +import java.time.LocalDate; +import java.time.format.DateTimeFormatter; + +@TemplateExtension +public class Temporals { + + private static final DateTimeFormatter FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd"); + + public static String format(LocalDate localDate) { + return localDate.format(FORMATTER); + } +} diff --git a/src/main/resources/templates/createOrUpdateVisitForm.html b/src/main/resources/templates/createOrUpdateVisitForm.html index 9ab4e56..4d381f6 100644 --- a/src/main/resources/templates/createOrUpdateVisitForm.html +++ b/src/main/resources/templates/createOrUpdateVisitForm.html @@ -17,7 +17,7 @@

{pet.name} - {pet.birthDate.format('yyyy-MM-dd')} + {pet.birthDate.format()} {pet.type.name} {pet.owner.firstName} {pet.owner.lastName} @@ -74,7 +74,7 @@

{#if visit} {#for v in pet.visits} - {v.date.format('yyyy-MM-dd')} + {v.date.format()} {v.description} {/for} {/if} diff --git a/src/main/resources/templates/ownerDetails.html b/src/main/resources/templates/ownerDetails.html index 264b956..6dc2039 100644 --- a/src/main/resources/templates/ownerDetails.html +++ b/src/main/resources/templates/ownerDetails.html @@ -42,7 +42,7 @@

{msg:pets_and_visits}

{msg:name}
{pet.name}
{msg:birthdate}
-
{pet.birthDate.format('yyyy-MM-dd')}
+
{pet.birthDate.format()}
{msg:type}
{pet.type.stringify}
@@ -62,7 +62,7 @@

{msg:pets_and_visits}

{#for visit in pet.visits} - {visit.date.format('yyyy-MM-dd')} + {visit.date.format()} {visit.description ?: ''} {/for}