summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/src/main/java/de/danoeh/antennapod/core/util/DateUtils.java7
-rw-r--r--core/src/test/java/de/danoeh/antennapod/core/util/DateUtilsTest.java (renamed from core/src/androidTest/java/de/danoeh/antennapod/core/util/DateUtilsTest.java)48
2 files changed, 23 insertions, 32 deletions
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 833ff33f1..196583bcd 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
@@ -30,9 +30,12 @@ public class DateUtils {
}
String date = input.trim().replace('/', '-').replaceAll("( ){2,}+", " ");
+ // remove colon from timezone to avoid differences between Android and Java SimpleDateFormat
+ date = date.replaceAll("([+-]\\d\\d):(\\d\\d)$", "$1$2");
+
// CEST is widely used but not in the "ISO 8601 Time zone" list. Let's hack around.
- date = date.replaceAll("CEST$", "+02:00");
- date = date.replaceAll("CET$", "+01:00");
+ date = date.replaceAll("CEST$", "+0200");
+ date = date.replaceAll("CET$", "+0100");
// some generators use "Sept" for September
date = date.replaceAll("\\bSept\\b", "Sep");
diff --git a/core/src/androidTest/java/de/danoeh/antennapod/core/util/DateUtilsTest.java b/core/src/test/java/de/danoeh/antennapod/core/util/DateUtilsTest.java
index 5d98f133c..92888ae8b 100644
--- a/core/src/androidTest/java/de/danoeh/antennapod/core/util/DateUtilsTest.java
+++ b/core/src/test/java/de/danoeh/antennapod/core/util/DateUtilsTest.java
@@ -1,6 +1,5 @@
package de.danoeh.antennapod.core.util;
-import androidx.test.filters.SmallTest;
import org.junit.Test;
import java.util.Calendar;
@@ -12,16 +11,11 @@ import static org.junit.Assert.assertEquals;
/**
* Unit test for {@link DateUtils}.
- *
- * Note: It NEEDS to be run in android devices, i.e., it cannot be run in standard JDK, because
- * the test invokes some android platform-specific behavior in the underlying
- * {@link java.text.SimpleDateFormat} used by {@link DateUtils}.
- *
*/
-@SmallTest
public class DateUtilsTest {
+
@Test
- public void testParseDateWithMicroseconds() throws Exception {
+ public void testParseDateWithMicroseconds() {
GregorianCalendar exp = new GregorianCalendar(2015, 2, 28, 13, 31, 4);
exp.setTimeZone(TimeZone.getTimeZone("UTC"));
Date expected = new Date(exp.getTimeInMillis() + 963);
@@ -30,7 +24,7 @@ public class DateUtilsTest {
}
@Test
- public void testParseDateWithCentiseconds() throws Exception {
+ public void testParseDateWithCentiseconds() {
GregorianCalendar exp = new GregorianCalendar(2015, 2, 28, 13, 31, 4);
exp.setTimeZone(TimeZone.getTimeZone("UTC"));
Date expected = new Date(exp.getTimeInMillis() + 960);
@@ -39,17 +33,17 @@ public class DateUtilsTest {
}
@Test
- public void testParseDateWithDeciseconds() throws Exception {
+ public void testParseDateWithDeciseconds() {
GregorianCalendar exp = new GregorianCalendar(2015, 2, 28, 13, 31, 4);
exp.setTimeZone(TimeZone.getTimeZone("UTC"));
Date expected = new Date(exp.getTimeInMillis() + 900);
Date actual = DateUtils.parse("2015-03-28T13:31:04.9");
- assertEquals(expected.getTime()/1000, actual.getTime()/1000);
- assertEquals(900, actual.getTime()%1000);
+ assertEquals(expected.getTime() / 1000, actual.getTime() / 1000);
+ assertEquals(900, actual.getTime() % 1000);
}
@Test
- public void testParseDateWithMicrosecondsAndTimezone() throws Exception {
+ public void testParseDateWithMicrosecondsAndTimezone() {
GregorianCalendar exp = new GregorianCalendar(2015, 2, 28, 6, 31, 4);
exp.setTimeZone(TimeZone.getTimeZone("UTC"));
Date expected = new Date(exp.getTimeInMillis() + 963);
@@ -58,7 +52,7 @@ public class DateUtilsTest {
}
@Test
- public void testParseDateWithCentisecondsAndTimezone() throws Exception {
+ public void testParseDateWithCentisecondsAndTimezone() {
GregorianCalendar exp = new GregorianCalendar(2015, 2, 28, 6, 31, 4);
exp.setTimeZone(TimeZone.getTimeZone("UTC"));
Date expected = new Date(exp.getTimeInMillis() + 960);
@@ -67,17 +61,17 @@ public class DateUtilsTest {
}
@Test
- public void testParseDateWithDecisecondsAndTimezone() throws Exception {
+ public void testParseDateWithDecisecondsAndTimezone() {
GregorianCalendar exp = new GregorianCalendar(2015, 2, 28, 6, 31, 4);
exp.setTimeZone(TimeZone.getTimeZone("UTC"));
Date expected = new Date(exp.getTimeInMillis() + 900);
Date actual = DateUtils.parse("2015-03-28T13:31:04.9 +0700");
- assertEquals(expected.getTime()/1000, actual.getTime()/1000);
- assertEquals(900, actual.getTime()%1000);
+ assertEquals(expected.getTime() / 1000, actual.getTime() / 1000);
+ assertEquals(900, actual.getTime() % 1000);
}
@Test
- public void testParseDateWithTimezoneName() throws Exception {
+ public void testParseDateWithTimezoneName() {
GregorianCalendar exp = new GregorianCalendar(2015, 2, 28, 6, 31, 4);
exp.setTimeZone(TimeZone.getTimeZone("UTC"));
Date expected = new Date(exp.getTimeInMillis());
@@ -86,7 +80,7 @@ public class DateUtilsTest {
}
@Test
- public void testParseDateWithTimezoneName2() throws Exception {
+ public void testParseDateWithTimezoneName2() {
GregorianCalendar exp = new GregorianCalendar(2015, 2, 28, 6, 31, 0);
exp.setTimeZone(TimeZone.getTimeZone("UTC"));
Date expected = new Date(exp.getTimeInMillis());
@@ -95,7 +89,7 @@ public class DateUtilsTest {
}
@Test
- public void testParseDateWithTimeZoneOffset() throws Exception {
+ public void testParseDateWithTimeZoneOffset() {
GregorianCalendar exp = new GregorianCalendar(2015, 2, 28, 12, 16, 12);
exp.setTimeZone(TimeZone.getTimeZone("UTC"));
Date expected = new Date(exp.getTimeInMillis());
@@ -104,7 +98,7 @@ public class DateUtilsTest {
}
@Test
- public void testAsctime() throws Exception {
+ public void testAsctime() {
GregorianCalendar exp = new GregorianCalendar(2011, 4, 25, 12, 33, 0);
exp.setTimeZone(TimeZone.getTimeZone("UTC"));
Date expected = new Date(exp.getTimeInMillis());
@@ -113,7 +107,7 @@ public class DateUtilsTest {
}
@Test
- public void testMultipleConsecutiveSpaces() throws Exception {
+ public void testMultipleConsecutiveSpaces() {
GregorianCalendar exp = new GregorianCalendar(2010, 2, 23, 6, 6, 26);
exp.setTimeZone(TimeZone.getTimeZone("UTC"));
Date expected = new Date(exp.getTimeInMillis());
@@ -121,14 +115,8 @@ public class DateUtilsTest {
assertEquals(expected, actual);
}
- /**
- * Requires Android platform.
- *
- * Reason: Standard JDK cannot parse timezone <code>-08:00</code> (ISO 8601 format). It only accepts
- * <code>-0800</code> (RFC 822 format)
- */
@Test
- public void testParseDateWithNoTimezonePadding() throws Exception {
+ public void testParseDateWithNoTimezonePadding() {
GregorianCalendar exp = new GregorianCalendar(2017, 1, 22, 22, 28, 0);
exp.setTimeZone(TimeZone.getTimeZone("UTC"));
Date expected = new Date(exp.getTimeInMillis() + 2);
@@ -143,7 +131,7 @@ public class DateUtilsTest {
* @see #testParseDateWithNoTimezonePadding()
*/
@Test
- public void testParseDateWithForCest() throws Exception {
+ public void testParseDateWithForCest() {
GregorianCalendar exp1 = new GregorianCalendar(2017, 0, 28, 22, 0, 0);
exp1.setTimeZone(TimeZone.getTimeZone("UTC"));
Date expected1 = new Date(exp1.getTimeInMillis());