Class DateBuilder
- java.lang.Object
-
- org.quartz.DateBuilder
-
public class DateBuilder extends java.lang.ObjectDateBuilderis used to conveniently createjava.util.Dateinstances 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,TriggerKeyand the variousScheduleBuilderimplementations.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
Nested Classes Modifier and Type Class Description static classDateBuilder.IntervalUnit
-
Field Summary
Fields Modifier and Type Field Description static intAPRILstatic intAUGUSTstatic intDECEMBERstatic intFEBRUARYstatic intFRIDAYstatic intJANUARYstatic intJULYstatic intJUNEstatic intMARCHstatic intMAYstatic longMILLISECONDS_IN_DAYstatic longMILLISECONDS_IN_HOURstatic longMILLISECONDS_IN_MINUTEstatic intMONDAYstatic intNOVEMBERstatic intOCTOBERstatic intSATURDAYstatic longSECONDS_IN_MOST_DAYSstatic intSEPTEMBERstatic intSUNDAYstatic intTHURSDAYstatic intTUESDAYstatic intWEDNESDAY
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description DateBuilderatHourMinuteAndSecond(int atHour, int atMinute, int atSecond)DateBuilderatHourOfDay(int atHour)Set the hour (0-23) for the Date that will be built by this builder.DateBuilderatMinute(int atMinute)Set the minute (0-59) for the Date that will be built by this builder.DateBuilderatSecond(int atSecond)Set the second (0-59) for the Date that will be built by this builder, and truncate the milliseconds to 000.java.util.Datebuild()Build the Date defined by this builder instance.static java.util.DatedateOf(int hour, int minute, int second)Get aDateobject that represents the given time, on today's date (equivalent totodayAt(int, int, int)).static java.util.DatedateOf(int hour, int minute, int second, int dayOfMonth, int month)Get aDateobject that represents the given time, on the given date.static java.util.DatedateOf(int hour, int minute, int second, int dayOfMonth, int month, int year)Get aDateobject that represents the given time, on the given date.static java.util.DateevenHourDate(java.util.Date date)Returns a date that is rounded to the next even hour above the given date.static java.util.DateevenHourDateAfterNow()Returns a date that is rounded to the next even hour after the current time.static java.util.DateevenHourDateBefore(java.util.Date date)Returns a date that is rounded to the previous even hour below the given date.static java.util.DateevenMinuteDate(java.util.Date date)Returns a date that is rounded to the next even minute above the given date.static java.util.DateevenMinuteDate(java.util.Date date, java.time.Clock clock)static java.util.DateevenMinuteDateAfterNow()Returns a date that is rounded to the next even minute after the current time.static java.util.DateevenMinuteDateBefore(java.util.Date date)Returns a date that is rounded to the previous even minute below the given date.static java.util.DateevenSecondDate(java.util.Date date)Returns a date that is rounded to the next even second above the given date.static java.util.DateevenSecondDateAfterNow()Returns a date that is rounded to the next even second after the current time.static java.util.DateevenSecondDateBefore(java.util.Date date)Returns a date that is rounded to the previous even second below the given date.static java.util.DatefutureDate(int interval, DateBuilder.IntervalUnit unit)DateBuilderinLocale(java.util.Locale locale)Set the Locale for the Date that will be built by this builder (if "null", system default will be used)DateBuilderinMonth(int inMonth)Set the month (1-12) for the Date that will be built by this builder.DateBuilderinMonthOnDay(int inMonth, int onDay)DateBuilderinTimeZone(java.util.TimeZone timezone)Set the TimeZone for the Date that will be built by this builder (if "null", system default will be used)DateBuilderinYear(int inYear)Set the year for the Date that will be built by this builder.static DateBuildernewDate()Create a DateBuilder, with initial settings for the current date and time in the system default timezone.static DateBuildernewDateInLocale(java.util.Locale lc)Create a DateBuilder, with initial settings for the current date and time in the given locale.static DateBuildernewDateInTimezone(java.util.TimeZone tz)Create a DateBuilder, with initial settings for the current date and time in the given timezone.static DateBuildernewDateInTimeZoneAndLocale(java.util.TimeZone tz, java.util.Locale lc)Create a DateBuilder, with initial settings for the current date and time in the given timezone and locale.static java.util.DatenextGivenMinuteDate(java.util.Date date, int minuteBase)Returns a date that is rounded to the next even multiple of the given minute.static java.util.DatenextGivenSecondDate(java.util.Date date, int secondBase)Returns a date that is rounded to the next even multiple of the given second.DateBuilderonDay(int onDay)Set the day of month (1-31) for the Date that will be built by this builder.static java.util.DatetodayAt(int hour, int minute, int second)Get aDateobject that represents the given time, on today's date (equivalent todateOf(int, int, int)).static java.util.DatetomorrowAt(int hour, int minute, int second)Get aDateobject that represents the given time, on tomorrow's date.static java.util.DatetranslateTime(java.util.Date date, java.util.TimeZone src, java.util.TimeZone dest)Translate a date and time from a users time zone to the another (probably server) time zone to assist in creating a simple trigger with the right date and time.static voidvalidateDayOfMonth(int day)static voidvalidateDayOfWeek(int dayOfWeek)static voidvalidateHour(int hour)static voidvalidateMinute(int minute)static voidvalidateMonth(int month)static voidvalidateSecond(int second)static voidvalidateYear(int year)
-
-
-
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
-
JANUARY
public static final int JANUARY
- See Also:
- Constant Field Values
-
FEBRUARY
public static final int FEBRUARY
- See Also:
- Constant Field Values
-
MARCH
public static final int MARCH
- See Also:
- Constant Field Values
-
APRIL
public static final int APRIL
- See Also:
- Constant Field Values
-
MAY
public static final int MAY
- See Also:
- Constant Field Values
-
JUNE
public static final int JUNE
- See Also:
- Constant Field Values
-
JULY
public static final int JULY
- See Also:
- Constant Field Values
-
AUGUST
public static final int AUGUST
- See Also:
- Constant Field Values
-
SEPTEMBER
public static final int SEPTEMBER
- See Also:
- Constant Field Values
-
OCTOBER
public static final int OCTOBER
- See Also:
- Constant Field Values
-
NOVEMBER
public static final int NOVEMBER
- See Also:
- Constant Field Values
-
DECEMBER
public static final int DECEMBER
- 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(java.util.TimeZone tz)
Create a DateBuilder, with initial settings for the current date and time in the given timezone.
-
newDateInLocale
public static DateBuilder newDateInLocale(java.util.Locale lc)
Create a DateBuilder, with initial settings for the current date and time in the given locale.
-
newDateInTimeZoneAndLocale
public static DateBuilder newDateInTimeZoneAndLocale(java.util.TimeZone tz, java.util.Locale lc)
Create a DateBuilder, with initial settings for the current date and time in the given timezone and locale.
-
build
public java.util.Date build()
Build the Date defined by this builder instance.
-
atHourOfDay
public DateBuilder atHourOfDay(int atHour)
Set the hour (0-23) for the Date that will be built by this builder.
-
atMinute
public DateBuilder atMinute(int atMinute)
Set the minute (0-59) for the Date that will be built by this builder.
-
atSecond
public DateBuilder atSecond(int atSecond)
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 atHour, int atMinute, int atSecond)
-
onDay
public DateBuilder onDay(int onDay)
Set the day of month (1-31) for the Date that will be built by this builder.
-
inMonth
public DateBuilder inMonth(int inMonth)
Set the month (1-12) for the Date that will be built by this builder.
-
inMonthOnDay
public DateBuilder inMonthOnDay(int inMonth, int onDay)
-
inYear
public DateBuilder inYear(int inYear)
Set the year for the Date that will be built by this builder.
-
inTimeZone
public DateBuilder inTimeZone(java.util.TimeZone timezone)
Set the TimeZone for the Date that will be built by this builder (if "null", system default will be used)
-
inLocale
public DateBuilder inLocale(java.util.Locale locale)
Set the Locale for the Date that will be built by this builder (if "null", system default will be used)
-
futureDate
public static java.util.Date futureDate(int interval, DateBuilder.IntervalUnit unit)
-
tomorrowAt
public static java.util.Date tomorrowAt(int hour, int minute, int second)Get a
Dateobject that represents the given time, on tomorrow's date.- Parameters:
hour- The value (0-23) to give the hours field of the dateminute- The value (0-59) to give the minutes field of the datesecond- The value (0-59) to give the seconds field of the date- Returns:
- the new date
-
todayAt
public static java.util.Date todayAt(int hour, int minute, int second)Get a
Dateobject that represents the given time, on today's date (equivalent todateOf(int, int, int)).- Parameters:
hour- The value (0-23) to give the hours field of the dateminute- The value (0-59) to give the minutes field of the datesecond- The value (0-59) to give the seconds field of the date- Returns:
- the new date
-
dateOf
public static java.util.Date dateOf(int hour, int minute, int second)Get a
Dateobject that represents the given time, on today's date (equivalent totodayAt(int, int, int)).- Parameters:
hour- The value (0-23) to give the hours field of the dateminute- The value (0-59) to give the minutes field of the datesecond- The value (0-59) to give the seconds field of the date- Returns:
- the new date
-
dateOf
public static java.util.Date dateOf(int hour, int minute, int second, int dayOfMonth, int month)Get a
Dateobject that represents the given time, on the given date.- Parameters:
hour- The value (0-23) to give the hours field of the dateminute- The value (0-59) to give the minutes field of the datesecond- The value (0-59) to give the seconds field of the datedayOfMonth- The value (1-31) to give the day of month field of the datemonth- The value (1-12) to give the month field of the date- Returns:
- the new date
-
dateOf
public static java.util.Date dateOf(int hour, int minute, int second, int dayOfMonth, int month, int year)Get a
Dateobject that represents the given time, on the given date.- Parameters:
hour- The value (0-23) to give the hours field of the dateminute- The value (0-59) to give the minutes field of the datesecond- The value (0-59) to give the seconds field of the datedayOfMonth- The value (1-31) to give the day of month field of the datemonth- The value (1-12) to give the month field of the dateyear- The value (1970-999999999) to give the year field of the date- Returns:
- the new date
-
evenHourDateAfterNow
public static java.util.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 java.util.Date evenHourDate(java.util.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, ifnullthe current time will be used- Returns:
- the new rounded date
-
evenHourDateBefore
public static java.util.Date evenHourDateBefore(java.util.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, ifnullthe current time will be used- Returns:
- the new rounded date
-
evenMinuteDateAfterNow
public static java.util.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 java.util.Date evenMinuteDate(java.util.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, ifnullthe current time will be used- Returns:
- the new rounded date
-
evenMinuteDate
public static java.util.Date evenMinuteDate(java.util.Date date, java.time.Clock clock)
-
evenMinuteDateBefore
public static java.util.Date evenMinuteDateBefore(java.util.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, ifnullthe current time will be used- Returns:
- the new rounded date
-
evenSecondDateAfterNow
public static java.util.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 java.util.Date evenSecondDate(java.util.Date date)
Returns a date that is rounded to the next even second above the given date.
- Parameters:
date- the Date to round, ifnullthe current time will be used- Returns:
- the new rounded date
-
evenSecondDateBefore
public static java.util.Date evenSecondDateBefore(java.util.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:54.000.
- Parameters:
date- the Date to round, ifnullthe current time will be used- Returns:
- the new rounded date
-
nextGivenMinuteDate
public static java.util.Date nextGivenMinuteDate(java.util.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:
Examples of inputs and corresponding outputs. 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, ifnullthe current time will be usedminuteBase- the base-minute to set the time on- Returns:
- the new rounded date
- See Also:
nextGivenSecondDate(Date, int)
-
nextGivenSecondDate
public static java.util.Date nextGivenSecondDate(java.util.Date date, int secondBase)Returns a date that is rounded to the next even multiple of the given second.
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, ifnullthe current time will be usedsecondBase- the base-second to set the time on- Returns:
- the new rounded date
- See Also:
nextGivenMinuteDate(Date, int)
-
translateTime
public static java.util.Date translateTime(java.util.Date date, java.util.TimeZone src, java.util.TimeZone dest)Translate a date and time from a users time zone to the another (probably server) time zone to assist in creating a simple trigger with the right date and time.- Parameters:
date- the date to translatesrc- the original time-zonedest- 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)
-
-