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 bfe418dec2..0d677f96d6 100644 --- a/dspace-api/src/main/java/org/dspace/content/DCDate.java +++ b/dspace-api/src/main/java/org/dspace/content/DCDate.java @@ -82,6 +82,9 @@ public class DCDate // UTC timezone private static final TimeZone utcZone = TimeZone.getTimeZone("UTC"); + // local timezone + private static final TimeZone localZone = new GregorianCalendar().getTimeZone(); + // Full ISO 8601 is e.g. "2009-07-16T13:59:21Z" private static final SimpleDateFormat fullIso = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'"); static { fullIso.setTimeZone(utcZone); } @@ -182,18 +185,36 @@ public class DCDate date = tryParse(fullIso3, fromDC); if (date == null) { + // NOTE: move GMT date to local midnight when granularity is coarse date = tryParse(dateIso, fromDC); - granularity = DateGran.DAY; + if (date != null) + { + long ldate = date.getTime(); + date = new Date(ldate - localZone.getOffset(ldate)); + granularity = DateGran.DAY; + } } if (date == null) { + // NOTE: move GMT date to local midnight when granularity is coarse date = tryParse(yearMonthIso, fromDC); - granularity = DateGran.MONTH; + if (date != null) + { + long ldate = date.getTime(); + date = new Date(ldate - localZone.getOffset(ldate)); + granularity = DateGran.MONTH; + } } if (date == null) { + // NOTE: move GMT date to local midnight when granularity is coarse date = tryParse(yearIso, fromDC); - granularity = DateGran.YEAR; + if (date != null) + { + long ldate = date.getTime(); + date = new Date(ldate - localZone.getOffset(ldate)); + granularity = DateGran.YEAR; + } } if (date == null) @@ -249,14 +270,16 @@ public class DCDate return toStringInternal(); } + // When granularity is "day" or more, show the _local-time_ day because + // when the granularity was coarse the local time value was set. private synchronized String toStringInternal() { if (granularity == DateGran.YEAR) - return yearIso.format(calendar.getTime()); + return String.format("%4d", getYear()); else if (granularity == DateGran.MONTH) - return yearMonthIso.format(calendar.getTime()); + return String.format("%4d-%02d", getYear(), getMonth()); else if (granularity == DateGran.DAY) - return dateIso.format(calendar.getTime()); + return String.format("%4d-%02d-%02d", getYear(), getMonth(), getDay()); else return fullIso.format(calendar.getTime()); } @@ -502,6 +525,8 @@ public class DCDate /** * Simple test program * Usage: java org.dspace.content.DCdate [DCDate | -l yyyy [mm [dd ..]]] ] + * where "DCDate" is the kind of value that would be in metadata, + * e.g. "2006", "2006-02-03", etc. * (-l form tests local time parsing) * Default is to use current time. */ diff --git a/dspace-xmlui/dspace-xmlui-api/src/main/java/org/dspace/app/xmlui/aspect/submission/submit/DescribeStep.java b/dspace-xmlui/dspace-xmlui-api/src/main/java/org/dspace/app/xmlui/aspect/submission/submit/DescribeStep.java index 808896acdc..85d11609b0 100644 --- a/dspace-xmlui/dspace-xmlui-api/src/main/java/org/dspace/app/xmlui/aspect/submission/submit/DescribeStep.java +++ b/dspace-xmlui/dspace-xmlui-api/src/main/java/org/dspace/app/xmlui/aspect/submission/submit/DescribeStep.java @@ -579,9 +579,9 @@ public class DescribeStep extends AbstractSubmissionStep { DCDate dcDate = new DCDate(dcValue.value); - year.addInstance().setValue(String.valueOf(dcDate.getYearGMT())); - month.addInstance().setOptionSelected(dcDate.getMonthGMT()); - day.addInstance().setValue(String.valueOf(dcDate.getDayGMT())); + year.addInstance().setValue(String.valueOf(dcDate.getYear())); + month.addInstance().setOptionSelected(dcDate.getMonth()); + day.addInstance().setValue(String.valueOf(dcDate.getDay())); fullDate.addInstance().setValue(dcDate.toString()); } } @@ -589,15 +589,15 @@ public class DescribeStep extends AbstractSubmissionStep { DCDate dcDate = new DCDate(dcValues[0].value); - year.setValue(String.valueOf(dcDate.getYearGMT())); - month.setOptionSelected(dcDate.getMonthGMT()); + year.setValue(String.valueOf(dcDate.getYear())); + month.setOptionSelected(dcDate.getMonth()); // Check if the day field is not specified, if so then just // put a blank value in instead of the wiered looking -1. - if (dcDate.getDayGMT() == -1) + if (dcDate.getDay() == -1) day.setValue(""); else - day.setValue(String.valueOf(dcDate.getDayGMT())); + day.setValue(String.valueOf(dcDate.getDay())); } } diff --git a/dspace/CHANGES b/dspace/CHANGES index a47a576e23..3ab4f661ae 100644 --- a/dspace/CHANGES +++ b/dspace/CHANGES @@ -65,6 +65,7 @@ - [DS-389] Misleading label: "Submit to This Collection" (Larry Stone) + - [DS-393] Fix DCDate and submission timezone bugs that changed date on page reload - [DS-377] Add META tags identifying DSpace source version - [DS-373] Fix "Letter" link URLs in 2nd-stage Browse - [DS-294] Add preferred language setting to Edit Profile page in XMLUI