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. Multimonth periods can be supported in the 2, 3, 4, 6 and 12 month periods. We will not support multiyear periods and any currently specified will be rounded down to a single year period.
Constructor and Description 

SimpleToCronTriggerConverter() 
Modifier and Type  Method and Description 

ConversionResult 
convertToCronString(Date nextFireDate,
long intervalMs)
Converts trigger data taken from the database entries into a
quartz CronTrigger String.

protected long 
determineBaseTimeUnit(long intervalMs)
Return the time unit (SECONDS, MINUTES, MONTHS etc.) that the supplied interval (ms) is closest to.

protected long 
getSucceedingTimeUnit(long timeUnit)
Given a unit of time (e.g.

protected String 
makeIncrementalCronElement(int targetTime,
long frequency,
int base)
Make a cron element of the form 'START_TIME''/''FREQUENCY'.

protected long 
roundInterval(long intervalMs,
long baseTimeUnit)
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 fireintervalMs
 a time delay in milliseconds between trigger firingConversionResult
which 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 fieldfrequency
 The delay between trigger firingsbase
 The base of the cron timeunit: 0 or 1. Seconds [059], minutes [059] & hours [023] are zerobased.
Day of Month [131], Months [112] and Days of Week [17] are onebased.protected long roundInterval(long intervalMs, long baseTimeUnit)
intervalMs
 the original interval in millisecondsbaseTimeUnit
 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 classprotected long determineBaseTimeUnit(long intervalMs)
intervalMs
 the supplied interval in millisecondsCopyright © 20022017 Atlassian. All Rights Reserved.