de.unkrig.commons.util
Class TimeTable

java.lang.Object
  extended by de.unkrig.commons.util.TimeTable

public abstract class TimeTable
extends java.lang.Object

Represents singular or periodic time events.


Field Summary
static java.util.Date MAX_DATE
          A Date very far in the future.
static java.util.Date MIN_DATE
          A Date very far in the past.
static TimeTable NEVER
          A TimeTable who's next(Date) method always returns MAX_DATE.
 
Method Summary
abstract  java.util.Date next(java.util.Date previous)
           
static TimeTable once(java.util.Date date)
          A TimeTable who's next(Date) method will return date if previous is before date, and MAX_DATE otherwise.
static TimeTable parse(java.lang.String s)
          Creates a TimeTable from a string: ExampleMeaning 2012-12-31 23:59:59
2012-12-31 23:59
2012-12-31One-time *-12-31 23:59:59
*-12-31 23:59
*-12-31Once per year *-*-31 23:59:59
*-*-31 23:59
*-*-31Once per month Mon 23:59:59
Mon 23:59
MonOnce per week 23:59:59
23:59Once per day *:59:59
*:59Once per hour *:*:59
*:*Once per minute *:*:*Every second Instead of '*', integer ranges, integer lists, and combinations thereof can be given: (1,2,3) (2020-2031) (12-3,7) Instead of 'Mon', weekday ranges, weekday lists, and combinations thereof can be given: Sat,Sun Mon-Fri Sun-Mon Mon-Wed,Sat If both day-of-month and day-of-week are specified, then both must match; e.g. '*-2-(8-14) Mon' means 'second monday of february'.
abstract  java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

NEVER

public static final TimeTable NEVER
A TimeTable who's next(Date) method always returns MAX_DATE.


MAX_DATE

public static final java.util.Date MAX_DATE
A Date very far in the future.


MIN_DATE

public static final java.util.Date MIN_DATE
A Date very far in the past.

Method Detail

next

public abstract java.util.Date next(java.util.Date previous)
Returns:
The next scheduled point in time after previous, or MAX_DATE iff there is no "next" execution

once

public static TimeTable once(java.util.Date date)
A TimeTable who's next(Date) method will return date if previous is before date, and MAX_DATE otherwise.


parse

public static TimeTable parse(java.lang.String s)
                       throws ParseException
Creates a TimeTable from a string:
ExampleMeaning
2012-12-31 23:59:59
2012-12-31 23:59
2012-12-31
One-time
*-12-31 23:59:59
*-12-31 23:59
*-12-31
Once per year
*-*-31 23:59:59
*-*-31 23:59
*-*-31
Once per month
Mon 23:59:59
Mon 23:59
Mon
Once per week
23:59:59
23:59
Once per day
*:59:59
*:59
Once per hour
*:*:59
*:*
Once per minute
*:*:*Every second
Instead of '*', integer ranges, integer lists, and combinations thereof can be given:
(1,2,3)
(2020-2031)
(12-3,7)
Instead of 'Mon', weekday ranges, weekday lists, and combinations thereof can be given:
Sat,Sun
Mon-Fri
Sun-Mon
Mon-Wed,Sat
If both day-of-month and day-of-week are specified, then both must match; e.g. '*-2-(8-14) Mon' means 'second monday of february'.

Multiple patterns can be specified, separated with commas, which means that the next(Date) method will return the earliest next point-in-time that matches any of the patterns. Example: '*-*-1,Mon' - next first-of-month or next monday, whichever comes first.

Throws:
ParseException

toString

public abstract java.lang.String toString()
Overrides:
toString in class java.lang.Object