Documentation
¶
Index ¶
- Variables
- type Expression
- func (expr Expression) Countdown(from time.Time) int64
- func (expr Expression) Due(of time.Time) bool
- func (expr Expression) DueDay(of time.Time) bool
- func (expr Expression) DueHour(of time.Time) bool
- func (expr Expression) DueMinute(of time.Time) bool
- func (expr Expression) DueMonth(of time.Time) bool
- func (expr Expression) Next(from time.Time) time.Time
- type Field
Constants ¶
This section is empty.
Variables ¶
var ( // ErrUnknownAlias is returned when an @alias does not match any known alias. ErrUnknownAlias = errors.New("unknown alias for an expression") // ErrInvalidFormat is returned when the expression has more than six fields. ErrInvalidFormat = errors.New("invalid format") // ErrEmptyExpr is returned when the expression string is empty after trimming. ErrEmptyExpr = errors.New("empty expression not allowed") )
var ( // ErrParseDigits is returned when a token contains non-digit characters. ErrParseDigits = errors.New("unable to parse digits") // ErrOverflow is returned when a numeric value exceeds the uint8 maximum (255). ErrOverflow = errors.New("value out of range for uint8 (overflow)") // ErrNumberOutOfBounds is returned when a value falls outside a field's // valid range (e.g. 60 in the seconds field). ErrNumberOutOfBounds = errors.New("number was out of bounds") )
Functions ¶
This section is empty.
Types ¶
type Expression ¶
type Expression struct {
// contains filtered or unexported fields
}
Expression is a compiled cron expression.
Each field is stored as a bitmask for O(1) match checks. Construct an Expression with NewExpression.
func NewExpression ¶
func NewExpression(expr string) (Expression, error)
NewExpression parses a cron expression string and returns a compiled Expression.
The expression supports six space-separated fields:
second minute hour day-of-month month day-of-week
Fewer than six fields are left-padded with "*". Month names (jan-dec) and day-of-week names (sun-sat) are accepted case-insensitively. The "@" prefix expands named aliases such as "@hourly", "@daily", "@weekly", and "@ticks".
NewExpression returns an error for empty input, invalid syntax, out-of-bounds values, overflow, too many fields, or unknown aliases.
func (Expression) Countdown ¶
func (expr Expression) Countdown(from time.Time) int64
Countdown returns the number of whole seconds from from until the next scheduled time. It returns -1 if no match exists within the 4-year lookahead window.
func (Expression) Due ¶
func (expr Expression) Due(of time.Time) bool
Due reports whether the time of matches the full expression at second precision.
func (Expression) DueDay ¶
func (expr Expression) DueDay(of time.Time) bool
DueDay reports whether the month, day-of-month, and day-of-week all match the time of.
Unlike Next, DueDay requires both dayOfMonth and dayOfWeek to match.
func (Expression) DueHour ¶
func (expr Expression) DueHour(of time.Time) bool
DueHour reports whether month, day, and hour all match the time of.
func (Expression) DueMinute ¶
func (expr Expression) DueMinute(of time.Time) bool
DueMinute reports whether month, day, hour, and minute all match the time of.
func (Expression) DueMonth ¶
func (expr Expression) DueMonth(of time.Time) bool
DueMonth reports whether the month field matches the month of of.
func (Expression) Next ¶
func (expr Expression) Next(from time.Time) time.Time
Next returns the first time.Time strictly after from that matches the expression. It searches forward through seconds, minutes, hours, days, and months, rolling over to the next higher unit when no match is found.
Next applies a 4-year lookahead window to prevent infinite loops on sparse schedules. It returns the zero time.Time if no match is found within the window.
type Field ¶
type Field[T fieldMask] struct {
Value T
Range [2]uint8
}
Field is a bitmask-based cron field parameterised over an unsigned integer type.
Value holds a bitmask where each set bit represents a matching value in the schedule. Range records the effective [min, max] of the set bits, used for bounds checking in Match.
T must be one of uint8, uint16, uint32, or uint64. Choose the smallest type that covers the field's range.
func ParseField ¶
ParseField parses a single cron field token into a typed Field[T].
The token supports standard cron notation:
- — every value N — single value N,M,... — multiple values N-M — inclusive range */S — step over full range N-M/S — step over a range
bounds is the inclusive [min, max] for the field (e.g. [0, 59] for seconds). T must be uint8, uint16, uint32, or uint64.
ParseField returns an error for invalid syntax, out-of-range values, or numeric overflow.
func (Field[T]) List ¶
List returns all set values in ascending order.
List returns nil if the field is empty.