I need to create Job that will :
is this cron expression valid?
Date start = 12/20/2012;
Date endDate = 12/31/2017;
SimpleTrigger trigger = newTrigger()
.withIdentity("trigger3", "group1")
.startAt(startDate)
.withSchedule(cronSchedule("* * 17 0 0/2 *,SUN,MON").build())
.endAt(endDate)
.build;
Please advise.
I suggest, that you make a unit test based on your cron expression. With kudos to Van de Voorde Toni, you can base it on this code, and use it to verify that the "nextValidTimeAfter" matches your expectation:
import java.text.ParseException;
import java.util.Date;
import org.quartz.CronExpression;
public class CronTester {
public static void main(String[] args) throws ParseException {
final String expression = "* * 17 0 0/2 *,SUN,MON";
final CronExpression cronExpression = new CronExpression(expression);
final Date nextValidDate1 = cronExpression.getNextValidTimeAfter(new Date());
final Date nextValidDate2 = cronExpression.getNextValidTimeAfter(nextValidDate1);
System.out.println(nextValidDate1);
System.out.println(nextValidDate2);
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With