tags:

views:

110

answers:

1

I want to code a function to get a list of Entry objects whose date field is between a beginPeriod and endPeriod I post below a code snippet which works with a HACK. I have to substract a day from the begin period date. It seems the condition great or equal does not work.

Any idea why I have this issue?

public static List<Entry> getEntries(Date beginPeriod, Date endPeriod) {
/* TODO 
 * The great or equal condition does not seem to work in the filter below
 * Substract a day and it seems to work 
 */
Calendar calendar = Calendar.getInstance();
calendar.set(beginPeriod.getYear(), beginPeriod.getMonth(), beginPeriod.getDate() - 1);
beginPeriod = calendar.getTime();

PersistenceManager pm = JdoUtil.getPm();
Query q = pm.newQuery(Entry.class);     
q.setFilter("this.date >= beginPeriodParam && this.date <= endPeriodParam");
q.declareParameters("java.util.Date beginPeriodParam, java.util.Date endPeriodParam");         
List<Entry> entries = (List<Entry>) q.execute(beginPeriod,endPeriod);
return entries;
}
A: 

my guess is it's because arrays begin at 0. i was trying to your (my query doesn't return anything??) and noticed that it's true for months - 1 => february, 4=>may, etc.

Jan Kuboschek