<br> Michael,<br><br> Just an important note, that sometimes is overlooked by users: <br><br>*** Inline evals and return value predicates MUST be time constant ***<br><br> 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.<br>
The correct way would be to use a top level eval() that does not suffer from the same restriction:<br><br>
MyFact( $value : value )<br> eval( $value.before(DateHelper.getModifiedDate(-6, "MONTHS")))<br><br> The use of a non-time-constant inline eval (or return value predicates) causes unpredictable behavior in the engine.<br>
<br> []s<br> Edson<br><br><br><div class="gmail_quote">2008/5/7 Michael B. <<a href="mailto:michael.bain@mckesson.com">michael.bain@mckesson.com</a>>:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<br>
I dont know if this is still outstanding since the original post seems to<br>
have disappeared, but this is what I did during my proof of concept that I<br>
am going through:<br>
<br>
In a helper class (i.e. DateHelper) I had this method:<br>
<br>
public static Date getModifiedDate(int amount, String unit) {<br>
Calendar cal = Calendar.getInstance();<br>
cal.setTime(getNow());<br>
BusinessObject.stripTime(cal);<br>
<br>
int calUnit = Calendar.DAY_OF_YEAR;<br>
<br>
if (UNIT_MONTHS.equals(unit))<br>
calUnit = Calendar.MONTH;<br>
else if (UNIT_YEARS.equals(unit))<br>
calUnit = Calendar.YEAR;<br>
<br>
cal.add(calUnit, amount);<br>
return cal.getTime();<br>
}<br>
<br>
Then in my rule it would be like this:<br>
<br>
MyFact( eval( value.before(DateHelper.getModifiedDate(-6, "MONTHS"))))<br>
<br>
Hope that helps.<br>
<br>
-----<br>
Drools Noob since 5/2008<br>
<font color="#888888">--<br>
View this message in context: <a href="http://www.nabble.com/Re%3A-Date-arithmetic-in--%C3%A2%C2%80%C2%9Cwhen%C3%A2%C2%80%C2%9D-session-tp17103754p17106177.html" target="_blank">http://www.nabble.com/Re%3A-Date-arithmetic-in--%C3%A2%C2%80%C2%9Cwhen%C3%A2%C2%80%C2%9D-session-tp17103754p17106177.html</a><br>
</font><div><div></div><div class="Wj3C7c">Sent from the drools - user mailing list archive at Nabble.com.<br>
<br>
_______________________________________________<br>
rules-users mailing list<br>
<a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
</div></div></blockquote></div><br><br clear="all"><br>-- <br> Edson Tirelli<br> JBoss Drools Core Development<br> Office: +55 11 3529-6000<br> Mobile: +55 11 9287-5646<br> JBoss, a division of Red Hat @ <a href="http://www.jboss.com">www.jboss.com</a>