diff --git a/twidere.component.common/src/main/java/org/mariotaku/twidere/api/twitter/util/TwitterDateConverter.java b/twidere.component.common/src/main/java/org/mariotaku/twidere/api/twitter/util/TwitterDateConverter.java index 198aa646d..c466638ee 100644 --- a/twidere.component.common/src/main/java/org/mariotaku/twidere/api/twitter/util/TwitterDateConverter.java +++ b/twidere.component.common/src/main/java/org/mariotaku/twidere/api/twitter/util/TwitterDateConverter.java @@ -47,7 +47,6 @@ public class TwitterDateConverter extends StringBasedTypeConverter { private static final String[] MONTH_NAMES = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"}; - private static final long ONE_MINUTE = TimeUnit.MILLISECONDS.convert(1, TimeUnit.MINUTES); private static final TimeZone TIME_ZONE = TimeZone.getTimeZone("UTC"); private static final Locale LOCALE = Locale.ENGLISH; private final DateFormat mDateFormat; @@ -99,7 +98,7 @@ public class TwitterDateConverter extends StringBasedTypeConverter { calendar.set(Calendar.HOUR_OF_DAY, Integer.parseInt(timeSegs[0])); calendar.set(Calendar.MINUTE, Integer.parseInt(timeSegs[1])); calendar.set(Calendar.SECOND, Integer.parseInt(timeSegs[2])); - calendar.set(Calendar.ZONE_OFFSET, SimpleTimeZone.getTimeZone("GMT" + segs[4]).getRawOffset()); + calendar.setTimeZone(SimpleTimeZone.getTimeZone(getTimezoneText(segs[4]))); final Date date = calendar.getTime(); if (!WEEK_NAMES[calendar.get(Calendar.DAY_OF_WEEK) - 1].equals(segs[0])) { BugReporter.error("Week mismatch " + string + " => " + date); @@ -108,6 +107,11 @@ public class TwitterDateConverter extends StringBasedTypeConverter { return date; } + private String getTimezoneText(String seg) { + if (seg.startsWith("GMT") || seg.startsWith("UTC")) return seg; + return "GMT" + seg; + } + @Override public String convertToString(Date date) { final Calendar calendar = Calendar.getInstance(); diff --git a/twidere/build.gradle b/twidere/build.gradle index 6f9d25128..f376165f8 100644 --- a/twidere/build.gradle +++ b/twidere/build.gradle @@ -29,6 +29,7 @@ android { buildConfigField 'boolean', 'ENABLE_MEDIA_VIEWER', 'Boolean.parseBoolean("true")' + testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" } compileOptions { sourceCompatibility JavaVersion.VERSION_1_7 @@ -131,6 +132,10 @@ dependencies { provided 'javax.annotation:jsr250-api:1.0' testCompile 'junit:junit:4.12' + + androidTestCompile 'com.android.support:support-annotations:23.1.1' + androidTestCompile 'com.android.support.test:runner:0.4.1' + androidTestCompile 'com.android.support.test:rules:0.4.1' } task svgToDrawable(type: SvgDrawableTask) { diff --git a/twidere/src/androidTest/java/org/mariotaku/twidere/api/twitter/util/TwitterDateConverterTest.java b/twidere/src/androidTest/java/org/mariotaku/twidere/api/twitter/util/TwitterDateConverterTest.java new file mode 100644 index 000000000..017db0215 --- /dev/null +++ b/twidere/src/androidTest/java/org/mariotaku/twidere/api/twitter/util/TwitterDateConverterTest.java @@ -0,0 +1,35 @@ +package org.mariotaku.twidere.api.twitter.util; + +import org.junit.Test; + +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.Locale; + +import static org.junit.Assert.assertEquals; + +/** + * Created by mariotaku on 16/1/29. + */ +public class TwitterDateConverterTest { + + private final TwitterDateConverter converter = new TwitterDateConverter(); + private final SimpleDateFormat format = new SimpleDateFormat("EEE MMM dd HH:mm:ss ZZZZZ yyyy", Locale.ENGLISH); + + @Test + public void testGetFromString() throws Exception { + testDate("Fri Jan 29 04:12:49 +0100 2016"); + testDate("Thu Jan 28 11:08:47 +0000 2016"); + testDate("Sat Oct 03 16:05:32 +0000 2015"); + testDate("Tue Jan 26 18:30:19 +0100 2016"); + } + + private void testDate(String s) throws ParseException { + assertEquals(converter.getFromString(s), format.parse(s)); + } + + @Test + public void testConvertToString() throws Exception { + + } +} \ No newline at end of file diff --git a/twidere/src/test/java/org/mariotaku/twidere/util/TwidereMathUtilsTest.java b/twidere/src/androidTest/java/org/mariotaku/twidere/util/TwidereMathUtilsTest.java similarity index 100% rename from twidere/src/test/java/org/mariotaku/twidere/util/TwidereMathUtilsTest.java rename to twidere/src/androidTest/java/org/mariotaku/twidere/util/TwidereMathUtilsTest.java