Let me fix CET/CEST once again

This commit is contained in:
Danial Klimkin 2017-04-12 23:31:53 +02:00
parent 7da9e8876b
commit 78d11570e4
2 changed files with 13 additions and 6 deletions

View File

@ -110,10 +110,16 @@ public class DateUtilsTest extends AndroidTestCase {
}
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);
GregorianCalendar exp1 = new GregorianCalendar(2017, 0, 28, 22, 00, 00);
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);
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);
}
}

View File

@ -28,7 +28,8 @@ 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");
date = date.replaceAll("CEST$", "+02:00");
date = date.replaceAll("CET$", "+01:00");
// if datetime is more precise than seconds, make sure the value is in ms
if (date.contains(".")) {