Class DailyCalendar
This implementation of the Calendar excludes (or includes - see below) a specified time range each day.
[Serializable]
public sealed class DailyCalendar : BaseCalendar, ICalendar, ISerializable, IEquatable<BaseCalendar>, IEquatable<DailyCalendar>
- Inheritance
-
DailyCalendar
- Implements
- Inherited Members
Remarks
For example, you could use this calendar to exclude business hours (8AM - 5PM) every day. Each DailyCalendar only allows a single time range to be specified, and that time range may not cross daily boundaries (i.e. you cannot specify a time range from 8PM - 5AM). If the property InvertTimeRange is false (default), the time range defines a range of times in which triggers are not allowed to fire. If InvertTimeRange is true, the time range is inverted: that is, all times outside the defined time range are excluded.
Note when using DailyCalendar, it behaves on the same principals as, for example, WeeklyCalendar defines a set of days that are excluded every week. Likewise, DailyCalendar defines a set of times that are excluded every day.
Constructors
DailyCalendar(TimeOnly, TimeOnly, ICalendar?)
Create a DailyCalendar excluding (or, with InvertTimeRange, including) the given time range of every day.
public DailyCalendar(TimeOnly rangeStart, TimeOnly rangeEnd, ICalendar? baseCalendar = null)
Parameters
rangeStartTimeOnlyThe time of day the range starts at.
rangeEndTimeOnlyThe time of day the range ends at.
baseCalendarICalendarThe base calendar for this calendar instance, see BaseCalendar for more information on base calendar functionality.
Remarks
The range may not cross a daily boundary, so rangeStart must come
before rangeEnd. Both are kept with one-millisecond resolution, which
is what the calendar's serialized form carries.
Exceptions
- ArgumentException
A bound carries precision finer than a whole millisecond, or the range does not start before it ends.
Properties
InvertTimeRange
Indicates whether the time range represents an inverted time range (see class description).
public bool InvertTimeRange { get; set; }
Property Value
- bool
trueif invert time range; otherwise,false.
TimeRange
The time range this calendar excludes (or, with InvertTimeRange, includes) every day.
public TimeRange TimeRange { get; set; }
Property Value
Remarks
The range may not cross a daily boundary, so Start must come before End.
Both bounds are kept with one-millisecond resolution.
Exceptions
- ArgumentException
A bound carries precision finer than a whole millisecond, or the range does not start before it ends.
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(DailyCalendar?)
Whether this calendar and other exclude the same times.
public bool Equals(DailyCalendar? other)
Parameters
otherDailyCalendarThe calendar to compare with.
Returns
Equals(object?)
Determines whether the specified object is equal to the current object.
public override bool Equals(object? obj)
Parameters
objobjectThe object to compare with the current object.
Returns
GetHashCode()
Serves as the default hash function.
[SuppressMessage("Sonar", "S2328:GetHashCode should not reference mutable fields", Justification = "Content equality over mutable state is what a calendar is; see BaseCalendar.GetHashCode.")]
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 (in milliseconds) 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
timeUtcDateTimeOffset
Returns
Remarks
The question is answered in TimeZone whatever offset it is asked in, because the window is a wall-clock window of the calendar's own zone: the argument is converted first, exactly as IsTimeIncluded(DateTimeOffset) converts it, and the day's edges are named as wall-clock times on the local date and resolved back to instants there. Computing them at the offset the argument happened to carry made the two methods disagree whenever those offsets differed, and the walk then crept forward a millisecond at a time through a stretch it had already been told was excluded - minutes of spinning for an answer months out of place (#3466).
- See Also
GetObjectData(SerializationInfo, StreamingContext)
Writes this calendar's fields into a serialization payload.
[SecurityCritical]
public override void GetObjectData(SerializationInfo info, StreamingContext context)
Parameters
infoSerializationInfoThe payload being written.
contextStreamingContextThe serialization context.
GetTimeRangeEndingTimeUtc(DateTimeOffset)
Returns the end time of the time range of the day
specified in timeUtc
public DateTimeOffset GetTimeRangeEndingTimeUtc(DateTimeOffset timeUtc)
Parameters
timeUtcDateTimeOffset
Returns
- DateTimeOffset
A DateTime representing the end time of the time range for the specified date.
Remarks
The day is the local day of TimeZone; see GetTimeRangeStartingTimeUtc(DateTimeOffset).
GetTimeRangeStartingTimeUtc(DateTimeOffset)
Returns the start time of the time range of the day
specified in timeUtc.
public DateTimeOffset GetTimeRangeStartingTimeUtc(DateTimeOffset timeUtc)
Parameters
timeUtcDateTimeOffset
Returns
- DateTimeOffset
a DateTime representing the start time of the time range for the specified date.
Remarks
The day is the local day of TimeZone, so the argument is converted into the zone before its date is read: asked in UTC about a calendar that keeps another zone's hours, the answer is about the local date the instant falls in rather than the UTC one. The value is a wall clock paired with the offset that instant carries, which is what makes it comparable with the instant it was derived from; around a transition that offset need not be the one the edge itself would be resolved at, and GetNextIncludedTimeUtc(DateTimeOffset), which needs instants rather than comparands, resolves the edges through the zone instead.
IsTimeIncluded(DateTimeOffset)
Determine whether the given time is 'included' by the Calendar.
public override bool IsTimeIncluded(DateTimeOffset timeUtc)
Parameters
timeUtcDateTimeOffset
Returns
ToString()
public override string ToString()