Class DateBuilder
- Namespace
- Quartz
- Assembly
- Quartz.dll
DateBuilder is used to conveniently create DateTimeOffset instances that meet particular criteria.
public sealed class DateBuilder
- Inheritance
-
DateBuilder
- Inherited Members
Remarks
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 IScheduleBuilder implementations.
Client code can then use the DSL to write code such as this:
IJobDetail job = JobBuilder.Create<MyJob>()
.WithIdentity("myJob")
.Build();
ITrigger trigger = TriggerBuilder.Create()
.WithIdentity("myTrigger", "myTriggerGroup")
.WithSimpleSchedule(x => x
.WithInterval(TimeSpan.FromHours(1))
.RepeatForever())
.StartAt(DateBuilder.Create().AtHourMinuteAndSecond(10, 0, 0).Build())
.Build();
await scheduler.ScheduleJob(job, trigger);
For dates that are simply "now plus something", or a rounding of an existing date, use
DateTimeOffset arithmetic directly — DateTimeOffset.UtcNow.AddMinutes(10)
says what it does without a builder in the way.
Methods
AtHourMinuteAndSecond(int, int, int)
Set the hour (0-23), minute (0-59) and second (0-59) for the date that will be built by this builder.
public DateBuilder AtHourMinuteAndSecond(int hour, int minute, int second)
Parameters
hourintThe hour of the day.
minuteintThe minute of the hour.
secondintThe second of the minute.
Returns
AtHourOfDay(int)
Set the hour (0-23) for the Date that will be built by this builder.
public DateBuilder AtHourOfDay(int hour)
Parameters
hourint
Returns
AtMinute(int)
Set the minute (0-59) for the Date that will be built by this builder.
public DateBuilder AtMinute(int minute)
Parameters
minuteint
Returns
AtSecond(int)
Set the second (0-59) for the Date that will be built by this builder, and truncate the milliseconds to 000.
public DateBuilder AtSecond(int second)
Parameters
secondint
Returns
Build()
Build the DateTimeOffset defined by this builder instance.
public DateTimeOffset Build()
Returns
- DateTimeOffset
New date time based on builder parameters.
Create(TimeProvider?)
Create a DateBuilder, with initial settings for the current date and time in the system default timezone.
public static DateBuilder Create(TimeProvider? timeProvider = null)
Parameters
timeProviderTimeProviderTime provider instance to use, defaults to System
Returns
- DateBuilder
the new DateBuilder
CreateInTimeZone(TimeZoneInfo, TimeProvider?)
Create a DateBuilder seeded with the machine's current local date and time, whose result is built in the given time zone.
public static DateBuilder CreateInTimeZone(TimeZoneInfo timeZone, TimeProvider? timeProvider = null)
Parameters
timeZoneTimeZoneInfoTime zone to use.
timeProviderTimeProviderTime provider instance to use, defaults to System
Returns
- DateBuilder
the new DateBuilder
Remarks
The seed values come from the clock's local time, not from the given zone's wall clock; the zone decides the offset the built DateTimeOffset carries. Set the fields that matter explicitly rather than relying on the seed.
InMonth(int)
Set the month (1-12) for the Date that will be built by this builder.
public DateBuilder InMonth(int month)
Parameters
monthint
Returns
InMonthOnDay(int, int)
Set the month (1-12) and the day of the month (1-31) for the date that will be built by this builder.
public DateBuilder InMonthOnDay(int month, int day)
Parameters
Returns
InTimeZone(TimeZoneInfo?)
Set the TimeZoneInfo for the Date that will be built by this builder (if "null", system default will be used)
public DateBuilder InTimeZone(TimeZoneInfo? timeZone)
Parameters
timeZoneTimeZoneInfo
Returns
InYear(int)
Set the year for the Date that will be built by this builder.
public DateBuilder InYear(int year)
Parameters
yearint
Returns
OnDay(int)
Set the day of month (1-31) for the Date that will be built by this builder.
public DateBuilder OnDay(int day)
Parameters
dayint