Table of Contents

Class TimeZoneAwareCronExpression

Namespace
Excalibur.Dispatch.Delivery
Assembly
Excalibur.Dispatch.dll

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

expression string

The cron expression string.

timeZone TimeZoneInfo

The timezone for this expression.

includeSeconds bool

Optional 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

expression string

The cron expression.

timeZoneId string

The timezone ID (e.g., "America/New_York").

includeSeconds bool

Whether the expression includes seconds.

Returns

TimeZoneAwareCronExpression

A new TimeZoneAwareCronExpression instance.

GetDescription()

Gets a human-readable description of the cron expression.

public string GetDescription()

Returns

string

GetNextOccurrence(DateTimeOffset)

Calculates the next occurrence of the cron expression after the specified time.

public DateTimeOffset? GetNextOccurrence(DateTimeOffset from)

Parameters

from DateTimeOffset

The 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

fromUtc DateTimeOffset

Returns

DateTimeOffset?

GetOccurrencesBetween(DateTimeOffset, DateTimeOffset)

Gets all occurrences between the specified times.

public IEnumerable<DateTimeOffset> GetOccurrencesBetween(DateTimeOffset from, DateTimeOffset endTime)

Parameters

from DateTimeOffset
endTime DateTimeOffset

Returns

IEnumerable<DateTimeOffset>

IsValid()

Validates whether the cron expression is valid.

public bool IsValid()

Returns

bool

True if the expression is valid; otherwise, false.