views:

45

answers:

1

I'm probably just being an idiot - it's been a long day! I've misunderstood something in my first foray into Quartz...

Given this code:

DateTime dt = new DateTime();
dt = dt.withDayOfMonth(20);

Calendar cal = new CronCalendar("0 0/10 * * * ?" );
long start = dt.getMillis();
System.out.println("Starting at " + start);
long end = start + 10;
long current = start;
int i = 0;
while (current < end) {
  if (i > 0) {
    System.out.println(i + ":" + current);
  }
  long next = cal.getNextIncludedTime(current);
  current = next;
  i++;
}

I expect that there will be at most one included time in the output, as the time window is 10ms and the times included in the Calendar are 10 minutes apart.

But when I run it:

Starting at 1250796103004
1:1250796103005
2:1250796103006
3:1250796103007
4:1250796103008
5:1250796103009
6:1250796103010
7:1250796103011
8:1250796103012
9:1250796103013

Please help!

A: 

Yep, just me being a dumbass.

Calendars specify EXCLUDED times.

I should have been using a CronTrigger to specify the times I wanted to include. The code should look more like this...

CronTrigger cal = new CronTrigger("Test", "Test", "0 0/10 * * * ?" );
...
end = start + 1000000;
...
while (current < end) {
  if (i > 0) {
  System.out.println(i + ":" + current);
  }
  Date next = cal.getFireTimeAfter(new Date(current));
  current = next.getTime();
  i++;
}

Which gives the output I was expecting.

Starting at 1250798091337
1:1250798400000
2:1250799000000
Brabster