public class SimpleToCronTriggerConverter extends Object
There are a number of things a cronspec cannot handle cleanly when converting a arbitrary fixed millisecond repeat
from a specific DateTime into a cronspec. Things such as "every 15 min from 9.53am Jan 23rd 2006" (closest cronspec
would be "every 15min").
Basic parsing rules for the algorithm are that the main Unit that will be used is the largest unit it is close to
(minutes, hours, days, week, months) and then rounded to the nearest neighbour that is a denominator of the next
largest unit. So an unit of 5 hours is specified in hours, but as 5 is not a denominator of 24 it must be rounded
to 4 or 6. Similarly 15 hours would be rounded down to 12 and 20 hours would be rounded up to 24 (daily).
Once the time period is specified as a number of days there are some fairly intractable issues. Firstly, the number of days in a week - 7 - is prime and has no denominators apart from 1 and itself, and months may have 28, 29, 30 or 31 days so exact arithmetic is not possible. For these periods we will need to round periods above 7 days and up to 15 days down to 7 days, and of over 15 days to one month. Multi-month periods can be supported in the 2, 3, 4, 6 and 12 month periods. We will not support multi-year periods and any currently specified will be rounded down to a single year period.
|Constructor and Description|
|Modifier and Type||Method and Description|
Converts trigger data taken from the database entries into a quartz CronTrigger String.
Return the time unit (SECONDS, MINUTES, MONTHS etc.) that the supplied interval (ms) is closest to.
Given a unit of time (e.g.
Make a cron element of the form 'START_TIME''/''FREQUENCY'.
Round the interval to the nearest time unit multiple that is a denominator of the succeeding time unit.
public ConversionResult convertToCronString(Date nextFireDate, long intervalMs)
nextFireDate- a time a trigger will next fire
intervalMs- a time delay in milliseconds between trigger firing
ConversionResultwhich contains composed of the following cron fields:
protected String makeIncrementalCronElement(int targetTime, long frequency, int base)
In order for the trigger to fire the right number of times, we must pick the earliest possible start time where START_TIME + N * FREQUENCY = TARGET_TIME, where N is some positive integer, holds true.
targetTime- The time that the trigger should fire on, parsed from the nextFire quartz trigger field
frequency- The delay between trigger firings
base- The base of the cron timeunit: 0 or 1. Seconds [0-59], minutes [0-59] & hours [0-23] are zero-based. Day of Month [1-31], Months [1-12] and Days of Week [1-7] are one-based.
protected long roundInterval(long intervalMs, long baseTimeUnit)
intervalMs- the original interval in milliseconds
baseTimeUnit- the time unit that is the major component of the cron string (e.g. SECONDS, HOURS, etc.)
protected long getSucceedingTimeUnit(long timeUnit)
timeUnit- a unit of time, defined at the top of this class
protected long determineBaseTimeUnit(long intervalMs)
intervalMs- the supplied interval in milliseconds
Copyright © 2002-2021 Atlassian. All Rights Reserved.