Re: svn commit: r1089946 - /ofbiz/trunk/framework/base/src/org/ofbiz/base/conversion/DateTimeConverters.java

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Re: svn commit: r1089946 - /ofbiz/trunk/framework/base/src/org/ofbiz/base/conversion/DateTimeConverters.java

Adrian Crum-3
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, [hidden email] 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 | Threaded
Open this post in threaded view
|

Re: Re: svn commit: r1089946 - /ofbiz/trunk/framework/base/src/org/ofbiz/base/conversion/DateTimeConverters.java

jaz-3
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 <
[hidden email]> 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
> <[hidden email]> <[hidden email]>  Reply-To:
> [hidden email]  Organization: Sandglass Software  To:
> [hidden email]
>
> 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, [hidden email] 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 | Threaded
Open this post in threaded view
|

Re: svn commit: r1089946 - /ofbiz/trunk/framework/base/src/org/ofbiz/base/conversion/DateTimeConverters.java

Adrian Crum-3
It might be beneficial to look at the issue a little more closely.

The "pre-defined format in UtilDateTime" is actually the JDBC String
format used by all JDBC drivers. It is not an arbitrary or OFBiz-defined
format. If you call Timestamp.toString() you will get a String formatted
in JDBC format. So conversley, if you want to convert a String to a
Timestamp, then the String should be in the proper JDBC format.

 From my perspective, if a service requires a Timestamp parameter, then
it is up to the caller to format a String data type properly so that the
service will accept it.

-Adrian


On 4/11/2011 4:41 PM, Andrew Zeneski wrote:

> 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<
> [hidden email]>  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
>> <[hidden email]>  <[hidden email]>   Reply-To:
>> [hidden email]  Organization: Sandglass Software  To:
>> [hidden email]
>>
>> 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, [hidden email] 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);
>>> +                }
>>>                }
>>>            }
>>>        }
>>>
>>>
>>