DOT: '.' ;
QUESTION: '?' ;
OTHER: . ;
-UNKNOWN: 'unknown' | 'UNKNOWN' ;
+UNKNOWN: 'unknown' ;
STRING: [a-z]+ ;
/**
* Calculates the latest date that may be considered to be "after"
- * a given date range. We define "after" as the current date.
+ * a given date range.
*
* @param startDate The first date in the range
* @param endDate The last date in the range
* @return The latest date "after" the range
*/
public static Date getLatestAfterDate(Date startDate, Date endDate) {
- // TODO
- return getCurrentDate();
+ Date currentDate = getCurrentDate();
+ if (endDate == null) {
+ return currentDate;
+ }
+ MutableDateTime currentDateTime = convertToDateTime(currentDate);
+ MutableDateTime endDateTime = convertToDateTime(endDate);
+
+ int comparisonResult = currentDateTime.compareTo(endDateTime);
+ if (comparisonResult == 1 || comparisonResult == 0) {
+ return currentDate;
+ }
+ return null;
}
public static Date getCurrentDate() {
Integer year = (Integer) localDate.getYear();
Integer month = (Integer) localDate.getMonthOfYear();
Integer dayOfMonth = (Integer) localDate.getDayOfMonth();
- return new Date(year, month, dayOfMonth, Date.DEFAULT_ERA);
+ Era era = (localDate.getEra() == DateTimeConstants.BC) ? Era.BCE : Era.CE;
+ return new Date(year, month, dayOfMonth, era);
}
public static int getYearsBetween(Date startDate, Date endDate) {
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);
+ Object latestDate = structuredDateFields.get("latestDate");
+ if (latestDate instanceof String) {
+ if (latestDate.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(currentDate.getEra() == Era.BCE ? "BCE" : "CE");
+ structuredDateFields.put("latestDate", items);
+ }
}
}
"13 april 15": # oneDisplayDate - ambiguous day and year, intepreted as year month day
earliestSingleDate: [13, 4, 15, CE]
+ "04/5-6/2018": # Month/Day - Day/Year date
+ earliestSingleDate: [2018, 4, 5, CE]
+ latestDate: [2018, 4, 6, CE]
+
+ "04/03-07/09": # Ambigious NumDayInMonthRange - should be interpreted as Month/Day - Day/Year date
+ earliestSingleDate: [9, 4, 3, CE]
+ latestDate: [9, 4, 7, CE]
+
+ '04/1996-07/09': # Semi-ambigious NumDayInMonthRange - should be interpreted as Month/Year - Month/Year date
+ earliestSingleDate: [1996, 4, 1, CE]
+ latestDate: [9, 7, 31, CE]
# -------------------------------------------------------------------------------------------------------
# Invalid dates
# -------------------------------------------------------------------------------------------------------
'3/4?/2005': # question mark
null
- '100 June 2010':
+ '100 June 2010': # invalid day
null
- '13 June 0':
- null
-
\ No newline at end of file
+ '13 June 0': # year 0
+ null
\ No newline at end of file