details: https://code.openbravo.com/erp/devel/pi/rev/2c2841f894b4 changeset: 25400:2c2841f894b4 user: Augusto Mauch <augusto.mauch <at> openbravo.com> date: Tue Nov 25 15:44:05 2014 +0100 summary: Fixes issue 28265, fixes issue 27628: Prevents exception when parsing date
Instead of converting the date to String and then parsing it back to Date, just pass the Date object as a parameter to the convertLocalTimeToUTC method details: https://code.openbravo.com/erp/devel/pi/rev/d8acdd64b6bf changeset: 25401:d8acdd64b6bf user: Augusto Mauch <augusto.mauch <at> openbravo.com> date: Tue Nov 25 15:45:15 2014 +0100 summary: Related with issue 27628: Renames method to convertLocalDateTimeToUTC diffstat: modules/org.openbravo.client.kernel/src/org/openbravo/client/kernel/reference/DateTimeUIDefinition.java | 31 ++++----- 1 files changed, 13 insertions(+), 18 deletions(-) diffs (54 lines): diff -r 7d2529edd900 -r d8acdd64b6bf modules/org.openbravo.client.kernel/src/org/openbravo/client/kernel/reference/DateTimeUIDefinition.java --- a/modules/org.openbravo.client.kernel/src/org/openbravo/client/kernel/reference/DateTimeUIDefinition.java Tue Nov 25 12:39:46 2014 +0100 +++ b/modules/org.openbravo.client.kernel/src/org/openbravo/client/kernel/reference/DateTimeUIDefinition.java Tue Nov 25 15:45:15 2014 +0100 @@ -19,7 +19,6 @@ package org.openbravo.client.kernel.reference; import java.text.FieldPosition; -import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; @@ -62,29 +61,25 @@ return (String) value; } - StringBuffer convertedValue = convertLocalTimeToUTC(value.toString()); + StringBuffer convertedValue = convertLocalDateTimeToUTC((Date) value); return convertedValue.toString(); } - private StringBuffer convertLocalTimeToUTC(String value) { + private StringBuffer convertLocalDateTimeToUTC(Date UTCDate) { StringBuffer localTimeColumnValue = null; - try { - Date UTCDate = ficDateFormat.parse(value); - Calendar now = Calendar.getInstance(); + 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)); + 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); - } + 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)); + return localTimeColumnValue; } ------------------------------------------------------------------------------ Download BIRT iHub F-Type - The Free Enterprise-Grade BIRT Server from Actuate! Instantly Supercharge Your Business Reports and Dashboards with Interactivity, Sharing, Native Excel Exports, App Integration & more Get technology previously reserved for billion-dollar corporations, FREE http://pubads.g.doubleclick.net/gampad/clk?id=157005751&iu=/4140/ostg.clktrk _______________________________________________ Openbravo-commits mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/openbravo-commits
