diff --git a/source/net/yacy/document/DateDetection.java b/source/net/yacy/document/DateDetection.java index 781101665..c5ecb0a1c 100644 --- a/source/net/yacy/document/DateDetection.java +++ b/source/net/yacy/document/DateDetection.java @@ -127,7 +127,7 @@ public class DateDetection { private final static Date TODAY = new Date(); private final static int CURRENT_YEAR = Integer.parseInt(CONFORM.format(TODAY).substring(0, 4)); // we need that to parse dates without given years, see the ShortStyle class - private final static String BODNCG = "(?:\\b|^)"; // begin of date non-capturing group + private final static String BODNCG = "(?:\\s|^)"; // begin of date non-capturing group private final static String EODNCG = "(?:[).:;! ]|$)"; // end of date non-capturing group private final static String SEPARATORNCG = "(?:/|-| - |\\.\\s|,\\s|\\.|,|\\s)"; // separator non-capturing group private final static String DAYCAPTURE = "(\\d{1,2})"; diff --git a/test/java/net/yacy/document/DateDetectionTest.java b/test/java/net/yacy/document/DateDetectionTest.java index cedcea6de..eba322d7a 100644 --- a/test/java/net/yacy/document/DateDetectionTest.java +++ b/test/java/net/yacy/document/DateDetectionTest.java @@ -28,6 +28,9 @@ public class DateDetectionTest { testtext.add("1.1.2016"); testtext.add("1. Januar 2016"); testtext.add("2016, January 1."); + + testtext.add("beginning text 1.1.2016"); + testtext.add("line break\n1.1.2016"); for (String text : testtext) { Date d = DateDetection.parseLine(text, 0); @@ -82,4 +85,23 @@ public class DateDetectionTest { } } + /** + * Negative test of parseLine method, of class DateDetection + * with cases that represent NOT a date + */ + @Test + public void testParseLineNoDate() { + + // test input representations + Set testtext = new LinkedHashSet(); + testtext.add("3.1.2.0102"); // example of a program version string + // testtext.add("3.1.20.0102"); // date end-capture not working (on modification conflict with YMD parser) + testtext.add("v3.1.21"); + testtext.add("v3.1.22."); + + for (String text : testtext) { + Date d = DateDetection.parseLine(text, 0); + assertNull("not a date: " + text, d); + } + } }