Refactor & polish DateTimeFormatterFactory[Bean]
This commit refactors the logic in DateTimeFormatterFactory's createDateTimeFormatter() method to ensure forward compatibility with possible future changes to the ISO enum. This commit also polishes the Javadoc for DateTimeFormatterFactoryBean. Issue: SPR-9959
This commit is contained in:
parent
c348be2511
commit
85ab789f2f
|
|
@ -94,14 +94,21 @@ public class DateTimeFormatterFactory {
|
|||
dateTimeFormatter = DateTimeFormat.forPattern(pattern);
|
||||
}
|
||||
else if (iso != null && iso != ISO.NONE) {
|
||||
if (iso == ISO.DATE) {
|
||||
dateTimeFormatter = ISODateTimeFormat.date();
|
||||
}
|
||||
else if (iso == ISO.TIME) {
|
||||
dateTimeFormatter = ISODateTimeFormat.time();
|
||||
}
|
||||
else {
|
||||
dateTimeFormatter = ISODateTimeFormat.dateTime();
|
||||
switch (iso) {
|
||||
case DATE:
|
||||
dateTimeFormatter = ISODateTimeFormat.date();
|
||||
break;
|
||||
case TIME:
|
||||
dateTimeFormatter = ISODateTimeFormat.time();
|
||||
break;
|
||||
case DATE_TIME:
|
||||
dateTimeFormatter = ISODateTimeFormat.dateTime();
|
||||
break;
|
||||
case NONE:
|
||||
/* no-op */
|
||||
break;
|
||||
default:
|
||||
throw new IllegalStateException("Unsupported ISO format: " + iso);
|
||||
}
|
||||
}
|
||||
else if (StringUtils.hasLength(style)) {
|
||||
|
|
|
|||
|
|
@ -21,8 +21,8 @@ import org.springframework.beans.factory.FactoryBean;
|
|||
import org.springframework.beans.factory.InitializingBean;
|
||||
|
||||
/**
|
||||
* {@link FactoryBean} that creates a Joda {@link DateTimeFormatter}. See the base class
|
||||
* {@linkplain DateTimeFormatterFactory} for configuration details.
|
||||
* {@link FactoryBean} that creates a Joda {@link DateTimeFormatter}. See the
|
||||
* {@linkplain DateTimeFormatterFactory base class} for configuration details.
|
||||
*
|
||||
* @author Phillip Webb
|
||||
* @author Sam Brannen
|
||||
|
|
|
|||
Loading…
Reference in New Issue