@ -19,7 +19,10 @@ package org.springframework.boot.autoconfigure.web.format;
import java.time.LocalDate ;
import java.time.LocalDateTime ;
import java.time.LocalTime ;
import java.time.OffsetDateTime ;
import java.time.OffsetTime ;
import java.time.ZoneId ;
import java.time.ZoneOffset ;
import java.time.ZonedDateTime ;
import java.time.format.DateTimeFormatter ;
import java.time.format.FormatStyle ;
@ -35,6 +38,7 @@ import static org.assertj.core.api.Assertions.assertThat;
*
* @author Brian Clozel
* @author Madhura Bhave
* @author Gaurav Pareek
* /
class WebConversionServiceTests {
@ -80,6 +84,23 @@ class WebConversionServiceTests {
. isEqualTo ( DateTimeFormatter . ISO_LOCAL_TIME . format ( time ) ) ;
}
@Test
void isoOffsetTimeFormat ( ) {
isoOffsetTimeFormat ( new DateTimeFormatters ( ) . timeFormat ( "isooffset" ) ) ;
}
@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 ) )
. isEqualTo ( DateTimeFormatter . ISO_OFFSET_TIME . format ( offsetTime ) ) ;
}
@Test
void customTimeFormat ( ) {
WebConversionService conversionService = new WebConversionService (
@ -105,6 +126,24 @@ class WebConversionServiceTests {
. isEqualTo ( DateTimeFormatter . ISO_LOCAL_DATE_TIME . format ( dateTime ) ) ;
}
@Test
void isoOffsetDateTimeFormat ( ) {
isoOffsetDateTimeFormat ( new DateTimeFormatters ( ) . dateTimeFormat ( "isooffset" ) ) ;
}
@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 ) )
. isEqualTo ( DateTimeFormatter . ISO_OFFSET_DATE_TIME . format ( offsetdate ) ) ;
}
@Test
void customDateTimeFormat ( ) {
WebConversionService conversionService = new WebConversionService (