Hans,
Thank you for reverting this. One thing to keep in mind: Timestamps are ALWAYS referenced to GMT - your commit didn't change that. If you have questions about dates/times/time zones/Timestamps - just ask. I am willing to help. Also keep in mind that UtilDateTime.java has an excellent API for handling all of these things. Much of your commit duplicated that code. -Adrian [hidden email] wrote: > Author: hansbak > Date: Fri Aug 14 08:48:06 2009 > New Revision: 804130 > > URL: http://svn.apache.org/viewvc?rev=804130&view=rev > Log: > reverted 804104 because of compile error > > Modified: > ofbiz/trunk/framework/base/src/org/ofbiz/base/util/template/FreeMarkerWorker.java > ofbiz/trunk/framework/entity/src/org/ofbiz/entity/jdbc/SQLProcessor.java > ofbiz/trunk/framework/entity/src/org/ofbiz/entity/jdbc/SqlJdbcUtil.java > ofbiz/trunk/framework/widget/src/org/ofbiz/widget/form/ModelFormField.java > > Modified: ofbiz/trunk/framework/base/src/org/ofbiz/base/util/template/FreeMarkerWorker.java > URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/src/org/ofbiz/base/util/template/FreeMarkerWorker.java?rev=804130&r1=804129&r2=804130&view=diff > ============================================================================== > --- ofbiz/trunk/framework/base/src/org/ofbiz/base/util/template/FreeMarkerWorker.java (original) > +++ ofbiz/trunk/framework/base/src/org/ofbiz/base/util/template/FreeMarkerWorker.java Fri Aug 14 08:48:06 2009 > @@ -78,7 +78,7 @@ > > public static Configuration makeConfiguration(BeansWrapper wrapper) { > Configuration newConfig = new Configuration(); > - > + > newConfig.setObjectWrapper(wrapper); > newConfig.setSharedVariable("Static", wrapper.getStaticModels()); > newConfig.setLocalizedLookup(false); > @@ -218,11 +218,11 @@ > } > env.setLocale(locale); > > -// TimeZone timeZone = (TimeZone) context.get("timeZone"); > -// if (timeZone == null) { > -// timeZone = TimeZone.getDefault(); > -// } > -// env.setTimeZone(timeZone); > + TimeZone timeZone = (TimeZone) context.get("timeZone"); > + if (timeZone == null) { > + timeZone = TimeZone.getDefault(); > + } > + env.setTimeZone(timeZone); > } > > public static Configuration getDefaultOfbizConfig() { > > Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/jdbc/SQLProcessor.java > URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/jdbc/SQLProcessor.java?rev=804130&r1=804129&r2=804130&view=diff > ============================================================================== > --- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/jdbc/SQLProcessor.java (original) > +++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/jdbc/SQLProcessor.java Fri Aug 14 08:48:06 2009 > @@ -27,15 +27,10 @@ > import java.util.ArrayList; > import java.util.List; > import java.util.Map; > -import java.util.TimeZone; > > import org.ofbiz.base.util.Debug; > -import org.ofbiz.base.util.UtilMisc; > -import org.ofbiz.base.util.UtilValidate; > import org.ofbiz.entity.GenericDataSourceException; > -import org.ofbiz.entity.GenericDelegator; > import org.ofbiz.entity.GenericEntityException; > -import org.ofbiz.entity.GenericValue; > import org.ofbiz.entity.config.DatasourceInfo; > import org.ofbiz.entity.config.EntityConfigUtil; > import org.ofbiz.entity.transaction.GenericTransactionException; > @@ -583,27 +578,6 @@ > */ > public void setValue(java.sql.Timestamp field) throws SQLException { > if (field != null) { > - GenericDelegator delegator=GenericDelegator.getGenericDelegator("default"); > - String userId=delegator.getCurrentUserIdentifier(); > - try { > - if(userId!=null){ > - String timeZoneId=TimeZone.getDefault().getID(); > - GenericValue userLogin=delegator.findByPrimaryKey("UserLogin", UtilMisc.toMap("userLoginId", userId)); > - if(userLogin!=null){ > - if(UtilValidate.isNotEmpty(userLogin.get("lastTimeZone"))){ > - timeZoneId=userLogin.getString("lastTimeZone"); > - SqlJdbcUtil.setLastTimeZoneId(timeZoneId); > - } > - } > - if (field instanceof java.sql.Timestamp) { > - String dateField=SqlJdbcUtil.convertTimeZone(field.toString(),timeZoneId, "GMT"); > - field= java.sql.Timestamp.valueOf(dateField); > - } > - } > - } catch (GenericEntityException e) { > - // TODO Auto-generated catch block > - e.printStackTrace(); > - } > _ps.setTimestamp(_ind, field); > } else { > _ps.setNull(_ind, Types.TIMESTAMP); > > Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/jdbc/SqlJdbcUtil.java > URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/jdbc/SqlJdbcUtil.java?rev=804130&r1=804129&r2=804130&view=diff > ============================================================================== > --- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/jdbc/SqlJdbcUtil.java (original) > +++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/jdbc/SqlJdbcUtil.java Fri Aug 14 08:48:06 2009 > @@ -30,15 +30,11 @@ > import java.sql.ResultSetMetaData; > import java.sql.SQLException; > import java.sql.Clob; > -import java.text.ParseException; > -import java.text.SimpleDateFormat; > import java.util.Collection; > -import java.util.Date; > import java.util.Iterator; > import java.util.List; > import java.util.Map; > import java.util.Set; > -import java.util.TimeZone; > import java.util.TreeSet; > > import javax.sql.rowset.serial.SerialBlob; > @@ -48,7 +44,6 @@ > > import org.ofbiz.base.util.Debug; > import org.ofbiz.base.util.ObjectType; > -import org.ofbiz.base.util.UtilDateTime; > import org.ofbiz.base.util.UtilGenerics; > import org.ofbiz.base.util.UtilValidate; > import org.ofbiz.entity.GenericDataSourceException; > @@ -491,35 +486,7 @@ > } > } > } > - > - public static String lastTimeZoneId=TimeZone.getDefault().getID(); > - public static void setLastTimeZoneId(String timeZoneId){ > - lastTimeZoneId=timeZoneId; > - } > - public static String getLastTimeZoneId(){ > - return lastTimeZoneId; > - } > - public static String convertTimeZone(String time, String sourceTZ, String destTZ){ > - SimpleDateFormat sdf = new SimpleDateFormat(UtilDateTime.DATE_TIME_FORMAT); > - Date specifiedTime=null; > - try { > - if (sourceTZ != null) > - sdf.setTimeZone(TimeZone.getTimeZone(sourceTZ)); > - else > - sdf.setTimeZone(TimeZone.getDefault()); > - specifiedTime = sdf.parse(time); > - > - if (destTZ != null) > - sdf.setTimeZone(TimeZone.getTimeZone(destTZ)); > - else > - sdf.setTimeZone(TimeZone.getDefault()); > - } catch (ParseException e) { > - // TODO Auto-generated catch block > - Debug.logError("Error Convert time zone: "+e.getMessage(), module); > - } > - return sdf.format(specifiedTime); > - } > - > + > public static void getValue(ResultSet rs, int ind, ModelField curField, GenericEntity entity, ModelFieldTypeReader modelFieldTypeReader) throws GenericEntityException { > ModelFieldType mft = modelFieldTypeReader.getModelFieldType(curField.getType()); > > @@ -572,12 +539,7 @@ > break; > > case 2: > - Object value=rs.getTimestamp(ind); > - if (value!=null&&value instanceof java.sql.Timestamp) { > - String dateField=convertTimeZone(value.toString(),"GMT",lastTimeZoneId); > - value= java.sql.Timestamp.valueOf(dateField); > - } > - entity.dangerousSetNoCheckButFast(curField,value); > + entity.dangerousSetNoCheckButFast(curField, rs.getTimestamp(ind)); > break; > > case 3: > > Modified: ofbiz/trunk/framework/widget/src/org/ofbiz/widget/form/ModelFormField.java > URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/widget/src/org/ofbiz/widget/form/ModelFormField.java?rev=804130&r1=804129&r2=804130&view=diff > ============================================================================== > --- ofbiz/trunk/framework/widget/src/org/ofbiz/widget/form/ModelFormField.java (original) > +++ ofbiz/trunk/framework/widget/src/org/ofbiz/widget/form/ModelFormField.java Fri Aug 14 08:48:06 2009 > @@ -22,7 +22,6 @@ > import java.math.BigDecimal; > import java.text.DateFormat; > import java.text.NumberFormat; > -import java.text.SimpleDateFormat; > import java.util.HashMap; > import java.util.LinkedList; > import java.util.List; > @@ -676,8 +675,7 @@ > if (locale == null) locale = Locale.getDefault(); > TimeZone timeZone = (TimeZone) context.get("timeZone"); > if (timeZone == null) timeZone = TimeZone.getDefault(); > - > - SimpleDateFormat sdf=new SimpleDateFormat(UtilDateTime.DATE_TIME_FORMAT); > + > String returnValue; > > // if useRequestParameters is TRUE then parameters will always be used, if FALSE then parameters will never be used > @@ -738,32 +736,27 @@ > } > } > > - if (retVal != null) { > - // format string based on the user's locale and time zone > - if (retVal instanceof Double || retVal instanceof Float || retVal instanceof BigDecimal) { > - NumberFormat nf = NumberFormat.getInstance(locale); > - nf.setMaximumFractionDigits(10); > - returnValue = nf.format(retVal); > - } else if (retVal instanceof java.sql.Date) { > -// DateFormat df = UtilDateTime.toDateFormat(UtilDateTime.DATE_FORMAT, timeZone, null); > -// returnValue = df.format((java.util.Date) retVal); > - returnValue=sdf.format((java.util.Date)retVal); > - } else if (retVal instanceof java.sql.Time) { > -// DateFormat df = UtilDateTime.toTimeFormat(UtilDateTime.TIME_FORMAT, timeZone, null); > -// returnValue = df.format((java.util.Date) retVal); > - returnValue=sdf.format((java.util.Date)retVal); > - } else if (retVal instanceof java.sql.Timestamp) { > -// DateFormat df = UtilDateTime.toTimeFormat(UtilDateTime.TIME_FORMAT, timeZone, null); > -// returnValue = df.format((java.util.Date) retVal); > - returnValue=sdf.format((java.util.Date)retVal); > - } else if (retVal instanceof java.util.Date) { > -// DateFormat df = UtilDateTime.toDateTimeFormat("EEE MMM dd hh:mm:ss z yyyy", timeZone, null); > -// returnValue = df.format((java.util.Date) retVal); > - SimpleDateFormat sdfz=new SimpleDateFormat("EEE MMM dd hh:mm:ss z yyyy"); > - returnValue=sdfz.format((java.util.Date)retVal); > - } else { > - returnValue = retVal.toString(); > - } > + if (retVal != null) { > + // format string based on the user's locale and time zone > + if (retVal instanceof Double || retVal instanceof Float || retVal instanceof BigDecimal) { > + NumberFormat nf = NumberFormat.getInstance(locale); > + nf.setMaximumFractionDigits(10); > + returnValue = nf.format(retVal); > + } else if (retVal instanceof java.sql.Date) { > + DateFormat df = UtilDateTime.toDateFormat(UtilDateTime.DATE_FORMAT, timeZone, null); > + returnValue = df.format((java.util.Date) retVal); > + } else if (retVal instanceof java.sql.Time) { > + DateFormat df = UtilDateTime.toTimeFormat(UtilDateTime.TIME_FORMAT, timeZone, null); > + returnValue = df.format((java.util.Date) retVal); > + } else if (retVal instanceof java.sql.Timestamp) { > + DateFormat df = UtilDateTime.toDateTimeFormat(UtilDateTime.DATE_TIME_FORMAT, timeZone, null); > + returnValue = df.format((java.util.Date) retVal); > + } else if (retVal instanceof java.util.Date) { > + DateFormat df = UtilDateTime.toDateTimeFormat("EEE MMM dd hh:mm:ss z yyyy", timeZone, null); > + returnValue = df.format((java.util.Date) retVal); > + } else { > + returnValue = retVal.toString(); > + } > return returnValue; // do not encode date and number type fields > } else { > returnValue = defaultValue; > > > |
Free forum by Nabble | Edit this page |