Miguel,
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.
Edson
2007/10/26, Miguel Figueiredo <mfigueiredo(a)telbit.pt>:
Hi listers,
I have a fact MyFact that has a Date field in it, and I want to check if
the
difference between this date and the current date is greater than 10
seconds:
The function timediff() returns the difference in seconds between a date
and
the current date.
Rule:
rule myRule
when
fact : MyFact(date : fact, eval(timediff(date) > 10));
then
System.out.println("Greater than 10 seconds");
end
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?
Best regards,
Miguel
_______________________________________________
rules-users mailing list
rules-users(a)lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users
--
Edson Tirelli
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