Re: [rules-users] Date arithmetic in “when” session

Michael B. michael.bain at mckesson.com
Wed May 7 10:31:33 EDT 2008


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.




More information about the rules-users mailing list