Efficient ISO_LOCAL_* variants for printing LocalDate/LocalTime/LocalDateTime

Issue: SPR-14958
(cherry picked from commit 1ae17c2)
This commit is contained in:
Juergen Hoeller
2016-11-30 23:41:00 +01:00
parent 17f7f1fc15
commit af41dd1ed6
3 changed files with 77 additions and 31 deletions

View File

@@ -311,6 +311,15 @@ public class DateTimeFormattingTests {
@Test
public void testBindISOTime() {
MutablePropertyValues propertyValues = new MutablePropertyValues();
propertyValues.add("isoTime", "12:00:00");
binder.bind(propertyValues);
assertEquals(0, binder.getBindingResult().getErrorCount());
assertEquals("12:00:00", binder.getBindingResult().getFieldValue("isoTime"));
}
@Test
public void testBindISOTimeWithZone() {
MutablePropertyValues propertyValues = new MutablePropertyValues();
propertyValues.add("isoTime", "12:00:00.000-05:00");
binder.bind(propertyValues);
@@ -320,6 +329,15 @@ public class DateTimeFormattingTests {
@Test
public void testBindISODateTime() {
MutablePropertyValues propertyValues = new MutablePropertyValues();
propertyValues.add("isoDateTime", "2009-10-31T12:00:00");
binder.bind(propertyValues);
assertEquals(0, binder.getBindingResult().getErrorCount());
assertEquals("2009-10-31T12:00:00", binder.getBindingResult().getFieldValue("isoDateTime"));
}
@Test
public void testBindISODateTimeWithZone() {
MutablePropertyValues propertyValues = new MutablePropertyValues();
propertyValues.add("isoDateTime", "2009-10-31T12:00:00.000Z");
binder.bind(propertyValues);
@@ -386,29 +404,29 @@ public class DateTimeFormattingTests {
private LocalDate localDate;
@DateTimeFormat(style="M-")
@DateTimeFormat(style = "M-")
private LocalDate localDateAnnotated;
private LocalTime localTime;
@DateTimeFormat(style="-M")
@DateTimeFormat(style = "-M")
private LocalTime localTimeAnnotated;
private LocalDateTime localDateTime;
@DateTimeFormat(style="MM")
@DateTimeFormat(style = "MM")
private LocalDateTime localDateTimeAnnotated;
@DateTimeFormat(pattern="M/d/yy h:mm a")
@DateTimeFormat(pattern = "M/d/yy h:mm a")
private LocalDateTime dateTimeAnnotatedPattern;
@DateTimeFormat(iso=ISO.DATE)
@DateTimeFormat(iso = ISO.DATE)
private LocalDate isoDate;
@DateTimeFormat(iso=ISO.TIME)
@DateTimeFormat(iso = ISO.TIME)
private LocalTime isoTime;
@DateTimeFormat(iso=ISO.DATE_TIME)
@DateTimeFormat(iso = ISO.DATE_TIME)
private LocalDateTime isoDateTime;
private Instant instant;
@@ -421,7 +439,7 @@ public class DateTimeFormattingTests {
private MonthDay monthDay;
private final List<DateTimeBean> children = new ArrayList<DateTimeBean>();
private final List<DateTimeBean> children = new ArrayList<>();
public LocalDate getLocalDate() {
return localDate;