DATACMNS-773 - Added support for persisting ZoneId instances as Strings.
We now ship converters for JSR-310 and ThreeTenBP's ZoneId conversion to String and back.
This commit is contained in:
@@ -23,7 +23,11 @@ import java.time.Instant;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.LocalTime;
|
||||
import java.time.ZoneId;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.core.convert.ConversionService;
|
||||
@@ -126,6 +130,19 @@ public class Jsr310ConvertersUnitTests {
|
||||
assertThat(CONVERSION_SERVICE.convert(now.toInstant(), Date.class), is(now));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void convertsZoneIdToStringAndBack() {
|
||||
|
||||
Map<String, ZoneId> ids = new HashMap<String, ZoneId>();
|
||||
ids.put("Europe/Berlin", ZoneId.of("Europe/Berlin"));
|
||||
ids.put("+06:00", ZoneId.of("+06:00"));
|
||||
|
||||
for (Entry<String, ZoneId> entry : ids.entrySet()) {
|
||||
assertThat(CONVERSION_SERVICE.convert(entry.getValue(), String.class), is(entry.getKey()));
|
||||
assertThat(CONVERSION_SERVICE.convert(entry.getKey(), ZoneId.class), is(entry.getValue()));
|
||||
}
|
||||
}
|
||||
|
||||
private static String format(Date date, String format) {
|
||||
return new SimpleDateFormat(format).format(date);
|
||||
}
|
||||
|
||||
@@ -21,6 +21,9 @@ import static org.threeten.bp.DateTimeUtils.*;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.core.convert.ConversionService;
|
||||
@@ -30,12 +33,13 @@ import org.threeten.bp.Instant;
|
||||
import org.threeten.bp.LocalDate;
|
||||
import org.threeten.bp.LocalDateTime;
|
||||
import org.threeten.bp.LocalTime;
|
||||
import org.threeten.bp.ZoneId;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link ThreeTenBackPortConverters}.
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
* @ssince 1.10
|
||||
* @since 1.10
|
||||
*/
|
||||
public class ThreeTenBackPortConvertersUnitTests {
|
||||
|
||||
@@ -128,6 +132,19 @@ public class ThreeTenBackPortConvertersUnitTests {
|
||||
assertThat(CONVERSION_SERVICE.convert(toInstant(now), Date.class), is(now));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void convertsZoneIdToStringAndBack() {
|
||||
|
||||
Map<String, ZoneId> ids = new HashMap<String, ZoneId>();
|
||||
ids.put("Europe/Berlin", ZoneId.of("Europe/Berlin"));
|
||||
ids.put("+06:00", ZoneId.of("+06:00"));
|
||||
|
||||
for (Entry<String, ZoneId> entry : ids.entrySet()) {
|
||||
assertThat(CONVERSION_SERVICE.convert(entry.getValue(), String.class), is(entry.getKey()));
|
||||
assertThat(CONVERSION_SERVICE.convert(entry.getKey(), ZoneId.class), is(entry.getValue()));
|
||||
}
|
||||
}
|
||||
|
||||
private static String format(Date date, String format) {
|
||||
return new SimpleDateFormat(format).format(date);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user