@Test public void testGetNextExecutionAfter() { Calendar c = null; Date expectedFireDate = null; expectedFireDate = rollUp(Calendar.getInstance(), Calendar.MINUTE, minutes); assertEquals(expectedFireDate, minuteTrigger.getNextExecutionAfter(now)); c = Calendar.getInstance(); c.set(Calendar.MINUTE, 0); expectedFireDate = rollUp(c, Calendar.HOUR_OF_DAY, hours); assertEquals(expectedFireDate, hourTrigger.getNextExecutionAfter(now)); c = Calendar.getInstance(); c.set(Calendar.MINUTE, 0); c.set(Calendar.HOUR_OF_DAY, 0); expectedFireDate = rollUp(c, Calendar.DAY_OF_MONTH, daysOfMonth); assertEquals(expectedFireDate, dayOfMonthTrigger.getNextExecutionAfter(now)); c = Calendar.getInstance(); c.set(Calendar.MINUTE, 0); c.set(Calendar.HOUR_OF_DAY, 0); c.set(Calendar.DAY_OF_MONTH, 1); expectedFireDate = rollUp(c, Calendar.MONTH, months); c = Calendar.getInstance(); c.set(Calendar.MINUTE, 0); c.set(Calendar.HOUR_OF_DAY, 0); c.set(Calendar.DAY_OF_MONTH, 1); if (c.get(Calendar.MONTH) != Calendar.JANUARY) { while (c.get(Calendar.MONTH) != Calendar.JANUARY) { while (c.get(Calendar.MONTH) != Calendar.JANUARY) { c.add(Calendar.MONTH, 1); } c.set(Calendar.DATE, 1); expectedFireDate = rollUp(c, Calendar.DAY_OF_WEEK, daysOfWeek); } } else { expectedFireDate = rollUp(c, Calendar.DAY_OF_WEEK, daysOfWeek); } while (c.get(Calendar.MONTH) != Calendar.JANUARY) { expectedFireDate = rollUp(c, Calendar.DAY_OF_WEEK, daysOfWeek); if (c.get(Calendar.MONTH) > 1) { c.roll(Calendar.YEAR, 1); c.set(Calendar.MONTH, 1); c.set(Calendar.DAY_OF_MONTH, 1); expectedFireDate = rollUp(c, Calendar.DAY_OF_WEEK, daysOfWeek); } } assertEquals(expectedFireDate, dayOfWeekTrigger.getNextExecutionAfter(now)); }
public Date getNextExecutionAfter(Date date) { if (date == null) return null; if (nextExecution > date.getTime()) return new Date(nextExecution); else if (once) { if (lastExecution > -1) return null; lastExecution = date.getTime(); return date; } Calendar c = Calendar.getInstance(); c.setFirstDayOfWeek(Calendar.SUNDAY); c.setTime(date); c.set(Calendar.MILLISECOND, 0); c.add(Calendar.SECOND, 60 - c.get(Calendar.SECOND)); if (c.getTime().equals(date)) c.add(Calendar.MINUTE, 1); while (!matches(c, Calendar.MINUTE, minutes)) { c.add(Calendar.MINUTE, 1); } while (!matches(c, Calendar.HOUR_OF_DAY, hours)) { c.add(Calendar.HOUR_OF_DAY, 1); } while (!matches(c, daysOfMonth, daysOfWeek)) { c.add(Calendar.DAY_OF_MONTH, 1); } while (!matches(c, Calendar.MONTH, months)) { c.add(Calendar.MONTH, 1); c.set(Calendar.DAY_OF_MONTH, 1); } while (!matches(c, daysOfMonth, daysOfWeek)) { c.add(Calendar.DAY_OF_MONTH, 1); } return new Date(c.getTimeInMillis()); }
CronJobTrigger implements JobTrigger { public Date getNextExecutionAfter(Date date) { if (date == null) return null; if (nextExecution > date.getTime()) return new Date(nextExecution); else if (once) { if (lastExecution > -1) return null; lastExecution = date.getTime(); return date; } Calendar c = Calendar.getInstance(); c.setFirstDayOfWeek(Calendar.SUNDAY); c.setTime(date); c.set(Calendar.MILLISECOND, 0); c.add(Calendar.SECOND, 60 - c.get(Calendar.SECOND)); if (c.getTime().equals(date)) c.add(Calendar.MINUTE, 1); while (!matches(c, Calendar.MINUTE, minutes)) { c.add(Calendar.MINUTE, 1); } while (!matches(c, Calendar.HOUR_OF_DAY, hours)) { c.add(Calendar.HOUR_OF_DAY, 1); } while (!matches(c, daysOfMonth, daysOfWeek)) { c.add(Calendar.DAY_OF_MONTH, 1); } while (!matches(c, Calendar.MONTH, months)) { c.add(Calendar.MONTH, 1); c.set(Calendar.DAY_OF_MONTH, 1); } while (!matches(c, daysOfMonth, daysOfWeek)) { c.add(Calendar.DAY_OF_MONTH, 1); } return new Date(c.getTimeInMillis()); } }
CronJobTrigger implements JobTrigger { public Date getNextExecutionAfter(Date date) { if (date == null) return null; if (nextExecution > date.getTime()) return new Date(nextExecution); else if (once) { if (lastExecution > -1) return null; lastExecution = date.getTime(); return date; } Calendar c = Calendar.getInstance(); c.setFirstDayOfWeek(Calendar.SUNDAY); c.setTime(date); c.set(Calendar.MILLISECOND, 0); c.add(Calendar.SECOND, 60 - c.get(Calendar.SECOND)); if (c.getTime().equals(date)) c.add(Calendar.MINUTE, 1); while (!matches(c, Calendar.MINUTE, minutes)) { c.add(Calendar.MINUTE, 1); } while (!matches(c, Calendar.HOUR_OF_DAY, hours)) { c.add(Calendar.HOUR_OF_DAY, 1); } while (!matches(c, daysOfMonth, daysOfWeek)) { c.add(Calendar.DAY_OF_MONTH, 1); } while (!matches(c, Calendar.MONTH, months)) { c.add(Calendar.MONTH, 1); c.set(Calendar.DAY_OF_MONTH, 1); } while (!matches(c, daysOfMonth, daysOfWeek)) { c.add(Calendar.DAY_OF_MONTH, 1); } return new Date(c.getTimeInMillis()); } CronJobTrigger();  CronJobTrigger(String entry); }
CronJobTrigger implements JobTrigger { public Date getNextExecutionAfter(Date date) { if (date == null) return null; if (nextExecution > date.getTime()) return new Date(nextExecution); else if (once) { if (lastExecution > -1) return null; lastExecution = date.getTime(); return date; } Calendar c = Calendar.getInstance(); c.setFirstDayOfWeek(Calendar.SUNDAY); c.setTime(date); c.set(Calendar.MILLISECOND, 0); c.add(Calendar.SECOND, 60 - c.get(Calendar.SECOND)); if (c.getTime().equals(date)) c.add(Calendar.MINUTE, 1); while (!matches(c, Calendar.MINUTE, minutes)) { c.add(Calendar.MINUTE, 1); } while (!matches(c, Calendar.HOUR_OF_DAY, hours)) { c.add(Calendar.HOUR_OF_DAY, 1); } while (!matches(c, daysOfMonth, daysOfWeek)) { c.add(Calendar.DAY_OF_MONTH, 1); } while (!matches(c, Calendar.MONTH, months)) { c.add(Calendar.MONTH, 1); c.set(Calendar.DAY_OF_MONTH, 1); } while (!matches(c, daysOfMonth, daysOfWeek)) { c.add(Calendar.DAY_OF_MONTH, 1); } return new Date(c.getTimeInMillis()); } CronJobTrigger();  CronJobTrigger(String entry); @Override Object clone(); void reset(); Date getNextExecutionAfter(Date date); void triggered(Date date); int[] getMinutes(); void setMinutes(int[] minutes); void setMinutes(String minutes); int[] getHours(); void setHours(int[] hours); void setHours(String hours); int[] getMonths(); void setMonths(int[] months); void setMonths(String months); int[] getDaysOfMonth(); void setDaysOfMonth(int[] daysOfMonth); void setDaysOfMonth(String daysOfMonth); int[] getDaysOfWeek(); void setDaysOfWeek(int[] daysOfWeek); void setDaysOfWeek(String daysOfWeek); Object getCronExpression(); @Override int hashCode(); @Override boolean equals(Object obj); @Override String toString(); }
CronJobTrigger implements JobTrigger { public Date getNextExecutionAfter(Date date) { if (date == null) return null; if (nextExecution > date.getTime()) return new Date(nextExecution); else if (once) { if (lastExecution > -1) return null; lastExecution = date.getTime(); return date; } Calendar c = Calendar.getInstance(); c.setFirstDayOfWeek(Calendar.SUNDAY); c.setTime(date); c.set(Calendar.MILLISECOND, 0); c.add(Calendar.SECOND, 60 - c.get(Calendar.SECOND)); if (c.getTime().equals(date)) c.add(Calendar.MINUTE, 1); while (!matches(c, Calendar.MINUTE, minutes)) { c.add(Calendar.MINUTE, 1); } while (!matches(c, Calendar.HOUR_OF_DAY, hours)) { c.add(Calendar.HOUR_OF_DAY, 1); } while (!matches(c, daysOfMonth, daysOfWeek)) { c.add(Calendar.DAY_OF_MONTH, 1); } while (!matches(c, Calendar.MONTH, months)) { c.add(Calendar.MONTH, 1); c.set(Calendar.DAY_OF_MONTH, 1); } while (!matches(c, daysOfMonth, daysOfWeek)) { c.add(Calendar.DAY_OF_MONTH, 1); } return new Date(c.getTimeInMillis()); } CronJobTrigger();  CronJobTrigger(String entry); @Override Object clone(); void reset(); Date getNextExecutionAfter(Date date); void triggered(Date date); int[] getMinutes(); void setMinutes(int[] minutes); void setMinutes(String minutes); int[] getHours(); void setHours(int[] hours); void setHours(String hours); int[] getMonths(); void setMonths(int[] months); void setMonths(String months); int[] getDaysOfMonth(); void setDaysOfMonth(int[] daysOfMonth); void setDaysOfMonth(String daysOfMonth); int[] getDaysOfWeek(); void setDaysOfWeek(int[] daysOfWeek); void setDaysOfWeek(String daysOfWeek); Object getCronExpression(); @Override int hashCode(); @Override boolean equals(Object obj); @Override String toString();  }