diff gnv-artifacts/src/main/java/de/intevation/gnv/utils/InputValidator.java @ 1088:46cc1ab1ee15

Improved the validation of user inserted time periods (issue286). gnv-artifacts/trunk@1191 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Thu, 10 Jun 2010 10:16:29 +0000
parents 8f836fb6f592
children 2b4d197a538c
line wrap: on
line diff
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/utils/InputValidator.java	Thu Jun 10 09:23:33 2010 +0000
+++ b/gnv-artifacts/src/main/java/de/intevation/gnv/utils/InputValidator.java	Thu Jun 10 10:16:29 2010 +0000
@@ -28,11 +28,6 @@
      */
     private static Logger log = Logger.getLogger(InputValidator.class);
 
-    /**
-     * Epsilon for handling unprecise date objects (in ms).
-     */
-    public final static long DATE_EPSILON = 750;
-
 
     public final static String NODATASELECTEDVALUE = "n/n";
 
@@ -226,11 +221,19 @@
      * @return true, if tmp is valid, otherwise false.
      */
     public static boolean isDateValid(Date tmp, Date lo, Date up) {
-        long tmpTime = tmp.getTime();
-        long tmpLow  = lo.getTime();
-        long tmpUp   = up.getTime();
+        // take the time in seconds to compare
+        long tmpTime = tmp.getTime() / 1000;
+        long tmpLow  = lo.getTime() / 1000;
+        long tmpUp   = up.getTime() / 1000;
 
-        if (tmpTime < tmpLow - DATE_EPSILON || tmpTime > tmpUp + DATE_EPSILON) {
+        if (log.isDebugEnabled()) {
+            log.debug("Date validation...");
+            log.debug("-> lower bound [sec]: " + tmpLow);
+            log.debug("-> upper bound [sec]: " + tmpUp);
+            log.debug("-> input data  [sec]: " + tmpTime);
+        }
+
+        if (tmpTime < tmpLow || tmpTime > tmpUp) {
             log.warn(
                 "Date [" + tmp.toString() + "] is out of range ["
                 + lo.toString() + " to "+ up.toString() + "].");

http://dive4elements.wald.intevation.org