年と月のみに基づいて(つまり、日を気にせずに)2つの日付を比較できるようにする必要があります。また、JAVAとHQLの日付も比較できる必要があります。
d1
が以下であるかどうかを確認する必要があるとしましょうd2
。これが私が試したことです:
JAVA
calendar.setTime(d1);
int y1 = calendar.get(Calendar.YEAR);
int m1 = calendar.get(Calendar.MONTH);
calendar.setTime(d2);
int y2 = calendar.get(Calendar.YEAR);
int m2 = calendar.get(Calendar.MONTH);
return y1 <= y2 && m1 <= m2;
HQL
select item from Item item
where year(item.d1) <= year(:d2)
and month(item.d1) <= month(:d2)
アルゴリズムは上記の両方のコードで同じですが、間違っています。
2011-10 LTE 2012-09
戻る必要true
がありますfalse
が2011 < 2012
、10 !< 09
OR
の代わりにを使用する場合AND
、それはまだ間違っています:
2013-01 LTE 2012-05
戻る必要false
がありますtrue
が2013 !< 2012
、01 < 05
では、どのように処理すればよいですか?お願いします、JAVAとHQLに必要です。