Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You could convert the string to an int (watch out for rollovers!) and compare as per <a href="http://sourceforge.net/projects/freemarker/forums/forum/2345/topic/3027925?message=6479650" rel="nofollow">http://sourceforge.net/projects/freemarker/forums/forum/2345/topic/3027925?message=6479650</a></p> <p>Be careful not exceed the maximum int value if you add extra digits like milliseconds.</p> <p>(from the above link)</p> <pre><code>[#assign Adate = myDateA?string("yyyyMMdd")?number?int ] [#assign Atime = myDateA?string("HHmmss")?number?int ] [#assign Bdate = myDateB?string("yyyyMMdd")?number?int ] [#assign Btime = myDateB?string("HHmmss")?number?int ] </code></pre> <p>What I did was create a TemplateMethodModel for comparing dates (Note: df is a custom thread safe SimpleDateFormatter with a timezone):</p> <pre><code>public BooleanModel exec(List args) throws TemplateModelException { int argcnt = args.size(); if (argcnt != 3) { throw new TemplateModelException("Wrong arguments. Use \"exec(Date?string(\"yyyyMMddHHmmss\"), " + "CompareString, Date?string(\"yyyyMMddHHmmss\"))\"," + " where CompareString is &lt; = &gt; "); } String firstDate = (String) args.get(0); String compareString = (String) args.get(1); String secondDate = (String) args.get(2); if (null == firstDate || null == secondDate || null == compareString || compareString.length() != 1) { throw new TemplateModelException("Wrong arguments. Use \"exec(Date?string(\"yyyyMMddHHmmss\"), " + "CompareString, Date?string(\"yyyyMMddHHmmss\"))\"," + " where CompareString is &lt; = &gt; "); } Date first = null; Date second = null; try { first = df.parse(firstDate); second = df.parse(secondDate); } catch (ParseException e) { throw new TemplateModelException("Wrong arguments. Use \"exec(Date?string(\"yyyyMMddHHmmss\"), " + "CompareString, Date?string(\"yyyyMMddHHmmss\"))\"," + " where CompareString is &lt; = &gt; "); } if ("&lt;".equals(compareString)) { return new BooleanModel(first.before(second), BeansWrapper.getDefaultInstance()); } else if ("=".equals(compareString)) { return new BooleanModel(first.equals(second), BeansWrapper.getDefaultInstance()); } else if ("&gt;".equals(compareString)) { return new BooleanModel(first.after(second), BeansWrapper.getDefaultInstance()); } return new BooleanModel(Boolean.FALSE, BeansWrapper.getDefaultInstance()); } </code></pre> <p>In the template I call it as follows:</p> <pre><code>[#if compareDate(now?string("yyyyMMddHHmmss"),"&lt;", program.resStartDateTime?string("yyyyMMddHHmmss"))] </code></pre> <p>FYI, "now" is a DateModel object added before template processing.</p> <pre><code>model.put("now", new DateModel(new Date(), BeansWrapper.getDefaultInstance())); </code></pre> <p>The TemplateMethodModel could be made more general by passing in a parsing string as an argument and creating the date formatter on execution.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload