Jan Novotný created FREEMARKER-179:
--------------------------------------

             Summary: 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ý


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" 
that 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