Documentation
¶
Overview ¶
Package cron provides cron expression parsing and next-fire-time calculation. It implements the standard 5-field cron syntax plus optional seconds and descriptors.
Supported Syntax ¶
Standard 5-field: minute hour day-of-month month day-of-week Optional 6-field: second minute hour day-of-month month day-of-week
- * matches any value
- 5 literal value
- 1,3,5 comma-separated list
- 1-5 range
- */2 step (every 2 units)
- 1-10/3 range with step
- 5L last weekday of month (e.g. "5L" = last Friday)
- 15W nearest weekday to day 15
Quick start ¶
expr, err := cron.Parse("*/5 * * * *")
next := expr.Next(time.Now())
// 6-field with seconds
expr, err := cron.Parse("0 */30 * * * *")
// Descriptors
expr, err := cron.Parse("@hourly")
expr, err := cron.Parse("@every 10s")
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Expression ¶
type Expression struct {
// contains filtered or unexported fields
}
Expression represents a parsed cron expression.
func MustParse ¶
func MustParse(expr string) *Expression
MustParse is like Parse but panics on error.
func Parse ¶
func Parse(expr string) (*Expression, error)
Parse parses a cron expression string. Supports 5-field, 6-field, and descriptor (@hourly, @every, etc.) syntax.
func (*Expression) EveryDuration ¶
func (e *Expression) EveryDuration() time.Duration
EveryDuration returns the duration for @every expressions. Returns 0 for non-@every expressions.
func (*Expression) HasSeconds ¶
func (e *Expression) HasSeconds() bool
HasSeconds returns true if the expression includes a seconds field.
func (*Expression) IsEvery ¶
func (e *Expression) IsEvery() bool
IsEvery returns true if the expression is an @every descriptor.
func (*Expression) Next ¶
Next returns the next time after t that the expression should fire. If t is zero, it uses time.Now(). Returns an error if no future fire time is found within 5 years.
func (*Expression) String ¶
func (e *Expression) String() string
String returns the original expression text.
type Schedule ¶
type Schedule struct {
// contains filtered or unexported fields
}
Schedule represents a sequence of fire times.
func NewSchedule ¶
func NewSchedule(expr *Expression) *Schedule
NewSchedule creates a schedule from a parsed expression.