C# Class Quartz.DateBuilder

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); 
显示文件 Open project: quartznet/quartznet Class Usage Examples

Public Methods

Method Description
AtHourMinuteAndSecond ( int hour, int minute, int second ) : DateBuilder
AtHourOfDay ( int hour ) : DateBuilder

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

AtMinute ( int minute ) : DateBuilder

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

AtSecond ( int second ) : DateBuilder

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

Build ( ) : DateTimeOffset

Build the DateTimeOffset defined by this builder instance.

DateOf ( int hour, int minute, int second ) : DateTimeOffset

Get a DateTimeOffset object that represents the given time, on today's date.

DateOf ( int hour, int minute, int second, int dayOfMonth, int month ) : DateTimeOffset

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

DateOf ( int hour, int minute, int second, int dayOfMonth, int month, int year ) : DateTimeOffset

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

EvenHourDate ( DateTimeOffset date ) : DateTimeOffset

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.

EvenHourDateAfterNow ( ) : DateTimeOffset

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.

EvenHourDateBefore ( DateTimeOffset date ) : DateTimeOffset

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.

EvenMinuteDate ( DateTimeOffset date ) : DateTimeOffset

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.

EvenMinuteDateAfterNow ( ) : DateTimeOffset

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.

EvenMinuteDateBefore ( DateTimeOffset date ) : DateTimeOffset

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.

EvenSecondDate ( DateTimeOffset date ) : DateTimeOffset

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

EvenSecondDateAfterNow ( ) : DateTimeOffset

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

EvenSecondDateBefore ( DateTimeOffset date ) : DateTimeOffset

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.

FutureDate ( int interval, IntervalUnit unit ) : DateTimeOffset
InMonth ( int month ) : DateBuilder

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

InMonthOnDay ( int month, int day ) : DateBuilder
InTimeZone ( TimeZoneInfo tz ) : DateBuilder

Set the TimeZoneInfo for the Date that will be built by this builder (if "null", system default will be used)

InYear ( int year ) : DateBuilder

Set the year for the Date that will be built by this builder.

NewDate ( ) : DateBuilder

Create a DateBuilder, with initial settings for the current date and time in the system default timezone.

NewDateInTimeZone ( TimeZoneInfo tz ) : DateBuilder

Create a DateBuilder, with initial settings for the current date and time in the given timezone.

NextGivenMinuteDate ( DateTimeOffset date, int minuteBase ) : DateTimeOffset

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

NextGivenSecondDate ( DateTimeOffset date, int secondBase ) : DateTimeOffset

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 NextGivenMinuteDate.

OnDay ( int day ) : DateBuilder

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

TodayAt ( int hour, int minute, int second ) : DateTimeOffset

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

TomorrowAt ( int hour, int minute, int second ) : DateTimeOffset

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

ValidateDayOfMonth ( int day ) : void
ValidateHour ( int hour ) : void
ValidateMinute ( int minute ) : void
ValidateMonth ( int month ) : void
ValidateSecond ( int second ) : void
ValidateYear ( int year ) : void

Private Methods

Method Description
DateBuilder ( ) : System

Create a DateBuilder, with initial settings for the current date and time in the system default timezone.

DateBuilder ( TimeZoneInfo tz ) : System

Create a DateBuilder, with initial settings for the current date and time in the given timezone.

TranslatedAdd ( DateTimeOffset date, IntervalUnit unit, int amountToAdd ) : DateTimeOffset

Method Details

AtHourMinuteAndSecond() public method

public AtHourMinuteAndSecond ( int hour, int minute, int second ) : DateBuilder
hour int
minute int
second int
return DateBuilder

AtHourOfDay() public method

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

AtMinute() public method

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

AtSecond() public method

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

Build() public method

Build the DateTimeOffset defined by this builder instance.
public Build ( ) : DateTimeOffset
return DateTimeOffset

DateOf() public static method

Get a DateTimeOffset object that represents the given time, on today's date.
public static DateOf ( int hour, int minute, int second ) : DateTimeOffset
hour int The value (0-23) to give the hours field of the date
minute int The value (0-59) to give the minutes field of the date
second int The value (0-59) to give the seconds field of the date
return DateTimeOffset

DateOf() public static method

Get a DateTimeOffset object that represents the given time, on the given date.
public static DateOf ( int hour, int minute, int second, int dayOfMonth, int month ) : DateTimeOffset
hour int The value (0-23) to give the hours field of the date
minute int The value (0-59) to give the minutes field of the date
second int The value (0-59) to give the seconds field of the date
dayOfMonth int The value (1-31) to give the day of month field of the date
month int The value (1-12) to give the month field of the date
return DateTimeOffset

DateOf() public static method

