Example usage for org.joda.time.format DateTimeFormatter withChronology

List of usage examples for org.joda.time.format DateTimeFormatter withChronology

Introduction

In this page you can find the example usage for org.joda.time.format DateTimeFormatter withChronology.

Prototype

public DateTimeFormatter withChronology(Chronology chrono) 

Source Link

Document

Returns a new formatter that will use the specified chronology in preference to that of the printed object, or ISO on a parse.

Usage

From source file:de.fraunhofer.iosb.ilt.sta.model.ext.TimeInterval.java

License:Open Source License

@Override
public String asISO8601() {
    DateTimeFormatter printer = ISODateTimeFormat.dateTime().withZone(DateTimeZone.UTC);
    printer = printer.withChronology(interval.getChronology());
    StringBuffer buf = new StringBuffer(48);
    printer.printTo(buf, interval.getStartMillis());
    buf.append('/');
    printer.printTo(buf, interval.getEndMillis());
    return buf.toString();
}

From source file:net.asfun.jangod.lib.filter.DatetimeFilter.java

License:Apache License

@Override
public Object filter(Object object, JangodInterpreter interpreter, String... arg) throws InterpretException {
    if (object == null) {
        return object;
    }//from www .  j av a 2 s .co m
    if (object instanceof DateTime) { // joda DateTime
        DateTimeFormatter formatter;
        DateTimeFormatter a = DateTimeFormat.forPattern(interpreter.evaluateExpressionAsString(arg[0]));
        if (arg.length == 1) {
            DateTimeFormatter forPattern = a;
            JodaTimeContext jodaTimeContext = JodaTimeContextHolder.getJodaTimeContext();
            if (jodaTimeContext == null) {
                jodaTimeContext = new JodaTimeContext();
            }
            formatter = jodaTimeContext.getFormatter(forPattern);
        } else if (arg.length == 2) {
            formatter = a.withChronology(ISOChronology
                    .getInstance(DateTimeZone.forID(interpreter.evaluateExpressionAsString(arg[1]))));
        } else {
            throw new InterpretException("filter date expects 1 or 2 args >>> " + arg.length);
        }
        return formatter.print((DateTime) object);
    } else {
        SimpleDateFormat sdf;
        if (arg.length == 1) {
            sdf = new SimpleDateFormat(interpreter.evaluateExpressionAsString(arg[0]));
            sdf.setTimeZone(interpreter.getConfiguration().getTimezone());
        } else if (arg.length == 2) {
            sdf = new SimpleDateFormat(interpreter.evaluateExpressionAsString(arg[0]));
            sdf.setTimeZone(TimeZone.getTimeZone(interpreter.evaluateExpressionAsString(arg[1])));
        } else {
            throw new InterpretException("filter date expects 1 or 2 args >>> " + arg.length);
        }
        return sdf.format(object);
    }
}

From source file:org.opensaml.Configuration.java

License:Open Source License

/**
 * Gets the date format used to string'ify SAML's {@link org.joda.time.DateTime} objects.
 * /*from  w w  w  .  j av  a  2 s  .c o m*/
 * @return date format used to string'ify date objects
 */
public static DateTimeFormatter getSAMLDateFormatter() {
    if (dateFormatter == null) {
        DateTimeFormatter formatter = DateTimeFormat.forPattern(defaultDateFormat);
        dateFormatter = formatter.withChronology(ISOChronology.getInstanceUTC());
    }

    return dateFormatter;
}

From source file:org.opensaml.Configuration.java

License:Open Source License

/**
 * Sets the date format used to string'ify SAML's date/time objects.
 * /*from ww w  .ja  va  2s.c  o m*/
 * See the
 * {@link <a href="http://java.sun.com/j2se/1.4.2/docs/api/java/text/SimpleDateFormat.html">SimpleDateFormat</a>}
 * documentation for format syntax.
 * 
 * @param format date format used to string'ify date objects
 */
