Add support for Instant in @DateTimeFormat

Closes gh-19846
This commit is contained in:
Stephane Nicoll
2021-12-03 16:17:52 +01:00
parent 0a41da9ec9
commit 110e0f7f2b
3 changed files with 27 additions and 1 deletions

View File

@@ -397,6 +397,15 @@ class DateTimeFormattingTests {
assertThat(binder.getBindingResult().getFieldValue("instant").toString().startsWith("2009-10-31T12:00")).isTrue();
}
@Test
void testBindInstantAnnotated() {
MutablePropertyValues propertyValues = new MutablePropertyValues();
propertyValues.add("styleInstant", "2017-02-21T13:00");
binder.bind(propertyValues);
assertThat(binder.getBindingResult().getErrorCount()).isEqualTo(0);
assertThat(binder.getBindingResult().getFieldValue("styleInstant")).isEqualTo("2017-02-21T13:00");
}
@Test
@SuppressWarnings("deprecation")
void testBindInstantFromJavaUtilDate() {
@@ -622,6 +631,9 @@ class DateTimeFormattingTests {
private Instant instant;
@DateTimeFormat(pattern = "yyyy-MM-dd'T'HH:mm")
private Instant styleInstant;
private Period period;
private Duration duration;
@@ -762,6 +774,14 @@ class DateTimeFormattingTests {
this.instant = instant;
}
public Instant getStyleInstant() {
return this.styleInstant;
}
public void setStyleInstant(Instant styleInstant) {
this.styleInstant = styleInstant;
}
public Period getPeriod() {
return this.period;
}