I'm having some trouble while trying to use the Freemarker Template to display dates in the desired format.
I store points with a date information in a PostGIS database written through an FME-process in an ISO format (%Y-%m-%d) to use them in an time-enabled WMS with GeoServer.
When calling the GetFeatureInfo, the date is displayed in the following format 10/4/12 12:00 AM, where it should be 2012-10-04. We allready changened the server setting to -Dorg.geotools.localDateTimeHandling=true -Duser.country=DE -Duser.timezone=GMT -Duser.language=de.
Since this didn't give the desired outcome, we tried it with the Freemarker Template. The idea was to check the attributes for date format and format them accordingly. Somehow, I can't make it work. I tried this:
<#if attribute.is_unknown_date_like>
${attribute.value?string("YYYY-MM-DD")}
<#else>
${attribute.value}
</#if>
I get an error message for the line where the condition starts:
freemarker.core.ParseException
How can I make this condition statement work?
Updated: Added parsing to the
#elsebranch, etc.You could do this if you don't know if
attribute.valuewill bejava.lang.Stringor ajava.util.Date:If you know the type of
attribute.value, then you only have to do what's inside the#if, or the#else.If you are using a really old version of FreeMarker, then instead of
?string.iso, you have to use?string("yyyy-MM-dd"). Also then?is_date_likemight not be available yet, and you had to useattribute.value?is_unknown_date_like || attribute.value?is_datetime || attribute.value?is_date.By the way, if you typically output date/time values with ISO format, then someone should just set the
date_format/time_format/datetime_formatconfiguration settings toiso, and then you can omit?string.iso. (Or, these can be set in the template too, like<#setting date_format='iso'>, etc.)