Browse Source

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
pull/180/head
Sam Brannen 13 years ago
parent
commit
85ab789f2f
  1. 23
      spring-context/src/main/java/org/springframework/format/datetime/joda/DateTimeFormatterFactory.java
  2. 4
      spring-context/src/main/java/org/springframework/format/datetime/joda/DateTimeFormatterFactoryBean.java

23
spring-context/src/main/java/org/springframework/format/datetime/joda/DateTimeFormatterFactory.java

@ -94,14 +94,21 @@ public class DateTimeFormatterFactory { @@ -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)) {

4
spring-context/src/main/java/org/springframework/format/datetime/joda/DateTimeFormatterFactoryBean.java

@ -21,8 +21,8 @@ import org.springframework.beans.factory.FactoryBean; @@ -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…
Cancel
Save