I hate that it breaks a pattern, but implementing the reverse would really
be pointless; the whole point of this is to catch dates passed to services
that are not formatted in pre-definied format in UtilDateTime (i.e. no
milliseconds, etc) that would be caught otherwise.

This is just a failsafe for those conditions.

Andrew

On Thu, Apr 7, 2011 at 3:59 PM, Adrian Crum <
[email protected]> wrote:

>
>
> -------- Original Message --------  Subject: Re: svn commit: r1089946 -
> /ofbiz/trunk/framework/base/src/org/ofbiz/base/conversion/DateTimeConverters.java
>   Date:
> Thu, 07 Apr 2011 12:30:37 -0700  From: Adrian Crum
> <[email protected]> <[email protected]>  
> Reply-To:
> [email protected]  Organization: Sandglass Software  To:
> [email protected]
>
> Keep in mind that this change breaks one of the converter design goals:
> Conversions should be bi-directional.
>
> -Adrian
>
>
> On 4/7/2011 12:27 PM, [email protected] wrote:
> > Author: jaz
> > Date: Thu Apr  7 19:27:53 2011
> > New Revision: 1089946
> >
> > URL: http://svn.apache.org/viewvc?rev=1089946&view=rev
> > Log:
> > added fall back to default date formatter when conversion fails before
> >
> > Modified:
> >      
> > ofbiz/trunk/framework/base/src/org/ofbiz/base/conversion/DateTimeConverters.java
> >
> > Modified: 
> > ofbiz/trunk/framework/base/src/org/ofbiz/base/conversion/DateTimeConverters.java
> > URL: 
> > http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/src/org/ofbiz/base/conversion/DateTimeConverters.java?rev=1089946&r1=1089945&r2=1089946&view=diff
> > ==============================================================================
> > --- 
> > ofbiz/trunk/framework/base/src/org/ofbiz/base/conversion/DateTimeConverters.java
> >  (original)
> > +++ 
> > ofbiz/trunk/framework/base/src/org/ofbiz/base/conversion/DateTimeConverters.java
> >  Thu Apr  7 19:27:53 2011
> > @@ -522,7 +522,16 @@ public class DateTimeConverters implemen
> >               try {
> >                   return new java.sql.Timestamp(df.parse(str).getTime());
> >               } catch (ParseException e) {
> > -                throw new ConversionException(e);
> > +                // before throwing an exception, try a generic format first
> > +                df = DateFormat.getDateTimeInstance();
> > +                if (timeZone != null) {
> > +                    df.setTimeZone(timeZone);
> > +                }
> > +                try {
> > +                    return new java.sql.Timestamp(df.parse(str).getTime());
> > +                } catch (ParseException e2) {
> > +                    throw new ConversionException(e);
> > +                }
> >               }
> >           }
> >       }
> >
> >
>
>

Reply via email to