aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--main/src/cgeo/geocaching/Settings.java4
-rw-r--r--main/src/cgeo/geocaching/cgBase.java29
-rw-r--r--tests/src/cgeo/geocaching/cgBaseTest.java10
-rw-r--r--tests/src/cgeo/geocaching/test/mock/GC1ZXX2.java2
-rw-r--r--tests/src/cgeo/geocaching/test/mock/GC2CJPF.java2
-rw-r--r--tests/src/cgeo/geocaching/test/mock/GC2JVEH.java2
-rw-r--r--tests/src/cgeo/geocaching/test/mock/MockedCache.java4
7 files changed, 33 insertions, 20 deletions
diff --git a/main/src/cgeo/geocaching/Settings.java b/main/src/cgeo/geocaching/Settings.java
index 3cd9213..4360b6d 100644
--- a/main/src/cgeo/geocaching/Settings.java
+++ b/main/src/cgeo/geocaching/Settings.java
@@ -425,6 +425,10 @@ public final class Settings {
});
}
+ /**
+ * @return User selected date format on GC.com
+ * @see cgBase.gcCustomDateFormats
+ */
public static String getGcCustomDate() {
return sharedPrefs.getString(KEY_GC_CUSTOM_DATE, null);
}
diff --git a/main/src/cgeo/geocaching/cgBase.java b/main/src/cgeo/geocaching/cgBase.java
index 58b7695..1036363 100644
--- a/main/src/cgeo/geocaching/cgBase.java
+++ b/main/src/cgeo/geocaching/cgBase.java
@@ -101,7 +101,7 @@ public class cgBase {
private static final String passMatch = "(?<=[\\?&])[Pp]ass(w(or)?d)?=[^&#$]+";
public final static Map<WaypointType, String> waypointTypes = new HashMap<WaypointType, String>();
- public final static Map<String, SimpleDateFormat> gcCustomDateFormats;
+ private final static Map<String, SimpleDateFormat> gcCustomDateFormats;
static {
final String[] formats = new String[] {
"MM/dd/yyyy",
@@ -1356,30 +1356,23 @@ public class cgBase {
}
}
- public static Date parseGcCustomDate(final String input)
- throws ParseException
- {
- if (StringUtils.isBlank(input))
- {
+ public static Date parseGcCustomDate(final String input, final String format) throws ParseException {
+ if (StringUtils.isBlank(input)) {
throw new ParseException("Input is null", 0);
}
final String trimmed = input.trim();
- if (gcCustomDateFormats.containsKey(Settings.getGcCustomDate()))
- {
- try
- {
- return gcCustomDateFormats.get(Settings.getGcCustomDate()).parse(trimmed);
+ if (gcCustomDateFormats.containsKey(format)) {
+ try {
+ return gcCustomDateFormats.get(format).parse(trimmed);
} catch (ParseException e) {
}
}
- for (SimpleDateFormat format : gcCustomDateFormats.values())
- {
- try
- {
- return format.parse(trimmed);
+ for (SimpleDateFormat sdf : gcCustomDateFormats.values()) {
+ try {
+ return sdf.parse(trimmed);
} catch (ParseException e) {
}
}
@@ -1387,6 +1380,10 @@ public class cgBase {
throw new ParseException("No matching pattern", 0);
}
+ public static Date parseGcCustomDate(final String input) throws ParseException {
+ return parseGcCustomDate(input, Settings.getGcCustomDate());
+ }
+
/**
* Detect user date settings on geocaching.com
*/
diff --git a/tests/src/cgeo/geocaching/cgBaseTest.java b/tests/src/cgeo/geocaching/cgBaseTest.java
index 3e8eea0..e9e65a8 100644
--- a/tests/src/cgeo/geocaching/cgBaseTest.java
+++ b/tests/src/cgeo/geocaching/cgBaseTest.java
@@ -10,6 +10,8 @@ import cgeo.geocaching.utils.CancellableHandler;
import android.test.AndroidTestCase;
import android.test.suitebuilder.annotation.MediumTest;
+import java.util.Date;
+
import junit.framework.Assert;
public class cgBaseTest extends AndroidTestCase {
@@ -48,7 +50,9 @@ public class cgBaseTest extends AndroidTestCase {
Assert.assertEquals(expected.isFavorite(), actual.isFavorite());
Assert.assertEquals(expected.getFavoritePoints(), actual.getFavoritePoints());
Assert.assertEquals(expected.isWatchlist(), actual.isWatchlist());
- Assert.assertEquals(expected.getHiddenDate().toString(), actual.getHiddenDate().toString());
+ Date date1 = expected.getHiddenDate();
+ Date date2 = actual.getHiddenDate();
+ Assert.assertEquals(date1.toString(), date2.toString());
for (String attribute : expected.getAttributes()) {
Assert.assertTrue(actual.getAttributes().contains(attribute));
}
@@ -71,11 +75,15 @@ public class cgBaseTest extends AndroidTestCase {
*/
@MediumTest
public static void testParseCacheFromTextWithMockedData() {
+ String gcCustomDate = Settings.getGcCustomDate();
for (MockedCache mockedCache : RegExPerformanceTest.MOCKED_CACHES) {
+ // to get the same results we have to use the date format used when the mocked data was created
+ Settings.setGcCustomDate(mockedCache.getDateFormat());
cgCacheWrap caches = cgBase.parseCacheFromText(mockedCache.getData(), 0, null);
cgCache parsedCache = caches.cacheList.get(0);
cgBaseTest.testCompareCaches(mockedCache, parsedCache);
}
+ Settings.setGcCustomDate(gcCustomDate);
}
public static void testHumanDistance() {
diff --git a/tests/src/cgeo/geocaching/test/mock/GC1ZXX2.java b/tests/src/cgeo/geocaching/test/mock/GC1ZXX2.java
index bfbde87..272bbe2 100644
--- a/tests/src/cgeo/geocaching/test/mock/GC1ZXX2.java
+++ b/tests/src/cgeo/geocaching/test/mock/GC1ZXX2.java
@@ -96,7 +96,7 @@ public class GC1ZXX2 extends MockedCache {
@Override
public Date getHiddenDate() {
try {
- return cgBase.parseGcCustomDate("16/10/2009");
+ return cgBase.parseGcCustomDate("16/10/2009", getDateFormat());
} catch (ParseException e) {
// intentionally left blank
}
diff --git a/tests/src/cgeo/geocaching/test/mock/GC2CJPF.java b/tests/src/cgeo/geocaching/test/mock/GC2CJPF.java
index 6f04e74..e86f253 100644
--- a/tests/src/cgeo/geocaching/test/mock/GC2CJPF.java
+++ b/tests/src/cgeo/geocaching/test/mock/GC2CJPF.java
@@ -126,7 +126,7 @@ public class GC2CJPF extends MockedCache {
@Override
public Date getHiddenDate() {
try {
- return cgBase.parseGcCustomDate("31/07/2010");
+ return cgBase.parseGcCustomDate("31/07/2010", getDateFormat());
} catch (ParseException e) {
// intentionally left blank
}
diff --git a/tests/src/cgeo/geocaching/test/mock/GC2JVEH.java b/tests/src/cgeo/geocaching/test/mock/GC2JVEH.java
index 7589eda..fa0d76b 100644
--- a/tests/src/cgeo/geocaching/test/mock/GC2JVEH.java
+++ b/tests/src/cgeo/geocaching/test/mock/GC2JVEH.java
@@ -90,7 +90,7 @@ public class GC2JVEH extends MockedCache {
@Override
public Date getHiddenDate() {
try {
- return cgBase.parseGcCustomDate("28/11/2010");
+ return cgBase.parseGcCustomDate("28/11/2010", getDateFormat());
} catch (ParseException e) {
// intentionally left blank
}
diff --git a/tests/src/cgeo/geocaching/test/mock/MockedCache.java b/tests/src/cgeo/geocaching/test/mock/MockedCache.java
index 46d72e2..911ee1c 100644
--- a/tests/src/cgeo/geocaching/test/mock/MockedCache.java
+++ b/tests/src/cgeo/geocaching/test/mock/MockedCache.java
@@ -35,6 +35,10 @@ public abstract class MockedCache implements ICache {
this.mockedDataUser = mockedDataUser;
}
+ public String getDateFormat() {
+ return "dd/MM/yyyy";
+ }
+
/*
* The data for the caches can be generated by entering the url
* http://www.geocaching.com/seek/cache_details.aspx?log=y&wp=GCxxxx&numlogs=35&decrypt=y