in tapestry-framework/src/org/apache/tapestry/valid/DateValidator.java [128:187]
public Object toObject(IFormComponent field, String value) throws ValidatorException
{
if (checkRequired(field, value))
return null;
DateFormat format = getEffectiveFormat();
Date result;
try
{
// DateFormat is not threadsafe, so guard access
// to it.
synchronized (format)
{
result = format.parse(value);
}
if (_calendar == null)
_calendar = new GregorianCalendar();
_calendar.setTime(result);
// SimpleDateFormat allows two-digit dates to be
// entered, i.e., 12/24/66 is Dec 24 0066 ... that's
// probably not what is really wanted, so treat
// it as an invalid date.
if (_calendar.get(Calendar.YEAR) < 1000)
result = null;
}
catch (ParseException ex)
{
// ParseException does not include a useful error message
// about what's wrong.
result = null;
}
if (result == null)
throw new ValidatorException(
buildInvalidDateFormatMessage(field),
ValidationConstraint.DATE_FORMAT);
// OK, check that the date is in range.
if (_minimum != null && _minimum.compareTo(result) > 0)
throw new ValidatorException(
buildDateTooEarlyMessage(field, format.format(_minimum)),
ValidationConstraint.TOO_SMALL);
if (_maximum != null && _maximum.compareTo(result) < 0)
throw new ValidatorException(
buildDateTooLateMessage(field, format.format(_maximum)),
ValidationConstraint.TOO_LARGE);
return result;
}