📄 dailycalendar.java
字号:
package org.quartz.impl.calendar;
import java.text.NumberFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.StringTokenizer;
import java.util.TimeZone;
/**
* This implementation of the Calendar excludes (or includes - see below) a
* specified time range each day. For example, you could use this calendar to
* exclude business hours (8AM - 5PM) every day. Each <CODE>DailyCalendar</CODE>
* only allows a single time range to be specified, and that time range may not
* cross daily boundaries (i.e. you cannot specify a time range from 8PM - 5AM).
* If the property <CODE>invertTimeRange</CODE> is <CODE>false</CODE> (default),
* the time range defines a range of times in which triggers are not allowed to
* fire. If <CODE>invertTimeRange</CODE> is <CODE>true</CODE>, the time range
* is inverted – that is, all times <I>outside</I> the defined time range
* are excluded.
* <P>
* Note when using <CODE>DailyCalendar</CODE>, it behaves on the same principals
* as, for example, {@link org.quartz.impl.calendar.WeeklyCalendar
* WeeklyCalendar}. <CODE>WeeklyCalendar</CODE> defines a set of days that are
* excluded <I>every week</I>. Likewise, <CODE>DailyCalendar</CODE> defines a
* set of times that are excluded <I>every day</I>.
*
* @author Mike Funk, Aaron Craven
*/
public class DailyCalendar extends BaseCalendar {
static final long serialVersionUID = -7561220099904944039L;
private static final String invalidHourOfDay = "Invalid hour of day: ";
private static final String invalidMinute = "Invalid minute: ";
private static final String invalidSecond = "Invalid second: ";
private static final String invalidMillis = "Invalid millis: ";
private static final String invalidTimeRange = "Invalid time range: ";
private static final String separator = " - ";
private static final long oneMillis = 1;
private static final String colon = ":";
/** @deprecated The use of <code>name</code> is no longer supported. */
private String name;
private int rangeStartingHourOfDay;
private int rangeStartingMinute;
private int rangeStartingSecond;
private int rangeStartingMillis;
private int rangeEndingHourOfDay;
private int rangeEndingMinute;
private int rangeEndingSecond;
private int rangeEndingMillis;
private boolean invertTimeRange = false;
/**
* Create a <CODE>DailyCalendar</CODE> with a time range defined by the
* specified strings and no <CODE>baseCalendar</CODE>.
* <CODE>rangeStartingTime</CODE> and <CODE>rangeEndingTime</CODE>
* must be in the format "HH:MM[:SS[:mmm]]" where:
* <UL><LI>HH is the hour of the specified time. The hour should be
* specified using military (24-hour) time and must be in the range
* 0 to 23.</LI>
* <LI>MM is the minute of the specified time and must be in the range
* 0 to 59.</LI>
* <LI>SS is the second of the specified time and must be in the range
* 0 to 59.</LI>
* <LI>mmm is the millisecond of the specified time and must be in the
* range 0 to 999.</LI>
* <LI>items enclosed in brackets ('[', ']') are optional.</LI>
* <LI>The time range starting time must be before the time range ending
* time. Note this means that a time range may not cross daily
* boundaries (10PM - 2AM)</LI>
* </UL>
*
* <p>
* <b>Note:</b> This <CODE>DailyCalendar</CODE> will use the
* <code>{@link TimeZone#getDefault()}</code> time zone unless an explicit
* time zone is set via <code>{@link BaseCalendar#setTimeZone(TimeZone)}</code>
* </p>
*
* @param rangeStartingTime a String representing the starting time for the
* time range
* @param rangeEndingTime a String representing the ending time for the
* the time range
*/
public DailyCalendar(String rangeStartingTime,
String rangeEndingTime) {
super();
setTimeRange(rangeStartingTime, rangeEndingTime);
}
/**
* Create a <CODE>DailyCalendar</CODE> with a time range defined by the
* specified strings and the specified <CODE>baseCalendar</CODE>.
* <CODE>rangeStartingTime</CODE> and <CODE>rangeEndingTime</CODE>
* must be in the format "HH:MM[:SS[:mmm]]" where:
* <UL><LI>HH is the hour of the specified time. The hour should be
* specified using military (24-hour) time and must be in the range
* 0 to 23.</LI>
* <LI>MM is the minute of the specified time and must be in the range
* 0 to 59.</LI>
* <LI>SS is the second of the specified time and must be in the range
* 0 to 59.</LI>
* <LI>mmm is the millisecond of the specified time and must be in the
* range 0 to 999.</LI>
* <LI>items enclosed in brackets ('[', ']') are optional.</LI>
* <LI>The time range starting time must be before the time range ending
* time. Note this means that a time range may not cross daily
* boundaries (10PM - 2AM)</LI>
* </UL>
*
* <p>
* <b>Note:</b> This <CODE>DailyCalendar</CODE> will use the
* <code>{@link TimeZone#getDefault()}</code> time zone unless an explicit
* time zone is set via <code>{@link BaseCalendar#setTimeZone(TimeZone)}</code>
* </p>
*
* @param baseCalendar the base calendar for this calendar instance
* – see {@link BaseCalendar} for more
* information on base calendar functionality
* @param rangeStartingTime a String representing the starting time for the
* time range
* @param rangeEndingTime a String representing the ending time for the
* time range
*/
public DailyCalendar(org.quartz.Calendar baseCalendar,
String rangeStartingTime,
String rangeEndingTime) {
super(baseCalendar);
setTimeRange(rangeStartingTime, rangeEndingTime);
}
/**
* Create a <CODE>DailyCalendar</CODE> with a time range defined by the
* specified values and no <CODE>baseCalendar</CODE>. Values are subject to
* the following validations:
* <UL><LI>Hours must be in the range 0-23 and are expressed using military
* (24-hour) time.</LI>
* <LI>Minutes must be in the range 0-59</LI>
* <LI>Seconds must be in the range 0-59</LI>
* <LI>Milliseconds must be in the range 0-999</LI>
* <LI>The time range starting time must be before the time range ending
* time. Note this means that a time range may not cross daily
* boundaries (10PM - 2AM)</LI>
* </UL>
*
* <p>
* <b>Note:</b> This <CODE>DailyCalendar</CODE> will use the
* <code>{@link TimeZone#getDefault()}</code> time zone unless an explicit
* time zone is set via <code>{@link BaseCalendar#setTimeZone(TimeZone)}</code>
* </p>
*
* @param rangeStartingHourOfDay the hour of the start of the time range
* @param rangeStartingMinute the minute of the start of the time range
* @param rangeStartingSecond the second of the start of the time range
* @param rangeStartingMillis the millisecond of the start of the time
* range
* @param rangeEndingHourOfDay the hour of the end of the time range
* @param rangeEndingMinute the minute of the end of the time range
* @param rangeEndingSecond the second of the end of the time range
* @param rangeEndingMillis the millisecond of the start of the time
* range
*/
public DailyCalendar(int rangeStartingHourOfDay,
int rangeStartingMinute,
int rangeStartingSecond,
int rangeStartingMillis,
int rangeEndingHourOfDay,
int rangeEndingMinute,
int rangeEndingSecond,
int rangeEndingMillis) {
super();
setTimeRange(rangeStartingHourOfDay,
rangeStartingMinute,
rangeStartingSecond,
rangeStartingMillis,
rangeEndingHourOfDay,
rangeEndingMinute,
rangeEndingSecond,
rangeEndingMillis);
}
/**
* Create a <CODE>DailyCalendar</CODE> with a time range defined by the
* specified values and the specified <CODE>baseCalendar</CODE>. Values are
* subject to the following validations:
* <UL><LI>Hours must be in the range 0-23 and are expressed using military
* (24-hour) time.</LI>
* <LI>Minutes must be in the range 0-59</LI>
* <LI>Seconds must be in the range 0-59</LI>
* <LI>Milliseconds must be in the range 0-999</LI>
* <LI>The time range starting time must be before the time range ending
* time. Note this means that a time range may not cross daily
* boundaries (10PM - 2AM)</LI>
* </UL>
*
* <p>
* <b>Note:</b> This <CODE>DailyCalendar</CODE> will use the
* <code>{@link TimeZone#getDefault()}</code> time zone unless an explicit
* time zone is set via <code>{@link BaseCalendar#setTimeZone(TimeZone)}</code>
* </p>
*
* @param baseCalendar the base calendar for this calendar
* instance – see
* {@link BaseCalendar} for more
* information on base calendar
* functionality
* @param rangeStartingHourOfDay the hour of the start of the time range
* @param rangeStartingMinute the minute of the start of the time range
* @param rangeStartingSecond the second of the start of the time range
* @param rangeStartingMillis the millisecond of the start of the time
* range
* @param rangeEndingHourOfDay the hour of the end of the time range
* @param rangeEndingMinute the minute of the end of the time range
* @param rangeEndingSecond the second of the end of the time range
* @param rangeEndingMillis the millisecond of the start of the time
* range
*/
public DailyCalendar(org.quartz.Calendar baseCalendar,
int rangeStartingHourOfDay,
int rangeStartingMinute,
int rangeStartingSecond,
int rangeStartingMillis,
int rangeEndingHourOfDay,
int rangeEndingMinute,
int rangeEndingSecond,
int rangeEndingMillis) {
super(baseCalendar);
setTimeRange(rangeStartingHourOfDay,
rangeStartingMinute,
rangeStartingSecond,
rangeStartingMillis,
rangeEndingHourOfDay,
rangeEndingMinute,
rangeEndingSecond,
rangeEndingMillis);
}
/**
* Create a <CODE>DailyCalendar</CODE> with a time range defined by the
* specified <CODE>java.util.Calendar</CODE>s and no
* <CODE>baseCalendar</CODE>. The Calendars are subject to the following
* considerations:
* <UL><LI>Only the time-of-day fields of the specified Calendars will be
* used (the date fields will be ignored)</LI>
* <LI>The starting time must be before the ending time of the defined
* time range. Note this means that a time range may not cross
* daily boundaries (10PM - 2AM). <I>(because only time fields are
* are used, it is possible for two Calendars to represent a valid
* time range and
* <CODE>rangeStartingCalendar.after(rangeEndingCalendar) ==
* true</CODE>)</I></LI>
* </UL>
*
* <p>
* <b>Note:</b> This <CODE>DailyCalendar</CODE> will use the
* <code>{@link TimeZone#getDefault()}</code> time zone unless an explicit
* time zone is set via <code>{@link BaseCalendar#setTimeZone(TimeZone)}</code>
* </p>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -