You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by ad...@apache.org on 2014/04/05 11:46:59 UTC

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

Author: adrianc
Date: Sat Apr  5 09:46:58 2014
New Revision: 1585033

URL: http://svn.apache.org/r1585033
Log:
Fixed a bug in String to java.sql.Date conversion. If the Date object includes time information, then the JDBC driver will adjust the date according to the default time zone - causing the wrong date to be stored in some circumstances.

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=1585033&r1=1585032&r2=1585033&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 Sat Apr  5 09:46:58 2014
@@ -555,6 +555,7 @@ public class DateTimeConverters implemen
             return ObjectType.instanceOf(sourceClass, this.getSourceClass()) && targetClass == this.getTargetClass();
         }
 
+        @SuppressWarnings("deprecation")
         public java.sql.Date convert(String obj, Locale locale, TimeZone timeZone, String formatString) throws ConversionException {
             String trimStr = obj.trim();
             if (trimStr.length() == 0) {
@@ -567,7 +568,8 @@ public class DateTimeConverters implemen
                 df = UtilDateTime.toDateFormat(formatString, timeZone, locale);
             }
             try {
-                return new java.sql.Date(df.parse(trimStr).getTime());
+                java.util.Date parsedDate = df.parse(trimStr);
+                return new java.sql.Date(parsedDate.getYear(), parsedDate.getMonth(), parsedDate.getDay());
             } catch (ParseException e) {
                 throw new ConversionException(e);
             }



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

Posted by Jacopo Cappellato <ja...@hotwaxmedia.com>.
Adrian,

thanks for fixing this in rev. 1585958

Jacopo

On Apr 5, 2014, at 8:34 AM, Jacopo Cappellato <ja...@hotwaxmedia.com> wrote:

> I understand this, but I think that we should not add new code that calls deprecated API.
> 
> Jacopo
> 
> On Apr 5, 2014, at 8:07 AM, adrian.crum@sandglass-software.com wrote:
> 
>> I was aware of that, but the long argument contains the time component.
>> 
>> -Adrian
>> 
>> 
>> Quoting Jacopo Cappellato <ja...@hotwaxmedia.com>:
>> 
>>> On Apr 5, 2014, at 3:46 AM, adrianc@apache.org wrote:
>>> 
>>>> +                return new java.sql.Date(parsedDate.getYear(), parsedDate.getMonth(), parsedDate.getDay());
>>> 
>>> This constructor is deprecated.
>>> 
>>> "Deprecated. instead use the constructor Date(long date)"
>>> 
>>> Jacopo
>>> 
>>> 
>> 
>> 
>> 
> 


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

Posted by Jacopo Cappellato <ja...@hotwaxmedia.com>.
I understand this, but I think that we should not add new code that calls deprecated API.

Jacopo

On Apr 5, 2014, at 8:07 AM, adrian.crum@sandglass-software.com wrote:

> I was aware of that, but the long argument contains the time component.
> 
> -Adrian
> 
> 
> Quoting Jacopo Cappellato <ja...@hotwaxmedia.com>:
> 
>> On Apr 5, 2014, at 3:46 AM, adrianc@apache.org wrote:
>> 
>>> +                return new java.sql.Date(parsedDate.getYear(), parsedDate.getMonth(), parsedDate.getDay());
>> 
>> This constructor is deprecated.
>> 
>> "Deprecated. instead use the constructor Date(long date)"
>> 
>> Jacopo
>> 
>> 
> 
> 
> 


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

Posted by ad...@sandglass-software.com.
I was aware of that, but the long argument contains the time component.

-Adrian


Quoting Jacopo Cappellato <ja...@hotwaxmedia.com>:

> On Apr 5, 2014, at 3:46 AM, adrianc@apache.org wrote:
>
>> +                return new java.sql.Date(parsedDate.getYear(),  
>> parsedDate.getMonth(), parsedDate.getDay());
>
> This constructor is deprecated.
>
> "Deprecated. instead use the constructor Date(long date)"
>
> Jacopo
>
>




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

Posted by Jacopo Cappellato <ja...@hotwaxmedia.com>.
On Apr 5, 2014, at 3:46 AM, adrianc@apache.org wrote:

> +                return new java.sql.Date(parsedDate.getYear(), parsedDate.getMonth(), parsedDate.getDay());

This constructor is deprecated.

"Deprecated. instead use the constructor Date(long date)"

Jacopo