Added LocalDate handling to KrillDate
Change-Id: Id3e7d901adc697fe1c897e0cca2d722a64b4e60f
diff --git a/Changes b/Changes
index dd7573d..77c439f 100644
--- a/Changes
+++ b/Changes
@@ -1,8 +1,9 @@
-0.58.5 2019-02-07
+0.58.5 2019-02-25
- [bugfix] Fix bug where duplicate keys occured in
field data output (diewald)
- [bugfix] Fix bug where fields already set where lifted
again, but ignored in the fields order list (diewald)
+ - [feature] Added LocalDate handling to KrillDate (diewald)
0.58.4 2019-02-05
- [cleanup] Remove deprecated methods setLicense/getLicense,
diff --git a/src/main/java/de/ids_mannheim/korap/util/KrillDate.java b/src/main/java/de/ids_mannheim/korap/util/KrillDate.java
index 3e5f3c1..396727b 100644
--- a/src/main/java/de/ids_mannheim/korap/util/KrillDate.java
+++ b/src/main/java/de/ids_mannheim/korap/util/KrillDate.java
@@ -2,6 +2,7 @@
import java.util.*;
import java.util.regex.*;
+import java.time.LocalDate;
/**
* KrillDate implements a helper object to stringify
@@ -92,6 +93,22 @@
/**
+ * Construct a new KrillDate object.
+ *
+ * @param date
+ * The date as a Date object.
+ */
+ public KrillDate (LocalDate date) {
+ if (date == null)
+ return;
+
+ this.year = date.getYear();
+ this.month = date.getMonthValue();
+ this.day = date.getDayOfMonth();
+ };
+
+
+ /**
* Get the date as an integer with ceiled values for
* undefined date segments.
*
diff --git a/src/test/java/de/ids_mannheim/korap/util/TestKrillDate.java b/src/test/java/de/ids_mannheim/korap/util/TestKrillDate.java
index f6f4fc3..f650d01 100644
--- a/src/test/java/de/ids_mannheim/korap/util/TestKrillDate.java
+++ b/src/test/java/de/ids_mannheim/korap/util/TestKrillDate.java
@@ -5,6 +5,8 @@
import de.ids_mannheim.korap.util.KrillDate;
import de.ids_mannheim.korap.util.QueryException;
+import java.time.LocalDate;
+
/**
* @author diewald
@@ -211,4 +213,18 @@
assertEquals(0, kd.day);
assertEquals("", kd.toDisplay());
};
+
+ @Test
+ public void testWithLocalDate () {
+ KrillDate kd =
+ new KrillDate(
+ LocalDate.of(2012, 12, 12)
+ );
+ assertEquals("2012-12-12", kd.toDisplay());
+
+ kd = new KrillDate(
+ LocalDate.of(2014, 1, 2)
+ );
+ assertEquals("2014-01-02", kd.toDisplay());
+ };
};