Date input format vs date output format

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
tim
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Date input format vs date output format

tim
Is there any way to set the INPUT format of dates independently from the OUTPUT format of dates??

Background:
I am currently in a German context, so I did
<#setting locale="de">. I want all date output to be in the German date format, i.e. "dd.MM.yyyy".

However from my data model I have the following input format for dates: "dd-MM-yyyy".

When I tried to access a date from the data model, it was displayed as-is, i.e. as "dd-MM-yyyy".
Then I tried to force Freemarker to parse it as a date using ?date. I got "unparseable date" as a reply.

Then I did
<#setting date_format="dd-MM-yyyy">.
With this setting and using ?date, freemarker accepted the input as a date, but the output was again in the format "dd-MM-yyyy".

I then reformatted it to the correct format using ?string, but this is not what I want, because I want to reuse the template for different locales, i.e. I do not want to have locale specific settings while I process the data.

I did find a solution to my problem, but I am not sure if this is very elegant. In the beginning I do

<#setting date_format="yyyy-MM-dd"> -> set INPUT format
...if current locale is DE then...
<#assign output_date_format="dd.MM.yyyy"> -> set OUTPUT format

and while processing my data I do
(some date)?date?string(output_date_format)

This works, but if there is a way to avoid writing ?date?string(output_date_format) behind each and every date, I would be glad. Guess my solution is also not very performant.

Ideas?
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Date input format vs date output format

Daniel Dekany
Unfortunately, there's no separate input and output format. In
general, template aren't supposed to do (much) parsing themselves. The
data model should already contain dates as dates. If that's possible.
If not, for now maybe the best would be if for the parsing (input)
part you don't relly on FreeMarker's format support (FreeMarker it's
pretty much only for output). Just create a TemplateMethodModelEx,
let's call it "parse", and then you could write ${parse(someDate)}.

Wednesday, February 11, 2015, 5:01:14 PM, tim wrote:

> Is there any way to set the INPUT format of dates independently from the
> OUTPUT format of dates??
>
> Background:
> I am currently in a German context, so I did
> <#setting locale="de">. I want all date output to be in the German date
> format, i.e. "dd.MM.yyyy".
>
> However from my data model I have the following input format for dates:
> "dd-MM-yyyy".
>
> When I tried to access a date from the data model, it was displayed as-is,
> i.e. as "dd-MM-yyyy".
> Then I tried to force Freemarker to parse it as a date using ?date. I got
> "unparseable date" as a reply.
>
> Then I did
> <#setting date_format="dd-MM-yyyy">.
> With this setting and using ?date, freemarker accepted the input as a date,
> but the output was again in the format "dd-MM-yyyy".
>
> I then reformatted it to the correct format using ?string, but this is not
> what I want, because I want to reuse the template for different locales,
> i.e. I do not want to have locale specific settings while I process the
> data.
>
> I did find a solution to my problem, but I am not sure if this is very
> elegant. In the beginning I do
>
> <#setting date_format="yyyy-MM-dd"> -> set INPUT format
> ...if current locale is DE then...
> <#assign output_date_format="dd.MM.yyyy"> -> set OUTPUT format
>
> and while processing my data I do
> (some date)?date?string(output_date_format)
>
> This works, but if there is a way to avoid writing
> ?date?string(output_date_format) behind each and every date, I would be
> glad. Guess my solution is also not very performant.
>
> Ideas?
>
>
>
> --
> View this message in context:
> http://freemarker.624813.n4.nabble.com/Date-input-format-vs-date-output-format-tp4655367.html
> Sent from the freemarker-user mailing list archive at Nabble.com.
>
> ------------------------------------------------------------------------------
> Dive into the World of Parallel Programming. The Go Parallel Website,
> sponsored by Intel and developed in partnership with Slashdot Media, is your
> hub for all things parallel software development, from weekly thought
> leadership blogs to news, videos, case studies, tutorials and more. Take a
> look and join the conversation now. http://goparallel.sourceforge.net/
> _______________________________________________
> FreeMarker-user mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/freemarker-user
>

--
Thanks,
 Daniel Dekany


------------------------------------------------------------------------------
Dive into the World of Parallel Programming. The Go Parallel Website,
sponsored by Intel and developed in partnership with Slashdot Media, is your
hub for all things parallel software development, from weekly thought
leadership blogs to news, videos, case studies, tutorials and more. Take a
look and join the conversation now. http://goparallel.sourceforge.net/
_______________________________________________
FreeMarker-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/freemarker-user
tim
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Date input format vs date output format

tim
Thanks so much again... from your reply I indirectly understood where the problem was: the model delivered dates as strings and not dates. The developer could fix that so now I'm good.
Loading...