For representing times, there are two distinct data types: <br>
- absolute time, as a sequence of points on a timeline (the real "Time");<br>
- durations, which are differences between points on a timeline.<br>
<br>
Absolute time can be represented in a number of ways:<br>
- as seconds (or milliseconds or nanoseconds), with 0 being some agreed-upon point in Time,<br>
- by Y,M,D,h,m,s according to some calendar;<br>
- as Julian Days, in fractions.<br>It's obvious that calculations of any kind are best done with one of the single-valued representations.<br>
<br>
Durations can be expressed in any convenient unit, as long as there is
a well-defined conversion between the units with which you represent
absolute time and the units you desire to express durations.<br>
There is no such well-defined conversion for (months and) years, and
therefore the idea to express a duration (precisely) in years is not
used commonly. (Astronomers settle for a year being equal to 365.25
Julian days; so if this suits you, go ahead and base your calculations
on that.)<br>
<br>
For efficiency in rules, you might consider using Date.getTime() (or Calendar.getTimeInMillis()) to
obtain a point on the timeline, and to express your notion of a year's
duration (whatever it is) in the suitable unit, and to use this for comparisons. <br>
<br>-W<br><br><div class="gmail_quote">On Thu, Feb 18, 2010 at 1:43 PM, Pavel Tavoda <span dir="ltr"><<a href="mailto:pavel.tavoda@gmail.com">pavel.tavoda@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Hello,<br>
I would like to calculate AGE of object based on Date inside object, I<br>
can use eval but I hope it's so basic functionality that Drools should<br>
have it. It's also performance problem if I need to use EVAL in many<br>
rules (let's say 100 in XLS). I'm playing with some FUSION features<br>
like:<br>
$now : Now() && $order : SecurityOrder(this before[400d, 0d] $now)<br>
should work but I can't specify YEARS as constant. That's a problem<br>
for long time because 30*365d isn't same as 30 years if you consider<br>
leap years. Is it possible some easy way to calculate AGE of something<br>
with correct time handling and compare to years? Something like:<br>
SecurityOrder( age(createdDate) > 20y, age(createdDate) < 25y)<br>
or by FUSION:<br>
$now : Now() && $order : SecurityOrder(this before[25y, 20y] $now)<br>
<br>
For now I'm using following function in eval() but it's becoming<br>
performance problem:<br>
function boolean between(Calendar currentDate, Date oldDate, int from, int to) {<br>
Calendar fromCal = Calendar.getInstance();<br>
fromCal.setTime(oldDate);<br>
fromCal.add(Calendar.YEAR, from);<br>
<br>
Calendar toCal = Calendar.getInstance();<br>
toCal.setTime(oldDate);<br>
toCal.add(Calendar.YEAR, to);<br>
return currentDate.after(fromCal) && currentDate.before(toCal);<br>
}<br>
<br>
Thank you<br>
<font color="#888888"><br>
Pavel<br>
</font><div><div></div><div class="h5">_______________________________________________<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>
</div></div></blockquote></div><br>