Parse abbreviated date fields
Add support for abbreviated dates with no timestamp (eg, "2009-01-02") to parseEmailDateTimeToMillis. Bug:14496986 Change-Id: Ifc77cb75fd9e23536b48c8f6ecefc0e2e8f1cc2c
This commit is contained in:
parent
f21e6a8983
commit
2fc13087e7
@ -263,6 +263,9 @@ public class Utility {
|
|||||||
return cal;
|
return cal;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static final ThreadLocalDateFormat mAbbrevEmailDateTimeFormat =
|
||||||
|
new ThreadLocalDateFormat("yyyy-MM-dd");
|
||||||
|
|
||||||
private static final ThreadLocalDateFormat mEmailDateTimeFormat =
|
private static final ThreadLocalDateFormat mEmailDateTimeFormat =
|
||||||
new ThreadLocalDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
|
new ThreadLocalDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
|
||||||
|
|
||||||
@ -277,7 +280,9 @@ public class Utility {
|
|||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
public static long parseEmailDateTimeToMillis(String date) throws ParseException {
|
public static long parseEmailDateTimeToMillis(String date) throws ParseException {
|
||||||
final GregorianCalendar cal = new GregorianCalendar(TimeZone.getTimeZone("GMT"));
|
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));
|
cal.setTime(mEmailDateTimeFormat.parse(date));
|
||||||
} else {
|
} else {
|
||||||
cal.setTime(mEmailDateTimeFormatWithMillis.parse(date));
|
cal.setTime(mEmailDateTimeFormatWithMillis.parse(date));
|
||||||
|
@ -63,8 +63,10 @@ public class UtilityTest extends TestCase {
|
|||||||
2010, 2, 23, 16, 1, 5, 0);
|
2010, 2, 23, 16, 1, 5, 0);
|
||||||
testParseEmailDateTimeHelper("2009-02-11T18:03:31.123Z",
|
testParseEmailDateTimeHelper("2009-02-11T18:03:31.123Z",
|
||||||
2009, 2, 11, 18, 3, 31, 123);
|
2009, 2, 11, 18, 3, 31, 123);
|
||||||
|
testParseEmailDateTimeHelper("2009-02-11",
|
||||||
|
2009, 2, 11, 0, 0, 0, 0);
|
||||||
try {
|
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");
|
fail("Expected ParseException");
|
||||||
} catch (ParseException e) {
|
} catch (ParseException e) {
|
||||||
// expected
|
// expected
|
||||||
|
Loading…
Reference in New Issue
Block a user