[rules-users] Drools and Date

AervTerrh woutervanisterdael at gmail.com
Mon Apr 5 18:45:40 EDT 2010


Hey all,

I'm having some problems.

The first one was rather easy:

I wanted to compare a Date (deadline) of my entity Task to a certain String
date.  
Apparently this does the trick: (Probably depends on Locale)
$task: Task ( deadline <  "01-APR-2009" )

But then I stumbled upon a second problem. I was wondering, how one would
allow:
$task : Task ((deadline < $currentDate) || (deadline < $currentDate +
OneDay))

I had solved this by putting a sort of object (DateKeeper) that holds the
currentDate + x * AmountOfDays in the KnowledgeSession.

Code:
 public class DateKeeper
     {

         public Date date;

         private int numberOfDaysAfterCurrentTime;

         public DateKeeper(int numberOfDays)
         {
            date = new Date(new Date().getTime() +  numberOfDays *
Timer.ONE_DAY);
            numberOfDaysAfterCurrentTime = numberOfDays;
         }

        public int getNumberOfDaysAfterCurrentTime() {
            return numberOfDaysAfterCurrentTime;
        }

        public Date getDate()
        {
            return date;
        }
     } 

Then calling it like: 
DateKeeper ( numberOfDaysAfterCurrentTime == 1, $date : date )
$task : Task ((deadline < $currentDate && priority != Priority.HIGH) ||
(deadline < $date && priority != Priority.HIGH))

But I would like to find a way to do this without the object. Like a clean
way... So users can easily create new rules by simply choosing a number of
days.

If anyone knows how to solve this, it would be very much appreciated!

Kind regards

Aerv 


-- 
View this message in context: http://n3.nabble.com/Drools-and-Date-tp698967p698967.html
Sent from the Drools - User mailing list archive at Nabble.com.



More information about the rules-users mailing list