use of org.quartz.CronExpression in project javautils by jiadongpo.
the class Utils method parseCronExpression.
/**
* @param cronExpression: A cron expression is a string separated by white space, to provide a
* parser and evaluator for Quartz cron expressions.
* @return : org.quartz.CronExpression object.
*
* TODO: Currently, we have to transform Joda Timezone to Java Timezone due to CronExpression.
* Since Java8 enhanced Time functionalities, We consider transform all Jodatime to Java Time in
* future.
*/
public static CronExpression parseCronExpression(final String cronExpression, final DateTimeZone timezone) {
if (cronExpression != null) {
try {
final CronExpression ce = new CronExpression(cronExpression);
ce.setTimeZone(TimeZone.getTimeZone(timezone.getID()));
return ce;
} catch (final ParseException pe) {
logger.error("this cron expression {" + cronExpression + "} can not be parsed. " + "Please Check Quartz Cron Syntax.");
}
return null;
} else {
return null;
}
}
use of org.quartz.CronExpression in project OpenOLAT by OpenOLAT.
the class ReminderModuleTest method testCronJob_everyTwoHours.
@Test
public void testCronJob_everyTwoHours() throws ParseException {
reminderModule.setScheduler("2", "9:30");
String cron = reminderModule.getCronExpression();
Calendar cal = Calendar.getInstance();
cal.set(Calendar.HOUR_OF_DAY, 0);
cal.set(Calendar.MINUTE, 5);
CronExpression cronExpression = new CronExpression(cron);
Date d1 = cronExpression.getNextValidTimeAfter(cal.getTime());
Calendar cal1 = Calendar.getInstance();
cal1.setTime(d1);
Assert.assertEquals(1, cal1.get(Calendar.HOUR_OF_DAY));
Assert.assertEquals(30, cal1.get(Calendar.MINUTE));
}
use of org.quartz.CronExpression in project yyl_example by Relucent.
the class CronExpressionExample method main.
public static void main(String[] args) throws Throwable {
DateFormat format = new SimpleDateFormat("HH:mm:ss");
CronExpression expression = new CronExpression("0 */1 * * * ?");
// 任意一个时间
Date from = new Date();
// 获得下一次满足条件的时间
Date after = expression.getNextValidTimeAfter(from);
System.out.println(format.format(from));
System.out.println(format.format(after));
}
use of org.quartz.CronExpression in project openolat by klemens.
the class ReminderModuleTest method testCronJob_everyTwoHours.
@Test
public void testCronJob_everyTwoHours() throws ParseException {
reminderModule.setScheduler("2", "9:30");
String cron = reminderModule.getCronExpression();
Calendar cal = Calendar.getInstance();
cal.set(Calendar.HOUR_OF_DAY, 0);
cal.set(Calendar.MINUTE, 5);
CronExpression cronExpression = new CronExpression(cron);
Date d1 = cronExpression.getNextValidTimeAfter(cal.getTime());
Calendar cal1 = Calendar.getInstance();
cal1.setTime(d1);
Assert.assertEquals(1, cal1.get(Calendar.HOUR_OF_DAY));
Assert.assertEquals(30, cal1.get(Calendar.MINUTE));
}
use of org.quartz.CronExpression in project plugin-vm by ligoj.
the class VmScheduleResource method findAll.
/**
* Return all schedules related to given subscription.
*
* @param subscription
* The subscription identifier.
* @return All schedules related to given subscription.
* @throws ParseException
* When CRON cannot be parsed.
*/
@org.springframework.transaction.annotation.Transactional(readOnly = true)
public List<VmScheduleVo> findAll(final int subscription) throws ParseException {
final List<VmScheduleVo> schedules = new ArrayList<>();
final Date now = DateUtils.newCalendar().getTime();
for (final VmSchedule schedule : repository.findBySubscription(subscription)) {
// Copy basic attributes
final VmScheduleVo vo = new VmScheduleVo();
vo.setCron(schedule.getCron());
vo.setOperation(schedule.getOperation());
vo.setId(schedule.getId());
vo.setNext(new CronExpression(schedule.getCron()).getNextValidTimeAfter(now));
schedules.add(vo);
}
return schedules;
}
Aggregations