diff --git a/org.springframework.context/src/main/java/org/springframework/format/annotation/DateTimeFormat.java b/org.springframework.context/src/main/java/org/springframework/format/annotation/DateTimeFormat.java
index fcf430d5811..01280a07b5a 100644
--- a/org.springframework.context/src/main/java/org/springframework/format/annotation/DateTimeFormat.java
+++ b/org.springframework.context/src/main/java/org/springframework/format/annotation/DateTimeFormat.java
@@ -22,104 +22,37 @@ import java.lang.annotation.Target;
/**
* Declares that a field should be formatted as a date time.
- * Supports formatting by {@link Style} or by pattern string.
+ * Supports formatting by style pattern or by format pattern string.
+ * Can be applied to java.util.Date, java.util.Calendar, java.long.Long, or Joda Time fields.
+ *
+ * For style-based formatting, set the style attribute to be the style pattern.
+ * The first character is the date style, and the second character is the time style.
+ * Specify a character of 'S' for short style, 'M' for medium, 'L' for long, and 'F' for full.
+ * A date or time may be omitted by specifying the style character '-'.
*
- * For style-based formatting: - *
dateStyle attribute to specify the style of the date portion of the DateTime.
- * timeStyle attribute to specify the style of the time portion of the DateTime.
- * pattern attribute to be the DateTime pattern, such as yyyy/mm/dd h:mm:ss a.
+ * If the pattern attribute is specified, it takes precedence over the style attribute.
*
- * If no annotation attributes are specified, the default format applied is style-based with dateStyle={@link Style#SHORT} and timeStyle={@link Style#SHORT}.
+ * If no annotation attributes are specified, the default format applied is style-based with a style code of 'SS' (short date, short time).
*
* @author Keith Donald
* @since 3.0
+ * @see org.joda.time.format.DateTimeFormat
*/
@Target( { ElementType.METHOD, ElementType.FIELD, ElementType.PARAMETER })
@Retention(RetentionPolicy.RUNTIME)
public @interface DateTimeFormat {
/**
- * The style to use for formatting the date portion of the property.
- * Defaults to {@link Style#NONE}.
+ * The style pattern to use to format the field.
+ * Defaults to 'SS' for short date time.
*/
- Style dateStyle() default Style.NONE;
+ String style() default "SS";
/**
- * The style to use for formatting the time portion of the property.
- * Defaults to {@link Style#NONE}.
- */
- Style timeStyle() default Style.NONE;
-
- /**
- * A pattern String that defines a custom format for the property.
- * Use this method or the *Style methods, not both.
+ * A pattern String to apply to format the field.
+ * Set this attribute or the style attribute, not both.
*/
String pattern() default "";
-
- /**
- * Supported DateTimeFormat styles.
- */
- public enum Style {
- /**
- * The short format style.
- *
Example short dateStyle: Locale.US="M/d/yy" e.g. 10/31/2009
- *
Example short timeStyle: Locale.US="h:mm a" e.g. 1:30 PM
- */
- SHORT {
- public String toString() {
- return "S";
- }
- },
-
- /**
- * The medium format style.
- *
Example medium dateStyle: Locale.US="MMM d, yyyy" e.g Oct 31, 2009
- *
Example medium timeStyle: Locale.US="h:mm:ss a" e.g. 1:30:00 PM
- */
- MEDIUM {
- public String toString() {
- return "M";
- }
- },
-
- /**
- * The long format style.
- *
Example long dateStyle: Locale.US="MMMM d, yyyy" e.g October 31, 2009
- *
Example long timeStyle: Locale.US="h:mm:ss a z" e.g. 1:30:00 PM Eastern Standard Time
- */
- LONG {
- public String toString() {
- return "L";
- }
- },
-
- /**
- * The full format style.
- *
Example full dateStyle: Locale.US="EEEE, MMMM d, yyyy" e.g. Saturday, October 31, 2009
- *
Example full timeStyle: Locale.US="h:mm:ss a z" e.g 1:30:00 PM Eastern Standard Time
- */
- FULL {
- public String toString() {
- return "F";
- }
- },
-
- /**
- * The none format style.
- * A dateStyle specified with this value results in date fields such as mm, dd, and yyyy being ignored.
- * A timeStyle specified with this value results in time fields such as hh, mm being ignored.
- * If both dateStyle and timeStyle are set to this value and the pattern attribute is also not specified,
- * a default value for each is selected based on the type of field being annotated.
- */
- NONE {
- public String toString() {
- return "-";
- }
- }
- }
-
}
diff --git a/org.springframework.context/src/main/java/org/springframework/format/annotation/ISODateTimeFormat.java b/org.springframework.context/src/main/java/org/springframework/format/annotation/ISODateTimeFormat.java
index 71a32ae834e..938a971d60e 100644
--- a/org.springframework.context/src/main/java/org/springframework/format/annotation/ISODateTimeFormat.java
+++ b/org.springframework.context/src/main/java/org/springframework/format/annotation/ISODateTimeFormat.java
@@ -31,11 +31,11 @@ public @interface ISODateTimeFormat {
/**
* The ISO style to use to format the date time.
- * Defaults to {@link Style#DATE_TIME}.
+ * Defaults to {@link ISO#DATE_TIME}.
*/
- Style value() default Style.DATE_TIME;
+ ISO value() default ISO.DATE_TIME;
- public enum Style {
+ public enum ISO {
/**
* The most common ISO Date Format yyyy-MM-dd e.g. 2000-10-31.
diff --git a/org.springframework.context/src/main/java/org/springframework/format/datetime/joda/DateTimeFormatAnnotationFormatterFactory.java b/org.springframework.context/src/main/java/org/springframework/format/datetime/joda/DateTimeFormatAnnotationFormatterFactory.java
index 58f2af0ba21..3e6b42b7384 100644
--- a/org.springframework.context/src/main/java/org/springframework/format/datetime/joda/DateTimeFormatAnnotationFormatterFactory.java
+++ b/org.springframework.context/src/main/java/org/springframework/format/datetime/joda/DateTimeFormatAnnotationFormatterFactory.java
@@ -17,7 +17,6 @@ package org.springframework.format.datetime.joda;
import org.joda.time.format.DateTimeFormatter;
import org.springframework.format.annotation.DateTimeFormat;
-import org.springframework.format.annotation.DateTimeFormat.Style;
/**
* Formats fields annotated with the {@link DateTimeFormat} annotation.
@@ -32,22 +31,16 @@ public final class DateTimeFormatAnnotationFormatterFactory extends AbstractDate
if (!pattern.isEmpty()) {
return forPattern(pattern);
} else {
- Style dateStyle = annotation.dateStyle();
- Style timeStyle = annotation.timeStyle();
- if (Style.NONE == dateStyle && Style.NONE == timeStyle) {
- return forDateTimeStyle(Style.SHORT, Style.SHORT);
- } else {
- return forDateTimeStyle(dateStyle, timeStyle);
- }
+ return forStyle(annotation.style());
}
}
- private DateTimeFormatter forDateTimeStyle(Style dateStyle, Style timeStyle) {
- return org.joda.time.format.DateTimeFormat.forStyle(dateStyle.toString() + timeStyle.toString());
- }
-
private DateTimeFormatter forPattern(String pattern) {
return org.joda.time.format.DateTimeFormat.forPattern(pattern);
}
+ private DateTimeFormatter forStyle(String style) {
+ return org.joda.time.format.DateTimeFormat.forStyle(style);
+ }
+
}
\ No newline at end of file
diff --git a/org.springframework.context/src/main/java/org/springframework/format/datetime/joda/ISODateTimeFormatAnnotationFormatterFactory.java b/org.springframework.context/src/main/java/org/springframework/format/datetime/joda/ISODateTimeFormatAnnotationFormatterFactory.java
index 8112160d5f0..46958ab0d09 100644
--- a/org.springframework.context/src/main/java/org/springframework/format/datetime/joda/ISODateTimeFormatAnnotationFormatterFactory.java
+++ b/org.springframework.context/src/main/java/org/springframework/format/datetime/joda/ISODateTimeFormatAnnotationFormatterFactory.java
@@ -17,7 +17,7 @@ package org.springframework.format.datetime.joda;
import org.joda.time.format.DateTimeFormatter;
import org.springframework.format.annotation.ISODateTimeFormat;
-import org.springframework.format.annotation.ISODateTimeFormat.Style;
+import org.springframework.format.annotation.ISODateTimeFormat.ISO;
/**
* Formats fields annotated with the {@link ISODateTimeFormat} annotation.
@@ -28,10 +28,10 @@ import org.springframework.format.annotation.ISODateTimeFormat.Style;
public final class ISODateTimeFormatAnnotationFormatterFactory extends AbstractDateTimeAnnotationFormatterFactory