0

From the List of Orders, i need to collect dates which are past to requesteffDate and requesteffTime and take the maximum of the past dates.

function boolean dateCheck(Date effdt, Date efftm) {
  String efffdt = new SimpleDateFormat("yyyyMMdd").format(effdt);
  String effftm = new SimpleDateFormat("HHmm").format(efftm);
  Date effdttm = new SimpleDateFormat("yyyyMMddHHmm").parse(efffdt + "" + effftm);
  return effdttm.before(new Date());
} 

rule "finding past maximum date"
when
  $company : Company( $date:requesteffDate, $time:requesteffTime, $reqdt : requesteffDate.getTime(), $reqtm : requesteffTime.getTime() )
eval(dateCheck($date,$time))
accumulate(Orders( effectiveDate != null,
                   effdate:effectiveDate.getTime()<$reqdt),
           maxEffDate:max(effdate))
then
  //error

While doing this,

accumulate(Orders(effectiveDate!=null,
                  effdate:effectiveDate.getTime()<$reqdt),
                  maxEffDate:max(effdate))

I am getting maxEffDate as -9223372036854775808 which when converted is showing 1940

Same I have tried using min functionn it is showing 2262.

My class goes like this.

Class Company{
  private Date requesteffDate;
  private Date requesteffTime;
  private Employee emp;
  private List<Orders> orderlist;
}

Class Orders{
  private Date effectiveDate;
  private Date effectiveTime;
}
laune
  • 31,114
  • 3
  • 29
  • 42
Anvesh
  • 1
  • 3
  • accumulate (Orders (effective date!=null,effcdate:effectivedate. getTime ()> $reqdt),maxdate: max (effecdate)) – Anvesh Jan 08 '18 at 03:58
  • This is not visible in post. So I wrote it as comment. But, This is not working – Anvesh Jan 08 '18 at 03:59
  • java.util.Date isn't meant for storing a time of the day. Why don't you combine xyDate and xyTime into a single Date? Or use LocalDate and LocalTime? – laune Jan 08 '18 at 09:21

1 Answers1

0

-9223372036854775808 is Long.MIN_VALUE. This is conclusive for indicating that the accumulate doesn't find any Orders.

Make sure that you insert some matching Orders facts.

Add a guard that the maxEffDate is != Long.MIN_VALUE.

Discontinue the usage of Date as a time-of-day value: Either use LocalDate and LocalTime or combine date and time into a single Date value.

Take care that conversions of date and time are not affected by your locale settings.

laune
  • 31,114
  • 3
  • 29
  • 42