Example usage for org.joda.time.format ISODateTimeFormat timeElementParser

List of usage examples for org.joda.time.format ISODateTimeFormat timeElementParser

Introduction

In this page you can find the example usage for org.joda.time.format ISODateTimeFormat timeElementParser.

Prototype

public static DateTimeFormatter timeElementParser() 

Source Link

Document

Returns a generic ISO time parser.

Usage

From source file:org.apache.druid.java.util.common.parsers.TimestampParser.java

License:Apache License

private static DateTimeFormatter createAutoParser() {
    final DateTimeFormatter offsetElement = new DateTimeFormatterBuilder().appendTimeZoneOffset("Z", true, 2, 4)
            .toFormatter();/*from  w  w  w  .j  a  v  a2  s .  c o m*/

    DateTimeParser timeOrOffset = new DateTimeFormatterBuilder()
            .append(null,
                    new DateTimeParser[] { new DateTimeFormatterBuilder().appendLiteral('T').toParser(),
                            new DateTimeFormatterBuilder().appendLiteral(' ').toParser() })
            .appendOptional(ISODateTimeFormat.timeElementParser().getParser())
            .appendOptional(offsetElement.getParser()).toParser();

    return new DateTimeFormatterBuilder().append(ISODateTimeFormat.dateElementParser())
            .appendOptional(timeOrOffset).toFormatter();
}

From source file:org.apache.druid.query.expression.TimestampParseExprMacro.java

License:Apache License

/**
 * Default formatter that parses according to the docs for this method: "If the pattern is not provided, this parses
 * time strings in either ISO8601 or SQL format."
 *//*from   ww  w.j  a v a 2s.c om*/
private static DateTimes.UtcFormatter createDefaultParser(final DateTimeZone timeZone) {
    final DateTimeFormatter offsetElement = new DateTimeFormatterBuilder().appendTimeZoneOffset("Z", true, 2, 4)
            .toFormatter();

    DateTimeParser timeOrOffset = new DateTimeFormatterBuilder()
            .append(null,
                    new DateTimeParser[] { new DateTimeFormatterBuilder().appendLiteral('T').toParser(),
                            new DateTimeFormatterBuilder().appendLiteral(' ').toParser() })
            .appendOptional(ISODateTimeFormat.timeElementParser().getParser())
            .appendOptional(offsetElement.getParser()).toParser();

    return DateTimes.wrapFormatter(new DateTimeFormatterBuilder().append(ISODateTimeFormat.dateElementParser())
            .appendOptional(timeOrOffset).toFormatter().withZone(timeZone));
}