[ 
https://issues.apache.org/jira/browse/FREEMARKER-179?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17313444#comment-17313444
 ] 

Dániel Dékány commented on FREEMARKER-179:
------------------------------------------

This occurred to me too for a few times, so, I guess it will be added in the 
next version.

> Allow to override current date and time in `.now` built in variable
> -------------------------------------------------------------------
>
>                 Key: FREEMARKER-179
>                 URL: https://issues.apache.org/jira/browse/FREEMARKER-179
>             Project: Apache Freemarker
>          Issue Type: Improvement
>          Components: engine
>    Affects Versions: 2.3.29
>            Reporter: Jan Novotný
>            Priority: Minor
>
> It would be handy if `.now` variable can be overriden by a custom code to a 
> fixed date. My use-case is rather special - we use Freemarker in 
> directmailing app when e-mails are generated for several minutes (date and 
> time changes) but I need to have fixed date and time for the sake of 
> statistics gathering. I've prepared special variable `sentDate` but the 
> developers keep using `.now` and cause problems by this.
> It's hard to fight the habit, so that it would be useful for me to override 
> the "now" for certain scope of Freemarker generation process and just alter 
> "now" so that it is correct for my use-case but it's not possible now - in 
> `freemarker.core.BuiltinVariable#_eval` the `now` variable is defined as `new 
> Date()` which cannot be changed in any way.
> Another use-case when this may be helpfull is for junit testing - when fixing 
> date and time is required for repeatability of the test execution that uses 
> `.now` inside tested FreeMarker template.
> Thank you for consideration.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to