[PATCH] Fixing overview filter: Accept date range as UNIX time stamps, too

Wald Commits scm-commit at wald.intevation.org
Thu Oct 9 11:57:22 CEST 2014


# HG changeset patch
# User Sascha L. Teichmann <teichmann at intevation.de>
# Date 1412848637 -7200
# Node ID da67b2bca1c09a7ff5a54bec15a5f0ec938931e4
# Parent  a201d475e50d294ec40418ee6e2616db54147f66
Fixing overview filter: Accept date range as UNIX time stamps, too.

diff -r a201d475e50d -r da67b2bca1c0 artifacts/src/main/java/org/dive4elements/river/artifacts/model/FixingsFilterBuilder.java
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/model/FixingsFilterBuilder.java	Wed Oct 08 16:28:02 2014 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/model/FixingsFilterBuilder.java	Thu Oct 09 11:57:17 2014 +0200
@@ -11,9 +11,7 @@
 import org.dive4elements.river.artifacts.model.FixingsOverview.AndFilter;
 import org.dive4elements.river.artifacts.model.FixingsOverview.DateFilter;
 import org.dive4elements.river.artifacts.model.FixingsOverview.DateRangeFilter;
-
 import org.dive4elements.river.artifacts.model.FixingsOverview.Fixing.Filter;
-
 import org.dive4elements.river.artifacts.model.FixingsOverview.IdFilter;
 import org.dive4elements.river.artifacts.model.FixingsOverview.IdsFilter;
 import org.dive4elements.river.artifacts.model.FixingsOverview.KmFilter;
@@ -24,13 +22,13 @@
 
 import java.text.ParsePosition;
 import java.text.SimpleDateFormat;
-
 import java.util.ArrayList;
 import java.util.Date;
 import java.util.List;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
 
 import org.apache.log4j.Logger;
-
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 import org.w3c.dom.Node;
@@ -40,6 +38,8 @@
 {
     private static Logger log = Logger.getLogger(FixingsFilterBuilder.class);
 
+    private static final Pattern IS_LONG = Pattern.compile("^\\s*(-?\\d+)\\s*$");
+
     protected Filter   filter;
     protected Range    range;
 
@@ -131,6 +131,10 @@
     }
 
     protected static final Date parseDate(String text) {
+        Matcher m = IS_LONG.matcher(text);
+        if (m.matches()) {
+            return new Date(Long.valueOf(m.group(1)));
+        }
         SimpleDateFormat format =
             new SimpleDateFormat(FixingsOverview.DATE_FORMAT);
         return format.parse(text, new ParsePosition(0));


More information about the Dive4Elements-commits mailing list