summaryrefslogtreecommitdiff
path: root/core/src
diff options
context:
space:
mode:
authorMartin Fietz <Martin.Fietz@gmail.com>2017-04-16 20:09:04 +0200
committerGitHub <noreply@github.com>2017-04-16 20:09:04 +0200
commit9542ef156989cefe9534f414f034195f8b717b8f (patch)
tree2ba63a2b03627feaa554d43f5b8c12c2677c1e85 /core/src
parent4e7402c214be9b031399be224f3ec4b8d6290c49 (diff)
parent2209e0e9b2e767888c3987741162f274064d1774 (diff)
downloadAntennaPod-9542ef156989cefe9534f414f034195f8b717b8f.zip
Merge pull request #2302 from mfietz/issue/2269-incorrect-weekdays
When date string parsing failed, try parsing the string without the weekday
Diffstat (limited to 'core/src')
-rw-r--r--core/src/androidTest/java/de/danoeh/antennapod/core/tests/util/DateUtilsTest.java16
-rw-r--r--core/src/main/java/de/danoeh/antennapod/core/util/DateUtils.java5
2 files changed, 17 insertions, 4 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..8adcc41c5 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
@@ -86,7 +86,7 @@ public class DateUtilsTest extends AndroidTestCase {
}
public void testAsctime() throws Exception {
- GregorianCalendar exp = new GregorianCalendar(2011, 4, 25, 12, 33, 00);
+ GregorianCalendar exp = new GregorianCalendar(2011, 4, 25, 12, 33, 0);
exp.setTimeZone(TimeZone.getTimeZone("UTC"));
Date expected = new Date(exp.getTimeInMillis());
Date actual = DateUtils.parse("Wed, 25 May 2011 12:33:00");
@@ -102,7 +102,7 @@ public class DateUtilsTest extends AndroidTestCase {
}
public void testParseDateWithNoTimezonePadding() throws Exception {
- GregorianCalendar exp = new GregorianCalendar(2017, 1, 22, 22, 28, 00);
+ GregorianCalendar exp = new GregorianCalendar(2017, 1, 22, 22, 28, 0);
exp.setTimeZone(TimeZone.getTimeZone("UTC"));
Date expected = new Date(exp.getTimeInMillis() + 2);
Date actual = DateUtils.parse("2017-02-22T14:28:00.002-08:00");
@@ -110,16 +110,24 @@ public class DateUtilsTest extends AndroidTestCase {
}
public void testParseDateWithForCest() throws Exception {
- GregorianCalendar exp1 = new GregorianCalendar(2017, 0, 28, 22, 00, 00);
+ GregorianCalendar exp1 = new GregorianCalendar(2017, 0, 28, 22, 0, 0);
exp1.setTimeZone(TimeZone.getTimeZone("UTC"));
Date expected1 = new Date(exp1.getTimeInMillis());
Date actual1 = DateUtils.parse("Sun, 29 Jan 2017 00:00:00 CEST");
assertEquals(expected1, actual1);
- GregorianCalendar exp2 = new GregorianCalendar(2017, 0, 28, 23, 00, 00);
+ GregorianCalendar exp2 = new GregorianCalendar(2017, 0, 28, 23, 0, 0);
exp2.setTimeZone(TimeZone.getTimeZone("UTC"));
Date expected2 = new Date(exp2.getTimeInMillis());
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, 0, 0);
+ 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;
}