1 18 19 23 24 package org.ofbiz.common.period; 25 26 import java.sql.Timestamp ; 27 import java.util.List ; 28 29 import org.ofbiz.base.util.UtilDateTime; 30 import org.ofbiz.base.util.UtilMisc; 31 import org.ofbiz.entity.GenericValue; 32 import org.ofbiz.entity.condition.EntityCondition; 33 import org.ofbiz.entity.condition.EntityConditionList; 34 import org.ofbiz.entity.condition.EntityExpr; 35 import org.ofbiz.entity.condition.EntityOperator; 36 37 public class PeriodWorker { 38 39 public static String module = PeriodWorker.class.getName(); 40 41 44 public static EntityCondition getFilterByPeriodExpr(String fieldName, GenericValue timePeriod) { 45 Timestamp fromDate; 46 Timestamp thruDate; 47 if (timePeriod.get("fromDate") instanceof Timestamp ) { 48 fromDate = timePeriod.getTimestamp("fromDate"); 49 thruDate = timePeriod.getTimestamp("thruDate"); 50 } else { 51 fromDate = UtilDateTime.toTimestamp(timePeriod.getDate("fromDate")); 52 thruDate = UtilDateTime.toTimestamp(timePeriod.getDate("thruDate")); 53 } 54 55 EntityConditionList betweenCondition = new EntityConditionList(UtilMisc.toList( 56 new EntityExpr( fieldName, EntityOperator.GREATER_THAN, fromDate ), 57 new EntityExpr( fieldName, EntityOperator.LESS_THAN_EQUAL_TO, thruDate ) 58 ), EntityOperator.AND); 59 List conditions = UtilMisc.toList(new EntityExpr( fieldName, EntityOperator.NOT_EQUAL, null ), betweenCondition); 60 return new EntityConditionList(UtilMisc.toList(conditions), EntityOperator.AND); 61 } 62 } 63 | Popular Tags |