if (Strings.isEmpty(value))
{
return null;
}
DateTimeFormatter format = getFormat();
if (format == null)
{
throw new IllegalStateException("format must be not null");
}
if (applyTimeZoneDifference)
{
TimeZone zone = getClientTimeZone();
// instantiate now/ current time
MutableDateTime dt = new MutableDateTime(new DateMidnight());
if (zone != null)
{
// set time zone for client
format = format.withZone(DateTimeZone.forTimeZone(zone));
dt.setZone(DateTimeZone.forTimeZone(zone));
}
try
{
// parse date retaining the time of the submission
int result = format.parseInto(dt, value, 0);
if (result < 0)
{
throw new ConversionException(new ParseException("unable to parse date "
+ value, ~result));
}
}
catch (RuntimeException e)
{
throw new ConversionException(e);
}
// apply the server time zone to the parsed value
dt.setZone(getTimeZone());
return dt.toDate();
}
else
{
try
{
DateTime date = format.parseDateTime(value);
return date.toDate();
}
catch (RuntimeException e)
{
throw new ConversionException(e);