[rules-users] Date arithmetic in when part

Wolfgang Laun wolfgang.laun at gmail.com
Wed Jun 29 03:20:48 EDT 2011


Currently (5.2.0, but not <= 5.1.1) you can do:

rule future
when
    Date( $t: time ) from new Date()
    $p: Person( $dob: dob after[0] $t )
then
    System.out.println( $p.getName() + " not born yet." );
end

There are indeed some restrictions w.r.t. the use of temporal operators but
comparing Date/long field to Date/long field is OK.

(@Lisa: You realize that new Date() is somewhat unprecise when used to mean
"today".)

-W

On 29 June 2011 01:04, lhorton <LHorton at abclegal.com> wrote:

> Interesting.  I tried to use this syntax to find out if a date is older
> than
> "now" using this source:
>
> $p2: Person( $dob2: dob before[3d] new Date() )
>
> but I get and exception: org.drools.RuntimeDroolsException: The 'before'
> operator can only be used to compare one event to another, and never to
> compare to literal constraints.
>
> any idea how to compare to "new Date()"?  I had already written a function
> to do this date comparison, but will use the Drools syntax instead if I can
> get this to work.
>
> --
> View this message in context:
> http://drools.46999.n3.nabble.com/rules-users-Date-arithmetic-in-when-part-tp3118246p3119793.html
> Sent from the Drools: User forum mailing list archive at Nabble.com.
> _______________________________________________
> rules-users mailing list
> rules-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-users/attachments/20110629/f1d6e7ca/attachment.html 


More information about the rules-users mailing list