Mercurial > dive4elements > gnv-client
changeset 1051:8f836fb6f592
Introduced an epsilon (750ms) to be more tolerant while comparing two data objects (issue286).
gnv-artifacts/trunk@1125 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Tue, 25 May 2010 17:46:28 +0000 |
parents | 7f3154331bc1 |
children | b30361464775 |
files | gnv-artifacts/ChangeLog gnv-artifacts/src/main/java/de/intevation/gnv/utils/InputValidator.java |
diffstat | 2 files changed, 17 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- a/gnv-artifacts/ChangeLog Tue May 25 15:41:31 2010 +0000 +++ b/gnv-artifacts/ChangeLog Tue May 25 17:46:28 2010 +0000 @@ -1,3 +1,11 @@ +2010-05-25 Ingo Weinzierl <ingo.weinzierl@intevation.de> + + Issue286 + + * src/main/java/de/intevation/gnv/utils/InputValidator.java: Introduced an + epsilon environment to be more tolerant while comparing date objects. The + value of the current epsilon is 750ms. + 2010-05-25 Ingo Weinzierl <ingo.weinzierl@intevation.de> Issue290
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/utils/InputValidator.java Tue May 25 15:41:31 2010 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/utils/InputValidator.java Tue May 25 17:46:28 2010 +0000 @@ -28,6 +28,11 @@ */ 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"; @@ -221,14 +226,11 @@ * @return true, if tmp is valid, otherwise false. */ public static 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; + long tmpTime = tmp.getTime(); + long tmpLow = lo.getTime(); + long tmpUp = up.getTime(); - if (tmpTime < tmpLow || tmpTime > tmpUp) { + if (tmpTime < tmpLow - DATE_EPSILON || tmpTime > tmpUp + DATE_EPSILON) { log.warn( "Date [" + tmp.toString() + "] is out of range [" + lo.toString() + " to "+ up.toString() + "].");