Package org.quartz.impl.calendar
Class CronCalendar
- java.lang.Object
-
- org.quartz.impl.calendar.BaseCalendar
-
- org.quartz.impl.calendar.CronCalendar
-
- All Implemented Interfaces:
java.io.Serializable
,java.lang.Cloneable
,Calendar
public class CronCalendar extends BaseCalendar
This implementation of the Calendar excludes the set of times expressed by a givenCronExpression
. For example, you could use this calendar to exclude all but business hours (8AM - 5PM) every day using the expression "* * 0-7,18-23 ? * *".It is important to remember that the cron expression here describes a set of times to be excluded from firing. Whereas the cron expression in
CronTrigger
describes a set of times that can be included for firing. Thus, if aCronTrigger
has a given cron expression and is associated with aCronCalendar
with the same expression, the calendar will exclude all the times the trigger includes, and they will cancel each other out.- Author:
- Aaron Craven
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description CronCalendar(java.lang.String expression)
Create aCronCalendar
with the given cron expression and nobaseCalendar
.CronCalendar(Calendar baseCalendar, java.lang.String expression)
Create aCronCalendar
with the given cron expression andbaseCalendar
.CronCalendar(Calendar baseCalendar, java.lang.String expression, java.util.TimeZone timeZone)
Create aCronCalendar
with the given cron exprssion,baseCalendar
, andTimeZone
.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.Object
clone()
CronExpression
getCronExpression()
Returns the object representation of the cron expression that defines the dates and times this calendar excludes.long
getNextIncludedTime(long timeInMillis)
Determines the next time included by theCronCalendar
after the specified time.java.util.TimeZone
getTimeZone()
Returns the time zone for which theCronExpression
of thisCronCalendar
will be resolved.boolean
isTimeIncluded(long timeInMillis)
Determines whether the given time (in milliseconds) is 'included' by theBaseCalendar
void
setCronExpression(java.lang.String expression)
Sets the cron expression for the calendar to a new valuevoid
setCronExpression(CronExpression expression)
Sets the cron expression for the calendar to a new valuevoid
setTimeZone(java.util.TimeZone timeZone)
Sets the time zone for which theCronExpression
of thisCronCalendar
will be resolved.java.lang.String
toString()
Returns a string representing the properties of theCronCalendar
-
Methods inherited from class org.quartz.impl.calendar.BaseCalendar
createJavaCalendar, createJavaCalendar, getBaseCalendar, getDescription, getEndOfDayJavaCalendar, getStartOfDayJavaCalendar, setBaseCalendar, setDescription
-
-
-
-
Constructor Detail
-
CronCalendar
public CronCalendar(java.lang.String expression) throws java.text.ParseException
Create aCronCalendar
with the given cron expression and nobaseCalendar
.- Parameters:
expression
- a String representation of the desired cron expression- Throws:
java.text.ParseException
-
CronCalendar
public CronCalendar(Calendar baseCalendar, java.lang.String expression) throws java.text.ParseException
Create aCronCalendar
with the given cron expression andbaseCalendar
.- Parameters:
baseCalendar
- the base calendar for this calendar instance – seeBaseCalendar
for more information on base calendar functionalityexpression
- a String representation of the desired cron expression- Throws:
java.text.ParseException
-
CronCalendar
public CronCalendar(Calendar baseCalendar, java.lang.String expression, java.util.TimeZone timeZone) throws java.text.ParseException
Create aCronCalendar
with the given cron exprssion,baseCalendar
, andTimeZone
.- Parameters:
baseCalendar
- the base calendar for this calendar instance – seeBaseCalendar
for more information on base calendar functionalityexpression
- a String representation of the desired cron expressiontimeZone
- Specifies for which time zone theexpression
should be interpreted, i.e. the expression 0 0 10 * * ?, is resolved to 10:00 am in this time zone. IftimeZone
isnull
thenTimeZone.getDefault()
will be used.- Throws:
java.text.ParseException
-
-
Method Detail
-
clone
public java.lang.Object clone()
- Specified by:
clone
in interfaceCalendar
- Overrides:
clone
in classBaseCalendar
-
getTimeZone
public java.util.TimeZone getTimeZone()
Returns the time zone for which theCronExpression
of thisCronCalendar
will be resolved.Overrides
to defer to itsBaseCalendar.getTimeZone()
CronExpression
.- Overrides:
getTimeZone
in classBaseCalendar
- Returns:
- This Calendar's timezone,
null
if Calendar should use theTimeZone.getDefault()
-
setTimeZone
public void setTimeZone(java.util.TimeZone timeZone)
Sets the time zone for which theCronExpression
of thisCronCalendar
will be resolved. IftimeZone
isnull
thenTimeZone.getDefault()
will be used.Overrides
to defer to itsBaseCalendar.setTimeZone(TimeZone)
CronExpression
.- Overrides:
setTimeZone
in classBaseCalendar
- Parameters:
timeZone
- The time zone to use for this Calendar,null
if
should be usedTimeZone.getDefault()
-
isTimeIncluded
public boolean isTimeIncluded(long timeInMillis)
Determines whether the given time (in milliseconds) is 'included' by theBaseCalendar
- Specified by:
isTimeIncluded
in interfaceCalendar
- Overrides:
isTimeIncluded
in classBaseCalendar
- Parameters:
timeInMillis
- the date/time to test- Returns:
- a boolean indicating whether the specified time is 'included' by
the
CronCalendar
- See Also:
Calendar.isTimeIncluded(long)
-
getNextIncludedTime
public long getNextIncludedTime(long timeInMillis)
Determines the next time included by theCronCalendar
after the specified time.- Specified by:
getNextIncludedTime
in interfaceCalendar
- Overrides:
getNextIncludedTime
in classBaseCalendar
- Parameters:
timeInMillis
- the initial date/time after which to find an included time- Returns:
- the time in milliseconds representing the next time included after the specified time.
- See Also:
Calendar.getNextIncludedTime(long)
-
toString
public java.lang.String toString()
Returns a string representing the properties of theCronCalendar
- Overrides:
toString
in classjava.lang.Object
- Returns:
- the properteis of the CronCalendar in a String format
-
getCronExpression
public CronExpression getCronExpression()
Returns the object representation of the cron expression that defines the dates and times this calendar excludes.- Returns:
- the cron expression
- See Also:
CronExpression
-
setCronExpression
public void setCronExpression(java.lang.String expression) throws java.text.ParseException
Sets the cron expression for the calendar to a new value- Parameters:
expression
- the new string value to build a cron expression from- Throws:
java.text.ParseException
- if the string expression cannot be parsed
-
setCronExpression
public void setCronExpression(CronExpression expression)
Sets the cron expression for the calendar to a new value- Parameters:
expression
- the new cron expression
-
-