@Test public void testGetNextOccurrenceTwice() throws Exception { now.set(2004, 0, 1, 0, 0, 0); now.set(Calendar.MILLISECOND, 0); expectedResult.set(2004, 0, 1, 0, 0, 0); expectedResult.set(Calendar.MILLISECOND, 0); Schedule schedule = new CrontabSchedule("0 0 * * *"); long res; res = schedule.getNextOccurrence(0, now.getTimeInMillis()); assertEquals(new Date(expectedResult.getTimeInMillis()), new Date(res)); expectedResult.set(2004, 0, 2, 0, 0, 0); expectedResult.set(Calendar.MILLISECOND, 0); res = schedule.getNextOccurrence(now.getTimeInMillis(), now.getTimeInMillis()); assertEquals(new Date(expectedResult.getTimeInMillis()), new Date(res)); }
@Override public long getNextOccurrence(long lastOccurence, long now) { if (now == lastOccurence) { now += 1000; } Calendar cal = Calendar.getInstance(); cal.setTimeInMillis(now); gotoNextOrStay(months.bArray, cal, Calendar.MONTH); if (months.all && daysOfMonth.all && !daysOfWeek.all) { gotoNextOrStay(daysOfWeek.bArray, cal, Calendar.DAY_OF_WEEK); } else { gotoNextOrStay(daysOfMonth.bArray, cal, Calendar.DAY_OF_MONTH); } gotoNextOrStay(hours.bArray, cal, Calendar.HOUR_OF_DAY); gotoNextOrStay(minutes.bArray, cal, Calendar.MINUTE); if ((cal.get(Calendar.SECOND) != 0) || (cal.get(Calendar.MILLISECOND) != 0)) { cal.set(Calendar.SECOND, 0); cal.set(Calendar.MILLISECOND, 0); gotoNext(minutes.bArray, cal, Calendar.MINUTE); } return cal.getTimeInMillis(); }
CrontabSchedule extends Schedule { @Override public long getNextOccurrence(long lastOccurence, long now) { if (now == lastOccurence) { now += 1000; } Calendar cal = Calendar.getInstance(); cal.setTimeInMillis(now); gotoNextOrStay(months.bArray, cal, Calendar.MONTH); if (months.all && daysOfMonth.all && !daysOfWeek.all) { gotoNextOrStay(daysOfWeek.bArray, cal, Calendar.DAY_OF_WEEK); } else { gotoNextOrStay(daysOfMonth.bArray, cal, Calendar.DAY_OF_MONTH); } gotoNextOrStay(hours.bArray, cal, Calendar.HOUR_OF_DAY); gotoNextOrStay(minutes.bArray, cal, Calendar.MINUTE); if ((cal.get(Calendar.SECOND) != 0) || (cal.get(Calendar.MILLISECOND) != 0)) { cal.set(Calendar.SECOND, 0); cal.set(Calendar.MILLISECOND, 0); gotoNext(minutes.bArray, cal, Calendar.MINUTE); } return cal.getTimeInMillis(); } }
CrontabSchedule extends Schedule { @Override public long getNextOccurrence(long lastOccurence, long now) { if (now == lastOccurence) { now += 1000; } Calendar cal = Calendar.getInstance(); cal.setTimeInMillis(now); gotoNextOrStay(months.bArray, cal, Calendar.MONTH); if (months.all && daysOfMonth.all && !daysOfWeek.all) { gotoNextOrStay(daysOfWeek.bArray, cal, Calendar.DAY_OF_WEEK); } else { gotoNextOrStay(daysOfMonth.bArray, cal, Calendar.DAY_OF_MONTH); } gotoNextOrStay(hours.bArray, cal, Calendar.HOUR_OF_DAY); gotoNextOrStay(minutes.bArray, cal, Calendar.MINUTE); if ((cal.get(Calendar.SECOND) != 0) || (cal.get(Calendar.MILLISECOND) != 0)) { cal.set(Calendar.SECOND, 0); cal.set(Calendar.MILLISECOND, 0); gotoNext(minutes.bArray, cal, Calendar.MINUTE); } return cal.getTimeInMillis(); } CrontabSchedule(final Element element);  CrontabSchedule();  CrontabSchedule(String pattern);  CrontabSchedule(CrontabPart.Instance minutes, CrontabPart.Instance hours, CrontabPart.Instance daysOfMonth,
		CrontabPart.Instance months, CrontabPart.Instance daysOfWeek); }
CrontabSchedule extends Schedule { @Override public long getNextOccurrence(long lastOccurence, long now) { if (now == lastOccurence) { now += 1000; } Calendar cal = Calendar.getInstance(); cal.setTimeInMillis(now); gotoNextOrStay(months.bArray, cal, Calendar.MONTH); if (months.all && daysOfMonth.all && !daysOfWeek.all) { gotoNextOrStay(daysOfWeek.bArray, cal, Calendar.DAY_OF_WEEK); } else { gotoNextOrStay(daysOfMonth.bArray, cal, Calendar.DAY_OF_MONTH); } gotoNextOrStay(hours.bArray, cal, Calendar.HOUR_OF_DAY); gotoNextOrStay(minutes.bArray, cal, Calendar.MINUTE); if ((cal.get(Calendar.SECOND) != 0) || (cal.get(Calendar.MILLISECOND) != 0)) { cal.set(Calendar.SECOND, 0); cal.set(Calendar.MILLISECOND, 0); gotoNext(minutes.bArray, cal, Calendar.MINUTE); } return cal.getTimeInMillis(); } CrontabSchedule(final Element element);  CrontabSchedule();  CrontabSchedule(String pattern);  CrontabSchedule(CrontabPart.Instance minutes, CrontabPart.Instance hours, CrontabPart.Instance daysOfMonth,
		CrontabPart.Instance months, CrontabPart.Instance daysOfWeek); @Override Element serialize(final Element element); String getPattern(); @Override long getNextOccurrence(long lastOccurence, long now); CrontabPart.Instance[] getParts(); @Override String toString(); }
CrontabSchedule extends Schedule { @Override public long getNextOccurrence(long lastOccurence, long now) { if (now == lastOccurence) { now += 1000; } Calendar cal = Calendar.getInstance(); cal.setTimeInMillis(now); gotoNextOrStay(months.bArray, cal, Calendar.MONTH); if (months.all && daysOfMonth.all && !daysOfWeek.all) { gotoNextOrStay(daysOfWeek.bArray, cal, Calendar.DAY_OF_WEEK); } else { gotoNextOrStay(daysOfMonth.bArray, cal, Calendar.DAY_OF_MONTH); } gotoNextOrStay(hours.bArray, cal, Calendar.HOUR_OF_DAY); gotoNextOrStay(minutes.bArray, cal, Calendar.MINUTE); if ((cal.get(Calendar.SECOND) != 0) || (cal.get(Calendar.MILLISECOND) != 0)) { cal.set(Calendar.SECOND, 0); cal.set(Calendar.MILLISECOND, 0); gotoNext(minutes.bArray, cal, Calendar.MINUTE); } return cal.getTimeInMillis(); } CrontabSchedule(final Element element);  CrontabSchedule();  CrontabSchedule(String pattern);  CrontabSchedule(CrontabPart.Instance minutes, CrontabPart.Instance hours, CrontabPart.Instance daysOfMonth,
		CrontabPart.Instance months, CrontabPart.Instance daysOfWeek); @Override Element serialize(final Element element); String getPattern(); @Override long getNextOccurrence(long lastOccurence, long now); CrontabPart.Instance[] getParts(); @Override String toString(); static final String SCHEDULE_TYPE; }