Commit f7135ff1 authored by Madhura Bhave's avatar Madhura Bhave

Use ResolverStyle.SMART when a custom format is specified

Fixes gh-13970
parent 51fd27fa
...@@ -89,7 +89,7 @@ public class WebConversionService extends DefaultFormattingConversionService { ...@@ -89,7 +89,7 @@ public class WebConversionService extends DefaultFormattingConversionService {
DateTimeFormatterRegistrar dateTime = new DateTimeFormatterRegistrar(); DateTimeFormatterRegistrar dateTime = new DateTimeFormatterRegistrar();
if (this.dateFormat != null) { if (this.dateFormat != null) {
dateTime.setDateFormatter(DateTimeFormatter.ofPattern(this.dateFormat) dateTime.setDateFormatter(DateTimeFormatter.ofPattern(this.dateFormat)
.withResolverStyle(ResolverStyle.STRICT)); .withResolverStyle(ResolverStyle.SMART));
} }
dateTime.registerFormatters(this); dateTime.registerFormatters(this);
} }
......
...@@ -28,6 +28,7 @@ import static org.assertj.core.api.Assertions.assertThat; ...@@ -28,6 +28,7 @@ import static org.assertj.core.api.Assertions.assertThat;
* Tests for {@link WebConversionService}. * Tests for {@link WebConversionService}.
* *
* @author Brian Clozel * @author Brian Clozel
* @author Madhura Bhave
*/ */
public class WebConversionServiceTests { public class WebConversionServiceTests {
...@@ -44,4 +45,12 @@ public class WebConversionServiceTests { ...@@ -44,4 +45,12 @@ public class WebConversionServiceTests {
.isEqualTo("01*01*2018"); .isEqualTo("01*01*2018");
} }
@Test
public void convertFromStringToDate() {
WebConversionService conversionService = new WebConversionService("yyyy-MM-dd");
java.time.LocalDate date = conversionService.convert("2018-01-01",
java.time.LocalDate.class);
assertThat(date).isEqualTo(java.time.LocalDate.of(2018, 1, 1));
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment