Skip to content

Commit b06bec8

Browse files
committed
Fix #1788
1 parent 4998754 commit b06bec8

File tree

3 files changed

+20
-3
lines changed

3 files changed

+20
-3
lines changed

release-notes/VERSION

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ Project: jackson-databind
1717
(suggested by Luís C)
1818
#1771: Pass missing argument for string formatting in `ObjectMapper`
1919
(reported by Nils B)
20+
#1788: `StdDateFormat._parseAsISO8601()` does not parse "fractional" timezone correctly
2021

2122
2.9.1 (07-Sep-2017)
2223

src/main/java/com/fasterxml/jackson/databind/util/StdDateFormat.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -623,9 +623,9 @@ protected Date _parseAsISO8601(String dateStr, ParsePosition bogus)
623623
int len = end-start;
624624
if (len > 1) { // 0 -> none, 1 -> 'Z'
625625
// NOTE: first char is sign; then 2 digits, then optional colon, optional 2 digits
626-
int offsetSecs = _parse2D(dateStr, start+1) * 3600;
626+
int offsetSecs = _parse2D(dateStr, start+1) * 3600; // hours
627627
if (len >= 5) {
628-
offsetSecs += _parse2D(dateStr, end-2);
628+
offsetSecs += _parse2D(dateStr, end-2) * 60; // minutes
629629
}
630630
if (dateStr.charAt(start) == '-') {
631631
offsetSecs *= -1000;

src/test/java/com/fasterxml/jackson/databind/deser/jdk/DateDeserializationTest.java

+17-1
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,23 @@ public void testISO8601PartialMilliseconds() throws Exception
256256
assertEquals(450, c.get(Calendar.MILLISECOND));
257257
}
258258

259-
// [Databind#1745]
259+
// Also: minutes-part of offset need not be all zeroes: [databind#1788]
260+
public void testISO8601FractionalTimezoneOffset() throws Exception
261+
{
262+
String inputStr = "1997-07-16T19:20:30.45+01:30";
263+
java.util.Date inputDate = MAPPER.readValue(quote(inputStr), java.util.Date.class);
264+
Calendar c = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
265+
c.setTime(inputDate);
266+
assertEquals(1997, c.get(Calendar.YEAR));
267+
assertEquals(Calendar.JULY, c.get(Calendar.MONTH));
268+
assertEquals(16, c.get(Calendar.DAY_OF_MONTH));
269+
assertEquals(19 - 2, c.get(Calendar.HOUR_OF_DAY));
270+
assertEquals(50, c.get(Calendar.MINUTE));
271+
assertEquals(30, c.get(Calendar.SECOND));
272+
assertEquals(450, c.get(Calendar.MILLISECOND));
273+
}
274+
275+
// [databind#1745]
260276
public void testISO8601FractSecondsLong() throws Exception
261277
{
262278
String inputStr;

0 commit comments

Comments
 (0)