Commit 94c8bcdc authored by Cristian Berner's avatar Cristian Berner 💎
Browse files

Fixes ISSUE-44683: Sets correct DateTime in window grid exported CSV file

DateTime in export to CSV was wrong, applying local time zone several times instead of once.

It has been fixed by using a function that doesn't try to transform to
UTC in DateTimeUIDefinition, convertToClassicStringInLocalTime. This
function formats the date as is, using the timezone received without
prior conversion to UTC.

Fixes regression introduced in commit
4ec715bf
parent 98193da5
......@@ -11,7 +11,7 @@
* under the License.
* The Original Code is Openbravo ERP.
* The Initial Developer of the Original Code is Openbravo SLU
* All portions are Copyright (C) 2010-2019 Openbravo SLU
* All portions are Copyright (C) 2010-2020 Openbravo SLU
* All Rights Reserved.
* Contributor(s): ______________________________________.
************************************************************************
......@@ -59,22 +59,46 @@ public class DateTimeUIDefinition extends DateUIDefinition {
if (value instanceof String) {
return (String) value;
}
Date date = (Date) value;
date = convertLocalDateTimeToUTC(date);
StringBuffer convertedValue = convertLocalDateTimeToUTC((Date) value);
return convertedValue.toString();
return formatDateTime(date);
}
private StringBuffer convertLocalDateTimeToUTC(Date date) {
/**
* Creates a classic string which is used by callouts from an object value.
* Date is formatted as is, using local timezone
*
* @param value Object to be converted
* @return converted of formatted date string
*/
public String convertToClassicStringInLocalTime(Object value) {
if (value == null || value == "") {
return "";
}
if (value instanceof String) {
return (String) value;
}
Date date = (Date) value;
return formatDateTime(date);
}
private Date convertLocalDateTimeToUTC(Date date) {
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
int gmtMillisecondOffset = (calendar.get(Calendar.ZONE_OFFSET)
+ calendar.get(Calendar.DST_OFFSET));
calendar.add(Calendar.MILLISECOND, -gmtMillisecondOffset);
return calendar.getTime();
}
private String formatDateTime(Date date) {
SimpleDateFormat dateTimeFormat = getClassicFormat();
synchronized (dateTimeFormat) {
return getClassicFormat().format(calendar.getTime(), new StringBuffer(),
new FieldPosition(0));
return getClassicFormat().format(date, new StringBuffer(), new FieldPosition(0)).toString();
}
}
......
......@@ -11,7 +11,7 @@
* under the License.
* The Original Code is Openbravo ERP.
* The Initial Developer of the Original Code is Openbravo SLU
* All portions are Copyright (C) 2009-2019 Openbravo SLU
* All portions are Copyright (C) 2009-2020 Openbravo SLU
* All Rights Reserved.
* Contributor(s): ______________________________________.
************************************************************************
......@@ -66,6 +66,7 @@ import org.openbravo.client.application.window.OBViewUtil;
import org.openbravo.client.kernel.BaseKernelServlet;
import org.openbravo.client.kernel.KernelUtils;
import org.openbravo.client.kernel.OBUserException;
import org.openbravo.client.kernel.reference.DateTimeUIDefinition;
import org.openbravo.client.kernel.reference.UIDefinitionController;
import org.openbravo.dal.core.DalUtil;
import org.openbravo.dal.core.OBContext;
......@@ -652,8 +653,8 @@ public class DataSourceServlet extends BaseKernelServlet {
Date localDate = JsonUtils.createDateTimeFormat().parse(repairedString);
Date clientTimezoneDate = null;
clientTimezoneDate = convertFromLocalToClientTimezone(localDate);
keyValue = UIDefinitionController.DATETIME_UI_DEFINITION
.convertToClassicString(clientTimezoneDate);
keyValue = ((DateTimeUIDefinition) UIDefinitionController.DATETIME_UI_DEFINITION)
.convertToClassicStringInLocalTime(clientTimezoneDate);
} else if (timeCols.contains(key) && keyValue != null
&& !keyValue.toString().equals("null")) {
Date UTCdate = JsonUtils.createTimeFormatWithoutGMTOffset().parse(keyValue.toString());
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment