SWF-603 Change default date format to yyyy-MM-dd
This commit is contained in:
@@ -27,6 +27,8 @@ import org.springframework.util.StringUtils;
|
||||
|
||||
public class DateFormatter implements Formatter {
|
||||
|
||||
public static final String DEFAULT_PATTERN = "yyyy-MM-dd";
|
||||
|
||||
private String pattern;
|
||||
|
||||
private Locale locale;
|
||||
@@ -68,12 +70,16 @@ public class DateFormatter implements Formatter {
|
||||
|
||||
protected DateFormat getDateFormat() {
|
||||
if (pattern != null) {
|
||||
return new SimpleDateFormat(pattern, locale);
|
||||
if (locale != null) {
|
||||
return new SimpleDateFormat(pattern, locale);
|
||||
} else {
|
||||
return new SimpleDateFormat(pattern);
|
||||
}
|
||||
} else {
|
||||
if (locale != null) {
|
||||
return DateFormat.getDateInstance(DateFormat.SHORT, locale);
|
||||
return new SimpleDateFormat(DEFAULT_PATTERN, locale);
|
||||
} else {
|
||||
return DateFormat.getDateInstance(DateFormat.SHORT);
|
||||
return new SimpleDateFormat(DEFAULT_PATTERN);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
package org.springframework.binding.format.formatters;
|
||||
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.GregorianCalendar;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
public class DateFormatterTests extends TestCase {
|
||||
|
||||
public void testFormatDefaultPattern() {
|
||||
DateFormatter dateFormatter = new DateFormatter();
|
||||
Calendar calendar = new GregorianCalendar(2008, 3, 1);
|
||||
assertEquals("2008-04-01", dateFormatter.format(calendar.getTime()));
|
||||
}
|
||||
|
||||
public void testParseDefaultPattern() {
|
||||
DateFormatter dateFormatter = new DateFormatter();
|
||||
Calendar calendar = new GregorianCalendar();
|
||||
calendar.setTime((Date) dateFormatter.parse("2008-04-01"));
|
||||
assertEquals(2008, calendar.get(Calendar.YEAR));
|
||||
assertEquals(3, calendar.get(Calendar.MONTH));
|
||||
assertEquals(1, calendar.get(Calendar.DAY_OF_MONTH));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -90,7 +90,7 @@ public class MvcViewTests extends TestCase {
|
||||
assertNotNull(bm);
|
||||
assertEquals(null, bm.getFieldValue("stringProperty"));
|
||||
assertEquals("3", bm.getFieldValue("integerProperty"));
|
||||
assertEquals("1/1/08", bm.getFieldValue("dateProperty"));
|
||||
assertEquals("2008-01-01", bm.getFieldValue("dateProperty"));
|
||||
}
|
||||
|
||||
public void testResumeNoEvent() throws Exception {
|
||||
@@ -126,7 +126,7 @@ public class MvcViewTests extends TestCase {
|
||||
context.putRequestParameter("_eventId", "submit");
|
||||
context.putRequestParameter("stringProperty", "foo");
|
||||
context.putRequestParameter("integerProperty", "5");
|
||||
context.putRequestParameter("dateProperty", "1/1/2007");
|
||||
context.putRequestParameter("dateProperty", "2007-01-01");
|
||||
BindBean bindBean = new BindBean();
|
||||
StaticExpression modelObject = new StaticExpression(bindBean);
|
||||
modelObject.setExpressionString("bindBean");
|
||||
|
||||
Reference in New Issue
Block a user