diff --git a/emailcommon/src/com/android/emailcommon/utility/Utility.java b/emailcommon/src/com/android/emailcommon/utility/Utility.java index 6ef1d8421..592d03c15 100644 --- a/emailcommon/src/com/android/emailcommon/utility/Utility.java +++ b/emailcommon/src/com/android/emailcommon/utility/Utility.java @@ -263,6 +263,9 @@ public class Utility { return cal; } + private static final ThreadLocalDateFormat mAbbrevEmailDateTimeFormat = + new ThreadLocalDateFormat("yyyy-MM-dd"); + private static final ThreadLocalDateFormat mEmailDateTimeFormat = new ThreadLocalDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'"); @@ -277,7 +280,9 @@ public class Utility { @VisibleForTesting public static long parseEmailDateTimeToMillis(String date) throws ParseException { final GregorianCalendar cal = new GregorianCalendar(TimeZone.getTimeZone("GMT")); - if (date.length() <= 20) { + if (date.length() <= 10) { + cal.setTime(mAbbrevEmailDateTimeFormat.parse(date)); + } else if (date.length() <= 20) { cal.setTime(mEmailDateTimeFormat.parse(date)); } else { cal.setTime(mEmailDateTimeFormatWithMillis.parse(date)); diff --git a/tests/src/com/android/emailcommon/utility/UtilityTest.java b/tests/src/com/android/emailcommon/utility/UtilityTest.java index 3d08244b4..c5b0e7f77 100644 --- a/tests/src/com/android/emailcommon/utility/UtilityTest.java +++ b/tests/src/com/android/emailcommon/utility/UtilityTest.java @@ -63,8 +63,10 @@ public class UtilityTest extends TestCase { 2010, 2, 23, 16, 1, 5, 0); testParseEmailDateTimeHelper("2009-02-11T18:03:31.123Z", 2009, 2, 11, 18, 3, 31, 123); + testParseEmailDateTimeHelper("2009-02-11", + 2009, 2, 11, 0, 0, 0, 0); try { - testParseEmailDateTimeHelper("2010-02-23", 1970, 1, 1, 0, 0, 0, 0); + testParseEmailDateTimeHelper("2010-02", 1970, 1, 1, 0, 0, 0, 0); fail("Expected ParseException"); } catch (ParseException e) { // expected