Merge pull request #2802 from 1nsidE/develop

[#2801] (AntennaPod failing to parse date in "Sun 01 Mar 2015 01:00:00 GMT-0400 (EDT)" format)
This commit is contained in:
Martin Fietz 2018-09-27 16:30:05 +02:00 committed by GitHub
commit 5a4219bf09
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 1 deletions

View File

@ -3,6 +3,7 @@ package de.danoeh.antennapod.core.util;
import android.test.AndroidTestCase; import android.test.AndroidTestCase;
import java.util.Calendar;
import java.util.Date; import java.util.Date;
import java.util.GregorianCalendar; import java.util.GregorianCalendar;
import java.util.TimeZone; import java.util.TimeZone;
@ -156,4 +157,12 @@ public class DateUtilsTest extends AndroidTestCase {
Date actual = DateUtils.parse("Mon, 8 Sept 2014 00:00:00 GMT"); // should be Sep Date actual = DateUtils.parse("Mon, 8 Sept 2014 00:00:00 GMT"); // should be Sep
assertEquals(expected, actual); assertEquals(expected, actual);
} }
public void testParseDateWithTwoTimezones() {
final GregorianCalendar exp1 = new GregorianCalendar(2015, Calendar.MARCH, 1, 1, 0, 0);
exp1.setTimeZone(TimeZone.getTimeZone("GMT-4"));
final Date expected = new Date(exp1.getTimeInMillis());
final Date actual = DateUtils.parse("Sun 01 Mar 2015 01:00:00 GMT-0400 (EDT)");
assertEquals(expected, actual);
}
} }

View File

@ -85,7 +85,8 @@ public class DateUtils {
"yyyy-MM-dd'T'HH:mm:ss'Z'", "yyyy-MM-dd'T'HH:mm:ss'Z'",
"yyyy-MM-dd'T'HH:mm:ss.SSSZ", "yyyy-MM-dd'T'HH:mm:ss.SSSZ",
"yyyy-MM-ddZ", "yyyy-MM-ddZ",
"yyyy-MM-dd" "yyyy-MM-dd",
"EEE d MMM yyyy HH:mm:ss 'GMT'Z (z)"
}; };
SimpleDateFormat parser = new SimpleDateFormat("", Locale.US); SimpleDateFormat parser = new SimpleDateFormat("", Locale.US);