I've seen that since AEM 6.3, date formatting has been natively supported in the markup, like so:
${ 'dd~MMMM-yyyy' @ format=currentPage.jcr:created }
(Reference: https://github.com/adobe/htl-spec/blob/master/SPECIFICATION.md#1222-dates )
I have tried playing with this formatter using that jcr:created property, as well as data coming from the backend in java.util.Date.
My question is, are other date types supported? Like say, java.time.LocalDate? It doesn't display on my test pages, although I'm not sure if I'm just missing some additional property that needs to be indicated on the HTL markup?
It's not mentioned in the documentation as far as I can tell but Apache Sling is an open source project so we can look it up on our own.
Looking at the implementation details, the only supported types as of now are
java.util.Dateandjava.util.Calendarand their sub-classes.Here's the
FormatFilterExtensionclass responsible for applying the chosen format in HTL.Let's have a look at the check it performs.
It uses
runtimeObjectModel.isDate()to verify if we're dealing with a date. If we look atruntimeObjectModel, we can see that it's an instance ofSlingRuntimeObjectModelwhich in turn extendsAbstractRuntimeModel.so if it's a
Dateor aCalendar, it will be handled.Even if you force the formatting type like this
the object you pass will end up being processed using
AbstractRuntimeObjectModel#toDate(Object object)which returnsnullfor all objects that aren't instances ofDateorCalendar.Since the check is based on
instanceof, this also includes instances ofDateandCalendar's sub-types.LocalDate, however, is not one of them so it's not surprising that it didn't work.