Class CronScheduler
Default implementation of ICronScheduler with timezone awareness.
public sealed class CronScheduler : ICronScheduler
- Inheritance
-
CronScheduler
- Implements
- Inherited Members
- Extension Methods
Remarks
Initializes a new instance of the CronScheduler class.
Constructors
CronScheduler(IOptions<CronScheduleOptions>, ILogger<CronScheduler>)
Default implementation of ICronScheduler with timezone awareness.
public CronScheduler(IOptions<CronScheduleOptions> options, ILogger<CronScheduler> logger)
Parameters
optionsIOptions<CronScheduleOptions>The cron schedule options.
loggerILogger<CronScheduler>The logger.
Remarks
Initializes a new instance of the CronScheduler class.
Methods
GetMissedExecutions(ICronExpression, DateTimeOffset, DateTimeOffset)
Calculates missed executions for a cron expression.
public IEnumerable<DateTimeOffset> GetMissedExecutions(ICronExpression cronExpression, DateTimeOffset lastRun, DateTimeOffset now)
Parameters
cronExpressionICronExpressionThe cron expression.
lastRunDateTimeOffsetThe last successful run time.
nowDateTimeOffsetThe current time.
Returns
- IEnumerable<DateTimeOffset>
List of missed execution times.
GetPreviousOccurrence(ICronExpression, DateTimeOffset)
Calculates when a cron expression should have last run.
public DateTimeOffset? GetPreviousOccurrence(ICronExpression cronExpression, DateTimeOffset from)
Parameters
cronExpressionICronExpressionThe cron expression.
fromDateTimeOffsetThe time from which to calculate backwards.
Returns
- DateTimeOffset?
The previous occurrence time, or null if there is no previous occurrence.
HandleDaylightSavingTransition(DateTimeOffset, TimeZoneInfo)
Handles daylight saving time transitions for a scheduled time.
public DateTimeOffset HandleDaylightSavingTransition(DateTimeOffset scheduledTime, TimeZoneInfo timeZone)
Parameters
scheduledTimeDateTimeOffsetThe local wall-clock fields to interpret in
timeZone. Its existing offset is preserved when no adjustment is needed.timeZoneTimeZoneInfoThe timezone.
Returns
- DateTimeOffset
A checked valid local time after a gap, or the earliest UTC instant for an ambiguous local time. Disabled adjustment and valid times return the original value.
Remarks
This explicit helper does not alter parsed cron evaluation, which delegates transition handling to Cronos. Gap resolution searches at tick precision within a local-date bracket; it does not guarantee the earliest valid tick for every historical rule representation. If adjustment fails, the error is logged and the original value is returned.
Parse(string, TimeZoneInfo?)
Parses a cron expression string into an ICronExpression.
public ICronExpression Parse(string expression, TimeZoneInfo? timeZone = null)
Parameters
expressionstringThe cron expression string.
timeZoneTimeZoneInfoThe timezone for evaluating the expression. If null, uses the system's local timezone.
Returns
- ICronExpression
A parsed cron expression.
TryParse(string, out ICronExpression?)
Validates whether a cron expression string is valid.
public bool TryParse(string expression, out ICronExpression? cronExpression)
Parameters
expressionstringThe cron expression to validate.
cronExpressionICronExpressionWhen this method returns, contains the parsed cron expression if the input is valid; otherwise, null.
Returns
- bool
True if the expression is valid; otherwise, false.
TryParse(string, TimeZoneInfo, out ICronExpression?)
Validates whether a cron expression string is valid for a specific timezone.
public bool TryParse(string expression, TimeZoneInfo timeZone, out ICronExpression? cronExpression)
Parameters
expressionstringThe cron expression to validate.
timeZoneTimeZoneInfoThe timezone for the expression.
cronExpressionICronExpressionThe parsed expression if valid.
Returns
- bool
True if the expression is valid; otherwise, false.
WouldTriggerAt(ICronExpression, DateTimeOffset)
Determines if a cron expression would trigger at a specific time.
public bool WouldTriggerAt(ICronExpression cronExpression, DateTimeOffset time)
Parameters
cronExpressionICronExpressionThe cron expression.
timeDateTimeOffsetThe time to check.
Returns
- bool
True if the expression would trigger at the specified time.