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