Method from org.quartz.TriggerUtils Detail: |
public static List computeFireTimes(Trigger trigg,
Calendar cal,
int numTimes) {
LinkedList lst = new LinkedList();
Trigger t = (Trigger) trigg.clone();
if (t.getNextFireTime() == null) {
t.computeFirstFireTime(cal);
}
for (int i = 0; i < numTimes; i++) {
Date d = t.getNextFireTime();
if (d != null) {
lst.add(d);
t.triggered(cal);
} else {
break;
}
}
return java.util.Collections.unmodifiableList(lst);
}
Returns a list of Dates that are the next fire times of a
Trigger .
The input trigger will be cloned before any work is done, so you need
not worry about its state being altered by this method. |
public static List computeFireTimesBetween(Trigger trigg,
Calendar cal,
Date from,
Date to) {
LinkedList lst = new LinkedList();
Trigger t = (Trigger) trigg.clone();
if (t.getNextFireTime() == null) {
t.setStartTime(from);
t.setEndTime(to);
t.computeFirstFireTime(cal);
}
// TODO: this method could be more efficient by using logic specific
// to the type of trigger ...
while (true) {
Date d = t.getNextFireTime();
if (d != null) {
if (d.before(from)) {
t.triggered(cal);
continue;
}
if (d.after(to)) {
break;
}
lst.add(d);
t.triggered(cal);
} else {
break;
}
}
return java.util.Collections.unmodifiableList(lst);
}
Returns a list of Dates that are the next fire times of a
Trigger
that fall within the given date range. The input trigger will be cloned
before any work is done, so you need not worry about its state being
altered by this method.
NOTE: if this is a trigger that has previously fired within the given
date range, then firings which have already occured will not be listed
in the output List.
|
public static int getDSTSavings(TimeZone tz) {
if (tz.useDaylightTime()) {
return 3600000;
}
return 0;
}
Equivalent of TimeZone.getDSTSavings() in JDK 1.4, but Quartz is trying
to support JDK 1.3.
|
public static Date getDateOf(int second,
int minute,
int hour) {
validateSecond(second);
validateMinute(minute);
validateHour(hour);
Date date = new Date();
Calendar c = Calendar.getInstance();
c.setTime(date);
c.setLenient(true);
c.set(Calendar.HOUR_OF_DAY, hour);
c.set(Calendar.MINUTE, minute);
c.set(Calendar.SECOND, second);
c.set(Calendar.MILLISECOND, 0);
return c.getTime();
}
Get a Date object that represents the given time, on
today's date.
|
public static Date getDateOf(int second,
int minute,
int hour,
int dayOfMonth,
int month) {
validateSecond(second);
validateMinute(minute);
validateHour(hour);
validateDayOfMonth(dayOfMonth);
validateMonth(month);
Date date = new Date();
Calendar c = Calendar.getInstance();
c.setTime(date);
c.set(Calendar.MONTH, month - 1);
c.set(Calendar.DAY_OF_MONTH, dayOfMonth);
c.set(Calendar.HOUR_OF_DAY, hour);
c.set(Calendar.MINUTE, minute);
c.set(Calendar.SECOND, second);
c.set(Calendar.MILLISECOND, 0);
return c.getTime();
}
Get a Date object that represents the given time, on the
given date.
|
public static Date getDateOf(int second,
int minute,
int hour,
int dayOfMonth,
int month,
int year) {
validateSecond(second);
validateMinute(minute);
validateHour(hour);
validateDayOfMonth(dayOfMonth);
validateMonth(month);
validateYear(year);
Date date = new Date();
Calendar c = Calendar.getInstance();
c.setTime(date);
c.set(Calendar.YEAR, year);
c.set(Calendar.MONTH, month - 1);
c.set(Calendar.DAY_OF_MONTH, dayOfMonth);
c.set(Calendar.HOUR_OF_DAY, hour);
c.set(Calendar.MINUTE, minute);
c.set(Calendar.SECOND, second);
c.set(Calendar.MILLISECOND, 0);
return c.getTime();
}
Get a Date object that represents the given time, on the
given date.
|
public static Date getEvenHourDate(Date date) {
if (date == null) {
date = new Date();
}
Calendar c = Calendar.getInstance();
c.setTime(date);
c.setLenient(true);
c.set(Calendar.HOUR_OF_DAY, c.get(Calendar.HOUR_OF_DAY) + 1);
c.set(Calendar.MINUTE, 0);
c.set(Calendar.SECOND, 0);
c.set(Calendar.MILLISECOND, 0);
return c.getTime();
}
Returns a date that is rounded to the next even hour above the given
date.
For example an input date with a time of 08:13:54 would result in a date
with the time of 09:00:00. If the date's time is in the 23rd hour, the
date's 'day' will be promoted, and the time will be set to 00:00:00.
|
public static Date getEvenHourDateBefore(Date date) {
if (date == null) {
date = new Date();
}
Calendar c = Calendar.getInstance();
c.setTime(date);
c.set(Calendar.MINUTE, 0);
c.set(Calendar.SECOND, 0);
c.set(Calendar.MILLISECOND, 0);
return c.getTime();
}
Returns a date that is rounded to the previous even hour below the given
date.
For example an input date with a time of 08:13:54 would result in a date
with the time of 08:00:00.
|
public static Date getEvenMinuteDate(Date date) {
if (date == null) {
date = new Date();
}
Calendar c = Calendar.getInstance();
c.setTime(date);
c.setLenient(true);
c.set(Calendar.MINUTE, c.get(Calendar.MINUTE) + 1);
c.set(Calendar.SECOND, 0);
c.set(Calendar.MILLISECOND, 0);
return c.getTime();
}
Returns a date that is rounded to the next even minute above the given
date.
For example an input date with a time of 08:13:54 would result in a date
with the time of 08:14:00. If the date's time is in the 59th minute,
then the hour (and possibly the day) will be promoted.
|
public static Date getEvenMinuteDateBefore(Date date) {
if (date == null) {
date = new Date();
}
Calendar c = Calendar.getInstance();
c.setTime(date);
c.set(Calendar.SECOND, 0);
c.set(Calendar.MILLISECOND, 0);
return c.getTime();
}
Returns a date that is rounded to the previous even minute below the
given date.
For example an input date with a time of 08:13:54 would result in a date
with the time of 08:13:00.
|
public static Date getEvenSecondDate(Date date) {
if (date == null) {
date = new Date();
}
Calendar c = Calendar.getInstance();
c.setTime(date);
c.setLenient(true);
c.set(Calendar.SECOND, c.get(Calendar.SECOND) + 1);
c.set(Calendar.MILLISECOND, 0);
return c.getTime();
}
|
public static Date getEvenSecondDateBefore(Date date) {
if (date == null) {
date = new Date();
}
Calendar c = Calendar.getInstance();
c.setTime(date);
c.set(Calendar.MILLISECOND, 0);
return c.getTime();
}
Returns a date that is rounded to the previous even second below the
given date.
For example an input date with a time of 08:13:54.341 would result in a
date with the time of 08:13:00.000.
|
public static Date getNextGivenMinuteDate(Date date,
int minuteBase) {
if (minuteBase < 0 || minuteBase > 59) {
throw new IllegalArgumentException(
"minuteBase must be >=0 and < = 59");
}
if (date == null) {
date = new Date();
}
Calendar c = Calendar.getInstance();
c.setTime(date);
c.setLenient(true);
if (minuteBase == 0) {
c.set(Calendar.HOUR_OF_DAY, c.get(Calendar.HOUR_OF_DAY) + 1);
c.set(Calendar.MINUTE, 0);
c.set(Calendar.SECOND, 0);
c.set(Calendar.MILLISECOND, 0);
return c.getTime();
}
int minute = c.get(Calendar.MINUTE);
int arItr = minute / minuteBase;
int nextMinuteOccurance = minuteBase * (arItr + 1);
if (nextMinuteOccurance < 60) {
c.set(Calendar.MINUTE, nextMinuteOccurance);
c.set(Calendar.SECOND, 0);
c.set(Calendar.MILLISECOND, 0);
return c.getTime();
} else {
c.set(Calendar.HOUR_OF_DAY, c.get(Calendar.HOUR_OF_DAY) + 1);
c.set(Calendar.MINUTE, 0);
c.set(Calendar.SECOND, 0);
c.set(Calendar.MILLISECOND, 0);
return c.getTime();
}
}
Returns a date that is rounded to the next even multiple of the given
minute.
For example an input date with a time of 08:13:54, and an input
minute-base of 5 would result in a date with the time of 08:15:00. The
same input date with an input minute-base of 10 would result in a date
with the time of 08:20:00. But a date with the time 08:53:31 and an
input minute-base of 45 would result in 09:00:00, because the even-hour
is the next 'base' for 45-minute intervals.
More examples:
Input Time |
Minute-Base |
Result Time |
11:16:41 |
20 |
11:20:00 |
11:36:41 |
20 |
11:40:00 |
11:46:41 |
20 |
12:00:00 |
11:26:41 |
30 |
11:30:00 |
11:36:41 |
30 |
12:00:00 |
11:16:41 |
17 |
11:17:00 |
11:17:41 |
17 |
11:34:00 |
11:52:41 |
17 |
12:00:00 |
11:52:41 |
5 |
11:55:00 |
11:57:41 |
5 |
12:00:00 |
11:17:41 |
0 |
12:00:00 |
11:17:41 |
1 |
11:08:00 |
|
public static Date getNextGivenSecondDate(Date date,
int secondBase) {
if (secondBase < 0 || secondBase > 59) {
throw new IllegalArgumentException(
"secondBase must be >=0 and < = 59");
}
if (date == null) {
date = new Date();
}
Calendar c = Calendar.getInstance();
c.setTime(date);
c.setLenient(true);
if (secondBase == 0) {
c.set(Calendar.MINUTE, c.get(Calendar.MINUTE) + 1);
c.set(Calendar.SECOND, 0);
c.set(Calendar.MILLISECOND, 0);
return c.getTime();
}
int second = c.get(Calendar.SECOND);
int arItr = second / secondBase;
int nextSecondOccurance = secondBase * (arItr + 1);
if (nextSecondOccurance < 60) {
c.set(Calendar.SECOND, nextSecondOccurance);
c.set(Calendar.MILLISECOND, 0);
return c.getTime();
} else {
c.set(Calendar.MINUTE, c.get(Calendar.MINUTE) + 1);
c.set(Calendar.SECOND, 0);
c.set(Calendar.MILLISECOND, 0);
return c.getTime();
}
}
Returns a date that is rounded to the next even multiple of the given
minute.
The rules for calculating the second are the same as those for
calculating the minute in the method
getNextGivenMinuteDate(..).
|
public static int getOffset(long date,
TimeZone tz) {
if (tz.inDaylightTime(new Date(date))) {
return tz.getRawOffset() + getDSTSavings(tz);
}
return tz.getRawOffset();
}
Gets the offset from UT for the given date in the given timezone,
taking into account daylight savings.
Equivalent of TimeZone.getOffset(date) in JDK 1.4, but Quartz is trying
to support JDK 1.3.
|
public static Trigger makeDailyTrigger(int hour,
int minute) {
validateHour(hour);
validateMinute(minute);
CronTrigger trig = new CronTrigger();
try {
trig.setCronExpression("0 " + minute + " " + hour + " ? * *");
} catch (Exception ignore) {
return null; /* never happens... */
}
trig.setStartTime(new Date());
return trig;
}
Make a trigger that will fire every day at the given time.
The generated trigger will not have its name, group,
or end-time set. The Start time defaults to 'now'.
|
public static Trigger makeDailyTrigger(String trigName,
int hour,
int minute) {
Trigger trig = makeDailyTrigger(hour, minute);
trig.setName(trigName);
return trig;
}
Make a trigger that will fire every day at the given time.
The generated trigger will not have its group or end-time set.
The Start time defaults to 'now'.
|
public static Trigger makeHourlyTrigger() {
return makeHourlyTrigger(1, SimpleTrigger.REPEAT_INDEFINITELY);
}
Make a trigger that will fire every hour, indefinitely.
The generated trigger will not have its name, group,
or end-time set. The Start time defaults to 'now'.
|
public static Trigger makeHourlyTrigger(String trigName) {
return makeHourlyTrigger(
trigName, 1, SimpleTrigger.REPEAT_INDEFINITELY);
}
Make a trigger that will fire every hour, indefinitely.
The generated trigger will not have its group,
or end-time set. The Start time defaults to 'now'.
|
public static Trigger makeHourlyTrigger(int intervalInHours) {
return makeHourlyTrigger(
intervalInHours, SimpleTrigger.REPEAT_INDEFINITELY);
}
Make a trigger that will fire every N hours, indefinitely.
The generated trigger will not have its name, group,
or end-time set. The Start time defaults to 'now'.
|
public static Trigger makeHourlyTrigger(int intervalInHours,
int repeatCount) {
SimpleTrigger trig = new SimpleTrigger();
trig.setRepeatInterval(intervalInHours * MILLISECONDS_IN_HOUR);
trig.setRepeatCount(repeatCount);
trig.setStartTime(new Date());
return trig;
}
Make a trigger that will fire every N hours, with the given number of
repeats.
The generated trigger will not have its name, group,
or end-time set. The Start time defaults to 'now'.
|
public static Trigger makeHourlyTrigger(String trigName,
int intervalInHours,
int repeatCount) {
Trigger trig =makeHourlyTrigger(intervalInHours, repeatCount);
trig.setName(trigName);
return trig;
}
Make a trigger that will fire every N hours, with the given number of
repeats.
The generated trigger will not have its group,
or end-time set. The Start time defaults to 'now'.
|
public static Trigger makeImmediateTrigger(int repeatCount,
long repeatInterval) {
SimpleTrigger trig = new SimpleTrigger();
trig.setStartTime( new Date() );
trig.setRepeatCount(repeatCount);
trig.setRepeatInterval(repeatInterval);
return trig;
}
Make a trigger that will fire repeatCount times, waiting
repeatInterval milliseconds between each fire.
The generated trigger will not have its name, group,
or end-time set. The Start time defaults to 'now'.
|
public static Trigger makeImmediateTrigger(String trigName,
int repeatCount,
long repeatInterval) {
Trigger trig = makeImmediateTrigger(repeatCount, repeatInterval);
trig.setName(trigName);
return trig;
}
Make a trigger that will fire repeatCount times, waiting
repeatInterval milliseconds between each fire.
The generated trigger will not have its name, group,
or end-time set. The Start time defaults to 'now'.
|
public static Trigger makeMinutelyTrigger() {
return makeMinutelyTrigger(1, SimpleTrigger.REPEAT_INDEFINITELY);
}
Make a trigger that will fire every minute, indefinitely.
The generated trigger will not have its name, group,
or end-time set. The Start time defaults to 'now'.
|
public static Trigger makeMinutelyTrigger(String trigName) {
return makeMinutelyTrigger(
trigName, 1, SimpleTrigger.REPEAT_INDEFINITELY);
}
Make a trigger that will fire every minute, indefinitely.
The generated trigger will not have its group,
or end-time set. The Start time defaults to 'now'.
|
public static Trigger makeMinutelyTrigger(int intervalInMinutes) {
return makeMinutelyTrigger(
intervalInMinutes, SimpleTrigger.REPEAT_INDEFINITELY);
}
Make a trigger that will fire every N minutes, indefinitely.
The generated trigger will not have its name, group,
or end-time set. The Start time defaults to 'now'.
|
public static Trigger makeMinutelyTrigger(int intervalInMinutes,
int repeatCount) {
SimpleTrigger trig = new SimpleTrigger();
trig.setRepeatInterval(intervalInMinutes * MILLISECONDS_IN_MINUTE);
trig.setRepeatCount(repeatCount);
trig.setStartTime(new Date());
return trig;
}
Make a trigger that will fire every N minutes, with the given number of
repeats.
The generated trigger will not have its name, group,
or end-time set. The Start time defaults to 'now'.
|
public static Trigger makeMinutelyTrigger(String trigName,
int intervalInMinutes,
int repeatCount) {
Trigger trig = makeMinutelyTrigger(intervalInMinutes, repeatCount);
trig.setName(trigName);
return trig;
}
Make a trigger that will fire every N minutes, with the given number of
repeats.
The generated trigger will not have its group,
or end-time set. The Start time defaults to 'now'.
|
public static Trigger makeMonthlyTrigger(int dayOfMonth,
int hour,
int minute) {
validateDayOfMonth(dayOfMonth);
validateHour(hour);
validateMinute(minute);
CronTrigger trig = new CronTrigger();
try {
if (dayOfMonth != LAST_DAY_OF_MONTH) {
trig.setCronExpression("0 " + minute + " " + hour + " " + dayOfMonth + " * ?");
} else {
trig.setCronExpression("0 " + minute + " " + hour + " L * ?");
}
} catch (Exception ignore) {
return null; /* never happens... */
}
trig.setStartTime(new Date());
return trig;
}
Make a trigger that will fire every month at the given day and time.
The generated trigger will not have its name, group,
or end-time set. The Start time defaults to 'now'.
If the day of the month specified does not occur in a given month, a
firing will not occur that month. (i.e. if dayOfMonth is specified as
31, no firing will occur in the months of the year with fewer than 31
days).
|
public static Trigger makeMonthlyTrigger(String trigName,
int dayOfMonth,
int hour,
int minute) {
Trigger trig = makeMonthlyTrigger(dayOfMonth, hour, minute);
trig.setName(trigName);
return trig;
}
Make a trigger that will fire every month at the given day and time.
The generated trigger will not have its group,
or end-time set. The Start time defaults to 'now'.
If the day of the month specified does not occur in a given month, a
firing will not occur that month. (i.e. if dayOfMonth is specified as
31, no firing will occur in the months of the year with fewer than 31
days).
|
public static Trigger makeSecondlyTrigger() {
return makeSecondlyTrigger(1, SimpleTrigger.REPEAT_INDEFINITELY);
}
Make a trigger that will fire every second, indefinitely.
The generated trigger will not have its name, group,
or end-time set. The Start time defaults to 'now'.
|
public static Trigger makeSecondlyTrigger(String trigName) {
return makeSecondlyTrigger(
trigName, 1, SimpleTrigger.REPEAT_INDEFINITELY);
}
Make a trigger that will fire every second, indefinitely.
The generated trigger will not have its group,
or end-time set. The Start time defaults to 'now'.
|
public static Trigger makeSecondlyTrigger(int intervalInSeconds) {
return makeSecondlyTrigger(
intervalInSeconds, SimpleTrigger.REPEAT_INDEFINITELY);
}
Make a trigger that will fire every N seconds, indefinitely.
The generated trigger will not have its name, group,
or end-time set. The Start time defaults to 'now'.
|
public static Trigger makeSecondlyTrigger(int intervalInSeconds,
int repeatCount) {
SimpleTrigger trig = new SimpleTrigger();
trig.setRepeatInterval(intervalInSeconds * 1000l);
trig.setRepeatCount(repeatCount);
trig.setStartTime(new Date());
return trig;
}
Make a trigger that will fire every N seconds, with the given number of
repeats.
The generated trigger will not have its name, group,
or end-time set. The Start time defaults to 'now'.
|
public static Trigger makeSecondlyTrigger(String trigName,
int intervalInSeconds,
int repeatCount) {
Trigger trig = makeSecondlyTrigger(intervalInSeconds, repeatCount);
trig.setName(trigName);
return trig;
}
Make a trigger that will fire every N seconds, with the given number of
repeats.
The generated trigger will not have its group,
or end-time set. The Start time defaults to 'now'.
|
public static Trigger makeWeeklyTrigger(int dayOfWeek,
int hour,
int minute) {
validateDayOfWeek(dayOfWeek);
validateHour(hour);
validateMinute(minute);
CronTrigger trig = new CronTrigger();
try {
trig.setCronExpression("0 " + minute + " " + hour + " ? * "
+ dayOfWeek);
} catch (Exception ignore) {
return null; /* never happens... */
}
trig.setStartTime(new Date());
return trig;
}
Make a trigger that will fire every week at the given day and time.
The generated trigger will not have its name, group,
or end-time set. The Start time defaults to 'now'.
|
public static Trigger makeWeeklyTrigger(String trigName,
int dayOfWeek,
int hour,
int minute) {
Trigger trig = makeWeeklyTrigger(dayOfWeek, hour, minute);
trig.setName(trigName);
return trig;
}
Make a trigger that will fire every week at the given day and time.
The generated trigger will not have its group,
or end-time set. The Start time defaults to 'now'.
|
public static void setTriggerIdentity(Trigger trig,
String name) {
setTriggerIdentity(trig, name, Scheduler.DEFAULT_GROUP);
}
Set the given Trigger 's name to the given value, and its
group to the default group (Scheduler.DEFAULT_GROUP ).
|
public static void setTriggerIdentity(Trigger trig,
String name,
String group) {
trig.setName(name);
trig.setGroup(group);
}
Set the given Trigger 's name to the given value, and its
group to the given group.
|
public static Date translateTime(Date date,
TimeZone src,
TimeZone dest) {
Date newDate = new Date();
int offset = (
getOffset(date.getTime(), dest) - getOffset(date.getTime(), src));
newDate.setTime(date.getTime() - offset);
return newDate;
}
Translate a date & time from a users timezone to the another
(probably server) timezone to assist in creating a simple trigger with
the right date & time. |