commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Martin Cooper" <mart...@apache.org>
Subject Re: DateUtils confusion possibly a bug ?
Date Thu, 25 Oct 2007 18:23:58 GMT
On 10/25/07, Narahari 'n' Savitha <savithari@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));
>      }
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message