You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@freemarker.apache.org by "Jan Novotný (Jira)" <ji...@apache.org> on 2021/04/01 07:36:00 UTC

[jira] [Updated] (FREEMARKER-179) Allow to override current date and time in `.now` built in variable

     [ https://issues.apache.org/jira/browse/FREEMARKER-179?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Jan Novotný updated FREEMARKER-179:
-----------------------------------
    Description: 
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.

  was:
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.


> 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)