]> git.aero2k.de Git - tmp/jakarta-migration.git/commitdiff
HM-18: Fixed test cases for AFTER formats, making the latestDate dynamic
authorcesarvh <cesarv.h@berkeley.edu>
Thu, 18 Oct 2018 00:52:56 +0000 (17:52 -0700)
committercesarvh <cesarv.h@berkeley.edu>
Tue, 19 Mar 2019 19:40:08 +0000 (12:40 -0700)
services/structureddate/structureddate/src/main/java/org/collectionspace/services/structureddate/DateUtils.java
services/structureddate/structureddate/src/test/java/org/collectionspace/services/structureddate/StructuredDateEvaluatorTest.java
services/structureddate/structureddate/src/test/resources/test-dates.yaml

index 2adc2d8c82d61ed666f8d3288618e3ece68f187a..cddb0e81d929a7559ac319b2bddc84938775b43e 100644 (file)
@@ -1116,12 +1116,16 @@ public class DateUtils {
         */
        public static Date getLatestAfterDate(Date startDate, Date endDate) {
                // TODO
+               return getCurrentDate();
+
+       }
+
+       public static Date getCurrentDate() {
                LocalDate localDate = new LocalDate();
                Integer year = (Integer) localDate.getYear();
                Integer month = (Integer) localDate.getMonthOfYear();
                Integer dayOfMonth = (Integer) localDate.getDayOfMonth();
                return new Date(year, month, dayOfMonth, Date.DEFAULT_ERA);
-
        }
 
        public static int getYearsBetween(Date startDate, Date endDate) {
index 3c4beb0569a8fc8c78fde3ae32522000ac2cf3a1..3d487babb323d1f0040baa735ea78b8db552fdc8 100644 (file)
@@ -1,6 +1,8 @@
 package org.collectionspace.services.structureddate;
 
+import java.lang.reflect.Array;
 import java.lang.reflect.InvocationTargetException;
+import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Iterator;
 import java.util.List;
@@ -52,6 +54,19 @@ public class StructuredDateEvaluatorTest {
        private StructuredDateInternal createStructuredDateFromYamlSpec(String displayDate, Map<String, Object> structuredDateFields) {
                StructuredDateInternal structuredDate = null;
 
+               // Can and should we calculate today's date for the "AFTER" dates?
+               if (structuredDateFields != null && structuredDateFields.containsKey("latestDate")) {
+                       if (structuredDateFields.get("latestDate").toString().equals("current date")) {
+                               ArrayList items = new ArrayList<>();
+                               Date currentDate = DateUtils.getCurrentDate();
+                               items.add(currentDate.getYear());
+                               items.add(currentDate.getMonth());
+                               items.add(currentDate.getDay());
+                               items.add(Date.DEFAULT_ERA.toString().toUpperCase());
+                               structuredDateFields.put("latestDate", items);
+                       }
+               }
+
                if (structuredDateFields != null) {
                        structuredDate = new StructuredDateInternal();
 
index 8d66b693881128f59673f047372833d8f047866f..82c238c95afe32ef845f98d8f3a6576ae8a7914a 100644 (file)
   "13 april 15":                        # oneDisplayDate - ambigous day and year - should be Year month day
                                          earliestSingleDate: [13,  4,  15, CE]
 
-  "13 april 1995":                           # oneDisplayDate - with question mark
+  "13 april 1995":                       # oneDisplayDate - with question mark
                                          earliestSingleDate: [1995,  4,  13, CE]
 
-  "13 apr 1995":                           # oneDisplayDate - with question mark
+  "13 apr 1995":                         # oneDisplayDate - with question mark
                                          earliestSingleDate: [1995,  4,  13, CE]
 
-  "13th APRIL 1995":                           # oneDisplayDate - with question mark
+  "13th APRIL 1995":                     # oneDisplayDate - with question mark
                                          earliestSingleDate: [1995,  4,  13, CE]
 
-  "13 april 1995 - 13 april 2018":    
+  "13 april 1995 - 13 april 2018":       # Hyphenated range - with Day Month Year format
                                          earliestSingleDate: [1995,  4, 13, CE]
                                          latestDate:         [2018,  4, 13, CE]
 
-  "before 13 april 1995":
+  "before 13 april 1995":                # beforeAfterDate - Empty earliestSingleDate - Day Month Year Format
                                          earliestSingleDate: []
                                          latestDate:         [1995,  4, 13, CE]
 
-  "before june 10 2017":
+  "before june 10 2017":                 # beforeAfterDate - Empty earliestSingleDate -  Month Day Year Format
                                          earliestSingleDate: []
                                          latestDate:         [2017,  6, 10, CE]
 
 
-  "after 13 april 1995":
+  "after 13 april 1995":                # beforeAfterDate - Empty latestDate calculated as current date - Day Month Year Format
                                          earliestSingleDate: [1995,  4, 13, CE]
-                                         latestDate:         [2018,  10, 17, CE]
+                                         latestDate:         "current date"
 
   "unknown":
                                          earliestSingleDate: []
-  "after april 13 1995":
+
+  "after april 13 1995":                # beforeAfterDate - Empty latestDate calculated as current date -  Month Day Year Format
                                          earliestSingleDate: [1995,  4, 13, CE]
-                                         latestDate:         [2018,  10, 17, CE]
+                                         latestDate:         "current date"
   
-  "10/2005-12/2006":
+  "10/2005-12/2006":                    # Month/Year - Month/Year date
                                          earliestSingleDate: [2005,  10, 1, CE]
                                          latestDate:         [2006,  12, 31, CE]
 
-  "04/1995-04/2018":
+  "04/1995-04/2018":                    # Month/Year - Month/Year date
                                          earliestSingleDate: [1995,  4, 1, CE]
-                                         latestDate:         [2018,  4, 30, CE] 
+                                         latestDate:         [2018,  4, 30, CE]
   # "unknown":
   #                                        earliestSingleDate: []