Merge pull request #1302 from mfietz/issue/1301-out-of-bounds

Fix datetime parsing StringIndexOutOfBoundsException
This commit is contained in:
Tom Hennen 2015-10-29 17:46:59 -04:00
commit e830a0fbfc
1 changed files with 7 additions and 3 deletions

View File

@ -88,10 +88,14 @@ public class DateUtils {
for(String pattern : patterns) { for(String pattern : patterns) {
parser.applyPattern(pattern); parser.applyPattern(pattern);
pos.setIndex(0); pos.setIndex(0);
try {
Date result = parser.parse(date, pos); Date result = parser.parse(date, pos);
if (result != null && pos.getIndex() == date.length()) { if (result != null && pos.getIndex() == date.length()) {
return result; return result;
} }
} catch(Exception e) {
Log.e(TAG, Log.getStackTraceString(e));
}
} }
Log.d(TAG, "Could not parse date string \"" + input + "\" [" + date + "]"); Log.d(TAG, "Could not parse date string \"" + input + "\" [" + date + "]");