When date string parsing failed, try parsing the string without the weekday

This commit is contained in:
Martin Fietz 2017-04-16 13:48:17 +02:00
parent aad56bea56
commit f7b35de919
2 changed files with 13 additions and 0 deletions

View File

@ -122,4 +122,12 @@ public class DateUtilsTest extends AndroidTestCase {
Date actual2 = DateUtils.parse("Sun, 29 Jan 2017 00:00:00 CET");
assertEquals(expected2, actual2);
}
public void testParseDateWithIncorrectWeekday() {
GregorianCalendar exp1 = new GregorianCalendar(2014, 9, 8, 9, 00, 00);
exp1.setTimeZone(TimeZone.getTimeZone("GMT"));
Date expected = new Date(exp1.getTimeInMillis());
Date actual = DateUtils.parse("Thu, 8 Oct 2014 09:00:00 GMT"); // actually a Wednesday
assertEquals(expected, actual);
}
}

View File

@ -103,6 +103,11 @@ public class DateUtils {
}
}
// if date string starts with a weekday, try parsing date string without it
if(date.matches("^\\w+, .*$")) {
return parse(date.substring(date.indexOf(',') + 1));
}
Log.d(TAG, "Could not parse date string \"" + input + "\" [" + date + "]");
return null;
}