<br>&nbsp;&nbsp;&nbsp; All,<br><br>&nbsp;&nbsp;&nbsp; Unfortunately the problem of dealing with a clock in a rules engine is a lot more complex than it seems at first.<br><br>&nbsp; &nbsp; David, your best bet is to create an instance of a clock class, insert as a fact and update this fact from time to time when you want your rules to be reevaluated. Do not use any Calendar.getInstance() or System.currentTimeMillis() in the LHS of your rules, because you will get inconsistent behavior. Also, once you have the clock as a fact, I back the suggestion of using a library like JodaTime for date arithmetics.<br>
<br>&nbsp;&nbsp;&nbsp; If you want to go the extra mile, you can implement your own operators in drools, but in Drools 4 this is still not as simple as in Drools 5.<br><br>&nbsp;&nbsp;&nbsp; Just to reinforce, the problem is not handling dates themselves. The problem is constraining your rules against the concept of &quot;current time&quot; because that is mutable.<br>
<br>&nbsp;&nbsp;&nbsp; Michael&#39;s idea of using collect/accumulate for counting days is creative, but unfortunately too heavy for practical uses I am afraid.<br><br>&nbsp;&nbsp;&nbsp; Good luck,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Edson<br><br>&nbsp;&nbsp;&nbsp; <br><br><div class="gmail_quote">
2009/1/29 Anstis, Michael (M.) <span dir="ltr">&lt;<a href="mailto:manstis1@ford.com">manstis1@ford.com</a>&gt;</span><br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">




<div>
<div dir="ltr" align="left"><span><font size="2" color="#0000ff" face="Arial">You got it.</font></span></div>
<div dir="ltr" align="left"><span><font size="2" color="#0000ff" face="Arial"></font></span>&nbsp;</div>
<div dir="ltr" align="left"><span><font size="2" color="#0000ff" face="Arial">You won&#39;t find this proposal in any pattern books!! 
;-)</font></span></div>
<div dir="ltr" align="left"><span><font size="2" color="#0000ff" face="Arial"></font></span>&nbsp;</div>
<div dir="ltr" align="left"><span><font size="2" color="#0000ff" face="Arial">At least you understood the syntax, so you can now 
officially consider yourself not a noob.</font></span></div><br>
<blockquote style="margin-right: 0px;">
  <div dir="ltr" align="left" lang="en-us">
  <hr>
  <font size="2" face="Tahoma"><div class="Ih2E3d"><b>From:</b> <a href="mailto:rules-users-bounces@lists.jboss.org" target="_blank">rules-users-bounces@lists.jboss.org</a> 
  [mailto:<a href="mailto:rules-users-bounces@lists.jboss.org" target="_blank">rules-users-bounces@lists.jboss.org</a>] <b>On Behalf Of </b>David 
  Siefert<br></div><b>Sent:</b> 29 January 2009 12:59<div><div></div><div class="Wj3C7c"><br><b>To:</b> Rules Users 
  List<br><b>Subject:</b> Re: [rules-users] Working with dates in 
  rules<br></div></div></font><br></div><div><div></div><div class="Wj3C7c">
  <div></div>
  <div>Ah! Sorry, I believe you were saying Day is a fact that I would have to 
  create for each likely day....&nbsp; The collect operation is what gathers all 
  those (Day) facts into a list that is counted. so the rule fires if there is 
  more than 0 day facts.</div>
  <div>&nbsp;</div>
  <div>My bad!</div>
  <div>&nbsp;</div>
  <div>Thanks,</div>
  <div>David<br><br></div>
  <div class="gmail_quote">On Thu, Jan 29, 2009 at 6:53 AM, David Siefert <span dir="ltr">&lt;<a href="mailto:siefert.david.mailinglist@gmail.com" target="_blank">siefert.david.mailinglist@gmail.com</a>&gt;</span> 
  wrote:<br>
  <blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0px 0px 0px 0.8ex; padding-left: 1ex;">
    <div>Hey, that was quite clever.&nbsp; Where can I find more about 
    Day()?&nbsp; I did some research about DateFactory which I can see how dates 
    get parsed according to the documentation, as well as compared with the 
    conditional operators (&lt;, &gt;, &lt;=, &gt;=, etc).</div>
    <div>&nbsp;</div>
    <div>Thanks,</div>
    <div>David<font color="#888888"><br><br></font></div>
    <div>
    <div></div>
    <div>
    <div class="gmail_quote">On Thu, Jan 29, 2009 at 5:57 AM, Anstis, Michael (M.) 
    <span dir="ltr">&lt;<a href="mailto:manstis1@ford.com" target="_blank">manstis1@ford.com</a>&gt;</span> wrote:<br>
    <blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0px 0px 0px 0.8ex; padding-left: 1ex;">
      <div>
      <div dir="ltr" align="left"><span><font size="2" color="#0000ff" face="Arial">Hi 
      David,</font></span></div>
      <div dir="ltr" align="left"><span><font size="2" color="#0000ff" face="Arial"></font></span>&nbsp;</div>
      <div dir="ltr" align="left"><span><font size="2" color="#0000ff" face="Arial">Sorry 
      it was of little help.</font></span></div>
      <div dir="ltr" align="left"><span><font size="2" color="#0000ff" face="Arial"></font></span>&nbsp;</div>
      <div dir="ltr" align="left"><span><font size="2" color="#0000ff" face="Arial">A rule 
      of thumb is to stay away from &quot;eval&quot; as it kills performance (the patterns 
      can&#39;t be indexed).</font></span></div>
      <div dir="ltr" align="left"><span><font size="2" color="#0000ff" face="Arial"></font></span>&nbsp;</div>
      <div dir="ltr" align="left"><span><font size="2" color="#0000ff" face="Arial">I&#39;m 
      not sure if Drools can handle Date variables (the docs state it handles 
      Data literals formatted as &quot;dd-mmm-yyyy&quot; so Cheese( date == &quot;27-Oct-2008&quot;) 
      works).</font></span></div>
      <div dir="ltr" align="left"><span><font size="2" color="#0000ff" face="Arial"></font></span>&nbsp;</div>
      <div dir="ltr" align="left"><span><font size="2" color="#0000ff" face="Arial">I 
      guess you could look at something like this (gees, this is going to show 
      how &quot;green&quot; I am with Drools now):-</font></span></div>
      <div dir="ltr" align="left"><span><font size="2" color="#0000ff" face="Arial"></font></span>&nbsp;</div>
      <div dir="ltr" align="left"><span><font size="2" color="#0000ff" face="Courier New">rule &quot;yuck&quot;</font></span></div>
      <div dir="ltr" align="left"><span><font face="Courier New"><font size="2" color="#0000ff">&nbsp;&nbsp;&nbsp; when</font></font></span></div>
      <div dir="ltr" align="left"><span><font face="Courier New"><font size="2" color="#0000ff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; DateFactory($today : 
      today&nbsp;)</font></font></span></div>
      <div dir="ltr" align="left"><span><font face="Courier New"><font size="2" color="#0000ff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $c : CreditCard( 
      $expires : expirationDate )</font></font></span></div>
      <div dir="ltr" align="left"><span><font size="2" color="#0000ff" face="Courier New">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ArrayList( size &gt;= 0 
      ) from collect( Day(&nbsp;date&nbsp;&gt;= $today, date &lt;= $expires 
      ))<br>&nbsp;&nbsp;&nbsp; then</font></span></div>
      <div dir="ltr" align="left"><span><font face="Courier New"><font size="2" color="#0000ff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //Difference between 
      &quot;today&quot; and &quot;expiry date&quot; is more than zero 
