One way would be to do dateOfBirth.time < nnnnnn
Where nnnnn is (new Date(-1900, 1,1)).getTime()
By the way be very very wary of Date objects coming back from the database and check what the actual implementation class type is (and not the variable type).
Even though java.sql.Timestamp extends java.util.Date they don’t mix.
From the Javadocs
Note: This type is a composite of a java.util.Date
and
a separate nanoseconds value. Only integral seconds are stored in the java.util.Date
component.
The fractional seconds - the nanos - are separate. TheTimestamp.equals(Object)
method
never returns true
when
passed an object that isn't an instance of java.sql.Timestamp
, because the nanos component of a date
is unknown. As a result, theTimestamp.equals(Object)
method
is not symmetric with respect to the java.util.Date.equals(Object)
method.
Also, the hashcode
method
uses the underlying java.util.Date
implementation
and therefore does not include nanos in its computation.
Due to the differences between the Timestamp
class
and the java.util.Date
class
mentioned above, it is recommended that code not view Timestamp
values
generically as an instance of java.util.Date
. The inheritance relationship between Timestamp
and java.util.Date
really
denotes implementation inheritance, and not type inheritance.
We had great fun tracking down issues in our rules caused by this – our fields were Date classes, but when fetched back from the database the instance type
would be Timestamp. The rules worked fine in unit tests and first execution (as they were all new objects the type was java.util.Date) but not on subsequent executions when they were returned from the DB!
Thomas
From: rules-users-bounces@lists.jboss.org [mailto:rules-users-bounces@lists.jboss.org]
On Behalf Of Nancy Henggeler
Sent: 09 February 2012 17:24
To: Rules Users List
Subject: Re: [rules-users] Low Date question in drools
It is a java date. We use some java binding objects to build it. Below is just a sampling of this. The second entry below indicates what to name it in Java, it's java type,
what DB2 table (cogentTable) and data field it is coming from (cogentField). The snippets below might not help much.
1) bindHistory((ECDField) object.getElement("dateOfBirth"), this.getDateOfBirthHistory());
2) <attribute name="dateOfBirth">
<type>Date</type>
<cogenTable>W1V0</cogenTable>
<cogenField>BIRTH-DATE</cogenField>
<description>Date Of Birth</description>
</attribute>
From: Wolfgang Laun <wolfgang.laun@gmail.com>
To: Rules Users List <rules-users@lists.jboss.org>
Date: 02/09/2012 11:00 AM
Subject: Re: [rules-users] Low Date question in drools
Sent by: rules-users-bounces@lists.jboss.org
So what is the Java type of dateOfBirth, please?
-W
2012/2/9 Nancy Henggeler <Nancy.Henggeler@fblfinancial.com>
Hello Laun,
Thank you for your quick response. This date is a date coming from a DB2 date field and is valid in my incoming data. Frankly, I am with you, why not null versus a silly low date as such, arggggh. But since it is coming in as such do you know of a work around?
Thank so much,
Nancy
From: Wolfgang Laun <wolfgang.laun@gmail.com>
To: Rules Users List <rules-users@lists.jboss.org>
Date: 02/09/2012 10:31 AM
Subject: Re: [rules-users] Low Date question in drools
Sent by: rules-users-bounces@lists.jboss.org
Why would you want to test for January 1st in year 1? This is not a
value an object of type java.util.Date can represent. See that type's
javadoc for details, but the epoch begins January 1, 1970.
-W
On 9 February 2012 17:19, Nancy Henggeler <nancy.henggeler@fblfinancial.com> wrote:
I have a simple rule where I want to bypass elements that have a low date but
drools seems to be interpreting the date different then I am expecting.
Drools statement and error follows:
ClientSupplement ( dateOfBirth : dateOfBirth != null && != 0001-01-01)
throws error -- Error: [Error: badly formatted number: For input string:
"001-01-01"] [Near : {... 0001-01-01 ....}] ^ [Line: 1, Column: 1]
How do I get drools to understand this low date? I have tried single,
double, and no quotes around the low date and all result in a similiar error
message. Please Help!
--
View this message in context: http://drools.46999.n3.nabble.com/Low-Date-question-in-drools-tp3729940p3729940.html
Sent from the Drools: User forum mailing list archive at Nabble.com.
_______________________________________________
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users
_______________________________________________
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users
The information contained in this message may be privileged and confidential and protected from disclosure. If you are |
_______________________________________________
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users
_______________________________________________
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users
The information contained in this message may be privileged and confidential and protected from disclosure. If you are
not the intended recipient of this message, you are hereby notified that any dissemination, distribution, or copying of this
communication is strictly prohibited. If you have received this communication in error, please notify us immediately by
replying to the message, and please delete it from your computer.
|