Michael,

   Just an important note, that sometimes is overlooked by users:

*** Inline evals and return value predicates MUST be time constant ***

   It means that an inline eval() must return the exact same value if it is executed now, or in 5 minutes from now, or whatever. So, it is not advisable for you to write the constraint as you did.
   The correct way would be to use a top level eval() that does not suffer from the same restriction:

  MyFact( $value : value )
  eval( $value.before(DateHelper.getModifiedDate(-6, "MONTHS")))

    The use of a non-time-constant inline eval (or return value predicates) causes unpredictable behavior in the engine.

    []s
    Edson


2008/5/7 Michael B. <michael.bain@mckesson.com>:

I dont know if this is still outstanding since the original post seems to
have disappeared, but this is what I did during my proof of concept that I
am going through:

In a helper class (i.e. DateHelper) I had this method:

   public static Date getModifiedDate(int amount, String unit) {
       Calendar cal = Calendar.getInstance();
       cal.setTime(getNow());
       BusinessObject.stripTime(cal);

       int calUnit = Calendar.DAY_OF_YEAR;

       if (UNIT_MONTHS.equals(unit))
           calUnit = Calendar.MONTH;
       else if (UNIT_YEARS.equals(unit))
           calUnit = Calendar.YEAR;

       cal.add(calUnit, amount);
       return cal.getTime();
   }

Then in my rule it would be like this:

 MyFact( eval( value.before(DateHelper.getModifiedDate(-6, "MONTHS"))))

Hope that helps.

-----
Drools Noob since 5/2008
--
View this message in context: http://www.nabble.com/Re%3A-Date-arithmetic-in--%C3%A2%C2%80%C2%9Cwhen%C3%A2%C2%80%C2%9D-session-tp17103754p17106177.html
Sent from the drools - user mailing list archive at Nabble.com.

_______________________________________________
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users



--
Edson Tirelli
JBoss Drools Core Development
Office: +55 11 3529-6000
Mobile: +55 11 9287-5646
JBoss, a division of Red Hat @ www.jboss.com