diff gnv-artifacts/src/main/java/de/intevation/gnv/utils/InputValidator.java @ 784:7b81d563c8c0

Improved date input validation. A given date needs to be in a specific range (issue212). gnv-artifacts/trunk@866 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Tue, 30 Mar 2010 09:17:53 +0000
parents c4156275c1e1
children e764cab8c885
line wrap: on
line diff
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/utils/InputValidator.java	Mon Mar 29 12:56:13 2010 +0000
+++ b/gnv-artifacts/src/main/java/de/intevation/gnv/utils/InputValidator.java	Tue Mar 30 09:17:53 2010 +0000
@@ -163,4 +163,22 @@
         }
     }
 
+
+    public boolean isDateValid(Date tmp, Date lo, Date up) {
+        // we need to transform the given dates into seconds, because
+        // they differ in milliseconds -> that's why we cannot use the
+        // Date.compareTo(Date) method.
+        long tmpTime = tmp.getTime() / 1000;
+        long tmpLow  = lo.getTime() / 1000;
+        long tmpUp   = up.getTime() / 1000;
+
+        if (tmpTime < tmpLow || tmpTime > tmpUp) {
+            log.warn(
+                "Date [" + tmp.toString() + "] is out of range ["
+                + lo.toString() + " to "+ up.toString() + "].");
+            return false;
+        }
+
+        return true;
+    }
 }

http://dive4elements.wald.intevation.org