details:   https://code.openbravo.com/erp/devel/pi/rev/eec8991a4efd
changeset: 16825:eec8991a4efd
user:      Augusto Mauch <augusto.mauch <at> openbravo.com>
date:      Wed Jun 13 13:55:34 2012 +0545
summary:   Fixes issue 20684: Hour and minutes time zone offset is supported

Instead of using the hour time zone offset, now the millisecond time zone 
offset is applied, supporting the time zones where the offset with UTC is 
measured in hours and minutes.

diffstat:

 
modules/org.openbravo.client.application/web/org.openbravo.client.application/js/form/ob-view-form.js
 |  14 +---
 
modules/org.openbravo.client.application/web/org.openbravo.client.application/js/grid/ob-view-grid.js
 |  15 +---
 
modules/org.openbravo.client.kernel/src/org/openbravo/client/kernel/reference/TimeUIDefinition.java
   |  10 +--
 
modules/org.openbravo.service.json/src/org/openbravo/service/json/DataToJsonConverter.java
            |   5 +-
 
modules/org.openbravo.service.json/src/org/openbravo/service/json/JsonToDataConverter.java
            |  26 +++++-----
 5 files changed, 29 insertions(+), 41 deletions(-)

diffs (156 lines):

diff -r 8837bc9da36d -r eec8991a4efd 
modules/org.openbravo.client.application/web/org.openbravo.client.application/js/form/ob-view-form.js
--- 
a/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/form/ob-view-form.js
     Wed Jun 13 09:48:05 2012 +0200
+++ 
b/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/form/ob-view-form.js
     Wed Jun 13 13:55:34 2012 +0545
@@ -271,20 +271,16 @@
   },
 
   convertUTCTimeToLocalTime: function (record, timeFields) {
-    var textField, fieldToDate, i, localHour, timeFieldsLength = 
timeFields.length,
-        UTCOffset = isc.Time.getUTCHoursDisplayOffset(new Date());
+    var textField, fieldToDate, i, timeFieldsLength = timeFields.length,
+        UTCHourOffset = isc.Time.getUTCHoursDisplayOffset(new Date()),
+        UTCMinuteOffset = isc.Time.getUTCMinutesDisplayOffset(new Date());
     for (i = 0; i < timeFieldsLength; i++) {
       textField = record[timeFields[i]];
       if (textField && textField.length > 0) {
         fieldToDate = isc.Time.parseInput(textField);
-        localHour = fieldToDate.getHours() + UTCOffset;
-        if (localHour > 23) {
-          localHour = localHour - 24;
-        } else if (localHour < 0) {
-          localHour = localHour + 24;
-        }
+        fieldToDate.setTime(fieldToDate.getTime() + (UTCHourOffset * 60 * 60 * 
1000) + (UTCMinuteOffset * 60 * 1000));
         // TODO: support time formats other than HH:mm:ss
-        record[timeFields[i]] = String(localHour) + ':' + 
fieldToDate.getMinutes() + ':' + fieldToDate.getSeconds();
+        record[timeFields[i]] = fieldToDate.getHours() + ':' + 
fieldToDate.getMinutes() + ':' + fieldToDate.getSeconds();
       }
     }
   },
diff -r 8837bc9da36d -r eec8991a4efd 
modules/org.openbravo.client.application/web/org.openbravo.client.application/js/grid/ob-view-grid.js
--- 
a/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/grid/ob-view-grid.js
     Wed Jun 13 09:48:05 2012 +0200
+++ 
b/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/grid/ob-view-grid.js
     Wed Jun 13 13:55:34 2012 +0545
@@ -249,22 +249,17 @@
   },
 
   convertUTCTimeToLocalTime: function (newData, timeFields) {
-    var textField, fieldToDate, i, j, localHour,
-    timeFieldsLength = timeFields.length,
+    var textField, fieldToDate, i, j, timeFieldsLength = timeFields.length,
         newDataLength = newData.length,
-        UTCOffset = isc.Time.getUTCHoursDisplayOffset(new Date());
+        UTCHourOffset = isc.Time.getUTCHoursDisplayOffset(new Date()),
+        UTCMinuteOffset = isc.Time.getUTCMinutesDisplayOffset(new Date());
     for (i = 0; i < timeFieldsLength; i++) {
       for (j = 0; j < newDataLength; j++) {
         textField = newData[j][timeFields[i]];
         if (textField && textField.length > 0) {
           fieldToDate = isc.Time.parseInput(textField);
-          localHour = fieldToDate.getHours() + UTCOffset;
-          if (localHour > 23) {
-            localHour = localHour - 24;
-          } else if (localHour < 0) {
-            localHour = localHour + 24;
-          }
-          newData[j][timeFields[i]] = String(localHour) + ':' + 
fieldToDate.getMinutes() + ':' + fieldToDate.getSeconds();
+          fieldToDate.setTime(fieldToDate.getTime() + (UTCHourOffset * 60 * 60 
* 1000) + (UTCMinuteOffset * 60 * 1000));
+          newData[j][timeFields[i]] = fieldToDate.getHours() + ':' + 
fieldToDate.getMinutes() + ':' + fieldToDate.getSeconds();
         }
       }
     }
diff -r 8837bc9da36d -r eec8991a4efd 
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 Jun 13 09:48:05 2012 +0200
+++ 
b/modules/org.openbravo.client.kernel/src/org/openbravo/client/kernel/reference/TimeUIDefinition.java
       Wed Jun 13 13:55:34 2012 +0545
@@ -103,9 +103,8 @@
         calendar.set(Calendar.MONTH, now.get(Calendar.MONTH));
         calendar.set(Calendar.YEAR, now.get(Calendar.YEAR));
 
-        int gmtHourOffset = (now.get(Calendar.ZONE_OFFSET) + 
now.get(Calendar.DST_OFFSET))
-            / (1000 * 60 * 60);
-        calendar.add(Calendar.HOUR, gmtHourOffset);
+        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));
         jsnobject.put("value", 
createFromClassicString(localTimeColumnValue.toString()));
@@ -139,9 +138,8 @@
       calendar.set(Calendar.YEAR, now.get(Calendar.YEAR));
 
       // Applies the zone offset and the dst offset to convert the time from 
