Table of Contents

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

hour int

The hour of the day.

minute int

The minute of the hour.

second int

The second of the minute.

Returns

DateBuilder

AtHourOfDay(int)

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

public DateBuilder AtHourOfDay(int hour)

Parameters

hour int

Returns

DateBuilder

AtMinute(int)

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

public DateBuilder AtMinute(int minute)

Parameters

minute int

Returns

DateBuilder

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

second int

Returns

DateBuilder

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

timeProvider TimeProvider

Time 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

timeZone TimeZoneInfo

Time zone to use.

timeProvider TimeProvider

Time 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

month int

Returns

DateBuilder

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

month int

The month of the year.

day int

The day of the month.

Returns

DateBuilder

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

timeZone TimeZoneInfo

Returns

DateBuilder

InYear(int)

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

public DateBuilder InYear(int year)

Parameters

year int

Returns

DateBuilder

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

day int

Returns

DateBuilder

See Also