diff --git a/gson/src/main/java/com/google/gson/internal/bind/util/ISO8601Utils.java b/gson/src/main/java/com/google/gson/internal/bind/util/ISO8601Utils.java index 3fd22d7407..420123c414 100644 --- a/gson/src/main/java/com/google/gson/internal/bind/util/ISO8601Utils.java +++ b/gson/src/main/java/com/google/gson/internal/bind/util/ISO8601Utils.java @@ -170,6 +170,7 @@ public static Date parse(String date, ParsePosition pos) throws ParseException { if (!hasT && (date.length() <= offset)) { Calendar calendar = new GregorianCalendar(year, month - 1, day); + calendar.setTimeZone(TIMEZONE_UTC); calendar.setLenient(false); pos.setIndex(offset); diff --git a/gson/src/test/java/com/google/gson/internal/bind/util/ISO8601UtilsTest.java b/gson/src/test/java/com/google/gson/internal/bind/util/ISO8601UtilsTest.java index 4a16ee9f8a..d7ee700f76 100644 --- a/gson/src/test/java/com/google/gson/internal/bind/util/ISO8601UtilsTest.java +++ b/gson/src/test/java/com/google/gson/internal/bind/util/ISO8601UtilsTest.java @@ -78,10 +78,12 @@ public void testDateFormatWithTimezone() { @Test @SuppressWarnings("UndefinedEquals") - public void testDateParseWithDefaultTimezone() throws ParseException { + public void testDateParseDefaultsToUTC() throws ParseException { String dateStr = "2018-06-25"; Date date = ISO8601Utils.parse(dateStr, new ParsePosition(0)); - Date expectedDate = new GregorianCalendar(2018, Calendar.JUNE, 25).getTime(); + GregorianCalendar calendar = createUtcCalendar(); + calendar.set(2018, Calendar.JUNE, 25); + Date expectedDate = calendar.getTime(); assertThat(date).isEqualTo(expectedDate); }