You could add that check for date between the range of dates in either a static helper method or within one of your entities. In my opinion this will make your rules more readable and you can easily write unit tests for the date check method.
Option 1 - Static helper method
Create a class for having static helper methods, something like this
public class DateUtils {
private DateUtils() {} // Cannot be initialized
public static boolean dateInRange( Date toCheck, Date min, Date max ) {
// Add null checks here
// Use Date#before(Date) and Date#after(Date) for checking
return true|false
}
}
Your rule would then be like
import static DateUtils.*
rule "date in range"
when:
dateInRange( e1.date, e2.start, e2.end )
then:
// logic
end
Option 2 - Method within fact/entity
Create the check method inside one of your facts. In which entity to put this depends on your use case, the information you've given does not specify this yet. I think you can figure out the best place by yourself. Anyway, the code would be something like this
public class Entity1 {
Date date
}
public class Entity2 {
Date start
Date end
public boolean entity1InRange( Entity1 e ) {
// null checks
// Use the Date#before() and Date#after() as above
}
}
And the rule
rule "date in range"
when:
e2.entity1InRange( e1 )
then:
// Logic
end