@Override public Date resolve(String duedateDescription, ClockReader clockReader, TimeZone timeZone) { Calendar nextRun = null; try { if (duedateDescription.startsWith("R")) { nextRun = new DurationHelper(duedateDescription, clockReader).getCalendarAfter(clockReader.getCurrentCalendar(timeZone)); } else { CronExpression cronExpression = new CronExpression(duedateDescription, clockReader); cronExpression.setTimeZone(timeZone); Date nextRunDate = cronExpression.getTimeAfter(clockReader.getCurrentCalendar(timeZone).getTime()); nextRun = new GregorianCalendar(); nextRun.setTime(nextRunDate); } } catch (Exception e) { throw new FlowableException("Failed to parse scheduler expression: " + duedateDescription, e); } return nextRun == null ? null : nextRun.getTime(); }
/** * Constructs a new {@code CronExpression} as a copy of an existing * instance. * * @param expression * The existing cron expression to be copied */ public CronExpression(CronExpression expression, ClockReader clockReader) { /* * We don't call the other constructor here since we need to swallow the * ParseException. We also elide some of the sanity checking as it is * not logically trippable. */ this.cronExpression = expression.getCronExpression(); this.clockReader = clockReader; try { buildExpression(cronExpression); } catch (ParseException ex) { throw new AssertionError(ex); } if (expression.getTimeZone() != null) { setTimeZone((TimeZone) expression.getTimeZone().clone()); } }