Re: [rules-users] Date arithmetic in when part

2011-07-01 Thread Mark Proctor
The times attempt to be ISO8601 compliant, for Hours and earlier. 
Although I noticed that tidbit of information is missing for the docs, 
we'll get it added. See TimeUtils


private static final Pattern SIMPLE  = Pattern.compile( 
([+-])?((\\d+)[Dd])?\\s*((\\d+)[Hh])?\\s*((\\d+)[Mm])?\\s*((\\d+)[Ss])?\\s*((\\d+)([Mm][Ss])?)? 
);


public static long parseTimeString( String time ) {
String trimmed = time.trim();
long result = 0;
if( trimmed.length()  0 ) {
Matcher mat = SIMPLE.matcher( trimmed );
if ( mat.matches() ) {
int days = (mat.group( SIM_DAY ) != null) ? 
Integer.parseInt( mat.group( SIM_DAY ) ) : 0;
int hours = (mat.group( SIM_HOU ) != null) ? 
Integer.parseInt( mat.group( SIM_HOU ) ) : 0;
int min = (mat.group( SIM_MIN ) != null) ? 
Integer.parseInt( mat.group( SIM_MIN ) ) : 0;
int sec = (mat.group( SIM_SEC ) != null) ? 
Integer.parseInt( mat.group( SIM_SEC ) ) : 0;
int ms = (mat.group( SIM_MS ) != null) ? 
Integer.parseInt( mat.group( SIM_MS ) ) : 0;
long r = days * DAY_MS + hours * HOU_MS + min * MIN_MS 
+ sec * SEC_MS + ms;
if( mat.group(SIM_SGN) != null  mat.group( SIM_SGN 
).equals( - ) ) {

r = -r;
}
result = r;
} else if( *.equals( trimmed ) || +*.equals( trimmed ) ) {
// positive infinity
result = Long.MAX_VALUE;
} else if( -*.equals( trimmed ) ) {
// negative infinity
result = Long.MIN_VALUE;
} else {
throw new RuntimeDroolsException( Error parsing time 
string: [  + time +  ] );

}
}
return result;
}


On 01/07/2011 06:21, Wolfgang Laun wrote:

2011/6/30 rou...@mm.di.uoa.gr mailto:rou...@mm.di.uoa.gr

What are the available symbolics for temporal values?
That is, d is for days, m is for minutes, h is for hours, s is for
seconds.
Are there any other symbolics specifically for months and years?


You can use ms for millisecond. There are no universally acceptable 
duration values for monts and years .

-W


I haven't found any mentioning of them in the Fusion manual.
I'm using 5.0.1

Thank you,
-Stathis

Wolfgang Laun wrote:
 See the Fusion manual, section on Temporal Reasoning/Temporal
Operators.
 Even when the facts aren't events, these operators can still be
applied to
 fields of type Date, e.g.

 $p1: Person( $dob1: dob )
 $p2: Person( $dob2: dob after[3d] $dob1 )

 -W


 On 28 June 2011 18:02, rou...@mm.di.uoa.gr
mailto:rou...@mm.di.uoa.gr wrote:

 Hi list,

 I feel this should be an elementary question but unfortunately
I haven't
 been able to find a solution.

 I would like to perform date arithmetic in the when part of a rule.

 For example, I would like to express something like:

 rule Date compare rule
  dialect mvel
 when
  a : A()
  b : B( a.creationDate = b.creationDate after 3 months)
 then
  ...
 end

 Apart from using eval()'s is there any other way to express
these types
 of
 comparisons?

 Thank you for your time,
 -Stathis


 ___
 rules-users mailing list
 rules-users@lists.jboss.org mailto: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


___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users


Re: [rules-users] Date arithmetic in when part

2011-07-01 Thread rouvas
Wolfgang Laun wrote:
 2011/6/30 rou...@mm.di.uoa.gr

 What are the available symbolics for temporal values?
 That is, d is for days, m is for minutes, h is for hours, s is for
 seconds.
 Are there any other symbolics specifically for months and years?


Thanks for the clarification.


 You can use ms for millisecond. There are no universally acceptable
 duration
 values for monts and years .

Neither are the chosen values universally acceptable.
How about following man date conventions?

-Stathis

 -W



 I haven't found any mentioning of them in the Fusion manual.
 I'm using 5.0.1

 Thank you,
 -Stathis

 Wolfgang Laun wrote:
  See the Fusion manual, section on Temporal Reasoning/Temporal
 Operators.
  Even when the facts aren't events, these operators can still be
 applied
 to
  fields of type Date, e.g.
 
  $p1: Person( $dob1: dob )
  $p2: Person( $dob2: dob after[3d] $dob1 )
 
  -W
 
 
  On 28 June 2011 18:02, rou...@mm.di.uoa.gr wrote:
 
  Hi list,
 
  I feel this should be an elementary question but unfortunately I
 haven't
  been able to find a solution.
 
  I would like to perform date arithmetic in the when part of a rule.
 
  For example, I would like to express something like:
 
  rule Date compare rule
   dialect mvel
  when
   a : A()
   b : B( a.creationDate = b.creationDate after 3 months)
  then
   ...
  end
 
  Apart from using eval()'s is there any other way to express these
 types
  of
  comparisons?
 
  Thank you for your time,
  -Stathis
 
 
  ___
  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


Re: [rules-users] Date arithmetic in when part

2011-06-30 Thread lhorton
Thanks!  I converted over to these and my tests are all passing so far. 
Examples (snippets):

//  one day old
when
$step : Step(status == Status.ACTIVE, task.job.statuteOfLimitationsDate 
!=
null)
Date($now : time) from Calendar.getInstance().getTime()
Date($solDate : time before[1d] $now) from
$step.task.job.statuteOfLimitationsDate

