mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-13 04:53:16 +00:00
[DS-401] Validate and reject invalid dates during submission.
git-svn-id: http://scm.dspace.org/svn/repo/dspace/trunk@5719 9c30dcfa-912a-0410-8fc2-9e0234be79fd
This commit is contained in:
@@ -150,7 +150,7 @@ public class DCDate
|
||||
* @param ss
|
||||
* the seconds
|
||||
*/
|
||||
public DCDate(int yyyy, int mm, int dd, int hh, int mn, int ss)
|
||||
public DCDate(int yyyy, int mm, int dd, int hh, int mn, int ss) throws DCDateIllegalArgumentException
|
||||
{
|
||||
setUTCForFormatting();
|
||||
|
||||
@@ -194,8 +194,20 @@ public class DCDate
|
||||
}
|
||||
|
||||
// Set the local calendar.
|
||||
localCalendar = new GregorianCalendar(lyear, lmonth - 1, lday,
|
||||
lhours, lminutes, lseconds);
|
||||
localCalendar = new GregorianCalendar();
|
||||
localCalendar.setLenient(false);
|
||||
localCalendar.set(lyear, lmonth - 1, lday, lhours, lminutes, lseconds);
|
||||
try
|
||||
{
|
||||
// Unfortunately GregorianCalendar doesn't throw an exception when you 'set' an invalid value so
|
||||
// we have to call a method that causes all the values to be inspected in order to check that they are valid.
|
||||
localCalendar.get(Calendar.YEAR);
|
||||
}
|
||||
catch (IllegalArgumentException e)
|
||||
{
|
||||
// Re-throw exception as a checked exception so that the calling classes have to deal with it.
|
||||
throw new DCDateIllegalArgumentException("Invalid parameter", e);
|
||||
}
|
||||
|
||||
if (granularity == DateGran.TIME)
|
||||
{
|
||||
|
Reference in New Issue
Block a user