Merge pull request #2288 from dklimkin/datefix
Additional date format and a hack for CEST
This commit is contained in:
commit
e42a76219d
@ -101,4 +101,19 @@ public class DateUtilsTest extends AndroidTestCase {
|
||||
assertEquals(expected, actual);
|
||||
}
|
||||
|
||||
public void testParseDateWithNoTimezonePadding() throws Exception {
|
||||
GregorianCalendar exp = new GregorianCalendar(2017, 1, 22, 22, 28, 00);
|
||||
exp.setTimeZone(TimeZone.getTimeZone("UTC"));
|
||||
Date expected = new Date(exp.getTimeInMillis() + 2);
|
||||
Date actual = DateUtils.parse("2017-02-22T14:28:00.002-08:00");
|
||||
assertEquals(expected, actual);
|
||||
}
|
||||
|
||||
public void testParseDateWithForCest() throws Exception {
|
||||
GregorianCalendar exp = new GregorianCalendar(2017, 0, 28, 23, 00, 00);
|
||||
exp.setTimeZone(TimeZone.getTimeZone("UTC"));
|
||||
Date expected = new Date(exp.getTimeInMillis());
|
||||
Date actual = DateUtils.parse("Sun, 29 Jan 2017 00:00:00 CEST");
|
||||
assertEquals(expected, actual);
|
||||
}
|
||||
}
|
||||
|
@ -27,6 +27,9 @@ public class DateUtils {
|
||||
}
|
||||
String date = input.trim().replace('/', '-').replaceAll("( ){2,}+", " ");
|
||||
|
||||
// CEST is widely used but not in the "ISO 8601 Time zone" list. Let's hack around.
|
||||
date = date.replaceAll("CEST$", "+01:00");
|
||||
|
||||
// if datetime is more precise than seconds, make sure the value is in ms
|
||||
if (date.contains(".")) {
|
||||
int start = date.indexOf('.');
|
||||
@ -50,7 +53,7 @@ public class DateUtils {
|
||||
}
|
||||
}
|
||||
}
|
||||
String[] patterns = {
|
||||
final String[] patterns = {
|
||||
"dd MMM yy HH:mm:ss Z",
|
||||
"dd MMM yy HH:mm Z",
|
||||
"EEE, dd MMM yyyy HH:mm:ss Z",
|
||||
@ -76,6 +79,7 @@ public class DateUtils {
|
||||
"yyyy-MM-dd'T'HH:mm:ss.SSS",
|
||||
"yyyy-MM-dd'T'HH:mm:ssZ",
|
||||
"yyyy-MM-dd'T'HH:mm:ss'Z'",
|
||||
"yyyy-MM-dd'T'HH:mm:ss.SSSZ",
|
||||
"yyyy-MM-ddZ",
|
||||
"yyyy-MM-dd"
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user