List of usage examples for org.springframework.format.datetime.joda LocalDateTimeParser LocalDateTimeParser
public LocalDateTimeParser(DateTimeFormatter formatter)
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 {// www .j a va 2 s . c o m 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(); } }