DateBuilder (Quartz Parent POM 2.0.1 API)

Quartz Java



org.quartz Class DateBuilder

java.lang.Object
  extended by org.quartz.DateBuilder

public class DateBuilder
extends Object

DateBuilder is used to conveniently create java.util.Date instances that meet particular criteria.

Quartz provides a builder-style API for constructing scheduling-related entities via a Domain-Specific Language (DSL). The DSL can best be utilized through the usage of static imports of the methods on the classes TriggerBuilder, JobBuilder, DateBuilder, JobKey, TriggerKey and the various ScheduleBuilder implementations.

Client code can then use the DSL to write code such as this:

         JobDetail job = newJob(MyJob.class)
             .withIdentity("myJob")
             .build();
             
         Trigger trigger = newTrigger() 
             .withIdentity(triggerKey("myTrigger", "myTriggerGroup"))
             .withSchedule(simpleSchedule()
                 .withIntervalInHours(1)
                 .repeatForever())
             .startAt(futureDate(10, MINUTES))
             .build();
         
         scheduler.scheduleJob(job, trigger);
 

See Also:
TriggerBuilder, JobBuilder

Nested Class Summary
static class DateBuilder.IntervalUnit
           
 
Field Summary
static int FRIDAY
           
static long MILLISECONDS_IN_DAY
           
static long MILLISECONDS_IN_HOUR
           
static long MILLISECONDS_IN_MINUTE
           
static int MONDAY
           
static int SATURDAY
           
static long SECONDS_IN_MOST_DAYS
           
static int SUNDAY
           
static int THURSDAY
           
static int TUESDAY
           
static int WEDNESDAY
           
 
Method Summary
 DateBuilder atHourMinuteAndSecond(int hour, int minute, int second)
           
 DateBuilder atHourOfDay(int hour)
          Set the hour (0-23) for the Date that will be built by this builder.
 DateBuilder atMinute(int minute)
          Set the minute (0-59) for the Date that will be built by this builder.
 DateBuilder atSecond(int second)
          Set the second (0-59) for the Date that will be built by this builder, and truncate the milliseconds to 000.
 Date build()
          Build the Date defined by this builder instance.
static Date dateOf(int hour, int minute, int second)
           Get a Date object that represents the given time, on today's date (equivalent to todayAt(int, int, int)).
static Date dateOf(int hour, int minute, int second, int dayOfMonth, int month)
           Get a Date object that represents the given time, on the given date.
static Date dateOf(int hour, int minute, int second, int dayOfMonth, int month, int year)
           Get a Date object that represents the given time, on the given date.
static Date evenHourDate(Date date)
           Returns a date that is rounded to the next even hour above the given date.
static Date evenHourDateAfterNow()
           Returns a date that is rounded to the next even hour after the current time.
static Date evenHourDateBefore(Date date)
           Returns a date that is rounded to the previous even hour below the given date.
static Date evenMinuteDate(Date date)
           Returns a date that is rounded to the next even minute above the given date.
static Date evenMinuteDateAfterNow()
           Returns a date that is rounded to the next even minute after the current time.
static Date evenMinuteDateBefore(Date date)
           Returns a date that is rounded to the previous even minute below the given date.
static Date evenSecondDate(Date date)
           Returns a date that is rounded to the next even second above the given date.
static Date evenSecondDateAfterNow()
           Returns a date that is rounded to the next even second after the current time.
static Date evenSecondDateBefore(Date date)
           Returns a date that is rounded to the previous even second below the given date.
static Date futureDate(int interval, DateBuilder.IntervalUnit unit)
           
 DateBuilder inLocale(Locale lc)
          Set the Locale for the Date that will be built by this builder (if "null", system default will be used)
 DateBuilder inMonth(int month)
          Set the month (1-12) for the Date that will be built by this builder.
 DateBuilder inMonthOnDay(int month, int day)
           
 DateBuilder inTimeZone(TimeZone tz)
          Set the TimeZone for the Date that will be built by this builder (if "null", system default will be used)
 DateBuilder inYear(int year)
          Set the year for the Date that will be built by this builder.
static DateBuilder newDate()
          Create a DateBuilder, with initial settings for the current date and time in the system default timezone.
static DateBuilder newDateInLocale(Locale lc)
          Create a DateBuilder, with initial settings for the current date and time in the given locale.
static DateBuilder newDateInTimezone(TimeZone tz)
          Create a DateBuilder, with initial settings for the current date and time in the given timezone.
static DateBuilder newDateInTimeZoneAndLocale(TimeZone tz, Locale lc)
          Create a DateBuilder, with initial settings for the current date and time in the given timezone and locale.