public static void setSAMLDateFormat(String format) {
    DateTimeFormatter formatter = DateTimeFormat.forPattern(format);
    dateFormatter = formatter.withChronology(ISOChronology.getInstanceUTC());
}

From source file:org.opensaml.saml.config.SAMLConfiguration.java

License:Open Source License

/**
 * Gets the date format used to string'ify SAML's {@link org.joda.time.DateTime} objects.
 * /*w w w. ja  v  a2s  . c  om*/
 * @return date format used to string'ify date objects
 */
public DateTimeFormatter getSAMLDateFormatter() {
    if (dateFormatter == null) {
        DateTimeFormatter formatter = DateTimeFormat.forPattern(defaultDateFormat);
        dateFormatter = formatter.withChronology(ISOChronology.getInstanceUTC());
    }

    return dateFormatter;
}

From source file:org.opensaml.saml.config.SAMLConfiguration.java

License:Open Source License

/**
 * Sets the date format used to string'ify SAML's date/time objects.
 * //from   w  w w .  j a v  a 2 s  .co m
 * See the
 * {@link <a href="http://java.sun.com/j2se/1.4.2/docs/api/java/text/SimpleDateFormat.html">SimpleDateFormat</a>}
 * documentation for format syntax.
 * 
 * @param format date format used to string'ify date objects
 */
public void setSAMLDateFormat(String format) {
    DateTimeFormatter formatter = DateTimeFormat.forPattern(format);
    dateFormatter = formatter.withChronology(ISOChronology.getInstanceUTC());
}

From source file:org.openxrd.Configuration.java

License:Apache License

/**
 * Gets the date format used to string'ify XRD's {@link org.joda.time.DateTime} objects.
 * /* ww  w .j  av  a 2s.  co m*/
 * @return date format used to string'ify date objects
 */
public static DateTimeFormatter getXRDDateFormatter() {
    if (dateFormatter == null) {
        DateTimeFormatter formatter = DateTimeFormat.forPattern(defaultDateFormat);
        dateFormatter = formatter.withChronology(ISOChronology.getInstanceUTC());
    }

    return dateFormatter;
}

From source file:org.openxrd.Configuration.java

License:Apache License

/**
 * Sets the date format used to string'ify XRD's date/time objects.
 * /*from  w ww . j  av a  2  s.c o m*/
 * See the
 * {@link <a href="http://java.sun.com/j2se/1.4.2/docs/api/java/text/SimpleDateFormat.html">SimpleDateFormat</a>}
 * documentation for format syntax.
 * 
 * @param format date format used to string'ify date objects
 */
public static void setXRDDateFormat(String format) {
    DateTimeFormatter formatter = DateTimeFormat.forPattern(format);
    dateFormatter = formatter.withChronology(ISOChronology.getInstanceUTC());
}

From source file:org.springframework.format.datetime.joda.JodaTimeContext.java

License:Apache License

/**
 * Get the DateTimeFormatter with the this context's settings
 * applied to the base {@code formatter}.
 * @param formatter the base formatter that establishes default
 * formatting rules, generally context-independent
 * @return the contextual DateTimeFormatter
 */// w ww  . j ava 2  s  .c o  m
public DateTimeFormatter getFormatter(DateTimeFormatter formatter) {
    if (this.chronology != null) {
        formatter = formatter.withChronology(this.chronology);
    }
    if (this.timeZone != null) {
        formatter = formatter.withZone(this.timeZone);
    } else {
        LocaleContext localeContext = LocaleContextHolder.getLocaleContext();
        if (localeContext instanceof TimeZoneAwareLocaleContext) {
            TimeZone timeZone = ((TimeZoneAwareLocaleContext) localeContext).getTimeZone();
            if (timeZone != null) {
                formatter = formatter.withZone(DateTimeZone.forTimeZone(timeZone));
            }
        }
    }
    return formatter;
}