diff --git a/dspace-api/src/main/java/org/dspace/content/DCDate.java b/dspace-api/src/main/java/org/dspace/content/DCDate.java index d58aff7b1e22..163e21cdc2c5 100644 --- a/dspace-api/src/main/java/org/dspace/content/DCDate.java +++ b/dspace-api/src/main/java/org/dspace/content/DCDate.java @@ -80,6 +80,9 @@ private enum DateGran { YEAR, MONTH, DAY, TIME } // just year, "2009" private final SimpleDateFormat yearIso = new SimpleDateFormat("yyyy"); + // Additional iso-like format which contains milliseconds + private final SimpleDateFormat fullIsoWithMs = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'.000'"); + private static Map dfsLocaleMap = new HashMap(); /** @@ -193,6 +196,9 @@ public DCDate(String fromDC) { if (date == null) { date = tryParse(fullIso4, fromDC); } + if (date == null) { + date = tryParse(fullIsoWithMs, fromDC); + } if (date == null) { // Seems there is no time component to the date. date = tryParse(dateIso, fromDC); @@ -244,6 +250,7 @@ private void setUTCForFormatting() { dateIso.setTimeZone(utcZone); yearMonthIso.setTimeZone(utcZone); yearIso.setTimeZone(utcZone); + fullIsoWithMs.setTimeZone(utcZone); } // Attempt to parse, swallowing errors; return null for failure. diff --git a/dspace-api/src/test/java/org/dspace/content/DCDateTest.java b/dspace-api/src/test/java/org/dspace/content/DCDateTest.java index 9f534b5dcf98..c3c84990ae4e 100644 --- a/dspace-api/src/test/java/org/dspace/content/DCDateTest.java +++ b/dspace-api/src/test/java/org/dspace/content/DCDateTest.java @@ -281,6 +281,23 @@ public void testDCDateString() { assertThat("testDCDateString 10", dc.getHourUTC(), equalTo(0)); assertThat("testDCDateString 11", dc.getMinuteUTC(), equalTo(0)); assertThat("testDCDateString 12", dc.getSecondUTC(), equalTo(1)); + + // test additional ISO format + dc = new DCDate("2010-04-14T00:00:01.000"); + assertThat("testDCDateString 1", dc.getYear(), equalTo(2010)); + assertThat("testDCDateString 2", dc.getMonth(), equalTo(04)); + assertThat("testDCDateString 3", dc.getDay(), equalTo(13)); + assertThat("testDCDateString 4", dc.getHour(), equalTo(16)); + assertThat("testDCDateString 5", dc.getMinute(), equalTo(0)); + assertThat("testDCDateIntBits 6", dc.getSecond(), equalTo(1)); + + assertThat("testDCDateString 7", dc.getYearUTC(), equalTo(2010)); + assertThat("testDCDateString 8", dc.getMonthUTC(), equalTo(04)); + assertThat("testDCDateString 9", dc.getDayUTC(), equalTo(14)); + assertThat("testDCDateString 10", dc.getHourUTC(), equalTo(0)); + assertThat("testDCDateString 11", dc.getMinuteUTC(), equalTo(0)); + assertThat("testDCDateString 12", dc.getSecondUTC(), equalTo(1)); + } @@ -381,6 +398,11 @@ public void testDisplayDate() { assertThat("testDisplayDate 7 ", dc.displayDate(false, false, new Locale("en_GB")), equalTo("14-Apr-2010")); + + dc = new DCDate("2010-04-14T00:00:01.000"); + assertThat("testDisplayDate 8 ", dc.displayDate(false, false, + new Locale("en_GB")), + equalTo("14-Apr-2010")); } /**