[DS-393] Fix DCDate and submission timezone bugs that changed date on page reload

git-svn-id: http://scm.dspace.org/svn/repo/dspace/trunk@4602 9c30dcfa-912a-0410-8fc2-9e0234be79fd
This commit is contained in:
Larry Stone
2009-12-03 06:23:30 +00:00
parent 17700ff654
commit 2a7d3bd10d
3 changed files with 39 additions and 13 deletions

View File

@@ -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.
*/

View File

@@ -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()));
}
}

View File

@@ -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