details:   https://code.openbravo.com/erp/devel/pi/rev/23fb5884456f
changeset: 18183:23fb5884456f
user:      Augusto Mauch <augusto.mauch <at> openbravo.com>
date:      Wed Oct 10 11:01:33 2012 +0200
summary:   Fixes issue 21810: Timezone convertion refactored

The function OB.Utilities.Date.convertUTCTimeToLocalTime has been refactored:
- Instead of modifying the first parameter, it makes a copy and it returns the 
copy after converting its timezone
- It uses the new getUTCOffsetInMiliseconds function

The two places where the convertUTCTimeToLocalTime was used have been modified 
accordingly.

diffstat:

 
modules/org.openbravo.client.application/web/org.openbravo.client.application/js/form/ob-view-form.js
           |   2 +-
 
modules/org.openbravo.client.application/web/org.openbravo.client.application/js/grid/ob-view-grid.js
           |   5 +-
 
modules/org.openbravo.client.application/web/org.openbravo.client.application/js/utilities/ob-utilities-date.js
 |  19 +++++----
 3 files changed, 14 insertions(+), 12 deletions(-)

diffs (76 lines):

diff -r 7b78a07d02b6 -r 23fb5884456f 
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 Oct 10 10:32:32 2012 +0200
+++ 
b/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/form/ob-view-form.js
     Wed Oct 10 11:01:33 2012 +0200
@@ -191,7 +191,7 @@
     //   from the datasource, so it has to be converted from UTC to local time
     // see issue https://issues.openbravo.com/view.php?id=20684
     if (!isLocalTime) {
-      OB.Utilities.Date.convertUTCTimeToLocalTime([record], this.fields);
+      record = OB.Utilities.Date.convertUTCTimeToLocalTime([record], 
this.fields)[0];
     }
 
     ret = this.Super('editRecord', arguments);
diff -r 7b78a07d02b6 -r 23fb5884456f 
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 Oct 10 10:32:32 2012 +0200
+++ 
b/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/grid/ob-view-grid.js
     Wed Oct 10 11:01:33 2012 +0200
@@ -214,13 +214,13 @@
       // when the data is received from the datasource, time fields are 
formatted in UTC time. They have to be converted to local time
       if (dsResponse && dsResponse.context && 
(dsResponse.context.operationType === 'fetch' || 
dsResponse.context.operationType === 'update' || 
dsResponse.context.operationType === 'add')) {
         if (this.grid) {
-          OB.Utilities.Date.convertUTCTimeToLocalTime(newData, 
this.grid.completeFields);
+          newData = OB.Utilities.Date.convertUTCTimeToLocalTime(newData, 
this.grid.completeFields);
         }
       }
       // only do this stuff for fetch operations, in other cases strange things
       // happen as update/delete operations do not return the totalRows 
parameter      
       if (dsResponse && dsResponse.context && dsResponse.context.operationType 
!== 'fetch') {
-        return;
+        return newData;
       }
       // correct the length if there is already data in the localData array
       if (this.localData) {
@@ -242,6 +242,7 @@
       if (this.localData && this.localData[dsResponse.totalRows]) {
         this.localData[dsResponse.totalRows] = null;
       }
+      return newData;
     }
   },
 
diff -r 7b78a07d02b6 -r 23fb5884456f 
modules/org.openbravo.client.application/web/org.openbravo.client.application/js/utilities/ob-utilities-date.js
--- 
a/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/utilities/ob-utilities-date.js
   Wed Oct 10 10:32:32 2012 +0200
+++ 
b/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/utilities/ob-utilities-date.js
   Wed Oct 10 11:01:33 2012 +0200
@@ -260,23 +260,24 @@
 // * {{{newData}}}: records to be converted
 // * {{{allFields}}}: array with the fields of the records
 // Return:
-// * Nothing. newData is modified, its time fields are converted from UTC to 
local time
+// * Nothing. newData, after converting its time fields from UTC timezone the 
the client side timezone
 OB.Utilities.Date.convertUTCTimeToLocalTime = function (newData, allFields) {
-  var textField, fieldToDate, i, j, newDataLength = newData.length,
-      UTCHourOffset = isc.Time.getUTCHoursDisplayOffset(new Date()),
-      UTCMinuteOffset = isc.Time.getUTCMinutesDisplayOffset(new Date()),
+  var textField, fieldToDate, i, j, UTCOffsetInMiliseconds = 
OB.Utilities.Date.getUTCOffsetInMiliseconds(),
       timeFields = OB.Utilities.Date.getTimeFields(allFields),
-      timeFieldsLength = timeFields.length;
+      timeFieldsLength = timeFields.length,
+      convertedData = isc.clone(newData),
+      convertedDataLength = convertedData.length;
   for (i = 0; i < timeFieldsLength; i++) {
-    for (j = 0; j < newDataLength; j++) {
-      textField = newData[j][timeFields[i]];
+    for (j = 0; j < convertedDataLength; j++) {
+      textField = convertedData[j][timeFields[i]];
       if (textField && textField.length > 0) {
         fieldToDate = isc.Time.parseInput(textField);
-        fieldToDate.setTime(fieldToDate.getTime() + (UTCHourOffset * 60 * 60 * 
1000) + (UTCMinuteOffset * 60 * 1000));
-        newData[j][timeFields[i]] = fieldToDate.getHours() + ':' + 
fieldToDate.getMinutes() + ':' + fieldToDate.getSeconds();
+        fieldToDate.setTime(fieldToDate.getTime() + UTCOffsetInMiliseconds);
+        convertedData[j][timeFields[i]] = fieldToDate.getHours() + ':' + 
fieldToDate.getMinutes() + ':' + fieldToDate.getSeconds();
       }
     }
   }
+  return convertedData;
 };
 
 //** {{{ OB.Utilities.Date.getUTCOffsetInMiliseconds }}} **

------------------------------------------------------------------------------
Don't let slow site performance ruin your business. Deploy New Relic APM
Deploy New Relic app performance management and know exactly
what is happening inside your Ruby, Python, PHP, Java, and .NET app
Try New Relic at no cost today and get our sweet Data Nerd shirt too!
http://p.sf.net/sfu/newrelic-dev2dev
_______________________________________________
Openbravo-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openbravo-commits

Reply via email to