Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  * Copyright 2014 Attila Szegedi, Daniel Dekany, Jonathan Revusky
  * Licensed 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
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * See the License for the specific language governing permissions and
 * limitations under the License.
package freemarker.core;
Represents a date/time/dateTime format; used in templates for formatting and parsing with that format. This is similar to Java's java.text.DateFormat, but made to fit the requirements of FreeMarker. Also, it makes easier to define formats that can't be represented with Java's existing java.text.DateFormat implementations.

Implementations need not be thread-safe. Usually, instances are bound to a single Environment, and Environment-s are thread-local objects. As the Environment is recreated for each top-level template processing, constructing these object should be cheap, or else the factory of the instances should do some caching.

// [Advanced formatting: planned public]
abstract class TemplateDateFormat {

dateModel The date/time/dateTime to format. Most implementations will just work with the return value of freemarker.template.TemplateDateModel.getAsDate(), but some may format differently depending on the properties of a custom freemarker.template.TemplateDateModel implementation.
The date/time/dateTime as text, with no escaping (like no HTML escaping). Can't be null.
UnformattableDateException When a freemarker.template.TemplateDateModel can't be formatted because of the value/properties of the freemarker.template.TemplateDateModel. The most often used subclass is UnknownDateTypeFormattingUnsupportedException.
freemarker.template.TemplateModelException Exception thrown by the dateModel object when calling its methods.
    public abstract String format(TemplateDateModel dateModel)
            throws UnformattableDateExceptionTemplateModelException;


The interpretation of the text as java.util.Date. Can't be null.
    public abstract Date parse(String sthrows java.text.ParseException;

Meant to be used in error messages to tell what format the parsed string didn't fit.
    public abstract String getDescription();
    // This isn't used yet, as we don't have markup formatting in the template language.
    // * Formats the date to markup instead of to plain text, or return {@code false} that will make FreeMarker call
    // * {@link #format(TemplateDateModel)} and escape its result. It must not write into {@code out} when it returns
    // * {@code false}!
    // * It should only write to {@code out} and return {@code true} if the markup format is not the same as the
    // * {@link #format(TemplateDateModel)} escaped.
    // */
    //public boolean formatAsMarkup(TemplateDateModel dateModel, boolean zonelessInput, Writer out) {
    //    return false;
Tells if this formatter should be re-created if the locale changes.
    public abstract boolean isLocaleBound();
New to GrepCode? Check out our FAQ X