static Date nextGivenMinuteDate(Date date, int minuteBase)
           Returns a date that is rounded to the next even multiple of the given minute.
static Date nextGivenSecondDate(Date date, int secondBase)
           Returns a date that is rounded to the next even multiple of the given minute.
 DateBuilder onDay(int day)
          Set the day of month (1-31) for the Date that will be built by this builder.
static Date todayAt(int hour, int minute, int second)
           Get a Date object that represents the given time, on today's date (equivalent to dateOf(int, int, int)).
static Date tomorrowAt(int hour, int minute, int second)
           Get a Date object that represents the given time, on tomorrow's date.
static Date translateTime(Date date, TimeZone src, TimeZone dest)
          Translate a date & time from a users time zone to the another (probably server) time zone to assist in creating a simple trigger with the right date & time.
static void validateDayOfMonth(int day)
           
static void validateDayOfWeek(int dayOfWeek)
           
static void validateHour(int hour)
           
static void validateMinute(int minute)
           
static void validateMonth(int month)
           
static void validateSecond(int second)
           
static void validateYear(int year)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SUNDAY

public static final int SUNDAY
See Also:
Constant Field Values

MONDAY

public static final int MONDAY
See Also:
Constant Field Values

TUESDAY

public static final int TUESDAY
See Also:
Constant Field Values

WEDNESDAY

public static final int WEDNESDAY
See Also:
Constant Field Values

THURSDAY

public static final int THURSDAY
See Also:
Constant Field Values

FRIDAY

public static final int FRIDAY
See Also:
Constant Field Values

SATURDAY

public static final int SATURDAY
See Also:
Constant Field Values

MILLISECONDS_IN_MINUTE

public static final long MILLISECONDS_IN_MINUTE
See Also:
Constant Field Values

MILLISECONDS_IN_HOUR

public static final long MILLISECONDS_IN_HOUR
See Also:
Constant Field Values

SECONDS_IN_MOST_DAYS

public static final long SECONDS_IN_MOST_DAYS
See Also:
Constant Field Values

MILLISECONDS_IN_DAY

public static final long MILLISECONDS_IN_DAY
See Also:
Constant Field Values
Method Detail

newDate

public static DateBuilder newDate()
Create a DateBuilder, with initial settings for the current date and time in the system default timezone.


newDateInTimezone

public static DateBuilder newDateInTimezone(TimeZone tz)
Create a DateBuilder, with initial settings for the current date and time in the given timezone.


newDateInLocale

public static DateBuilder newDateInLocale(Locale lc)
Create a DateBuilder, with initial settings for the current date and time in the given locale.


newDateInTimeZoneAndLocale

public static DateBuilder newDateInTimeZoneAndLocale(TimeZone tz,
                                                     Locale lc)
Create a DateBuilder, with initial settings for the current date and time in the given timezone and locale.


build

public Date build()
Build the Date defined by this builder instance.


atHourOfDay

public DateBuilder atHourOfDay(int hour)
Set the hour (0-23) for the Date that will be built by this builder.


atMinute

public DateBuilder atMinute(int minute)
Set the minute (0-59) for the Date that will be built by this builder.


atSecond

public DateBuilder atSecond(int second)
Set the second (0-59) for the Date that will be built by this builder, and truncate the milliseconds to 000.


atHourMinuteAndSecond

public DateBuilder atHourMinuteAndSecond(int hour,
                                         int minute,
                                         int second)

onDay

public DateBuilder onDay(int day)
Set the day of month (1-31) for the Date that will be built by this builder.


inMonth

public DateBuilder inMonth(int month)
Set the month (1-12) for the Date that will be built by this builder.


inMonthOnDay

public DateBuilder inMonthOnDay(int month,
                                int day)

inYear

public DateBuilder inYear(int year)
Set the year for the Date that will be built by this builder.


inTimeZone

public DateBuilder inTimeZone(TimeZone tz)
Set the TimeZone for the Date that will be built by this builder (if "null", system default will be used)


inLocale

public DateBuilder inLocale(Locale lc)
Set the Locale for the Date that will be built by this builder (if "null", system default will be used)


futureDate

public static Date futureDate(int interval,
                              DateBuilder.IntervalUnit unit)

tomorrowAt

public static Date tomorrowAt(int hour,
                              int minute,
                              int second)

Get a Date object that represents the given time, on tomorrow's date.

Parameters:
second - The value (0-59) to give the seconds field of the date
minute - The value (0-59) to give the minutes field of the date
hour - The value (0-23) to give the hours field of the date
Returns:
the new date

todayAt

public static Date todayAt(int hour,
                           int minute,
                           int second)