Get a DateTimeOffset object that represents the given time, on the given date.
public static DateOf ( int hour, int minute, int second, int dayOfMonth, int month, int year ) : DateTimeOffset
hour int The value (0-23) to give the hours field of the date
minute int The value (0-59) to give the minutes field of the date
second int The value (0-59) to give the seconds field of the date
dayOfMonth int The value (1-31) to give the day of month field of the date
month int The value (1-12) to give the month field of the date
year int The value (1970-2099) to give the year field of the date
return DateTimeOffset

EvenHourDate() public static method

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 EvenHourDate ( DateTimeOffset date ) : DateTimeOffset
date DateTimeOffset the Date to round, if the current time will /// be used
return DateTimeOffset

EvenHourDateAfterNow() public static method

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.
public static EvenHourDateAfterNow ( ) : DateTimeOffset
return DateTimeOffset

EvenHourDateBefore() public static method

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 EvenHourDateBefore ( DateTimeOffset date ) : DateTimeOffset
date DateTimeOffset the Date to round, if the current time will /// be used
return DateTimeOffset

EvenMinuteDate() public static method

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 EvenMinuteDate ( DateTimeOffset date ) : DateTimeOffset
date DateTimeOffset The Date to round, if the current time will be used
return DateTimeOffset

EvenMinuteDateAfterNow() public static method

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.
public static EvenMinuteDateAfterNow ( ) : DateTimeOffset
return DateTimeOffset

EvenMinuteDateBefore() public static method

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 EvenMinuteDateBefore ( DateTimeOffset date ) : DateTimeOffset
date DateTimeOffset the Date to round, if the current time will /// be used
return DateTimeOffset

EvenSecondDate() public static method

Returns a date that is rounded to the next even second above the given date.
public static EvenSecondDate ( DateTimeOffset date ) : DateTimeOffset
date DateTimeOffset
return DateTimeOffset

EvenSecondDateAfterNow() public static method

Returns a date that is rounded to the next even second after the current time.
public static EvenSecondDateAfterNow ( ) : DateTimeOffset
return DateTimeOffset

EvenSecondDateBefore() public static method

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 EvenSecondDateBefore ( DateTimeOffset date ) : DateTimeOffset
date DateTimeOffset
return DateTimeOffset

FutureDate() public static method

public static FutureDate ( int interval, IntervalUnit unit ) : DateTimeOffset
interval int
unit IntervalUnit
return DateTimeOffset

InMonth() public method

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

InMonthOnDay() public method

public InMonthOnDay ( int month, int day ) : DateBuilder
month int
day int
return DateBuilder

InTimeZone() public method

Set the TimeZoneInfo for the Date that will be built by this builder (if "null", system default will be used)
public InTimeZone ( TimeZoneInfo tz ) : DateBuilder
tz System.TimeZoneInfo
return DateBuilder

InYear() public method

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

NewDate() public static method

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

NewDateInTimeZone() public static method

Create a DateBuilder, with initial settings for the current date and time in the given timezone.
public static NewDateInTimeZone ( TimeZoneInfo tz ) : DateBuilder
tz System.TimeZoneInfo Time zone to use.
return DateBuilder

NextGivenMinuteDate() public static method

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 NextGivenMinuteDate ( DateTimeOffset date, int minuteBase ) : DateTimeOffset
date DateTimeOffset
minuteBase int
return DateTimeOffset

NextGivenSecondDate() public static method

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 NextGivenMinuteDate.
public static NextGivenSecondDate ( DateTimeOffset date, int secondBase ) : DateTimeOffset
date DateTimeOffset the Date to round, if the current time will
secondBase int the base-second to set the time on
return DateTimeOffset

OnDay() public method

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

TodayAt() public static method

Get a DateTimeOffset object that represents the given time, on today's date (equivalent to DateOf(int,int,int)).
public static TodayAt ( int hour, int minute, int second ) : DateTimeOffset
hour int
minute int
second int
return DateTimeOffset

TomorrowAt() public static method

Get a DateTimeOffset object that represents the given time, on tomorrow's date.
public static TomorrowAt ( int hour, int minute, int second ) : DateTimeOffset
hour int
minute int
second int
return DateTimeOffset

ValidateDayOfMonth() public static method

public static ValidateDayOfMonth ( int day ) : void
day int
return void

ValidateHour() public static method

public static ValidateHour ( int hour ) : void
hour int
return void

ValidateMinute() public static method

public static ValidateMinute ( int minute ) : void
minute int
return void

ValidateMonth() public static method

public static ValidateMonth ( int month ) : void
month int
return void

ValidateSecond() public static method

public static ValidateSecond ( int second ) : void
second int
return void

ValidateYear() public static method

public static ValidateYear ( int year ) : void
year int
return void