You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@freemarker.apache.org by dd...@apache.org on 2015/09/17 21:43:44 UTC

incubator-freemarker git commit: Figured out how TemplateDateFormat.parse will look. Also, ?date, ?time and ?datetime can now be called like ?date(), etc., which returns the exact object that TemplateDateFormat.parse returns. Also added TemplateNumberFor

Repository: incubator-freemarker
Updated Branches:
  refs/heads/2.3-gae 03e8fc070 -> 7f591d168


Figured out how TemplateDateFormat.parse will look. Also, ?date, ?time and ?datetime can now be called like ?date(), etc., which returns the exact object that TemplateDateFormat.parse returns. Also added TemplateNumberFormat.parse as a final method that always throws ParsingNotSupportedException, to reserve the place for this method for later versions.


Project: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/commit/7f591d16
Tree: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/tree/7f591d16
Diff: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/diff/7f591d16

Branch: refs/heads/2.3-gae
Commit: 7f591d168a0519bb558860a1fdc61d44384a2c79
Parents: 03e8fc0
Author: ddekany <dd...@apache.org>
Authored: Thu Sep 17 21:34:57 2015 +0200
Committer: ddekany <dd...@apache.org>
Committed: Thu Sep 17 21:43:22 2015 +0200

----------------------------------------------------------------------
 .../core/BuiltInsForMultipleTypes.java          |  34 +++--
 .../core/ISOLikeTemplateDateFormat.java         |   2 +-
 .../freemarker/core/JavaTemplateDateFormat.java |   2 +-
 src/main/java/freemarker/core/MessageUtil.java  |   4 +
 .../core/ParsingNotSupportedException.java      |  37 ++++++
 .../freemarker/core/TemplateDateFormat.java     |  25 +++-
 .../freemarker/core/TemplateNumberFormat.java   |  11 +-
 ...nownDateTypeParsingUnsupportedException.java |  36 ++++++
 src/manual/book.xml                             |  62 +++++++--
 .../core/AppMetaTemplateDateFormatFactory.java  | 129 +++++++++++++++++++
 .../java/freemarker/core/DateFormatTest.java    |  48 ++++++-
 ...EpochMillisDivTemplateDateFormatFactory.java |   2 +-
 .../EpochMillisTemplateDateFormatFactory.java   |   2 +-
 ...AndTZSensitiveTemplateDateFormatFactory.java |   2 +-
 14 files changed, 367 insertions(+), 29 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/7f591d16/src/main/java/freemarker/core/BuiltInsForMultipleTypes.java
