Table of Contents

Class CronCalendar

Namespace
Quartz.Impl.Calendar
Assembly
Quartz.dll

This implementation of the Calendar excludes the set of times expressed by a given CronExpression.

[Serializable]
public sealed class CronCalendar : BaseCalendar, ICalendar, ISerializable, IEquatable<BaseCalendar>, IEquatable<CronCalendar>
Inheritance
CronCalendar
Implements
Inherited Members

Remarks

For example, you could use this calendar to exclude all but business hours (8AM - 5PM) every day using the expression "* * 0-7,18-23 ? * *".

It is important to remember that the cron expression here describes a set of times to be excluded from firing. Whereas the cron expression in CronTrigger describes a set of times that can be included for firing. Thus, if a ICronTrigger has a given cron expression and is associated with a CronCalendar with the same expression, the calendar will exclude all the times the trigger includes, and they will cancel each other out.

Constructors

CronCalendar(ICalendar?, string)

Create a CronCalendar with the given cron expression and BaseCalendar.

public CronCalendar(ICalendar? baseCalendar, string expression)

Parameters

baseCalendar ICalendar

the base calendar for this calendar instance see BaseCalendar for more information on base calendar functionality

expression string

a string representation of the desired cron expression

CronCalendar(ICalendar?, string, TimeZoneInfo?)

Create a CronCalendar with the given cron expression and BaseCalendar.

public CronCalendar(ICalendar? baseCalendar, string expression, TimeZoneInfo? timeZone)

Parameters

baseCalendar ICalendar

the base calendar for this calendar instance see BaseCalendar for more information on base calendar functionality

expression string

a string representation of the desired cron expression

timeZone TimeZoneInfo

the time zone the expression's times are resolved in; null means the system's local time zone

CronCalendar(string)

Initializes a new instance of the CronCalendar class.

public CronCalendar(string expression)

Parameters

expression string

a string representation of the desired cron expression

Properties

CronExpression

Returns the object representation of the cron expression that defines the dates and times this calendar excludes.

public CronExpression CronExpression { get; set; }

Property Value

CronExpression

TimeZone

Gets or sets the time zone.

public override TimeZoneInfo TimeZone { get; set; }

Property Value

TimeZoneInfo

The time zone.

Methods

Clone()

Creates a new object that is a copy of the current instance.

public override ICalendar Clone()

Returns

ICalendar

A new object that is a copy of this instance.

Equals(CronCalendar?)

Whether this calendar and other exclude the same times.

public bool Equals(CronCalendar? other)

Parameters

other CronCalendar

The calendar to compare with.

Returns

bool

Equals(object?)

Determines whether the specified object is equal to the current object.

public override bool Equals(object? obj)

Parameters

obj object

The object to compare with the current object.

Returns

bool

true if the specified object is equal to the current object; otherwise, false.

GetHashCode()

Serves as the default hash function.

public override int GetHashCode()

Returns

int

A hash code for the current object.

Remarks

The hash is over the same mutable state Equals(BaseCalendar?) compares, which is what the two members have to agree on, and every calendar in this namespace is the same shape. A calendar is an editable description of excluded time — Description, the time zone, the excluded days — and the alternative to hashing it is a constant, which puts every calendar in one bucket and answers nothing. Nothing in Quartz keys a hash-based collection by a calendar instance: the stores hold calendars by name, and the name is a string.

GetNextIncludedTimeUtc(DateTimeOffset)

Determine the next time that is 'included' by the Calendar after the given time. Return the original value if timeStamp is included. Return 0 if all days are excluded.

public override DateTimeOffset GetNextIncludedTimeUtc(DateTimeOffset timeUtc)

Parameters

timeUtc DateTimeOffset

Returns

DateTimeOffset

Remarks

An expression can exclude every instant there is — * * * * * ? is the plain one — and then there is no time to answer with. That is a SchedulerException naming the expression, because a calendar excluding everything is a configuration mistake rather than a schedule with no next fire: a trigger it is attached to can never fire again.

Exceptions

SchedulerException

The calendar's expression excludes every instant.

GetObjectData(SerializationInfo, StreamingContext)

Writes this calendar's fields into a serialization payload.

[SecurityCritical]
public override void GetObjectData(SerializationInfo info, StreamingContext context)

Parameters

info SerializationInfo

The payload being written.

context StreamingContext

The serialization context.

IsTimeIncluded(DateTimeOffset)

Determine whether the given time is 'included' by the Calendar.

public override bool IsTimeIncluded(DateTimeOffset timeUtc)

Parameters

timeUtc DateTimeOffset

the time to test

Returns

bool

a boolean indicating whether the specified time is 'included' by the CronCalendar

ToString()

Returns a string that represents the current object.

public override string ToString()

Returns

string

A string that represents the current object.