SimpleCron { private Long move(final long millis, final boolean forward) { final Calendar time = Calendar.getInstance(); time.setTimeZone(UTC); time.setTimeInMillis(millis); time.set(Calendar.MILLISECOND, 0); time.set(Calendar.SECOND, 0); boolean hasRolled = false; if (!forward) { if (time.getTimeInMillis() != millis) { hasRolled = true; } } for (int i = 0; i < cronParts.size(); i++) { hasRolled = move(i, time, hasRolled, forward); } return time.getTime().getTime(); } private  SimpleCron(final String expression); static SimpleCron compile(final String expression); Scheduler createScheduler(); Long getNextTime(final Long millis); Long getLastTime(final Long millis); @Override String toString(); static final String CRON_ANY; }
@Test void testMove() { SimpleCron cron = SimpleCron.compile("0,10,20,30,40,50 * *"); assertThat(DateUtil.createNormalDateTimeString( cron.getNextTime(DateUtil.parseNormalDateTimeString("2010-01-01T08:00:00.000Z")))).isEqualTo("2010-01-01T08:10:00.000Z"); assertThat(DateUtil.createNormalDateTimeString( cron.getNextTime(DateUtil.parseNormalDateTimeString("2010-01-01T08:05:00.000Z")))).isEqualTo("2010-01-01T08:10:00.000Z"); assertThat(DateUtil.createNormalDateTimeString( cron.getNextTime(DateUtil.parseNormalDateTimeString("2010-01-01T08:09:00.000Z")))).isEqualTo("2010-01-01T08:10:00.000Z"); }