views:

336

answers:

3

Hello, I have a fairly simple question about these 2 templating engines.
I'm trying to make a future/paste date, a fixed time from now, e.g. 18 months ago, or tomorrow.

I know that it is possible to do this with a java date object inside a velocity/freemarker template (something like $date.add(2,-18)), but I would like to do this with DateTool or freemarker core.

This is something that I see as purely presentational (just think at the default dates you see in flight booking forms), so I can't see any reason why a templating engine shouldn't be able to do this.

Is it possible though? If so, how?

A: 

For freemarker, perhaps : Built-ins for dates.

Istao
I had already seen that doc page, and I cannot find any reference to date manipulation, just how to format them, perhaps I missed it?
Razor
Sorry, I think you need to write your own freemarker TemplateMethodModelEx for that... see this post : Calculate days between two dates at http://thread.gmane.org/gmane.comp.web.freemarker.user/4292
Istao
That's something different from what I need, but it doesn't look like freemarker has any better date manipulation possibilities, when compared to velocity tools.I'm guessing here that it's not possible to do what I need with this engine either.
Razor
A: 

In Velocity Tools there is no such method.

serg
+1  A: 

You can do it in Velocity too, but not with the DateTool (that belongs the Velocity Extras anyway).

It is a good practice to have a "Format" object with various utilities that are practical for presentational purposes only (you can see the various frameworks that use Velocity how they have "Format" objects).

So your code would look like $format.dateFromNow(), and there would be still a presentational approach.

A. Ionescu