1 package com.freemindcafe.quartz.sample1;
3 import java.text.ParseException;
4 import java.util.Calendar;
7 import org.junit.Assert;
9 import org.quartz.CronExpression;
15 public void cronTest(){
16 CronExpression cron1=null;
17 CronExpression cron2 = null;
18 CronExpression cron3 = null;
20 cron1 =
new CronExpression(
"0 0 11-23,0-1 * * ?");
21 cron2=
new CronExpression(
"* * 11-23,0-1 ? * MON-FRI");
22 cron3=
new CronExpression(
"* * 11-23,0-1 ? * SAT");
23 }
catch (ParseException e) {
27 Calendar cal=Calendar.getInstance();
28 cal.set(Calendar.YEAR, 2015);
29 cal.set(Calendar.MONTH, 3);
30 cal.set(Calendar.DATE, 30);
31 cal.set(Calendar.HOUR, 13);
32 cal.set(Calendar.MINUTE, 0);
33 cal.set(Calendar.SECOND, 0);
34 Date date = cal.getTime();
35 System.out.println(date);
38 System.out.println(
"---------------------------");
39 Assert.assertTrue(cron1.isSatisfiedBy(date));
40 System.out.println(cron1.isSatisfiedBy(date));
41 System.out.println(
"Invalid"+cron1.getNextInvalidTimeAfter(date));
42 System.out.println(
"Valid"+cron1.getNextValidTimeAfter(date));
44 System.out.println(
"---------------------------");
46 Assert.assertTrue(cron2.isSatisfiedBy(date));
47 System.out.println(cron2.isSatisfiedBy(date));
48 System.out.println(
"Invalid"+cron2.getNextInvalidTimeAfter(date));
49 System.out.println(
"Valid"+cron2.getNextValidTimeAfter(date));
50 System.out.println(
"---------------------------");
52 System.out.println(
"---------------------------");
54 Assert.assertFalse(cron3.isSatisfiedBy(date));
55 System.out.println(cron3.isSatisfiedBy(date));
56 System.out.println(
"Invalid"+cron3.getNextInvalidTimeAfter(date));
57 System.out.println(
"Valid"+cron3.getNextValidTimeAfter(date));