local to UTC
-      int gmtHourOffset = (now.get(Calendar.ZONE_OFFSET) + 
now.get(Calendar.DST_OFFSET))
-          / (1000 * 60 * 60);
-      calendar.add(Calendar.HOUR, -gmtHourOffset);
+      int gmtMillisecondOffset = (now.get(Calendar.ZONE_OFFSET) + 
now.get(Calendar.DST_OFFSET));
+      calendar.add(Calendar.MILLISECOND, -gmtMillisecondOffset);
 
       return xmlTimeFormat.format(calendar.getTime());
     } catch (Exception e) {
diff -r 8837bc9da36d -r eec8991a4efd 
modules/org.openbravo.service.json/src/org/openbravo/service/json/DataToJsonConverter.java
--- 
a/modules/org.openbravo.service.json/src/org/openbravo/service/json/DataToJsonConverter.java
        Wed Jun 13 09:48:05 2012 +0200
+++ 
b/modules/org.openbravo.service.json/src/org/openbravo/service/json/DataToJsonConverter.java
        Wed Jun 13 13:55:34 2012 +0545
@@ -301,9 +301,8 @@
     calendar.set(Calendar.MONTH, now.get(Calendar.MONTH));
     calendar.set(Calendar.YEAR, now.get(Calendar.YEAR));
 
-    int gmtHourOffset = (now.get(Calendar.ZONE_OFFSET) + 
now.get(Calendar.DST_OFFSET))
-        / (1000 * 60 * 60);
-    calendar.add(Calendar.HOUR, -gmtHourOffset);
+    int gmtMillisecondOffset = (now.get(Calendar.ZONE_OFFSET) + 
now.get(Calendar.DST_OFFSET));
+    calendar.add(Calendar.MILLISECOND, -gmtMillisecondOffset);
 
     return calendar.getTime();
   }
diff -r 8837bc9da36d -r eec8991a4efd 
modules/org.openbravo.service.json/src/org/openbravo/service/json/JsonToDataConverter.java
--- 
a/modules/org.openbravo.service.json/src/org/openbravo/service/json/JsonToDataConverter.java
        Wed Jun 13 09:48:05 2012 +0200
+++ 
b/modules/org.openbravo.service.json/src/org/openbravo/service/json/JsonToDataConverter.java
        Wed Jun 13 13:55:34 2012 +0545
@@ -126,6 +126,7 @@
   private final static SimpleDateFormat xmlDateFormat = 
JsonUtils.createDateFormat();
   private final static SimpleDateFormat xmlDateTimeFormat = 
JsonUtils.createDateTimeFormat();
   private final static SimpleDateFormat xmlTimeFormat = 
JsonUtils.createTimeFormat();
+  private final static SimpleDateFormat jsTimeFormat = 
JsonUtils.createJSTimeFormat();
 
   private final List<JsonConversionError> errors = new 
ArrayList<JsonConversionError>();
 
@@ -161,11 +162,13 @@
               strValue = JsonUtils.convertFromXSDToJavaFormat(strValue);
             }
 
-            Date localTime1970 = new 
Timestamp(xmlTimeFormat.parse(strValue).getTime());
+            Calendar now = Calendar.getInstance();
+            strValue = xmlDateFormat.format(now.getTime()) + "T" + strValue;
+            Date UTCTime = new 
Timestamp(jsTimeFormat.parse(strValue).getTime());
 
-            Date localTimeCurrentDate = convertToCurrentDate(localTime1970);
+            Date localTime = convertToLocalTime(UTCTime);
 
-            return new Timestamp(localTimeCurrentDate.getTime());
+            return new Timestamp(localTime.getTime());
           } else if (property.isDatetime() || 
Timestamp.class.isAssignableFrom(clz)) {
             final String repairedString = 
JsonUtils.convertFromXSDToJavaFormat((String) value);
             return new 
Timestamp(xmlDateTimeFormat.parse(repairedString).getTime());
@@ -222,18 +225,15 @@
     }
   }
 
-  private static Date convertToCurrentDate(Date localTime1970) {
-    Calendar now = Calendar.getInstance();
-    Calendar calendar = Calendar.getInstance();
-    calendar.setTime(localTime1970);
-    calendar.set(Calendar.DATE, now.get(Calendar.DATE));
-    calendar.set(Calendar.MONTH, now.get(Calendar.MONTH));
-    calendar.set(Calendar.YEAR, now.get(Calendar.YEAR));
+  private static Date convertToLocalTime(Date UTCTime) {
+    Calendar localTime = Calendar.getInstance();
+    localTime.setTime(UTCTime);
 
-    int dstOffset = now.get(Calendar.DST_OFFSET) / (1000 * 60 * 60);
-    calendar.add(Calendar.HOUR, dstOffset);
+    int gmtMillisecondOffset = (localTime.get(Calendar.ZONE_OFFSET) + localTime
+        .get(Calendar.DST_OFFSET));
+    localTime.add(Calendar.MILLISECOND, gmtMillisecondOffset);
 
-    return calendar.getTime();
+    return localTime.getTime();
   }
 
   private static boolean isEmptyOrNull(Object value) {

------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Openbravo-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openbravo-commits

Reply via email to