Class TimeZoneAwareCronExpression
A timezone-aware wrapper around Cronos CronExpression.
public sealed class TimeZoneAwareCronExpression : ICronExpression, ICronExpressionQuery
- Inheritance
-
TimeZoneAwareCronExpression
- Implements
- Inherited Members
- Extension Methods
Constructors
TimeZoneAwareCronExpression(string, TimeZoneInfo?, bool)
Initializes a new instance of the TimeZoneAwareCronExpression class.
public TimeZoneAwareCronExpression(string expression, TimeZoneInfo? timeZone = null, bool includeSeconds = false)
Parameters
expressionstringThe cron expression string.
timeZoneTimeZoneInfoThe timezone for this expression.
includeSecondsboolOptional hint. When true, forces 6-field (seconds-aware) parsing. When false (the default), the constructor auto-detects a 6-field expression by counting whitespace-separated fields so callers can pass either
"*/10 * * * "(5-field) or"/10 * * * * *"(6-field) without first tuning IncludeSeconds.
Properties
Expression
Gets the original cron expression string.
public string Expression { get; }
Property Value
- string
The original cron expression string.
IncludesSeconds
Gets a value indicating whether the cron expression includes seconds field.
public bool IncludesSeconds { get; }
Property Value
- bool
A value indicating whether the cron expression includes seconds field.
TimeZone
Gets the timezone for which this cron expression should be evaluated.
public TimeZoneInfo TimeZone { get; }
Property Value
- TimeZoneInfo
The timezone for which this cron expression should be evaluated.
Methods
FromTimeZoneId(string, string, bool)
Creates a TimeZoneAwareCronExpression from a standard cron string and timezone ID.
public static TimeZoneAwareCronExpression FromTimeZoneId(string expression, string timeZoneId, bool includeSeconds = false)
Parameters
expressionstringThe cron expression.
timeZoneIdstringThe timezone ID (e.g., "America/New_York").
includeSecondsboolWhether the expression includes seconds.
Returns
- TimeZoneAwareCronExpression
A new TimeZoneAwareCronExpression instance.
GetDescription()
Gets a human-readable description of the cron expression.
public string GetDescription()
Returns
GetNextOccurrence(DateTimeOffset)
Calculates the next occurrence of the cron expression after the specified time.
public DateTimeOffset? GetNextOccurrence(DateTimeOffset from)
Parameters
fromDateTimeOffsetThe time from which to calculate the next occurrence.
Returns
- DateTimeOffset?
The next occurrence time, or null if there is no next occurrence.
GetNextOccurrenceUtc(DateTimeOffset)
Calculates the next occurrence in UTC.
public DateTimeOffset? GetNextOccurrenceUtc(DateTimeOffset fromUtc)
Parameters
fromUtcDateTimeOffset
Returns
GetOccurrencesBetween(DateTimeOffset, DateTimeOffset)
Gets all occurrences between the specified times.
public IEnumerable<DateTimeOffset> GetOccurrencesBetween(DateTimeOffset from, DateTimeOffset endTime)
Parameters
fromDateTimeOffsetendTimeDateTimeOffset
Returns
IsValid()
Validates whether the cron expression is valid.
public bool IsValid()
Returns
- bool
True if the expression is valid; otherwise, false.