Date equal comparison fails - don't understand why

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Date equal comparison fails - don't understand why

karim
Hi

I am comparing SimpleAccount( dateAccountOpened == "5-Feb-2011")
where dateAccountOpened is "Sat Feb 05 00:00:00 GMT+02:00 2011" (if you
call toString()). The equal comparator fails (==) but the greater than
comparator passes (>) which I don't understand.

I feel I am missing something obvious here, but I have no idea what it
is.


rule "Test date equality"
        when
                $acc : SimpleAccount( dateAccountOpened == "5-Feb-2011")

        then
                System.out.println("Expected and found an account opened
on 5-Feb-2011: " + $acc);
end

rule "Some dates are more equal than others"
        when
                $acc : SimpleAccount( dateAccountOpened > "5-Feb-2011")

        then
                System.out.println("Unexpected match: " +
$acc.getDateAccountOpened());
end

Regards,
Karim

To read FirstRand Bank's Disclaimer for this email click on the following address or copy into your Internet browser:
https://www.fnb.co.za/disclaimer.html 

If you are unable to access the Disclaimer, send a blank e-mail to
[hidden email] and we will send you a copy of the Disclaimer.

_______________________________________________
rules-users mailing list
[hidden email]
https://lists.jboss.org/mailman/listinfo/rules-users

DroolsDateTest.java (3K) Download Attachment
DateTest.drl (666 bytes) Download Attachment
SimpleAccount.java (1K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Date equal comparison fails - don't understand why

laune
There is a time zone offset != 0 in the toString-ed date.
-W

2011/2/10 Saloojee, Karim <[hidden email]>
Hi

I am comparing SimpleAccount( dateAccountOpened == "5-Feb-2011")
where dateAccountOpened is "Sat Feb 05 00:00:00 GMT+02:00 2011" (if you
call toString()). The equal comparator fails (==) but the greater than
comparator passes (>) which I don't understand.

I feel I am missing something obvious here, but I have no idea what it
is.


rule "Test date equality"
       when
               $acc : SimpleAccount( dateAccountOpened == "5-Feb-2011")

       then
               System.out.println("Expected and found an account opened
on 5-Feb-2011: " + $acc);
end

rule "Some dates are more equal than others"
       when
               $acc : SimpleAccount( dateAccountOpened > "5-Feb-2011")

       then
               System.out.println("Unexpected match: " +
$acc.getDateAccountOpened());
end

Regards,
Karim

To read FirstRand Bank's Disclaimer for this email click on the following address or copy into your Internet browser:
https://www.fnb.co.za/disclaimer.html

If you are unable to access the Disclaimer, send a blank e-mail to
[hidden email] and we will send you a copy of the Disclaimer.

_______________________________________________
rules-users mailing list
[hidden email]
https://lists.jboss.org/mailman/listinfo/rules-users



_______________________________________________
rules-users mailing list
[hidden email]
https://lists.jboss.org/mailman/listinfo/rules-users
Reply | Threaded
Open this post in threaded view
|

Re: Date equal comparison fails - don't understand why

braveheart85
Hello,

I have the same issue of Karim.
Is there a way to tell Drools to not consider time zone offset?

I wrote:

     Person( birthDate > "15-Feb-1985" )

birthDate is created with SimpleDateFormat (dd-MMM-yyyy) and I checked it that doesn't have millis.

Best Regards
Andrea