Class Schedule
- All Implemented Interfaces:
Serializable
Schedule that encapsulates an interval of time, plus an optional relative starting date (the "at" property). For example, to create a schedule that repeats every 5 days, set the interval property to "5D" and don't set the at property. To create a schedule that repeats at 12:30 AM every 5 days, set the interval property to "5D" and the at property to "00:30".
When storing a schedule for repeated execution,
you'd usually store the interval and the previous/next date of execution.
To calculate the next date on the schedule at a later time,
restore the interval as a DateFields
object,
and invoke DateFields.addToDate(java.util.Date)
with the previous date,
looping until the resulting date is greater than the current date
(in case you missed some dates on the schedule
between the date stored and the current date).
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected DateFields
Relative starting date for the interval.protected DateFields
Interval at which schedule repeats. -
Constructor Summary
ConstructorsConstructorDescriptionSchedule()
New schedule with no interval or relative start.Schedule
(DateFields interval) New schedule with an interval and no relative start.Schedule
(DateFields interval, DateFields at) New schedule with an interval and a relative start. -
Method Summary
Modifier and TypeMethodDescriptiongetAt()
Relative starting date for the interval.Interval at which schedule repeats.Calculates the next date on the schedule, relative to the specified date.previousDate
(Date d) Calculates the previous date on the schedule, relative to the specified date.void
setAt
(DateFields at) Relative starting date for the interval.void
setInterval
(DateFields interval) Interval at which schedule repeats.
-
Field Details
-
m_at
Relative starting date for the interval. For example, if the interval is "5D", a relative start of "00:30" sets the schedule to repeat at 12:30 AM every 5th day. If the interval is more fine-grained than the start (for example, the interval is "5H" and the start is "00:30"),nextDate(java.util.Date)
andpreviousDate(java.util.Date)
may produce inconsistent results. -
m_interval
Interval at which schedule repeats. For example, "5D" sets the schedule to repeat every five days; "5H" sets the schedule to repeat every five hours; "5m" sets the schedule to repeat every five minutes.
-
-
Constructor Details
-
Schedule
public Schedule()New schedule with no interval or relative start. You must set an interval before calculating thenextDate(java.util.Date)
or the#prevDate
. -
Schedule
New schedule with an interval and no relative start. -
Schedule
New schedule with an interval and a relative start.
-
-
Method Details
-
nextDate
Calculates the next date on the schedule, relative to the specified date.- Parameters:
d
- Current date.- Returns:
- Next date.
-
previousDate
Calculates the previous date on the schedule, relative to the specified date.- Parameters:
d
- Current date.- Returns:
- Previous date.
-
getAt
Relative starting date for the interval. For example, if the interval is "5D", a relative start of "00:30" sets the schedule to repeat at 12:30 AM every 5th day. If the interval is more fine-grained than the start (for example, the interval is "5H" and the start is "00:30"),nextDate(java.util.Date)
andpreviousDate(java.util.Date)
may produce inconsistent results.- Returns:
- Relative starting date for the interval.
-
setAt
Relative starting date for the interval. For example, if the interval is "5D", a relative start of "00:30" sets the schedule to repeat at 12:30 AM every 5th day. If the interval is more fine-grained than the start (for example, the interval is "5H" and the start is "00:30"),nextDate(java.util.Date)
andpreviousDate(java.util.Date)
may produce inconsistent results. param at Relative starting date for the interval. -
getInterval
Interval at which schedule repeats. For example, "5D" sets the schedule to repeat every five days; "5H" sets the schedule to repeat every five hours; "5m" sets the schedule to repeat every five minutes.- Returns:
- Interval at which schedule repeats.
-
setInterval
Interval at which schedule repeats. For example, "5D" sets the schedule to repeat every five days; "5H" sets the schedule to repeat every five hours; "5m" sets the schedule to repeat every five minutes. param interval Interval at which schedule repeats.
-