date validity checks
diff --git a/src/main/java/de/ids_mannheim/korap/query/serialize/CollectionQueryTree.java b/src/main/java/de/ids_mannheim/korap/query/serialize/CollectionQueryTree.java
index e1bb0dd..d237e74 100644
--- a/src/main/java/de/ids_mannheim/korap/query/serialize/CollectionQueryTree.java
+++ b/src/main/java/de/ids_mannheim/korap/query/serialize/CollectionQueryTree.java
@@ -11,6 +11,7 @@
import java.lang.reflect.Method;
import java.util.*;
+import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
@@ -240,9 +241,27 @@
return map;
}
+ /**
+ * Checks if a date
+ * @param valueNode
+ * @return
+ */
private boolean checkDateValidity(ParseTree valueNode) {
- // TODO ensure month is <= 12, day is <= 31 etc.
-// Pattern p =
+ Pattern p = Pattern.compile("[0-9]{4}(-([0-9]{2})(-([0-9]{2}))?)?");
+ Matcher m = p.matcher(valueNode.getText());
+
+ if (!m.find()) return false;
+ String month = m.group(2);
+ String day = m.group(4);
+ if (month != null) {
+ if (Integer.parseInt(month) > 12) {
+ return false;
+ } else if (day != null) {
+ if (Integer.parseInt(day) > 31) {
+ return false;
+ }
+ }
+ }
return true;
}
@@ -457,7 +476,7 @@
query = "(textClass=wissenschaft & textClass=politik) | textClass=ausland";
query = "textClass=Sport & year=2014";
query = "title!~mannheim";
- query = "title=1984";
+ query = "title=1984-14";
CollectionQueryTree.verbose = true;
CollectionQueryTree filter = null;
try {
diff --git a/src/test/java/CollectionQueryTreeTest.java b/src/test/java/CollectionQueryTreeTest.java
index acf09d7..ee7b554 100644
--- a/src/test/java/CollectionQueryTreeTest.java
+++ b/src/test/java/CollectionQueryTreeTest.java
@@ -108,6 +108,7 @@
assertEquals("2014", res.at("/collection/operands/1/value").asText());
assertEquals(true, res.at("/collection/operands/1/type").isMissingNode());
assertEquals("match:eq", res.at("/collection/operands/1/match").asText());
+ assertEquals("", res.at("/warnings/0/"));
}
@Test