2017-09-04 66 views
0

流水的日期比較需要寫下列條件。在規則的一部分的時候,需要在規則的一部分

start_date < = end_date + 3 months 其中start_date和end_date是Date類型的字段。

請問誰能告訴我該怎麼辦?

+0

的可能的複製【如何做Drools的日期計算?(https://開頭計算器.com/questions/40781259/how-to-do-date-calculation-in-drools) –

+0

我已經經歷了這個。我需要在LHS部分添加3個月,而在你提到的問題中,這是在RHS部分完成的。 – Vijay

+0

沒有。在提到的問題中,它是在LHS中完成的。 LHS是'when'和'then'之間的評估部分,RHS是'then'和'end'之間的結果部分。但是,如果這有幫助,我會回答你的問題。 –

回答

0

首先,這感覺就像一個非常奇怪的規則。當start_dateend_date之後或正好在3個月後執行後果。

我假設start_dateend_date是一類Foo的領域,規則如下:

rule "I am checking if the start_date of Foo is more than or exactly three month after the end_date of Foo" 
when 
    Foo($start: start_date, $end: end_date, 
     $end_plus_3_month: DateUtils.addMonths($end, 3), 
     $start.compareTo($end_plus_3_month) <= 0) 
then 
    System.out.printf("The start_date %tD is more that or exactly 3 month after %tD.%n", $start, $end); 
end