[rules-users] AGE problem

Pavel Tavoda pavel.tavoda at gmail.com
Thu Feb 18 07:43:29 EST 2010


Hello,
I would like to calculate AGE of object based on Date inside object, I
can use eval but I hope it's so basic functionality that Drools should
have it. It's also performance problem if I need to use EVAL in many
rules (let's say 100 in XLS). I'm playing with some FUSION features
like:
     $now : Now() && $order : SecurityOrder(this before[400d, 0d] $now)
should work but I can't specify YEARS as constant. That's a problem
for long time because 30*365d isn't same as 30 years if you consider
leap years. Is it possible some easy way to calculate AGE of something
with correct time handling and compare to years? Something like:
    SecurityOrder( age(createdDate) > 20y, age(createdDate) < 25y)
or by FUSION:
     $now : Now() && $order : SecurityOrder(this before[25y, 20y] $now)

For now I'm using following function in eval() but it's becoming
performance problem:
function boolean between(Calendar currentDate, Date oldDate, int from, int to) {
	Calendar fromCal = Calendar.getInstance();
	fromCal.setTime(oldDate);
	fromCal.add(Calendar.YEAR, from);

	Calendar toCal = Calendar.getInstance();
	toCal.setTime(oldDate);
	toCal.add(Calendar.YEAR, to);
	return currentDate.after(fromCal) && currentDate.before(toCal);
}

Thank you

Pavel



More information about the rules-users mailing list