details:   https://code.openbravo.com/erp/devel/pi/rev/ead23f919c59
changeset: 18544:ead23f919c59
user:      Shankar Balachandran <shankar.balachandran <at> openbravo.com>
date:      Wed Nov 14 14:36:31 2012 +0100
summary:   Fixes Issue 0022119: Implemented convertToClassicString in 
TimeUIDefinition.

Implemented defined method convertToClassicString and refactored code to reuse 
time normalization logic.

diffstat:

 
modules/org.openbravo.client.kernel/src/org/openbravo/client/kernel/reference/TimeUIDefinition.java
 |  54 ++++++---
 1 files changed, 33 insertions(+), 21 deletions(-)

diffs (86 lines):

diff -r e46d705d6365 -r ead23f919c59 
modules/org.openbravo.client.kernel/src/org/openbravo/client/kernel/reference/TimeUIDefinition.java
--- 
a/modules/org.openbravo.client.kernel/src/org/openbravo/client/kernel/reference/TimeUIDefinition.java
       Wed Nov 14 13:09:06 2012 +0100
+++ 
b/modules/org.openbravo.client.kernel/src/org/openbravo/client/kernel/reference/TimeUIDefinition.java
       Wed Nov 14 14:36:31 2012 +0100
@@ -55,10 +55,13 @@
 
   @Override
   public synchronized String convertToClassicString(Object value) {
-    if (value == null) {
+    if (value == null || value == "") {
       return "";
     }
-    return value.toString();
+    String timestamp = value.toString();
+    timestamp = timestamp.substring(timestamp.indexOf(" ") + 1);
+    StringBuffer convertedValue = convertUtcToLocalTime(timestamp);
+    return convertedValue.toString();
   }
 
   private SimpleDateFormat getClassicFormat() {
@@ -76,6 +79,33 @@
     return classicFormat;
   }
 
+  /*
+   * createFromClassicString has been called with an UTC date, it expects a 
date in local time,so
+   * the time is going to be converted to local time, and going to be passed to
+   * createFromClassicString
+   */
+  private StringBuffer convertUtcToLocalTime(String value) {
+    StringBuffer localTimeColumnValue = null;
+    try {
+      Date UTCDate = getClassicFormat().parse(value);
+      Calendar now = Calendar.getInstance();
+
+      Calendar calendar = Calendar.getInstance();
+      calendar.setTime(UTCDate);
+      calendar.set(Calendar.DATE, now.get(Calendar.DATE));
+      calendar.set(Calendar.MONTH, now.get(Calendar.MONTH));
+      calendar.set(Calendar.YEAR, now.get(Calendar.YEAR));
+
+      int gmtMillisecondOffset = (now.get(Calendar.ZONE_OFFSET) + 
now.get(Calendar.DST_OFFSET));
+      calendar.add(Calendar.MILLISECOND, gmtMillisecondOffset);
+      localTimeColumnValue = getClassicFormat().format(calendar.getTime(), new 
StringBuffer(),
+          new FieldPosition(0));
+    } catch (ParseException e) {
+      throw new OBException("Exception when parsing date ", e);
+    }
+    return localTimeColumnValue;
+  }
+
   // getFieldProperties has to be overridden because depending on the value of 
getValueFromSession,
   // time fields have to be converted from localTime to UTC before sending the 
to the client
   @Override
@@ -91,31 +121,13 @@
           // If the date is empty, it does not have to be converted
           return result;
         }
-        // createFromClassicString has been called with an UTC date, it 
expects a date in local
-        // time,
-        // so the time is going to be converted to local time, and going to be 
passed to
-        // createFromClassicString
-        Date UTCDate = getClassicFormat().parse(columnValue);
-        Calendar now = Calendar.getInstance();
-
-        Calendar calendar = Calendar.getInstance();
-        calendar.setTime(UTCDate);
-        calendar.set(Calendar.DATE, now.get(Calendar.DATE));
-        calendar.set(Calendar.MONTH, now.get(Calendar.MONTH));
-        calendar.set(Calendar.YEAR, now.get(Calendar.YEAR));
-
-        int gmtMillisecondOffset = (now.get(Calendar.ZONE_OFFSET) + 
now.get(Calendar.DST_OFFSET));
-        calendar.add(Calendar.MILLISECOND, gmtMillisecondOffset);
-        StringBuffer localTimeColumnValue = 
getClassicFormat().format(calendar.getTime(),
-            new StringBuffer(), new FieldPosition(0));
+        StringBuffer localTimeColumnValue = convertUtcToLocalTime(columnValue);
         jsnobject.put("value", 
createFromClassicString(localTimeColumnValue.toString()));
         jsnobject.put("classicValue", localTimeColumnValue.toString());
         return jsnobject.toString();
       }
     } catch (JSONException e) {
       throw new OBException("Exception when parsing date ", e);
-    } catch (ParseException e) {
-      throw new OBException("Exception when parsing date ", e);
     }
     return result;
   }

------------------------------------------------------------------------------
Monitor your physical, virtual and cloud infrastructure from a single
web console. Get in-depth insight into apps, servers, databases, vmware,
SAP, cloud infrastructure, etc. Download 30-day Free Trial.
Pricing starts from $795 for 25 servers or applications!
http://p.sf.net/sfu/zoho_dev2dev_nov
_______________________________________________
Openbravo-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openbravo-commits

Reply via email to