details: https://code.openbravo.com/erp/devel/pi/rev/8c8d50bb5a14
changeset: 18149:8c8d50bb5a14
user: Augusto Mauch <augusto.mauch <at> openbravo.com>
date: Mon Oct 08 10:04:09 2012 +0200
summary: Fixes issue 21810: Times are exported to CSV using client timezone
Before this fix, when a hour field was exported, it was done using the timezone
of the server. Now the time offset used is the client's side.
In order to do this, when the user pushes the button to export a grid to CSV,
the UTC offset of the client is sent to the server.
diffstat:
modules/org.openbravo.client.application/web/org.openbravo.client.application/js/grid/ob-grid.js
| 3 +-
modules/org.openbravo.client.application/web/org.openbravo.client.application/js/utilities/ob-utilities-date.js
| 10 +++-
modules/org.openbravo.service.datasource/src/org/openbravo/service/datasource/DataSourceServlet.java
| 28 +++++++++-
3 files changed, 37 insertions(+), 4 deletions(-)
diffs (109 lines):
diff -r 71b64e0c4004 -r 8c8d50bb5a14
modules/org.openbravo.client.application/web/org.openbravo.client.application/js/grid/ob-grid.js
---
a/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/grid/ob-grid.js
Fri Oct 05 15:25:04 2012 +0200
+++
b/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/grid/ob-grid.js
Mon Oct 08 10:04:09 2012 +0200
@@ -656,7 +656,8 @@
viewState: expProp.viewState,
tab: expProp.tab,
exportToFile: true,
- _textMatchStyle: 'substring'
+ _textMatchStyle: 'substring',
+ _UTCOffsetMiliseconds: OB.Utilities.Date.getUTCOffsetInMiliseconds()
}, lcriteria, this.getFetchRequestParams());
if (this.getSortField()) {
sortCriteria = this.getSort();
diff -r 71b64e0c4004 -r 8c8d50bb5a14
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
Fri Oct 05 15:25:04 2012 +0200
+++
b/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/utilities/ob-utilities-date.js
Mon Oct 08 10:04:09 2012 +0200
@@ -23,7 +23,6 @@
// = Openbravo Date Utilities =
// Defines utility methods related to handling date, incl. formatting.
OB.Utilities.Date = {};
-
// ** {{{ OB.Utilities.Date.centuryReference }}} **
// For a two-digit year display format, it establishes where is the frontier
// between the 20th and the 21st century
@@ -272,4 +271,13 @@
}
}
}
+};
+
+//** {{{ OB.Utilities.Date.getUTCOffsetInMiliseconds }}} **
+//
+// Return the offset with UTC measured in miliseconds
+OB.Utilities.Date.getUTCOffsetInMiliseconds = function () {
+ var UTCHourOffset = isc.Time.getUTCHoursDisplayOffset(new Date()),
+ UTCMinuteOffset = isc.Time.getUTCMinutesDisplayOffset(new Date());
+ return (UTCHourOffset * 60 * 60 * 1000) + (UTCMinuteOffset * 60 * 1000);
};
\ No newline at end of file
diff -r 71b64e0c4004 -r 8c8d50bb5a14
modules/org.openbravo.service.datasource/src/org/openbravo/service/datasource/DataSourceServlet.java
---
a/modules/org.openbravo.service.datasource/src/org/openbravo/service/datasource/DataSourceServlet.java
Fri Oct 05 15:25:04 2012 +0200
+++
b/modules/org.openbravo.service.datasource/src/org/openbravo/service/datasource/DataSourceServlet.java
Mon Oct 08 10:04:09 2012 +0200
@@ -25,6 +25,7 @@
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
+import java.util.Calendar;
import java.util.Date;
import java.util.Enumeration;
import java.util.HashMap;
@@ -262,6 +263,7 @@
List<String> dateTimeCols = new ArrayList<String>();
List<String> numericCols = new ArrayList<String>();
Map<String, DecimalFormat> formats = new HashMap<String, DecimalFormat>();
+ int clientUTCOffsetMiliseconds;
public QueryJSONWriterToCSV(HttpServletRequest request,
HttpServletResponse response,
Map<String, String> parameters, Entity entity) {
@@ -301,6 +303,11 @@
log.warn("Warning: CSV Field separator is identical to the decimal
separator. Changing the field separator to "
+ fieldSeparator + " to avoid generating a wrong CSV file");
}
+ if (parameters.get("_UTCOffsetMiliseconds").length() > 0) {
+ clientUTCOffsetMiliseconds =
Integer.parseInt(parameters.get("_UTCOffsetMiliseconds"));
+ } else {
+ clientUTCOffsetMiliseconds = 0;
+ }
fieldProperties = new ArrayList<String>();
if (parameters.get("viewState") != null
&& !parameters.get("viewState").toString().equals("undefined")) {
@@ -515,12 +522,13 @@
} else if (dateTimeCols.contains(key) && keyValue != null
&& !keyValue.toString().equals("null")) {
final String repairedString =
JsonUtils.convertFromXSDToJavaFormat(keyValue.toString());
- Date date = JsonUtils.createDateTimeFormat().parse(repairedString);
+ Date localDate =
JsonUtils.createDateTimeFormat().parse(repairedString);
+ Date clientTimezoneDate =
convertFromLocalToClientTimezone(localDate);
String pattern =
RequestContext.get().getSessionAttribute("#AD_JAVADATETIMEFORMAT")
.toString();
SimpleDateFormat dateFormat = new SimpleDateFormat(pattern);
dateFormat.setLenient(true);
- keyValue = dateFormat.format(date);
+ keyValue = dateFormat.format(clientTimezoneDate);
}
if (keyValue != null && !keyValue.toString().equals("null")) {
@@ -537,6 +545,22 @@
throw new OBException("Error while exporting CSV information", e);
}
}
+
+ private Date convertFromLocalToClientTimezone(Date localDate) {
+ Calendar now = Calendar.getInstance();
+ Calendar calendar = Calendar.getInstance();
+ calendar.setTime(localDate);
+ 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);
+
+ calendar.add(Calendar.MILLISECOND, clientUTCOffsetMiliseconds);
+
+ return calendar.getTime();
+ }
}
private void handleException(Exception e, HttpServletResponse response)
throws IOException {
------------------------------------------------------------------------------
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