aboutsummaryrefslogtreecommitdiffstats
path: root/main
diff options
context:
space:
mode:
authorBananeweizen <bananeweizen@gmx.de>2013-09-22 09:58:36 +0200
committerBananeweizen <bananeweizen@gmx.de>2013-09-22 09:58:36 +0200
commitfe1c10d1cb072c5cf477ebbfb5e7d1ab06f35bcc (patch)
tree42cf24a47179092d3f136a24fd5456023e8d38a8 /main
parent8a539e82bac733031257e053b5994c8d662c5334 (diff)
downloadcgeo-fe1c10d1cb072c5cf477ebbfb5e7d1ab06f35bcc.zip
cgeo-fe1c10d1cb072c5cf477ebbfb5e7d1ab06f35bcc.tar.gz
cgeo-fe1c10d1cb072c5cf477ebbfb5e7d1ab06f35bcc.tar.bz2
improve calendar time detection
* now works for (wrong) time format "xx.00 o'clock" (where there is a dot instead of a colon)
Diffstat (limited to 'main')
-rw-r--r--main/src/cgeo/geocaching/Geocache.java40
1 files changed, 19 insertions, 21 deletions
diff --git a/main/src/cgeo/geocaching/Geocache.java b/main/src/cgeo/geocaching/Geocache.java
index 912d1be..76b55bc 100644
--- a/main/src/cgeo/geocaching/Geocache.java
+++ b/main/src/cgeo/geocaching/Geocache.java
@@ -1695,30 +1695,28 @@ public class Geocache implements ICache, IWaypoint {
if (!isEventCache()) {
return null;
}
- // 12:34
- final Pattern time = Pattern.compile("\\b(\\d{1,2})\\:(\\d\\d)\\b");
- final MatcherWrapper matcher = new MatcherWrapper(time, getDescription());
- while (matcher.find()) {
- try {
- final int hours = Integer.valueOf(matcher.group(1));
- final int minutes = Integer.valueOf(matcher.group(2));
- if (hours >= 0 && hours < 24 && minutes >= 0 && minutes < 60) {
- return String.valueOf(hours * 60 + minutes);
- }
- } catch (final NumberFormatException e) {
- // cannot happen, but static code analysis doesn't know
- }
- }
- // 12 o'clock
+
final String hourLocalized = CgeoApplication.getInstance().getString(R.string.cache_time_full_hours);
+ ArrayList<Pattern> patterns = new ArrayList<Pattern>();
+
+ // 12:34
+ patterns.add(Pattern.compile("\\b(\\d{1,2})\\:(\\d\\d)\\b"));
if (StringUtils.isNotBlank(hourLocalized)) {
- final Pattern fullHours = Pattern.compile("\\b(\\d{1,2})\\s+" + Pattern.quote(hourLocalized), Pattern.CASE_INSENSITIVE);
- final MatcherWrapper matcherHours = new MatcherWrapper(fullHours, getDescription());
- if (matcherHours.find()) {
+ // 12 o'clock, 12.00 o'clock
+ patterns.add(Pattern.compile("\\b(\\d{1,2})(?:\\.00)?\\s+" + Pattern.quote(hourLocalized), Pattern.CASE_INSENSITIVE));
+ }
+
+ for (Pattern pattern : patterns) {
+ final MatcherWrapper matcher = new MatcherWrapper(pattern, getDescription());
+ while (matcher.find()) {
try {
- final int hours = Integer.valueOf(matcherHours.group(1));
- if (hours >= 0 && hours < 24) {
- return String.valueOf(hours * 60);
+ final int hours = Integer.valueOf(matcher.group(1));
+ int minutes = 0;
+ if (matcher.groupCount() >= 2) {
+ minutes = Integer.valueOf(matcher.group(2));
+ }
+ if (hours >= 0 && hours < 24 && minutes >= 0 && minutes < 60) {
+ return String.valueOf(hours * 60 + minutes);
}
} catch (final NumberFormatException e) {
// cannot happen, but static code analysis doesn't know