|
3 | 3 | import java.io.IOException;
|
4 | 4 | import java.util.TimeZone;
|
5 | 5 |
|
| 6 | +import com.fasterxml.jackson.databind.DeserializationFeature; |
6 | 7 | import org.joda.time.DateTimeZone;
|
7 | 8 | import org.joda.time.Interval;
|
8 | 9 | import org.joda.time.chrono.ISOChronology;
|
@@ -64,4 +65,41 @@ public void testIntervalDeserWithTypeInfo() throws IOException
|
64 | 65 | assertEquals(1396439982, interval.getStartMillis());
|
65 | 66 | assertEquals(1396440001, interval.getEndMillis());
|
66 | 67 | }
|
| 68 | + |
| 69 | + public void testIntervalDeserFromIso8601WithTimezoneWithContextTimeZone() throws IOException |
| 70 | + { |
| 71 | + final ObjectMapper mapper = mapperWithModuleBuilder() |
| 72 | + .defaultTimeZone(TimeZone.getTimeZone("GMT-2:00")) |
| 73 | + .enable(DeserializationFeature.ADJUST_DATES_TO_CONTEXT_TIME_ZONE) |
| 74 | + .build(); |
| 75 | + final Interval expectedInterval = new Interval(1000, 2000, DateTimeZone.forOffsetHours(-2)); |
| 76 | + final Interval actualInterval = |
| 77 | + mapper.readValue(quote("1970-01-01T06:00:01.000+06:00/1970-01-01T06:00:02.000+06:00"), Interval.class); |
| 78 | + |
| 79 | + assertEquals(expectedInterval, actualInterval); |
| 80 | + } |
| 81 | + |
| 82 | + public void testIntervalDeserFromIso8601WithTimezoneWithoutContextTimeZone() throws IOException |
| 83 | + { |
| 84 | + final ObjectMapper mapper = mapperWithModuleBuilder() |
| 85 | + .disable(DeserializationFeature.ADJUST_DATES_TO_CONTEXT_TIME_ZONE) |
| 86 | + .build(); |
| 87 | + final Interval expectedInterval = new Interval(1000, 2000, DateTimeZone.forOffsetHours(6)); |
| 88 | + final Interval actualInterval = |
| 89 | + mapper.readValue(quote("1970-01-01T06:00:01.000+06:00/1970-01-01T06:00:02.000+06:00"), Interval.class); |
| 90 | + |
| 91 | + assertEquals(expectedInterval, actualInterval); |
| 92 | + } |
| 93 | + |
| 94 | + public void testIntervalDeserFromIso8601WithTimezoneWithDefaultTimeZone() throws IOException |
| 95 | + { |
| 96 | + final ObjectMapper mapper = mapperWithModuleBuilder() |
| 97 | + .enable(DeserializationFeature.ADJUST_DATES_TO_CONTEXT_TIME_ZONE) |
| 98 | + .build(); |
| 99 | + final Interval expectedInterval = new Interval(1000, 2000, DateTimeZone.UTC); |
| 100 | + final Interval actualInterval = |
| 101 | + mapper.readValue(quote("1970-01-01T06:00:01.000+06:00/1970-01-01T06:00:02.000+06:00"), Interval.class); |
| 102 | + |
| 103 | + assertEquals(expectedInterval, actualInterval); |
| 104 | + } |
67 | 105 | }
|
0 commit comments