//  13 hours old
when
$step  : Step(status == Status.ACTIVE)
Date($now : time) from Calendar.getInstance().getTime()
$checkpointTO : ArrayList(size  0) from collect (cp : CheckPoint(type 
==
CheckPointType.ABCOffice, created before[13h] $now) from
$step.getCheckPoints() )



--
View this message in context: 
http://drools.46999.n3.nabble.com/rules-users-Date-arithmetic-in-when-part-tp3118246p3126605.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


Re: [rules-users] Date arithmetic in when part

2011-06-30 Thread rouvas
What are the available symbolics for temporal values?
That is, d is for days, m is for minutes, h is for hours, s is for seconds.
Are there any other symbolics specifically for months and years?

I haven't found any mentioning of them in the Fusion manual.
I'm using 5.0.1

Thank you,
-Stathis

Wolfgang Laun wrote:
 See the Fusion manual, section on Temporal Reasoning/Temporal Operators.
 Even when the facts aren't events, these operators can still be applied to
 fields of type Date, e.g.

 $p1: Person( $dob1: dob )
 $p2: Person( $dob2: dob after[3d] $dob1 )

 -W


 On 28 June 2011 18:02, rou...@mm.di.uoa.gr wrote:

 Hi list,

 I feel this should be an elementary question but unfortunately I haven't
 been able to find a solution.

 I would like to perform date arithmetic in the when part of a rule.

 For example, I would like to express something like:

 rule Date compare rule
  dialect mvel
 when
  a : A()
  b : B( a.creationDate = b.creationDate after 3 months)
 then
  ...
 end

 Apart from using eval()'s is there any other way to express these types
 of
 comparisons?

 Thank you for your time,
 -Stathis


 ___
 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


Re: [rules-users] Date arithmetic in when part

2011-06-30 Thread Wolfgang Laun
2011/6/30 rou...@mm.di.uoa.gr

 What are the available symbolics for temporal values?
 That is, d is for days, m is for minutes, h is for hours, s is for seconds.
 Are there any other symbolics specifically for months and years?


You can use ms for millisecond. There are no universally acceptable duration
values for monts and years .
-W



 I haven't found any mentioning of them in the Fusion manual.
 I'm using 5.0.1

 Thank you,
 -Stathis

 Wolfgang Laun wrote:
  See the Fusion manual, section on Temporal Reasoning/Temporal
 Operators.
  Even when the facts aren't events, these operators can still be applied
 to
  fields of type Date, e.g.
 
  $p1: Person( $dob1: dob )
  $p2: Person( $dob2: dob after[3d] $dob1 )
 
  -W
 
 
  On 28 June 2011 18:02, rou...@mm.di.uoa.gr wrote:
 
  Hi list,
 
  I feel this should be an elementary question but unfortunately I haven't
  been able to find a solution.
 
  I would like to perform date arithmetic in the when part of a rule.
 
  For example, I would like to express something like:
 
  rule Date compare rule
   dialect mvel
  when
   a : A()
   b : B( a.creationDate = b.creationDate after 3 months)
  then
   ...
  end
 
  Apart from using eval()'s is there any other way to express these types
  of
  comparisons?
 
  Thank you for your time,
  -Stathis
 
 
  ___
  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


Re: [rules-users] Date arithmetic in when part

2011-06-29 Thread Wolfgang Laun
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 lhor...@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@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


Re: [rules-users] Date arithmetic in when part

2011-06-28 Thread Wolfgang Laun
See the Fusion manual, section on Temporal Reasoning/Temporal Operators.
Even when the facts aren't events, these operators can still be applied to
fields of type Date, e.g.

$p1: Person( $dob1: dob )
$p2: Person( $dob2: dob after[3d] $dob1 )

-W


On 28 June 2011 18:02, rou...@mm.di.uoa.gr wrote:

 Hi list,

 I feel this should be an elementary question but unfortunately I haven't
 been able to find a solution.

 I would like to perform date arithmetic in the when part of a rule.

 For example, I would like to express something like:

 rule Date compare rule
  dialect mvel
 when
  a : A()
  b : B( a.creationDate = b.creationDate after 3 months)
 then
  ...
 end

 Apart from using eval()'s is there any other way to express these types of
 comparisons?

 Thank you for your time,
 -Stathis


 ___
 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


Re: [rules-users] Date arithmetic in when part

2011-06-28 Thread lhorton
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@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users


Re: [rules-users] Date arithmetic in when part

2011-06-28 Thread rouvas
Thanks for the quick reply.
I forgot to mention that I'm using 5.0.1, but I'll look at the Fusion
manual for more info.

-Stathis

Wolfgang Laun wrote:
 See the Fusion manual, section on Temporal Reasoning/Temporal Operators.
 Even when the facts aren't events, these operators can still be applied to
 fields of type Date, e.g.

 $p1: Person( $dob1: dob )
 $p2: Person( $dob2: dob after[3d] $dob1 )

 -W


 On 28 June 2011 18:02, rou...@mm.di.uoa.gr wrote:

 Hi list,

 I feel this should be an elementary question but unfortunately I haven't
 been able to find a solution.

 I would like to perform date arithmetic in the when part of a rule.

 For example, I would like to express something like:

 rule Date compare rule
  dialect mvel
 when
  a : A()
  b : B( a.creationDate = b.creationDate after 3 months)
 then
  ...
 end

 Apart from using eval()'s is there any other way to express these types
 of
 comparisons?

 Thank you for your time,
 -Stathis


 ___
 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