diff options
author | Martin Fietz <Martin.Fietz@gmail.com> | 2017-04-16 13:48:17 +0200 |
---|---|---|
committer | Martin Fietz <Martin.Fietz@gmail.com> | 2017-04-16 13:48:17 +0200 |
commit | f7b35de91909e53db648d525f8c5b70b15737cf9 (patch) | |
tree | 2a1f5553912cf639c2a0dd9073bdb52792fe2bc3 /core | |
parent | aad56bea56c320cc84bd7f9472f3caff996e411c (diff) | |
download | AntennaPod-f7b35de91909e53db648d525f8c5b70b15737cf9.zip |
When date string parsing failed, try parsing the string without the weekday
Diffstat (limited to 'core')
-rw-r--r-- | core/src/androidTest/java/de/danoeh/antennapod/core/tests/util/DateUtilsTest.java | 8 | ||||
-rw-r--r-- | core/src/main/java/de/danoeh/antennapod/core/util/DateUtils.java | 5 |
2 files changed, 13 insertions, 0 deletions
diff --git a/core/src/androidTest/java/de/danoeh/antennapod/core/tests/util/DateUtilsTest.java b/core/src/androidTest/java/de/danoeh/antennapod/core/tests/util/DateUtilsTest.java index 0b28615a7..2f1ca5f2e 100644 --- a/core/src/androidTest/java/de/danoeh/antennapod/core/tests/util/DateUtilsTest.java +++ b/core/src/androidTest/java/de/danoeh/antennapod/core/tests/util/DateUtilsTest.java @@ -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); + } } diff --git a/core/src/main/java/de/danoeh/antennapod/core/util/DateUtils.java b/core/src/main/java/de/danoeh/antennapod/core/util/DateUtils.java index f118d4e53..f63f0983f 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/util/DateUtils.java +++ b/core/src/main/java/de/danoeh/antennapod/core/util/DateUtils.java @@ -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; } |