----------------------------------------------------------------------
diff --git a/src/main/java/freemarker/core/BuiltInsForMultipleTypes.java b/src/main/java/freemarker/core/BuiltInsForMultipleTypes.java
index 6520720..6a6a86e 100644
--- a/src/main/java/freemarker/core/BuiltInsForMultipleTypes.java
+++ b/src/main/java/freemarker/core/BuiltInsForMultipleTypes.java
@@ -142,7 +142,7 @@ class BuiltInsForMultipleTypes {
             private final String text;
             private final Environment env;
             private final TemplateDateFormat defaultFormat;
-            private Date cachedValue;
+            private TemplateDateModel cachedValue;
             
             DateParser(String text, Environment env)
             throws TemplateException {
@@ -152,8 +152,8 @@ class BuiltInsForMultipleTypes {
             }
             
             public Object exec(List args) throws TemplateModelException {
-                checkMethodArgCount(args, 1);
-                return get((String) args.get(0));
+                checkMethodArgCount(args, 0, 1);
+                return args.size() == 0 ? getAsDateModel() : get((String) args.get(0));
             }
             
             public TemplateModel get(String pattern) throws TemplateModelException {
@@ -164,15 +164,31 @@ class BuiltInsForMultipleTypes {
                     // `e` should always be a TemplateModelException here, but to be sure: 
                     throw _CoreAPI.ensureIsTemplateModelException("Failed to get format", e); 
                 }
-                return new SimpleDate(parse(format), dateType);
+                return toTemplateDateModel(parse(format));
             }
-    
-            public Date getAsDate() throws TemplateModelException {
+
+            private TemplateDateModel toTemplateDateModel(Object date) throws _TemplateModelException {
+                if (date instanceof Date) {
+                    return new SimpleDate((Date) date, dateType);
+                } else {
+                    TemplateDateModel tm = (TemplateDateModel) date;
+                    if (tm.getDateType() != dateType) {
+                        throw new _TemplateModelException("The result of the parsing was of the wrong date type.");
+                    }
+                    return tm;
+                }
+            }
+
+            private TemplateDateModel getAsDateModel() throws TemplateModelException {
                 if (cachedValue == null) {
-                    cachedValue = parse(defaultFormat);
+                    cachedValue = toTemplateDateModel(parse(defaultFormat));
                 }
                 return cachedValue;
             }
+            
+            public Date getAsDate() throws TemplateModelException {
+                return getAsDateModel().getAsDate();
+            }
     
             public int getDateType() {
                 return dateType;
@@ -182,10 +198,10 @@ class BuiltInsForMultipleTypes {
                 return false;
             }
     
-            private Date parse(TemplateDateFormat df)
+            private Object parse(TemplateDateFormat df)
             throws TemplateModelException {
                 try {
-                    return df.parse(text);
+                    return df.parse(text, dateType);
                 } catch (TemplateValueFormatException e) {
                     throw new _TemplateModelException(e,
                             "The string doesn't match the expected date/time/date-time format. "

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/7f591d16/src/main/java/freemarker/core/ISOLikeTemplateDateFormat.java
----------------------------------------------------------------------
diff --git a/src/main/java/freemarker/core/ISOLikeTemplateDateFormat.java b/src/main/java/freemarker/core/ISOLikeTemplateDateFormat.java
index b26352a..9c96a08 100644
--- a/src/main/java/freemarker/core/ISOLikeTemplateDateFormat.java
+++ b/src/main/java/freemarker/core/ISOLikeTemplateDateFormat.java
@@ -200,7 +200,7 @@ abstract class ISOLikeTemplateDateFormat  extends TemplateDateFormat {
     @Override
     @SuppressFBWarnings(value = "RC_REF_COMPARISON_BAD_PRACTICE_BOOLEAN",
             justification = "Known to use the singleton Boolean-s only")
-    public final Date parse(String s) throws UnparsableValueException {
+    public final Date parse(String s, int dateType) throws UnparsableValueException {
         CalendarFieldsToDateConverter calToDateConverter = factory.getCalendarFieldsToDateCalculator(env);
         TimeZone tz = forceUTC != Boolean.FALSE ? DateUtil.UTC : timeZone;
         try {

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/7f591d16/src/main/java/freemarker/core/JavaTemplateDateFormat.java
----------------------------------------------------------------------
diff --git a/src/main/java/freemarker/core/JavaTemplateDateFormat.java b/src/main/java/freemarker/core/JavaTemplateDateFormat.java
index 8183a88..996afcf 100644
--- a/src/main/java/freemarker/core/JavaTemplateDateFormat.java
+++ b/src/main/java/freemarker/core/JavaTemplateDateFormat.java
@@ -44,7 +44,7 @@ class JavaTemplateDateFormat extends TemplateDateFormat {
     }
 
     @Override
-    public Date parse(String s) throws UnparsableValueException {
+    public Date parse(String s, int dateType) throws UnparsableValueException {
         try {
             return javaDateFormat.parse(s);
         } catch (ParseException e) {

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/7f591d16/src/main/java/freemarker/core/MessageUtil.java
----------------------------------------------------------------------
diff --git a/src/main/java/freemarker/core/MessageUtil.java b/src/main/java/freemarker/core/MessageUtil.java
index ad0827a..2875aa3 100644
--- a/src/main/java/freemarker/core/MessageUtil.java
+++ b/src/main/java/freemarker/core/MessageUtil.java
@@ -36,6 +36,10 @@ class MessageUtil {
             = "Can't convert the date-like value to string because it isn't "
               + "known if it's a date (no time part), time or date-time value.";
     
+    static final String UNKNOWN_DATE_PARSING_ERROR_MESSAGE
+            = "Can't parse the string to date-like value because it isn't "
+              + "known if it's desired result should be a date (no time part), a time, or a date-time value.";
+
     static final String UNKNOWN_DATE_TYPE_ERROR_TIP = 
             "Use ?date, ?time, or ?datetime to tell FreeMarker the exact type.";
     

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/7f591d16/src/main/java/freemarker/core/ParsingNotSupportedException.java
----------------------------------------------------------------------
diff --git a/src/main/java/freemarker/core/ParsingNotSupportedException.java b/src/main/java/freemarker/core/ParsingNotSupportedException.java
new file mode 100644
index 0000000..7b6e064
--- /dev/null
+++ b/src/main/java/freemarker/core/ParsingNotSupportedException.java
@@ -0,0 +1,37 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package freemarker.core;
+
+/**
+ * Thrown when the {@link TemplateValueFormat} doesn't support parsing, and parsing was invoked.
+ * 
+ * @since 2.3.24
+ */
+public class ParsingNotSupportedException extends TemplateValueFormatException {
+
+    public ParsingNotSupportedException(String message, Throwable cause) {
+        super(message, cause);
+    }
+
+    public ParsingNotSupportedException(String message) {
+        this(message, null);
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/7f591d16/src/main/java/freemarker/core/TemplateDateFormat.java
----------------------------------------------------------------------
diff --git a/src/main/java/freemarker/core/TemplateDateFormat.java b/src/main/java/freemarker/core/TemplateDateFormat.java
index 92d63fa..980d543 100644
--- a/src/main/java/freemarker/core/TemplateDateFormat.java
+++ b/src/main/java/freemarker/core/TemplateDateFormat.java
@@ -91,14 +91,29 @@ public abstract class TemplateDateFormat extends TemplateValueFormat {
     }
 
     /**
-     * <b>[Unfinished - will change in 2.3.24 final]</b>.
+     * Parsers a string to date/time/datetime, according to this format. Some format implementations may throw
+     * {@link ParsingNotSupportedException} here. 
      * 
-     * TODO Thrown exceptions.
-     * TODO How can one return a TemplateDateModel instead?
+     * @param s
+     *            The string to parse
+     * @param dateType
+     *            The expected date type of the result. Not all {@link TemplateDateFormat}-s will care about this;
+     *            though those who return a {@link TemplateDateModel} instead of {@link Date} often will. When strings
+     *            are parsed via {@code ?date}, {@code ?time}, or {@code ?datetime}, then this parameter is
+     *            {@link TemplateDateModel#DATE}, {@link TemplateDateModel#TIME}, or {@link TemplateDateModel#DATETIME},
+     *            respectively. This parameter rarely if ever {@link TemplateDateModel#UNKNOWN}, but the implementation
+     *            that cares about this parameter should be prepared for that. If nothing else, it should throw
+     *            {@link UnknownDateTypeParsingUnsupportedException} then.
      * 
-     * @return The interpretation of the text as {@link Date}. Can't be {@code null}.
+     * @return The interpretation of the text either as a {@link Date} or {@link TemplateDateModel}. Typically, a
+     *         {@link Date}. {@link TemplateDateModel} is used if you have to attach some application-specific
+     *         meta-information thats also extracted during {@link #format(TemplateDateModel)} (so if you format
+     *         something and then parse it, you get back an equivalent result). It can't be {@code null}. Known issue
+     *         (at least in FTL 2): {@code ?date}/{@code ?time}/{@code ?datetime}, when not invoked as a method, can't
+     *         return the {@link TemplateDateModel}, only the {@link Date} from inside it, hence the additional
+     *         application-specific meta-info will be lost.
      */
-    public abstract Date parse(String s) throws TemplateValueFormatException;
+    public abstract Object parse(String s, int dateType) throws TemplateValueFormatException;
     
     /**
      * Tells if this formatter should be re-created if the locale changes.

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/7f591d16/src/main/java/freemarker/core/TemplateNumberFormat.java
----------------------------------------------------------------------
diff --git a/src/main/java/freemarker/core/TemplateNumberFormat.java b/src/main/java/freemarker/core/TemplateNumberFormat.java
index ee2ec83..68d2c4d 100644
--- a/src/main/java/freemarker/core/TemplateNumberFormat.java
+++ b/src/main/java/freemarker/core/TemplateNumberFormat.java
@@ -94,6 +94,15 @@ public abstract class TemplateNumberFormat extends TemplateValueFormat {
      */
     public abstract boolean isLocaleBound();
 
-    // We don't have parse(...) method, because currently FTL only parses to number with the ArithmeticEngine.
+    /**
+     * This method is reserved for future purposes; currently it always throws {@link ParsingNotSupportedException}. We
+     * don't yet support number parsing with {@link TemplateNumberFormat}-s, because currently FTL parses strings to
+     * number with the {@link ArithmeticEngine} ({@link TemplateNumberFormat} were only introduced in 2.3.24). If it
+     * will be support, it will be similar to {@link TemplateDateFormat#parse(String, int)}.
+     */
+    public final Object parse(String s) throws TemplateValueFormatException {
+        throw new ParsingNotSupportedException("Number formats currenly don't support parsing");
+    }
+    
     
 }

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/7f591d16/src/main/java/freemarker/core/UnknownDateTypeParsingUnsupportedException.java
----------------------------------------------------------------------
diff --git a/src/main/java/freemarker/core/UnknownDateTypeParsingUnsupportedException.java b/src/main/java/freemarker/core/UnknownDateTypeParsingUnsupportedException.java
new file mode 100644
index 0000000..a8deaf6
--- /dev/null
+++ b/src/main/java/freemarker/core/UnknownDateTypeParsingUnsupportedException.java
@@ -0,0 +1,36 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package freemarker.core;
+
+import freemarker.template.TemplateDateModel;
+
+/**
+ * Thrown when a string can't be parsed to {@link TemplateDateModel}, because the provided target type is
+ * {@link TemplateDateModel#UNKNOWN}.
+ * 
+ * @since 2.3.24
+ */
+public final class UnknownDateTypeParsingUnsupportedException extends UnformattableValueException {
+
+    public UnknownDateTypeParsingUnsupportedException() {
+        super(MessageUtil.UNKNOWN_DATE_PARSING_ERROR_MESSAGE);
+    }
+    
+}

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/7f591d16/src/manual/book.xml
----------------------------------------------------------------------
diff --git a/src/manual/book.xml b/src/manual/book.xml
index 5978a6d..b1135ff 100644
--- a/src/manual/book.xml
+++ b/src/manual/book.xml
@@ -12292,13 +12292,15 @@ Green Mouse</programlisting>
 </programlisting>
 
           <para>You can also specify the format explicitly like
-          <literal>?datetime.<replaceable>format</replaceable></literal> or
-          <literal>?datetime["<replaceable>format</replaceable>"]</literal>
-          (or
-          <literal>?datetime("<replaceable>format</replaceable>")</literal>
-          for historical reasons), and the same with <literal>?date</literal>
-          and <literal>?time</literal>. For the syntax and meaning of format
-          values see the possible values of the <link
+          <literal>?datetime.<replaceable>format</replaceable></literal> (and
+          hence also as
+          <literal>?datetime["<replaceable>format</replaceable>"]</literal>)
+          or
+          <literal>?datetime("<replaceable>format</replaceable>")</literal>;
+          these three forms do the same. The format can be specified similarly
+          with <literal>?date</literal> and <literal>?time</literal> too. For
+          the syntax and meaning of format values see the possible values of
+          the <link
           linkend="topic.dateTimeFormatSettings"><literal>date_format</literal>,
           <literal>time_format</literal> and
           <literal>datetime_format</literal> settings</link>. Example:</para>
@@ -12324,7 +12326,17 @@ Green Mouse</programlisting>
           value to a real date.</para>
 
           <para>Of course, the format also can be a variable, like in
-          <literal>"<replaceable>...</replaceable>"?datetime[myFormat]</literal>.</para>
+          <literal>"<replaceable>...</replaceable>"?datetime(myFormat)</literal>.</para>
+
+          <para>Note that since 2.3.24, these built-ins can also be called
+          with 0 arguments, like <literal>?date()</literal>. It's almost the
+          same as just writing <literal>?date</literal>. The difference is
+          highly technical and rarely matters: <literal>?date()</literal> and
+          such returns exactly the same Java object that the date parser
+          (<literal>freemarker.core.TemplateDateFormat</literal>
+          implementation) returns, while <literal>?date</literal> without the
+          <literal>()</literal> returns tricky wrapper that's a date and a
+          method and hash on the same time.</para>
         </section>
 
         <section xml:id="ref_builtin_ends_with">
@@ -25529,6 +25541,19 @@ TemplateModel x = env.getVariable("x");  // get variable x</programlisting>
               setting</link> of the current FreeMarker configuration, as a
               string.</para>
             </listitem>
+
+            <listitem>
+              <para><literal>?date</literal>, <literal>?time</literal> and
+              <literal>?datetime</literal> now can be called as 0 argument
+              method, like <literal>?date()</literal>, etc., which returns the
+              exact object that <literal>TemplateDateFormat.parse</literal>
+              returns, instead of the tricky multi-type object that just using
+              <literal>?date</literal> returns. Because custom
+              <literal>TemplateDateFormat</literal> implementations may return
+              custom <literal>TemplateDateModel</literal> implementations,
+              keeping the exact class can be important in some
+              applications.</para>
+            </listitem>
           </itemizedlist>
         </section>
 
@@ -25864,6 +25889,27 @@ TemplateModel x = env.getVariable("x");  // get variable x</programlisting>
               locale; this is especially useful for dates, where conventions
               can significantly differ in different countries.</para>
             </listitem>
+
+            <listitem>
+              <para><literal>?date</literal>, <literal>?time</literal> and
+              <literal>?datetime</literal> now can be called as 0 argument
+              method, like <literal>?date()</literal>, etc., which returns the
+              exact object that <literal>TemplateDateFormat.parse</literal>
+              returns, instead of the tricky multi-type object that just using
+              <literal>?date</literal> returns. Because custom
+              <literal>TemplateDateFormat</literal> implementations may return
+              custom <literal>TemplateDateModel</literal> implementations,
+              keeping the exact class can be important in some
+              applications.</para>
+            </listitem>
+
+            <listitem>
+              <para>The <literal>TemplateDateFormat.parse</literal> has been
+              worked out (earlier it was a but different and was marked as
+              draft). <literal>TemplateNumberFormat</literal> has also have a
+              parse method now, though it's just a <literal>final</literal>
+              placeholder now.</para>
+            </listitem>
           </itemizedlist>
         </section>
       </section>

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/7f591d16/src/test/java/freemarker/core/AppMetaTemplateDateFormatFactory.java
----------------------------------------------------------------------
diff --git a/src/test/java/freemarker/core/AppMetaTemplateDateFormatFactory.java b/src/test/java/freemarker/core/AppMetaTemplateDateFormatFactory.java
new file mode 100644
index 0000000..70a293f
--- /dev/null
+++ b/src/test/java/freemarker/core/AppMetaTemplateDateFormatFactory.java
@@ -0,0 +1,129 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package freemarker.core;
+
+import java.util.Date;
+import java.util.Locale;
+import java.util.TimeZone;
+
+import org.apache.commons.lang.NotImplementedException;
+
+import freemarker.template.TemplateDateModel;
+import freemarker.template.TemplateModelException;
+
+public class AppMetaTemplateDateFormatFactory extends TemplateDateFormatFactory {
+
+    public static final AppMetaTemplateDateFormatFactory INSTANCE = new AppMetaTemplateDateFormatFactory();
+    
+    private AppMetaTemplateDateFormatFactory() {
+        // Defined to decrease visibility
+    }
+    
+    @Override
+    public TemplateDateFormat get(String params, int dateType, Locale locale, TimeZone timeZone, boolean zonelessInput,
+            Environment env) throws UnknownDateTypeFormattingUnsupportedException, InvalidFormatParametersException {
+        TemplateFormatUtil.checkHasNoParameters(params);
+        return AppMetaTemplateDateFormat.INSTANCE;
+    }
+
+    private static class AppMetaTemplateDateFormat extends TemplateDateFormat {
+
+        private static final AppMetaTemplateDateFormat INSTANCE = new AppMetaTemplateDateFormat();
+        
+        private AppMetaTemplateDateFormat() { }
+        
+        @Override
+        public String format(TemplateDateModel dateModel)
+                throws UnformattableValueException, TemplateModelException {
+            String result = String.valueOf(TemplateFormatUtil.getNonNullDate(dateModel).getTime());
+            if (dateModel instanceof AppMetaTemplateDateModel) {
+                result += "/" + ((AppMetaTemplateDateModel) dateModel).getAppMeta(); 
+            }
+            return result;
+        }
+
+        @Override
+        public boolean isLocaleBound() {
+            return false;
+        }
+
+        @Override
+        public boolean isTimeZoneBound() {
+            return false;
+        }
+
+        @Override
+        public <MO extends TemplateMarkupOutputModel> MO format(TemplateDateModel dateModel,
+                MarkupOutputFormat<MO> outputFormat) throws UnformattableValueException, TemplateModelException {
+            throw new NotImplementedException();
+        }
+
+        @Override
+        public Object parse(String s, int dateType) throws UnparsableValueException {
+            int slashIdx = s.indexOf('/');
+            try {
+                if (slashIdx != -1) {
+                    return new AppMetaTemplateDateModel(
+                            new Date(Long.parseLong(s.substring(0,  slashIdx))),
+                            dateType,
+                            s.substring(slashIdx +1));
+                } else {
+                    return new Date(Long.parseLong(s));
+                }
+            } catch (NumberFormatException e) {
+                throw new UnparsableValueException("Malformed long");
+            }
+        }
+
+        @Override
+        public String getDescription() {
+            return "millis since the epoch";
+        }
+        
+    }
+    
+    public static class AppMetaTemplateDateModel implements TemplateDateModel {
+        
+        private final Date date;
+        private final int dateType;
+        private final String appMeta;
+
+        public AppMetaTemplateDateModel(Date date, int dateType, String appMeta) {
+            this.date = date;
+            this.dateType = dateType;
+            this.appMeta = appMeta;
+        }
+
+        @Override
+        public Date getAsDate() throws TemplateModelException {
+            return date;
+        }
+
+        @Override
+        public int getDateType() {
+            return dateType;
+        }
+
+        public String getAppMeta() {
+            return appMeta;
+        }
+        
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/7f591d16/src/test/java/freemarker/core/DateFormatTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/freemarker/core/DateFormatTest.java b/src/test/java/freemarker/core/DateFormatTest.java
index e421189..af57f77 100644
--- a/src/test/java/freemarker/core/DateFormatTest.java
+++ b/src/test/java/freemarker/core/DateFormatTest.java
@@ -21,6 +21,7 @@ package freemarker.core;
 import static org.hamcrest.Matchers.*;
 import static org.junit.Assert.*;
 
+import java.io.IOException;
 import java.sql.Time;
 import java.sql.Timestamp;
 import java.util.Date;
@@ -38,6 +39,7 @@ import freemarker.template.Configuration;
 import freemarker.template.SimpleDate;
 import freemarker.template.Template;
 import freemarker.template.TemplateDateModel;
+import freemarker.template.TemplateException;
 import freemarker.template.TemplateModelException;
 import freemarker.test.TemplateTest;
 
@@ -58,7 +60,8 @@ public class DateFormatTest extends TemplateTest {
         cfg.setCustomDateFormats(ImmutableMap.of(
                 "epoch", EpochMillisTemplateDateFormatFactory.INSTANCE,
                 "loc", LocAndTZSensitiveTemplateDateFormatFactory.INSTANCE,
-                "div", EpochMillisDivTemplateDateFormatFactory.INSTANCE));
+                "div", EpochMillisDivTemplateDateFormatFactory.INSTANCE,
+                "appMeta", AppMetaTemplateDateFormatFactory.INSTANCE));
     }
 
     @Test
@@ -351,6 +354,49 @@ public class DateFormatTest extends TemplateTest {
                 "2015-Sep_en 2015-Sep_en_GB 2015-Sep_en_GB 2015-sept._fr_FR 2015-szept.");
     }
     
+    /**
+     * ?date() and such are new in 2.3.24.
+     */
+    @Test
+    public void testZeroArgDateBI() throws IOException, TemplateException {
+        Configuration cfg = getConfiguration();
+        cfg.setDateFormat("@epoch");
+        cfg.setDateTimeFormat("@epoch");
+        cfg.setTimeFormat("@epoch");
+        
+        addToDataModel("t", String.valueOf(T));
+        
+        assertOutput(
+                "${t?date?string.xs_u} ${t?date()?string.xs_u}",
+                "2015-09-06Z 2015-09-06Z");
+        assertOutput(
+                "${t?time?string.xs_u} ${t?time()?string.xs_u}",
+                "12:00:00Z 12:00:00Z");
+        assertOutput(
+                "${t?datetime?string.xs_u} ${t?datetime()?string.xs_u}",
+                "2015-09-06T12:00:00Z 2015-09-06T12:00:00Z");
+    }
+
+    @Test
+    public void testAppMetaRoundtrip() throws IOException, TemplateException {
+        Configuration cfg = getConfiguration();
+        cfg.setDateFormat("@appMeta");
+        cfg.setDateTimeFormat("@appMeta");
+        cfg.setTimeFormat("@appMeta");
+        
+        addToDataModel("t", String.valueOf(T) + "/foo");
+        
+        assertOutput(
+                "${t?date} ${t?date()}",
+                T + " " + T + "/foo");
+        assertOutput(
+                "${t?time} ${t?time()}",
+                T + " " + T + "/foo");
+        assertOutput(
+                "${t?datetime} ${t?datetime()}",
+                T + " " + T + "/foo");
+    }
+    
     private static class MutableTemplateDateModel implements TemplateDateModel {
         
         private Date date;

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/7f591d16/src/test/java/freemarker/core/EpochMillisDivTemplateDateFormatFactory.java
----------------------------------------------------------------------
diff --git a/src/test/java/freemarker/core/EpochMillisDivTemplateDateFormatFactory.java b/src/test/java/freemarker/core/EpochMillisDivTemplateDateFormatFactory.java
index b056e7b..55fa980 100644
--- a/src/test/java/freemarker/core/EpochMillisDivTemplateDateFormatFactory.java
+++ b/src/test/java/freemarker/core/EpochMillisDivTemplateDateFormatFactory.java
@@ -84,7 +84,7 @@ public class EpochMillisDivTemplateDateFormatFactory extends TemplateDateFormatF
         }
 
         @Override
-        public Date parse(String s) throws UnparsableValueException {
+        public Date parse(String s, int dateType) throws UnparsableValueException {
             try {
                 return new Date(Long.parseLong(s));
             } catch (NumberFormatException e) {

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/7f591d16/src/test/java/freemarker/core/EpochMillisTemplateDateFormatFactory.java
----------------------------------------------------------------------
diff --git a/src/test/java/freemarker/core/EpochMillisTemplateDateFormatFactory.java b/src/test/java/freemarker/core/EpochMillisTemplateDateFormatFactory.java
index 176aec7..63e1287 100644
--- a/src/test/java/freemarker/core/EpochMillisTemplateDateFormatFactory.java
+++ b/src/test/java/freemarker/core/EpochMillisTemplateDateFormatFactory.java
@@ -71,7 +71,7 @@ public class EpochMillisTemplateDateFormatFactory extends TemplateDateFormatFact
         }
 
         @Override
-        public Date parse(String s) throws UnparsableValueException {
+        public Date parse(String s, int dateType) throws UnparsableValueException {
             try {
                 return new Date(Long.parseLong(s));
             } catch (NumberFormatException e) {

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/7f591d16/src/test/java/freemarker/core/LocAndTZSensitiveTemplateDateFormatFactory.java
----------------------------------------------------------------------
diff --git a/src/test/java/freemarker/core/LocAndTZSensitiveTemplateDateFormatFactory.java b/src/test/java/freemarker/core/LocAndTZSensitiveTemplateDateFormatFactory.java
index 7fd46fe..94edd6e 100644
--- a/src/test/java/freemarker/core/LocAndTZSensitiveTemplateDateFormatFactory.java
+++ b/src/test/java/freemarker/core/LocAndTZSensitiveTemplateDateFormatFactory.java
@@ -75,7 +75,7 @@ public class LocAndTZSensitiveTemplateDateFormatFactory extends TemplateDateForm
         }
 
         @Override
-        public Date parse(String s) throws UnparsableValueException {
+        public Date parse(String s, int dateType) throws UnparsableValueException {
             try {
                 int atIdx = s.indexOf("@");
                 if (atIdx == -1) {