formatting tests and polishing

This commit is contained in:
Keith Donald
2009-11-04 23:02:10 +00:00
parent 9ec337b736
commit ff39bc376f
6 changed files with 111 additions and 21 deletions

View File

@@ -30,15 +30,15 @@ public @interface DateTimeFormat {
/**
* The style to use for formatting the date portion of the property.
* Defaults to {@link FormatStyle#NONE}.
* Defaults to {@link Style#NONE}.
*/
FormatStyle dateStyle() default FormatStyle.NONE;
Style dateStyle() default Style.NONE;
/**
* The style to use for formatting the time portion of the property.
* Defaults to {@link FormatStyle#NONE}.
* Defaults to {@link Style#NONE}.
*/
FormatStyle timeStyle() default FormatStyle.NONE;
Style timeStyle() default Style.NONE;
/**
* A pattern String that defines a custom format for the property.
@@ -49,7 +49,7 @@ public @interface DateTimeFormat {
/**
* Supported DateTimeFormat styles.
*/
public enum FormatStyle {
public enum Style {
SHORT {
public String toString() {
return "S";

View File

@@ -16,7 +16,7 @@
package org.springframework.ui.format.jodatime;
import org.joda.time.format.DateTimeFormatter;
import org.springframework.ui.format.jodatime.DateTimeFormat.FormatStyle;
import org.springframework.ui.format.jodatime.DateTimeFormat.Style;
/**
* Formats properties annotated with the {@link DateTimeFormat} annotation.
@@ -32,13 +32,13 @@ public final class DateTimeFormatAnnotationFormatterFactory extends AbstractDate
if (!pattern.isEmpty()) {
return forPattern(pattern);
} else {
FormatStyle dateStyle = annotation.dateStyle();
FormatStyle timeStyle = annotation.timeStyle();
Style dateStyle = annotation.dateStyle();
Style timeStyle = annotation.timeStyle();
return forDateTimeStyle(dateStyle, timeStyle);
}
}
private DateTimeFormatter forDateTimeStyle(FormatStyle dateStyle, FormatStyle timeStyle) {
private DateTimeFormatter forDateTimeStyle(Style dateStyle, Style timeStyle) {
return org.joda.time.format.DateTimeFormat.forStyle(dateStyle.toString() + timeStyle.toString());
}

View File

@@ -28,9 +28,9 @@ import java.lang.annotation.Target;
@Retention(RetentionPolicy.RUNTIME)
public @interface ISODateTimeFormat {
FormatStyle value();
Style value();
public enum FormatStyle {
public enum Style {
DATE, TIME, DATE_TIME
}

View File

@@ -16,7 +16,7 @@
package org.springframework.ui.format.jodatime;
import org.joda.time.format.DateTimeFormatter;
import org.springframework.ui.format.jodatime.ISODateTimeFormat.FormatStyle;
import org.springframework.ui.format.jodatime.ISODateTimeFormat.Style;
/**
* Formats properties annotated with the {@link ISODateTimeFormat} annotation.
@@ -28,10 +28,10 @@ import org.springframework.ui.format.jodatime.ISODateTimeFormat.FormatStyle;
public final class ISODateTimeFormatAnnotationFormatterFactory extends AbstractDateTimeAnnotationFormatterFactory<ISODateTimeFormat> {
protected DateTimeFormatter configureDateTimeFormatterFrom(ISODateTimeFormat annotation) {
FormatStyle style = annotation.value();
if (style == FormatStyle.DATE) {
Style style = annotation.value();
if (style == Style.DATE) {
return org.joda.time.format.ISODateTimeFormat.date();
} else if (style == FormatStyle.TIME) {
} else if (style == Style.TIME) {
return org.joda.time.format.ISODateTimeFormat.time();
} else {
return org.joda.time.format.ISODateTimeFormat.dateTime();