Friends,
This might have been asked before but I am unable to find a searchable
archive for the LANG.
Here it is.
In the Example 1. which uses the DateUtisl.parseDate method the date I am
providing is 14/32/2007. This is an invalid date but since the parseDate
method uses a LENIENT SimpleDateFormat object the dates are being parsed as
valid. This is not something that will help me. I would rather, this throw
a ParseException.
Could we add a method called parseDateStrict or provide a setter/getter to
set the strict attribute so that can in turn set the attribute on the
SimpleDateFormat method ?
We could also allow a mechanish where the caller provides the
SimpleDateFormat object which can be used to set the attributest that the
user wants on the parser.
Please see Example 2 which is what I was thinking the parseDate method would
do.
Thanks for your time and attention.
-Narahari
Example 1:
try {
String [] patternArray = { "MM/dd/yyyy"};
Calendar c =DateUtils.parseDate("14/32/2007", patternArray);
Date d = c.getTime();
} catch(Exception e) {
assertTrue("It should only be a parse exception", (e instanceof
ParseException));
}
Example 2:
try {
SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy");
sdf.setLenient(false);
Date d = sdf.parse("14/32/2007");
} catch(Exception e) {
assertTrue("It should only be a parse exception", (e instanceof
ParseException));
}