days</font></font></span></div>
      <div dir="ltr" align="left"><font size="2"><font color="#0000ff"><font face="Courier New"><span>end</span><span></span></font></font></font></div>
      <div dir="ltr" align="left"><span><font size="2" color="#0000ff" face="Arial"></font></span>&nbsp;</div>
      <div dir="ltr" align="left"><span><font size="2" color="#0000ff" face="Arial">This 
      does require the insertion of (possibly) huge amounts of Day facts. Yuck. 
      There must be a better way (in fact your eval looks soooo much cleaner). 
      I&#39;m just throwing out ideas. </font></span></div>
      <div dir="ltr" align="left"><span><font size="2" color="#0000ff" face="Arial"></font></span>&nbsp;</div>
      <div dir="ltr" align="left"><span><font size="2" color="#0000ff" face="Arial">Good 
      luck with your adventures with Drools.</font></span></div>
      <div dir="ltr" align="left"><span><font size="2" color="#0000ff" face="Arial"></font></span>&nbsp;</div>
      <div dir="ltr" align="left"><span><font size="2" color="#0000ff" face="Arial">Mike</font></span></div><br>
      <blockquote style="margin-right: 0px;">
        <div dir="ltr" align="left" lang="en-us">
        <hr>
        <font size="2" face="Tahoma">
        <div><b>From:</b> <a href="mailto:rules-users-bounces@lists.jboss.org" target="_blank">rules-users-bounces@lists.jboss.org</a> [mailto:<a href="mailto:rules-users-bounces@lists.jboss.org" target="_blank">rules-users-bounces@lists.jboss.org</a>] <b>On Behalf Of 
        </b>David Siefert<br></div><b>Sent:</b> 29 January 2009 
        11:31<br><b>To:</b> Rules Users List<br><b>Subject:</b> Re: 
        [rules-users] Working with dates in rules<br></font><br></div>
        <div>
        <div></div>
        <div>
        <div></div>
        <div>Not sure--Drools 5 temporal reasoning looks like it would be the 
        answer.&nbsp; Only problem is that I need a solution now, so I am stuck 
        with Drools 4.</div>
        <div>&nbsp;</div>
        <div>This did give me some ideas though.&nbsp; I created myself a class 
        called TemporalReasoner.&nbsp; This has a few methods, namely to roll a 
        date (so I can tell it x amount of time from now), and then compare it 
        to another date.</div>
        <div>&nbsp;</div>
        <div>So in my rule, lets say I have a fact CreditCard with property 
        expiration:Date (speaking uml-ishly for &quot;a property 
        named&nbsp;&#39;expiration&#39; of type Date&quot;):</div>
        <div>&nbsp;</div>
        <div><font face="courier new,monospace">rule &quot;Fires when expiration less 
        than today&quot;</font></div>
        <div><font face="courier new,monospace">&nbsp; when</font></div>
        <div><font face="courier new,monospace">&nbsp;&nbsp;&nbsp; $c: 
        CreditCard($expires : expirationDate)</font></div>
        <div><font face="courier new,monospace">&nbsp;&nbsp;&nbsp; eval(new 
        TemporalReasoner(Calendar.getInstance()).lessThan($expires))</font></div>
        <div><font face="courier new,monospace">&nbsp; then</font></div>
        <div><font face="courier new,monospace">&nbsp;&nbsp;&nbsp; // do 
        something for when credit card is still valid</font></div>
        <div><font face="courier new,monospace">end</font></div>
        <div>&nbsp;</div>
        <div>Now, I&#39;m still generally a noob with BRs, so I&#39;m not sure how this 
        will affect performance.&nbsp; Any advice?</div>
        <div>&nbsp;</div>
        <div>Thanks,</div>
        <div>David<br><br></div>
        <div class="gmail_quote">On Thu, Jan 29, 2009 at 3:50 AM, Anstis, Michael 
        (M.) <span dir="ltr">&lt;<a href="mailto:manstis1@ford.com" target="_blank">manstis1@ford.com</a>&gt;</span> wrote:<br>
        <blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0px 0px 0px 0.8ex; padding-left: 1ex;">
          <div>
          <div dir="ltr" align="left"><span><font size="2" color="#0000ff" face="Arial">Hi,</font></span></div>
          <div dir="ltr" align="left"><span><font size="2" color="#0000ff" face="Arial"></font></span>&nbsp;</div>
          <div dir="ltr" align="left"><span><font size="2" color="#0000ff" face="Arial">I 
          wonder whether Drools 5 &quot;Complex Event Processing Support (Temporal 
          Reasoning)&quot; might be what you&#39;re looking for?</font></span></div>
          <div dir="ltr" align="left"><span><font size="2" color="#0000ff" face="Arial"></font></span>&nbsp;</div>
          <div dir="ltr" align="left"><span><font size="2" color="#0000ff" face="Arial"><a href="http://blog.athico.com/2008/07/drools-50-m1-new-and-noteworthy.html" target="_blank">http://blog.athico.com/2008/07/drools-50-m1-new-and-noteworthy.html</a></font></span></div>

          <div dir="ltr" align="left"><span><font size="2" color="#0000ff" face="Arial"></font></span>&nbsp;</div>
          <div dir="ltr" align="left"><span><font size="2" color="#0000ff" face="Arial">With kind regards,</font></span></div>
          <div dir="ltr" align="left"><span><font size="2" color="#0000ff" face="Arial"></font></span>&nbsp;</div>
          <div dir="ltr" align="left"><span><font size="2" color="#0000ff" face="Arial">Mike</font></span></div><br>
          <blockquote dir="ltr" style="margin-right: 0px;">
            <div dir="ltr" align="left" lang="en-us">
            <hr>
            <font size="2" face="Tahoma"><b>From:</b> <a href="mailto:rules-users-bounces@lists.jboss.org" target="_blank">rules-users-bounces@lists.jboss.org</a> [mailto:<a href="mailto:rules-users-bounces@lists.jboss.org" target="_blank">rules-users-bounces@lists.jboss.org</a>] <b>On Behalf 
            Of </b>David Siefert<br><b>Sent:</b> 29 January 2009 
            09:40<br><b>To:</b> Rules Users List<br><b>Subject:</b> 
            [rules-users] Working with dates in rules<br></font><br></div>
            <div>
            <div></div>
            <div>
            <div></div>
            <div>Hi-</div>
            <div>&nbsp;</div>
            <div>I&#39;m wondering how it would be possible to compare a part of a 
            date in the lhs condition of a rule in a Drool.&nbsp; In other 
            words, I need to compare a date to see if it is&nbsp;<i>x</i> days 
            from the current date,&nbsp;<i>n</i> hours from current time, 
            etc.&nbsp; Would anyone be kind enough to provide an example?&nbsp; 
            I&#39;m thinking I may have to implement something of my own to offer 
            that functionality?</div>
            <div>&nbsp;</div>
            <div>Big thanks,</div>
            <div>David</div></div></div></blockquote></div><br>_______________________________________________<br>rules-users 
          mailing list<br><a href="mailto:rules-users@lists.jboss.org" target="_blank">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>
<br></blockquote></div><br></div></div></blockquote></div><br>_______________________________________________<br>rules-users 
      mailing list<br><a href="mailto:rules-users@lists.jboss.org" target="_blank">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>
<br></blockquote></div><br></div></div></blockquote></div><br></div></div></blockquote></div>
<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>
<br></blockquote></div><br><br clear="all"><br>-- <br> &nbsp;Edson Tirelli<br> &nbsp;JBoss Drools Core Development<br> &nbsp;JBoss, a division of Red Hat @ <a href="http://www.jboss.com">www.jboss.com</a><br>