@Test public void cronScheduleComplexStuff() { Schedule sch = makeCronSchedule("0 0/15 14 * * ?"); ScheduledTime t1 = new ScheduledTime("2013-11-25T12:00Z"); ScheduledTime t2 = new ScheduledTime("2013-11-25T18:00Z"); Set<ScheduledTime> times = sch.getScheduledTimes(null, t1, t2); List<ScheduledTime> expectedMinutes = Arrays.asList( new ScheduledTime("2013-11-25T14:00Z"), new ScheduledTime("2013-11-25T14:15Z"), new ScheduledTime("2013-11-25T14:30Z"), new ScheduledTime("2013-11-25T14:45Z") ); Assert.assertEquals(new TreeSet<ScheduledTime>(expectedMinutes), times); }
@Override public SortedSet<ScheduledTime> getScheduledTimes(Scheduler scheduler, ScheduledTime start, ScheduledTime end) { SortedSet<ScheduledTime> scheduledTimes = new TreeSet<ScheduledTime>(); DateTime startDT = start.getDateTime(); DateTime endDT = end.getDateTime(); if (!startDT.isBefore(endDT)) { return scheduledTimes; } if (cronExpression.isSatisfiedBy(startDT.toDate())) { scheduledTimes.add(start); } DateTime candidate = startDT; while((candidate = getNextDateTime(candidate)) != null && candidate.isBefore(endDT)) { scheduledTimes.add(new ScheduledTime(candidate)); } return scheduledTimes; }
CronSchedule implements Schedule { @Override public SortedSet<ScheduledTime> getScheduledTimes(Scheduler scheduler, ScheduledTime start, ScheduledTime end) { SortedSet<ScheduledTime> scheduledTimes = new TreeSet<ScheduledTime>(); DateTime startDT = start.getDateTime(); DateTime endDT = end.getDateTime(); if (!startDT.isBefore(endDT)) { return scheduledTimes; } if (cronExpression.isSatisfiedBy(startDT.toDate())) { scheduledTimes.add(start); } DateTime candidate = startDT; while((candidate = getNextDateTime(candidate)) != null && candidate.isBefore(endDT)) { scheduledTimes.add(new ScheduledTime(candidate)); } return scheduledTimes; } }
CronSchedule implements Schedule { @Override public SortedSet<ScheduledTime> getScheduledTimes(Scheduler scheduler, ScheduledTime start, ScheduledTime end) { SortedSet<ScheduledTime> scheduledTimes = new TreeSet<ScheduledTime>(); DateTime startDT = start.getDateTime(); DateTime endDT = end.getDateTime(); if (!startDT.isBefore(endDT)) { return scheduledTimes; } if (cronExpression.isSatisfiedBy(startDT.toDate())) { scheduledTimes.add(start); } DateTime candidate = startDT; while((candidate = getNextDateTime(candidate)) != null && candidate.isBefore(endDT)) { scheduledTimes.add(new ScheduledTime(candidate)); } return scheduledTimes; } CronSchedule(String cronConfig); }
CronSchedule implements Schedule { @Override public SortedSet<ScheduledTime> getScheduledTimes(Scheduler scheduler, ScheduledTime start, ScheduledTime end) { SortedSet<ScheduledTime> scheduledTimes = new TreeSet<ScheduledTime>(); DateTime startDT = start.getDateTime(); DateTime endDT = end.getDateTime(); if (!startDT.isBefore(endDT)) { return scheduledTimes; } if (cronExpression.isSatisfiedBy(startDT.toDate())) { scheduledTimes.add(start); } DateTime candidate = startDT; while((candidate = getNextDateTime(candidate)) != null && candidate.isBefore(endDT)) { scheduledTimes.add(new ScheduledTime(candidate)); } return scheduledTimes; } CronSchedule(String cronConfig); String getCronExpression(); @Override SortedSet<ScheduledTime> getScheduledTimes(Scheduler scheduler, ScheduledTime start, ScheduledTime end); }
CronSchedule implements Schedule { @Override public SortedSet<ScheduledTime> getScheduledTimes(Scheduler scheduler, ScheduledTime start, ScheduledTime end) { SortedSet<ScheduledTime> scheduledTimes = new TreeSet<ScheduledTime>(); DateTime startDT = start.getDateTime(); DateTime endDT = end.getDateTime(); if (!startDT.isBefore(endDT)) { return scheduledTimes; } if (cronExpression.isSatisfiedBy(startDT.toDate())) { scheduledTimes.add(start); } DateTime candidate = startDT; while((candidate = getNextDateTime(candidate)) != null && candidate.isBefore(endDT)) { scheduledTimes.add(new ScheduledTime(candidate)); } return scheduledTimes; } CronSchedule(String cronConfig); String getCronExpression(); @Override SortedSet<ScheduledTime> getScheduledTimes(Scheduler scheduler, ScheduledTime start, ScheduledTime end);  }