You must be careful with the concept of "current date" when writing
rules in RETE: remember that RETE works in 2 stages:
1. at "insert" time, all the rule constraints are evaluated.
2. at "fire" time, the active rules are simply executed.
Also, note that using non-time constant expressions in an inline-eval is
wrong and will give you unpredictable results. The only way to use non-time
constant expressions is at a top level eval (not inline-eval).
So, having said all that, I suggest you use either a fact or a global to
represent your "clock", so that you have a way to control when and how the
clock is updated and use this pseudo clock to constrain your facts.
Also, we are working on supporting temporal constructs in drools as we
speak, and as soon as we have that, we hope it will be a lot easier to write
(safe) temporal constrained rules.
2007/10/26, Miguel Figueiredo <mfigueiredo(a)telbit.pt>:
I have a fact MyFact that has a Date field in it, and I want to check if
difference between this date and the current date is greater than 10
The function timediff() returns the difference in seconds between a date
the current date.
fact : MyFact(date : fact, eval(timediff(date) > 10));
System.out.println("Greater than 10 seconds");
When I fire the rules, and the difference is less than 10 seconds nothing
happens. The next time that I fire the rules and the difference is greater
than 10 seconds nothing happens as well.
How can I make this work?
rules-users mailing list
Software Engineer - JBoss Rules Core Developer
Office: +55 11 3529-6000
Mobile: +55 11 9287-5646
JBoss, a division of Red Hat @ www.jboss.com