Commit 9230ea4a authored by Andy Wilkinson's avatar Andy Wilkinson

Polish "Support iso-offset for date-time and time formatting with MVC"

See gh-21630
parent c3b1172a
...@@ -107,7 +107,7 @@ public class DateTimeFormatters { ...@@ -107,7 +107,7 @@ public class DateTimeFormatters {
} }
private static boolean isIsoOffset(String pattern) { private static boolean isIsoOffset(String pattern) {
return "isooffset".equalsIgnoreCase(pattern); return "isooffset".equalsIgnoreCase(pattern) || "iso-offset".equalsIgnoreCase(pattern);
} }
} }
...@@ -1966,8 +1966,8 @@ ...@@ -1966,8 +1966,8 @@
"description": "ISO-8601 extended local date-time format." "description": "ISO-8601 extended local date-time format."
}, },
{ {
"value": "isooffset", "value": "iso-offset",
"description": "ISO Offset local date-time format." "description": "ISO offset date-time format."
} }
], ],
"providers": [ "providers": [
...@@ -1988,8 +1988,8 @@ ...@@ -1988,8 +1988,8 @@
"description": "ISO-8601 extended local time format" "description": "ISO-8601 extended local time format"
}, },
{ {
"value": "isooffset", "value": "iso-offset",
"description": "ISO Offset local time format." "description": "ISO offset time format."
} }
], ],
"providers": [ "providers": [
......
...@@ -80,15 +80,23 @@ class WebConversionServiceTests { ...@@ -80,15 +80,23 @@ class WebConversionServiceTests {
void isoTimeFormat() { void isoTimeFormat() {
WebConversionService conversionService = new WebConversionService(new DateTimeFormatters().timeFormat("iso")); WebConversionService conversionService = new WebConversionService(new DateTimeFormatters().timeFormat("iso"));
LocalTime time = LocalTime.of(12, 45, 23); LocalTime time = LocalTime.of(12, 45, 23);
System.out.println(conversionService.convert(time, String.class));
assertThat(conversionService.convert(time, String.class)) assertThat(conversionService.convert(time, String.class))
.isEqualTo(DateTimeFormatter.ISO_LOCAL_TIME.format(time)); .isEqualTo(DateTimeFormatter.ISO_LOCAL_TIME.format(time));
} }
@Test @Test
void isoOffsetTimeFormat() { void isoOffsetTimeFormat() {
WebConversionService conversionService = new WebConversionService(new DateTimeFormatters().timeFormat("isooffset")); isoOffsetTimeFormat(new DateTimeFormatters().timeFormat("isooffset"));
OffsetTime offsetTime =OffsetTime.of(LocalTime.of(12, 45, 23), ZoneOffset.ofHoursMinutes(1, 30)); }
@Test
void hyphenatedIsoOffsetTimeFormat() {
isoOffsetTimeFormat(new DateTimeFormatters().timeFormat("iso-offset"));
}
private void isoOffsetTimeFormat(DateTimeFormatters formatters) {
WebConversionService conversionService = new WebConversionService(formatters);
OffsetTime offsetTime = OffsetTime.of(LocalTime.of(12, 45, 23), ZoneOffset.ofHoursMinutes(1, 30));
assertThat(conversionService.convert(offsetTime, String.class)) assertThat(conversionService.convert(offsetTime, String.class))
.isEqualTo(DateTimeFormatter.ISO_OFFSET_TIME.format(offsetTime)); .isEqualTo(DateTimeFormatter.ISO_OFFSET_TIME.format(offsetTime));
} }
...@@ -120,13 +128,22 @@ class WebConversionServiceTests { ...@@ -120,13 +128,22 @@ class WebConversionServiceTests {
@Test @Test
void isoOffsetDateTimeFormat() { void isoOffsetDateTimeFormat() {
WebConversionService conversionService = new WebConversionService( isoOffsetDateTimeFormat(new DateTimeFormatters().dateTimeFormat("isooffset"));
new DateTimeFormatters().dateTimeFormat("isooffset")); }
OffsetDateTime offsetdate =OffsetDateTime.of(LocalDate.of(2020, 4, 26), LocalTime.of(12, 45, 23), ZoneOffset.ofHoursMinutes(1, 30));
@Test
void hyphenatedIsoOffsetDateTimeFormat() {
isoOffsetDateTimeFormat(new DateTimeFormatters().dateTimeFormat("iso-offset"));
}
private void isoOffsetDateTimeFormat(DateTimeFormatters formatters) {
WebConversionService conversionService = new WebConversionService(formatters);
OffsetDateTime offsetdate = OffsetDateTime.of(LocalDate.of(2020, 4, 26), LocalTime.of(12, 45, 23),
ZoneOffset.ofHoursMinutes(1, 30));
assertThat(conversionService.convert(offsetdate, String.class)) assertThat(conversionService.convert(offsetdate, String.class))
.isEqualTo(DateTimeFormatter.ISO_OFFSET_DATE_TIME.format(offsetdate)); .isEqualTo(DateTimeFormatter.ISO_OFFSET_DATE_TIME.format(offsetdate));
} }
@Test @Test
void customDateTimeFormat() { void customDateTimeFormat() {
WebConversionService conversionService = new WebConversionService( WebConversionService conversionService = new WebConversionService(
......
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