Samples JDK
CronTest.java
1 package com.freemindcafe.quartz.sample1;
2 
3 import java.text.ParseException;
4 import java.util.Calendar;
5 import java.util.Date;
6 
7 import org.junit.Assert;
8 import org.junit.Test;
9 import org.quartz.CronExpression;
10 
11 
12 public class CronTest {
13 
14  @Test
15  public void cronTest(){
16  CronExpression cron1=null;
17  CronExpression cron2 = null;
18  CronExpression cron3 = null;
19  try {
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) {
24  // TODO Auto-generated catch block
25  e.printStackTrace();
26  }
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);
36 
37 
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));
43 
44  System.out.println("---------------------------");
45 
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("---------------------------");
51 
52  System.out.println("---------------------------");
53 
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));
58 
59  }
60 }