CronExpression Class
Represents a cron expression.
net10.0, net11.0
public sealed class CronExpression : IRecurrenceRule, IEquatable<CronExpression>, IParsable<CronExpression>, ISpanParsable<CronExpression>netstandard2.0
public sealed class CronExpression : IRecurrenceRule, IEquatable<CronExpression>Remarks
Two expressions are equal when their fields select the same values, whatever their text: */15 * * * * is equal to 0,15,30,45 * * * *, and @daily to 0 0 * * *. Expressions that are written with different special values, such as 0 0 29 2 * and 0 0 L 2 *, are not equal even when they happen to match the same dates. An expression holds no time zone: it is evaluated in the time zone given to GetNextOccurrences.
- Implements
Methods
| Name | Description |
|---|---|
| Equals(CronExpression?) | Determines whether this expression selects the same values as another one in every field. |
| Equals(object?) | Determines whether the specified object is equal to the current object. |
| GetHashCode() | Serves as the default hash function. |
| GetNextOccurrences(DateTime) | |
| GetNextOccurrences(DateTime, TimeZoneInfo) | Gets all occurrences of the expression, reading startDate as a wall-clock time in timeZone. |
| GetNextOccurrences(DateTimeOffset, TimeZoneInfo) | Gets all occurrences of the expression, starting from the instant startDate denotes. |
| Parse(ReadOnlySpan<char>) | |
| Parse(string) | |
| ToString() | Returns the text of the expression, as it was parsed without its leading and trailing spaces and tabs. |
| TryParse(ReadOnlySpan<char>, CronExpression?) | |
| TryParse(string?, CronExpression?) |
Equals overloads
Equals(CronExpression?)
CronExpression.csDetermines whether this expression selects the same values as another one in every field.
public bool Equals(CronExpression? other)Parameters
otherCronExpression?- The expression to compare with.
Returns
bool true if both expressions select the same values; otherwise, false.
Remarks
The text of the expressions is not compared: */15 * * * * is equal to 0,15,30,45 * * * *.
Equals(object?)
CronExpression.csGetHashCode()
CronExpression.csGetNextOccurrences overloads
GetNextOccurrences(DateTime)
CronExpression.cspublic IEnumerable<DateTime> GetNextOccurrences(DateTime startDate)No documentation is available.
GetNextOccurrences(DateTime, TimeZoneInfo)
CronExpression.csGets all occurrences of the expression, reading startDate as a wall-clock time in timeZone.
public IEnumerable<DateTimeOffset> GetNextOccurrences(DateTime startDate, TimeZoneInfo timeZone)Parameters
startDateDateTime- The wall-clock time to start generating occurrences from. Its
DateTime.Kindis ignored. timeZoneTimeZoneInfo- The time zone the expression is evaluated in.
Returns
IEnumerable<DateTimeOffset> An enumerable sequence of occurrences, each carrying the UTC offset in effect at that occurrence.
Exceptions
ArgumentNullExceptiontimeZoneisnull.
Remarks
The occurrences keep their wall-clock time across a daylight saving transition, so their UTC offset changes. A local time made invalid or ambiguous by a transition is resolved as RFC 5545 section 3.3.5 requires: an ambiguous time keeps its first occurrence, and an invalid time is read with the UTC offset in effect before the gap.
A time inside the gap of a forward transition therefore moves forward by the length of the gap, which can place its occurrence after the occurrences of the times that follow it: the occurrences are still returned in increasing order. An occurrence that denotes the same instant as another one, as the hour skipped by a forward transition does for an hourly expression, is returned once. Across a backward transition, the instants of the repeated hour are skipped.
An occurrence outside the range of DateTimeOffset is not returned: the enumeration ends at the first one after the range.
GetNextOccurrences(DateTimeOffset, TimeZoneInfo)
CronExpression.csGets all occurrences of the expression, starting from the instant startDate denotes.
public IEnumerable<DateTimeOffset> GetNextOccurrences(DateTimeOffset startDate, TimeZoneInfo timeZone)Parameters
startDateDateTimeOffset- The instant to start generating occurrences from.
timeZoneTimeZoneInfo- The time zone the expression is evaluated in.
Returns
IEnumerable<DateTimeOffset> An enumerable sequence of occurrences, each carrying the UTC offset in effect at that occurrence.
Exceptions
ArgumentNullExceptiontimeZoneisnull.
Remarks
Every occurrence at or after startDate is returned, and none before it. This includes an occurrence whose wall-clock time is before the reading of startDate, but which a forward transition moves after it, and excludes the first reading of a wall-clock time in the hour repeated by a backward transition when startDate is in its second pass.
The resolution of invalid and ambiguous local times is the same as for the DateTime overload.
Parse overloads
Parse(ReadOnlySpan<char>)
CronExpression.cspublic static CronExpression Parse(ReadOnlySpan<char> expression)No documentation is available.
Parse(string)
CronExpression.cspublic static CronExpression Parse(string expression)No documentation is available.
ToString()
CronExpression.csTryParse overloads
TryParse(ReadOnlySpan<char>, CronExpression?)
CronExpression.cspublic static bool TryParse(ReadOnlySpan<char> expression, out CronExpression? cronExpression)No documentation is available.
TryParse(string?, CronExpression?)
CronExpression.cspublic static bool TryParse(string? expression, out CronExpression? cronExpression)No documentation is available.
Operators
| Name | Description |
|---|---|
| operator ==(CronExpression?, CronExpression?) | Determines whether two expressions select the same values in every field. |
| operator !=(CronExpression?, CronExpression?) | Determines whether two expressions select different values in at least one field. |
operator ==(CronExpression?, CronExpression?)
CronExpression.csDetermines whether two expressions select the same values in every field.
public static bool operator ==(CronExpression? left, CronExpression? right)operator !=(CronExpression?, CronExpression?)
CronExpression.csDetermines whether two expressions select different values in at least one field.
public static bool operator !=(CronExpression? left, CronExpression? right)