You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Narahari 'n' Savitha <sa...@gmail.com> on 2007/10/25 16:55:03 UTC
DateUtils confusion possibly a bug ?
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));
}
Re: DateUtils confusion possibly a bug ?
Posted by Narahari 'n' Savitha <sa...@gmail.com>.
Your point Martin ?
On 10/25/07, Martin Cooper <ma...@apache.org> wrote:
>
> On 10/25/07, Narahari 'n' Savitha <sa...@gmail.com> wrote:
> >
> > Friends,
> >
> > This might have been asked before but I am unable to find a searchable
> > archive for the LANG.\
>
>
> Really? That's a little hard to believe. Here are the 5 that I'm aware of:
>
> http://mail-archives.apache.org/mod_mbox/commons-user/
> http://marc.info/?l=jakarta-commons-user&r=1&w=2
> http://www.mail-archive.com/user@commons.apache.org/
> http://www.nabble.com/Commons---User-f319.html
> http://dir.gmane.org/gmane.comp.jakarta.commons.user
>
> --
> Martin Cooper
>
>
> 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));
> > }
> >
>
Re: DateUtils confusion possibly a bug ?
Posted by Martin Cooper <ma...@apache.org>.
On 10/25/07, Narahari 'n' Savitha <sa...@gmail.com> wrote:
>
> Friends,
>
> This might have been asked before but I am unable to find a searchable
> archive for the LANG.\
Really? That's a little hard to believe. Here are the 5 that I'm aware of:
http://mail-archives.apache.org/mod_mbox/commons-user/
http://marc.info/?l=jakarta-commons-user&r=1&w=2
http://www.mail-archive.com/user@commons.apache.org/
http://www.nabble.com/Commons---User-f319.html
http://dir.gmane.org/gmane.comp.jakarta.commons.user
--
Martin Cooper
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));
> }
>
Re: DateUtils confusion possibly a bug ?
Posted by Henri Yandell <fl...@gmail.com>.
On 10/25/07, Narahari 'n' Savitha <sa...@gmail.com> wrote:
> 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 ?
Off the bat, I don't see any reason why not.
Could you add an issue to JIRA requesting this improvement?
http://issues.apache.org/jira/browse/LANG
Thanks,
Hen
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org