Example usage for org.springframework.format.datetime.joda LocalDateParser LocalDateParser

List of usage examples for org.springframework.format.datetime.joda LocalDateParser LocalDateParser

Introduction

In this page you can find the example usage for org.springframework.format.datetime.joda LocalDateParser LocalDateParser.

Prototype

public LocalDateParser(DateTimeFormatter formatter) 

Source Link

Document

Create a new DateTimeParser.

Usage

From source file:cherry.foundation.type.format.CustomDateTimeFormatAnnotationFormatterFactory.java

@Override
public Parser<?> getParser(CustomDateTimeFormat annotation, Class<?> fieldType) {
    if (fieldType == LocalDate.class) {
        DateTimeFormatterBuilder toParse = builder(dateToParse);
        if (annotation.value() == Range.TO) {
            return new LocalDateToParser(toParse.toFormatter());
        } else {//ww  w.  jav  a 2 s. com
            return new LocalDateParser(toParse.toFormatter());
        }
    } else if (fieldType == LocalTime.class) {
        if (annotation.optional()) {
            if (annotation.value() == Range.TO) {
                DateTimeFormatterBuilder hm = builder(timeToParseHm);
                DateTimeFormatterBuilder hms = builder(timeToParseHm).appendPattern(timeToParseS);
                return new LocalTimeToParser(hm.toFormatter(), hms.toFormatter());
            } else {
                DateTimeFormatterBuilder toParse = builder(timeToParseHm)
                        .appendOptional(builder(timeToParseS).toParser());
                return new LocalTimeParser(toParse.toFormatter());
            }
        } else {
            DateTimeFormatterBuilder toParse = builder(timeToParseHm).appendPattern(timeToParseS);
            return new LocalTimeParser(toParse.toFormatter());
        }
    } else if (fieldType == LocalDateTime.class) {
        if (annotation.optional()) {
            if (annotation.value() == Range.TO) {
                DateTimeFormatterBuilder ymd = builder(dateToParse);
                DateTimeFormatterBuilder ymdhm = builder(dateToParse).appendPattern(delimiterToParse)
                        .appendPattern(timeToParseHm);
                DateTimeFormatterBuilder ymdhms = builder(dateToParse).appendPattern(delimiterToParse)
                        .appendPattern(timeToParseHm).appendPattern(timeToParseS);
                return new LocalDateTimeToParser(ymd.toFormatter(), ymdhm.toFormatter(), ymdhms.toFormatter());
            } else {
                DateTimeFormatterBuilder toParse = builder(dateToParse)
                        .appendOptional(builder(delimiterToParse).appendPattern(timeToParseHm)
                                .appendOptional(builder(timeToParseS).toParser()).toParser());
                return new LocalDateTimeParser(toParse.toFormatter());
            }
        } else {
            DateTimeFormatterBuilder toParse = builder(dateToParse).appendPattern(delimiterToParse)
                    .appendPattern(timeToParseHm).appendPattern(timeToParseS);
            return new LocalDateTimeParser(toParse.toFormatter());
        }
    } else if (fieldType == DateTime.class) {
        if (annotation.optional()) {
            if (annotation.value() == Range.TO) {
                DateTimeFormatterBuilder ymd = builder(dateToParse);
                DateTimeFormatterBuilder ymdhm = builder(dateToParse).appendPattern(delimiterToParse)
                        .appendPattern(timeToParseHm);
                DateTimeFormatterBuilder ymdhms = builder(dateToParse).appendPattern(delimiterToParse)
                        .appendPattern(timeToParseHm).appendPattern(timeToParseS);
                return new DateTimeToParser(ymd.toFormatter(), ymdhm.toFormatter(), ymdhms.toFormatter());
            } else {
                DateTimeFormatterBuilder toParse = builder(dateToParse)
                        .appendOptional(builder(delimiterToParse).appendPattern(timeToParseHm)
                                .appendOptional(builder(timeToParseS).toParser()).toParser());
                return new DateTimeParser(toParse.toFormatter());
            }
        } else {
            DateTimeFormatterBuilder toParse = builder(dateToParse).appendPattern(delimiterToParse)
                    .appendPattern(timeToParseHm).appendPattern(timeToParseS);
            return new DateTimeParser(toParse.toFormatter());
        }
    } else {
        throw new IllegalStateException();
    }
}