in src/main/java/org/apache/commons/validator/GenericTypeValidator.java [117:164]
public static Date formatDate(final String value, final Locale locale) {
Date date = null;
if (value == null) {
return null;
}
try {
// Get the formatters to check against
DateFormat formatterShort = null;
DateFormat formatterDefault = null;
if (locale != null) {
formatterShort =
DateFormat.getDateInstance(DateFormat.SHORT, locale);
formatterDefault =
DateFormat.getDateInstance(DateFormat.DEFAULT, locale);
} else {
formatterShort =
DateFormat.getDateInstance(
DateFormat.SHORT,
Locale.getDefault());
formatterDefault =
DateFormat.getDateInstance(
DateFormat.DEFAULT,
Locale.getDefault());
}
// Turn off lenient parsing
formatterShort.setLenient(false);
formatterDefault.setLenient(false);
// Firstly, try with the short form
try {
date = formatterShort.parse(value);
} catch (final ParseException e) {
// Fall back on the default one
date = formatterDefault.parse(value);
}
} catch (final ParseException e) {
// Bad date, so LOG and return null
if (LOG.isDebugEnabled()) {
LOG.debug("Date parse failed value=[" + value + "], " +
"locale=[" + locale + "] " + e);
}
}
return date;
}