Skip to content

Commit

Permalink
One more fix wrt #2643
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Mar 6, 2020
1 parent 8273e1b commit 90d38a7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public class StdDateFormat
* to ISO-8601 date formatting standard, when it includes basic undecorated
* timezone definition.
*/
public final static String DATE_FORMAT_STR_ISO8601 = "yyyy-MM-dd'T'HH:mm:ss.SSSZ";
public final static String DATE_FORMAT_STR_ISO8601 = "yyyy-MM-dd'T'HH:mm:ss.SSSX";

/**
* ISO-8601 with just the Date part, no time: needed for error messages
Expand Down Expand Up @@ -490,12 +490,11 @@ protected void _format(TimeZone tz, Locale loc, Date date,
// 24-Jun-2017, tatu: While `Z` would be conveniently short, older specs
// mandate use of full `+0000`
// formatted.append('Z');
if( _tzSerializedWithColon ) {
buffer.append("+00:00");
}
else {
buffer.append("+0000");
}
if( _tzSerializedWithColon ) {
buffer.append("+00:00");
} else {
buffer.append("+0000");
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,9 @@ public void testDateISO8601_customTZ() throws IOException
mapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
mapper.setTimeZone(TimeZone.getTimeZone("GMT+2"));

serialize( mapper, judate(1970, 1, 1, 00, 00, 00, 0, "GMT+2"),
serialize(mapper, judate(1970, 1, 1, 00, 00, 00, 0, "GMT+2"),
"1970-01-01T00:00:00.000+"+zoneOffset("0200"));
serialize( mapper, judate(1970, 1, 1, 00, 00, 00, 0, "UTC"),
serialize(mapper, judate(1970, 1, 1, 00, 00, 00, 0, "UTC"),
"1970-01-01T02:00:00.000+"+zoneOffset("0200"));
}

Expand Down Expand Up @@ -296,10 +296,12 @@ public void testWithTimeZoneOverride() throws Exception
serialize( mapper, judate(1969, 12, 31, 16, 00, 00, 00, "PST"), "1969-12-31/16:00 PST");

// Also: should be able to dynamically change timezone:
ObjectWriter w = mapper.writer();
w = w.with(TimeZone.getTimeZone("EST"));
String json = w.writeValueAsString(new Date(0));
assertEquals(quote("1969-12-31/19:00 EST"), json);
ObjectWriter w = mapper.writer().with(TimeZone.getTimeZone("EST"));
assertEquals(quote("1969-12-31/"+zoneOffset("1900")+" EST"), w.writeValueAsString(new Date(0)));

// wrt [databind#2643]
w = mapper.writer().with(TimeZone.getTimeZone("Asia/Tehran"));
assertEquals(quote("1970-01-01/"+zoneOffset("0330")+" IRST"), w.writeValueAsString(new Date(0)));
}

/**
Expand Down

0 comments on commit 90d38a7

Please sign in to comment.