Author: jleroux
Date: Mon Aug 22 04:11:57 2016 New Revision: 1757103 URL: http://svn.apache.org/viewvc?rev=1757103&view=rev Log: An updated patch from Supatthra Nawicha for "PrepareFind Service Ignores timeZone Parameter When Performing Date/Time Calculations" https://issues.apache.org/jira/browse/OFBIZ-3739 The patch was stale for trunk, but OK for branches Modified: ofbiz/branches/release13.07/framework/common/src/org/ofbiz/common/FindServices.java ofbiz/branches/release14.12/framework/common/src/org/ofbiz/common/FindServices.java ofbiz/branches/release15.12/framework/common/src/org/ofbiz/common/FindServices.java Modified: ofbiz/branches/release13.07/framework/common/src/org/ofbiz/common/FindServices.java URL: http://svn.apache.org/viewvc/ofbiz/branches/release13.07/framework/common/src/org/ofbiz/common/FindServices.java?rev=1757103&r1=1757102&r2=1757103&view=diff ============================================================================== --- ofbiz/branches/release13.07/framework/common/src/org/ofbiz/common/FindServices.java (original) +++ ofbiz/branches/release13.07/framework/common/src/org/ofbiz/common/FindServices.java Mon Aug 22 04:11:57 2016 @@ -27,6 +27,7 @@ import java.util.List; import java.util.Locale; import java.util.Map; import java.util.Set; +import java.util.TimeZone; import javolution.util.FastList; import javolution.util.FastMap; @@ -293,6 +294,8 @@ public class FindServices { public static EntityCondition createSingleCondition(ModelField modelField, String operation, Object fieldValue, boolean ignoreCase, Delegator delegator, Map<String, ?> context) { EntityCondition cond = null; String fieldName = modelField.getName(); + Locale locale = (Locale) context.get("locale"); + TimeZone timeZone = (TimeZone) context.get("timeZone"); EntityComparisonOperator<?, ?> fieldOp = null; if (operation != null) { if (operation.equals("contains")) { @@ -317,13 +320,13 @@ public class FindServices { fieldOp = EntityOperator.LESS_THAN_EQUAL_TO; } else if (operation.equals("greaterThanFromDayStart")) { String timeStampString = (String) fieldValue; - Object startValue = modelField.getModelEntity().convertFieldValue(modelField, dayStart(timeStampString, 0), delegator, context); + Object startValue = modelField.getModelEntity().convertFieldValue(modelField, dayStart(timeStampString, 0, timeZone, locale), delegator, context); return EntityCondition.makeCondition(fieldName, EntityOperator.GREATER_THAN_EQUAL_TO, startValue); } else if (operation.equals("sameDay")) { String timeStampString = (String) fieldValue; - Object startValue = modelField.getModelEntity().convertFieldValue(modelField, dayStart(timeStampString, 0), delegator, context); + Object startValue = modelField.getModelEntity().convertFieldValue(modelField, dayStart(timeStampString, 0, timeZone, locale), delegator, context); EntityCondition startCond = EntityCondition.makeCondition(fieldName, EntityOperator.GREATER_THAN_EQUAL_TO, startValue); - Object endValue = modelField.getModelEntity().convertFieldValue(modelField, dayStart(timeStampString, 1), delegator, context); + Object endValue = modelField.getModelEntity().convertFieldValue(modelField, dayStart(timeStampString, 1, timeZone, locale), delegator, context); EntityCondition endCond = EntityCondition.makeCondition(fieldName, EntityOperator.LESS_THAN, endValue); return EntityCondition.makeCondition(startCond, endCond); } else { @@ -634,7 +637,7 @@ public class FindServices { return results; } - private static String dayStart(String timeStampString, int daysLater) { + private static String dayStart(String timeStampString, int daysLater, TimeZone timeZone, Locale locale) { String retValue = null; Timestamp ts = null; Timestamp startTs = null; @@ -648,7 +651,7 @@ public class FindServices { return retValue; } } - startTs = UtilDateTime.getDayStart(ts, daysLater); + startTs = UtilDateTime.getDayStart(ts, daysLater, timeZone, locale); retValue = startTs.toString(); return retValue; } Modified: ofbiz/branches/release14.12/framework/common/src/org/ofbiz/common/FindServices.java URL: http://svn.apache.org/viewvc/ofbiz/branches/release14.12/framework/common/src/org/ofbiz/common/FindServices.java?rev=1757103&r1=1757102&r2=1757103&view=diff ============================================================================== --- ofbiz/branches/release14.12/framework/common/src/org/ofbiz/common/FindServices.java (original) +++ ofbiz/branches/release14.12/framework/common/src/org/ofbiz/common/FindServices.java Mon Aug 22 04:11:57 2016 @@ -30,6 +30,7 @@ import java.util.List; import java.util.Locale; import java.util.Map; import java.util.Set; +import java.util.TimeZone; import org.ofbiz.base.util.Debug; import org.ofbiz.base.util.ObjectType; @@ -294,6 +295,8 @@ public class FindServices { public static EntityCondition createSingleCondition(ModelField modelField, String operation, Object fieldValue, boolean ignoreCase, Delegator delegator, Map<String, ?> context) { EntityCondition cond = null; String fieldName = modelField.getName(); + Locale locale = (Locale) context.get("locale"); + TimeZone timeZone = (TimeZone) context.get("timeZone"); EntityComparisonOperator<?, ?> fieldOp = null; if (operation != null) { if (operation.equals("contains")) { @@ -318,13 +321,13 @@ public class FindServices { fieldOp = EntityOperator.LESS_THAN_EQUAL_TO; } else if (operation.equals("greaterThanFromDayStart")) { String timeStampString = (String) fieldValue; - Object startValue = modelField.getModelEntity().convertFieldValue(modelField, dayStart(timeStampString, 0), delegator, context); + Object startValue = modelField.getModelEntity().convertFieldValue(modelField, dayStart(timeStampString, 0, timeZone, locale), delegator, context); return EntityCondition.makeCondition(fieldName, EntityOperator.GREATER_THAN_EQUAL_TO, startValue); } else if (operation.equals("sameDay")) { String timeStampString = (String) fieldValue; - Object startValue = modelField.getModelEntity().convertFieldValue(modelField, dayStart(timeStampString, 0), delegator, context); + Object startValue = modelField.getModelEntity().convertFieldValue(modelField, dayStart(timeStampString, 0, timeZone, locale), delegator, context); EntityCondition startCond = EntityCondition.makeCondition(fieldName, EntityOperator.GREATER_THAN_EQUAL_TO, startValue); - Object endValue = modelField.getModelEntity().convertFieldValue(modelField, dayStart(timeStampString, 1), delegator, context); + Object endValue = modelField.getModelEntity().convertFieldValue(modelField, dayStart(timeStampString, 1, timeZone, locale), delegator, context); EntityCondition endCond = EntityCondition.makeCondition(fieldName, EntityOperator.LESS_THAN, endValue); return EntityCondition.makeCondition(startCond, endCond); } else { @@ -643,7 +646,7 @@ public class FindServices { return results; } - private static String dayStart(String timeStampString, int daysLater) { + private static String dayStart(String timeStampString, int daysLater, TimeZone timeZone, Locale locale) { String retValue = null; Timestamp ts = null; Timestamp startTs = null; @@ -657,7 +660,7 @@ public class FindServices { return retValue; } } - startTs = UtilDateTime.getDayStart(ts, daysLater); + startTs = UtilDateTime.getDayStart(ts, daysLater, timeZone, locale); retValue = startTs.toString(); return retValue; } Modified: ofbiz/branches/release15.12/framework/common/src/org/ofbiz/common/FindServices.java URL: http://svn.apache.org/viewvc/ofbiz/branches/release15.12/framework/common/src/org/ofbiz/common/FindServices.java?rev=1757103&r1=1757102&r2=1757103&view=diff ============================================================================== --- ofbiz/branches/release15.12/framework/common/src/org/ofbiz/common/FindServices.java (original) +++ ofbiz/branches/release15.12/framework/common/src/org/ofbiz/common/FindServices.java Mon Aug 22 04:11:57 2016 @@ -30,6 +30,7 @@ import java.util.List; import java.util.Locale; import java.util.Map; import java.util.Set; +import java.util.TimeZone; import org.ofbiz.base.util.Debug; import org.ofbiz.base.util.ObjectType; @@ -293,6 +294,8 @@ public class FindServices { public static EntityCondition createSingleCondition(ModelField modelField, String operation, Object fieldValue, boolean ignoreCase, Delegator delegator, Map<String, ?> context) { EntityCondition cond = null; String fieldName = modelField.getName(); + Locale locale = (Locale) context.get("locale"); + TimeZone timeZone = (TimeZone) context.get("timeZone"); EntityComparisonOperator<?, ?> fieldOp = null; if (operation != null) { if (operation.equals("contains")) { @@ -317,13 +320,13 @@ public class FindServices { fieldOp = EntityOperator.LESS_THAN_EQUAL_TO; } else if (operation.equals("greaterThanFromDayStart")) { String timeStampString = (String) fieldValue; - Object startValue = modelField.getModelEntity().convertFieldValue(modelField, dayStart(timeStampString, 0), delegator, context); + Object startValue = modelField.getModelEntity().convertFieldValue(modelField, dayStart(timeStampString, 0, timeZone, locale), delegator, context); return EntityCondition.makeCondition(fieldName, EntityOperator.GREATER_THAN_EQUAL_TO, startValue); } else if (operation.equals("sameDay")) { String timeStampString = (String) fieldValue; - Object startValue = modelField.getModelEntity().convertFieldValue(modelField, dayStart(timeStampString, 0), delegator, context); + Object startValue = modelField.getModelEntity().convertFieldValue(modelField, dayStart(timeStampString, 0, timeZone, locale), delegator, context); EntityCondition startCond = EntityCondition.makeCondition(fieldName, EntityOperator.GREATER_THAN_EQUAL_TO, startValue); - Object endValue = modelField.getModelEntity().convertFieldValue(modelField, dayStart(timeStampString, 1), delegator, context); + Object endValue = modelField.getModelEntity().convertFieldValue(modelField, dayStart(timeStampString, 1, timeZone, locale), delegator, context); EntityCondition endCond = EntityCondition.makeCondition(fieldName, EntityOperator.LESS_THAN, endValue); return EntityCondition.makeCondition(startCond, endCond); } else { @@ -658,7 +661,7 @@ public class FindServices { return results; } - private static String dayStart(String timeStampString, int daysLater) { + private static String dayStart(String timeStampString, int daysLater, TimeZone timeZone, Locale locale) { String retValue = null; Timestamp ts = null; Timestamp startTs = null; @@ -672,7 +675,7 @@ public class FindServices { return retValue; } } - startTs = UtilDateTime.getDayStart(ts, daysLater); + startTs = UtilDateTime.getDayStart(ts, daysLater, timeZone, locale); retValue = startTs.toString(); return retValue; } |
Free forum by Nabble | Edit this page |