Get a Date object that represents the given time, on today's date (equivalent to dateOf(int, int, int)).

Parameters:
second - The value (0-59) to give the seconds field of the date
minute - The value (0-59) to give the minutes field of the date
hour - The value (0-23) to give the hours field of the date
Returns:
the new date

dateOf

public static Date dateOf(int hour,
                          int minute,
                          int second)

Get a Date object that represents the given time, on today's date (equivalent to todayAt(int, int, int)).

Parameters:
second - The value (0-59) to give the seconds field of the date
minute - The value (0-59) to give the minutes field of the date
hour - The value (0-23) to give the hours field of the date
Returns:
the new date

dateOf

public static Date dateOf(int hour,
                          int minute,
                          int second,
                          int dayOfMonth,
                          int month)

Get a Date object that represents the given time, on the given date.

Parameters:
second - The value (0-59) to give the seconds field of the date
minute - The value (0-59) to give the minutes field of the date
hour - The value (0-23) to give the hours field of the date
dayOfMonth - The value (1-31) to give the day of month field of the date
month - The value (1-12) to give the month field of the date
Returns:
the new date

dateOf

public static Date dateOf(int hour,
                          int minute,
                          int second,
                          int dayOfMonth,
                          int month,
                          int year)

Get a Date object that represents the given time, on the given date.

Parameters:
second - The value (0-59) to give the seconds field of the date
minute - The value (0-59) to give the minutes field of the date
hour - The value (0-23) to give the hours field of the date
dayOfMonth - The value (1-31) to give the day of month field of the date
month - The value (1-12) to give the month field of the date
year - The value (1970-2099) to give the year field of the date
Returns:
the new date

evenHourDateAfterNow

public static Date evenHourDateAfterNow()

Returns a date that is rounded to the next even hour after the current time.

For example a current 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.

Returns:
the new rounded date

evenHourDate

public static Date evenHourDate(Date date)

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.

Parameters:
date - the Date to round, if null the current time will be used
Returns:
the new rounded date

evenHourDateBefore

public static Date evenHourDateBefore(Date date)

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.

Parameters:
date - the Date to round, if null the current time will be used
Returns:
the new rounded date

evenMinuteDateAfterNow

public static Date evenMinuteDateAfterNow()

Returns a date that is rounded to the next even minute after the current time.

For example a current 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.

Returns:
the new rounded date

evenMinuteDate

public static Date evenMinuteDate(Date date)

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.

Parameters:
date - the Date to round, if null the current time will be used
Returns:
the new rounded date

evenMinuteDateBefore

public static Date evenMinuteDateBefore(Date date)

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.

Parameters:
date - the Date to round, if null the current time will be used
Returns:
the new rounded date

evenSecondDateAfterNow

public static Date evenSecondDateAfterNow()

Returns a date that is rounded to the next even second after the current time.

Returns:
the new rounded date

evenSecondDate

public static Date evenSecondDate(Date date)

Returns a date that is rounded to the next even second above the given date.

Parameters:
date - the Date to round, if null the current time will be used
Returns:
the new rounded date

evenSecondDateBefore

public static Date evenSecondDateBefore(Date date)

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.

Parameters:
date - the Date to round, if null the current time will be used
Returns:
the new rounded date

nextGivenMinuteDate

public static Date nextGivenMinuteDate(Date date,
                                       int minuteBase)

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

Parameters:
date - the Date to round, if null the current time will be used
minuteBase - the base-minute to set the time on
Returns:
the new rounded date
See Also:
nextGivenSecondDate(Date, int)

nextGivenSecondDate

public static Date nextGivenSecondDate(Date date,
                                       int secondBase)

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(..).

Parameters:
date - the Date to round, if null the current time will be used
secondBase - the base-second to set the time on
Returns:
the new rounded date
See Also:
nextGivenMinuteDate(Date, int)

translateTime

public static Date translateTime(Date date,
                                 TimeZone src,
                                 TimeZone dest)
Translate a date & time from a users time zone to the another (probably server) time zone to assist in creating a simple trigger with the right date & time.

Parameters:
date - the date to translate
src - the original time-zone
dest - the destination time-zone
Returns:
the translated date

validateDayOfWeek

public static void validateDayOfWeek(int dayOfWeek)

validateHour

public static void validateHour(int hour)

validateMinute

public static void validateMinute(int minute)

validateSecond

public static void validateSecond(int second)

validateDayOfMonth

public static void validateDayOfMonth(int day)

validateMonth

public static void validateMonth(int month)

validateYear

public static void validateYear(int year)


Copyright 2001-2011, Terracotta, Inc.