@ -1,5 +1,5 @@
@@ -1,5 +1,5 @@
/ *
* Copyright 2002 - 2015 the original author or authors .
* Copyright 2002 - 2016 the original author or authors .
*
* Licensed under the Apache License , Version 2 . 0 ( the "License" ) ;
* you may not use this file except in compliance with the License .
@ -29,7 +29,7 @@ import java.time.YearMonth;
@@ -29,7 +29,7 @@ import java.time.YearMonth;
import java.time.ZonedDateTime ;
import java.time.format.DateTimeFormatter ;
import java.time.format.FormatStyle ;
import java.util.Hash Map ;
import java.util.Enum Map ;
import java.util.Map ;
import org.springframework.format.FormatterRegistrar ;
@ -58,18 +58,19 @@ public class DateTimeFormatterRegistrar implements FormatterRegistrar {
@@ -58,18 +58,19 @@ public class DateTimeFormatterRegistrar implements FormatterRegistrar {
/ * *
* User defined formatters .
* User - defined formatters .
* /
private final Map < Type , DateTimeFormatter > formatters = new HashMap < Type , DateTimeFormatter > ( ) ;
private final Map < Type , DateTimeFormatter > formatters =
new EnumMap < Type , DateTimeFormatter > ( Type . class ) ;
/ * *
* Factories used when specific formatters have not been specified .
* /
private final Map < Type , DateTimeFormatterFactory > factories ;
private final Map < Type , DateTimeFormatterFactory > factories =
new EnumMap < Type , DateTimeFormatterFactory > ( Type . class ) ;
public DateTimeFormatterRegistrar ( ) {
this . factories = new HashMap < Type , DateTimeFormatterFactory > ( ) ;
for ( Type type : Type . values ( ) ) {
this . factories . put ( type , new DateTimeFormatterFactory ( ) ) ;
}
@ -157,33 +158,38 @@ public class DateTimeFormatterRegistrar implements FormatterRegistrar {
@@ -157,33 +158,38 @@ public class DateTimeFormatterRegistrar implements FormatterRegistrar {
public void registerFormatters ( FormatterRegistry registry ) {
DateTimeConverters . registerConverters ( registry ) ;
DateTimeFormatter dateFormatter = getFormatter ( Type . DATE ) ;
DateTimeFormatter timeFormatter = getFormatter ( Type . TIME ) ;
DateTimeFormatter dateTimeFormatter = getFormatter ( Type . DATE_TIME ) ;
DateTimeFormatter df = getFormatter ( Type . DATE ) ;
DateTimeFormatter tf = getFormatter ( Type . TIME ) ;
DateTimeFormatter dtf = getFormatter ( Type . DATE_TIME ) ;
// Efficient ISO_LOCAL_* variants for printing since they are twice as fast...
registry . addFormatterForFieldType ( LocalDate . class ,
new TemporalAccessorPrinter ( dateFormatter ) ,
new TemporalAccessorParser ( LocalDate . class , dateFormatter ) ) ;
new TemporalAccessorPrinter (
df = = DateTimeFormatter . ISO_DATE ? DateTimeFormatter . ISO_LOCAL_DATE : df ) ,
new TemporalAccessorParser ( LocalDate . class , df ) ) ;
registry . addFormatterForFieldType ( LocalTime . class ,
new TemporalAccessorPrinter ( timeFormatter ) ,
new TemporalAccessorParser ( LocalTime . class , timeFormatter ) ) ;
new TemporalAccessorPrinter (
tf = = DateTimeFormatter . ISO_TIME ? DateTimeFormatter . ISO_LOCAL_TIME : tf ) ,
new TemporalAccessorParser ( LocalTime . class , tf ) ) ;
registry . addFormatterForFieldType ( LocalDateTime . class ,
new TemporalAccessorPrinter ( dateTimeFormatter ) ,
new TemporalAccessorParser ( LocalDateTime . class , dateTimeFormatter ) ) ;
new TemporalAccessorPrinter (
dtf = = DateTimeFormatter . ISO_DATE_TIME ? DateTimeFormatter . ISO_LOCAL_DATE_TIME : dtf ) ,
new TemporalAccessorParser ( LocalDateTime . class , dtf ) ) ;
registry . addFormatterForFieldType ( ZonedDateTime . class ,
new TemporalAccessorPrinter ( dateTimeFormatter ) ,
new TemporalAccessorParser ( ZonedDateTime . class , dateTimeFormatter ) ) ;
new TemporalAccessorPrinter ( dtf ) ,
new TemporalAccessorParser ( ZonedDateTime . class , dtf ) ) ;
registry . addFormatterForFieldType ( OffsetDateTime . class ,
new TemporalAccessorPrinter ( dateTimeFormatter ) ,
new TemporalAccessorParser ( OffsetDateTime . class , dateTimeFormatter ) ) ;
new TemporalAccessorPrinter ( dtf ) ,
new TemporalAccessorParser ( OffsetDateTime . class , dtf ) ) ;
registry . addFormatterForFieldType ( OffsetTime . class ,
new TemporalAccessorPrinter ( timeFormatter ) ,
new TemporalAccessorParser ( OffsetTime . class , timeFormatter ) ) ;
new TemporalAccessorPrinter ( tf ) ,
new TemporalAccessorParser ( OffsetTime . class , tf ) ) ;
registry . addFormatterForFieldType ( Instant . class , new InstantFormatter ( ) ) ;
registry . addFormatterForFieldType ( Period . class , new PeriodFormatter ( ) ) ;