FindBugs inspection -- part of a test commit

This commit is contained in:
Sean Owen 2014-01-26 22:38:57 +00:00
parent a8c9897da3
commit 077ae83bc3

View file

@ -44,15 +44,6 @@ public final class CalendarParsedResult extends ParsedResult {
private static final Pattern DATE_TIME = Pattern.compile("[0-9]{8}(T[0-9]{6}Z?)?");
private static final DateFormat DATE_FORMAT = new SimpleDateFormat("yyyyMMdd", Locale.ENGLISH);
static {
// For dates without a time, for purposes of interacting with Android, the resulting timestamp
// needs to be midnight of that day in GMT. See:
// http://code.google.com/p/android/issues/detail?id=8330
DATE_FORMAT.setTimeZone(TimeZone.getTimeZone("GMT"));
}
private static final DateFormat DATE_TIME_FORMAT = new SimpleDateFormat("yyyyMMdd'T'HHmmss", Locale.ENGLISH);
private final String summary;
private final Date start;
private final boolean startAllDay;
@ -189,12 +180,12 @@ public final class CalendarParsedResult extends ParsedResult {
}
if (when.length() == 8) {
// Show only year/month/day
return DATE_FORMAT.parse(when);
return buildDateFormat().parse(when);
} else {
// The when string can be local time, or UTC if it ends with a Z
Date date;
if (when.length() == 16 && when.charAt(15) == 'Z') {
date = DATE_TIME_FORMAT.parse(when.substring(0, 15));
date = buildDateTimeFormat().parse(when.substring(0, 15));
Calendar calendar = new GregorianCalendar();
long milliseconds = date.getTime();
// Account for time zone difference
@ -205,7 +196,7 @@ public final class CalendarParsedResult extends ParsedResult {
milliseconds += calendar.get(Calendar.DST_OFFSET);
date = new Date(milliseconds);
} else {
date = DATE_TIME_FORMAT.parse(when);
date = buildDateTimeFormat().parse(when);
}
return date;
}
@ -239,4 +230,17 @@ public final class CalendarParsedResult extends ParsedResult {
return durationMS;
}
private static DateFormat buildDateFormat() {
DateFormat format = new SimpleDateFormat("yyyyMMdd", Locale.ENGLISH);
// For dates without a time, for purposes of interacting with Android, the resulting timestamp
// needs to be midnight of that day in GMT. See:
// http://code.google.com/p/android/issues/detail?id=8330
format.setTimeZone(TimeZone.getTimeZone("GMT"));
return format;
}
private static DateFormat buildDateTimeFormat() {
return new SimpleDateFormat("yyyyMMdd'T'HHmmss", Locale.ENGLISH);
}
}