cron

package
v0.17.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 23, 2026 License: MIT Imports: 5 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package cron parses standard five-field cron expressions and computes their next run times.

An expression has five fields separated by spaces: minute (0-59), hour (0-23), day of month (1-31), month (1-12 or JAN-DEC), and day of week (0-7 or SUN-SAT, where both 0 and 7 mean Sunday). Each field is "*", a value, a range "a-b", or a list of those separated by commas, and any of them may carry a step "/n". When both day fields are restricted, a day matches if either matches, as in classic cron. The macros @yearly, @annually, @monthly, @weekly, @daily, @midnight, and @hourly are also accepted.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Schedule

type Schedule struct {
	// Minute, Hour, Dom, Month, and Dow are the values that each field
	// matches, as sets of bits: bit v is set if the field matches v. Dow
	// counts the days of the week from Sunday, 0, to Saturday, 6.
	Minute, Hour, Dom, Month, Dow uint64

	// EitherDay says how the two day fields combine. If it is true, a day
	// matches when Dom or Dow matches it: that is so when neither field is
	// "*". If it is false, a day matches when both match it.
	EitherDay bool
}

Schedule is a parsed cron expression, as Parse returns it. Its fields say what the expression matches, for the dashboard, which puts it into words.

func Parse

func Parse(expr string) (*Schedule, error)

Parse parses a cron expression.

func (*Schedule) Next

func (s *Schedule) Next(t time.Time) (time.Time, error)

Next returns the first time after t that the schedule matches, in t's location. It fails if the schedule never matches, such as on February 31.

The schedule is matched against the wall clock, and each wall-clock time that it matches runs once, whatever the clock does. A time that the clock skips, when clocks go forward, runs as far after the jump as it is into the gap, among the times that the clock shows then. A time that the clock shows twice, when clocks go back, runs the first time only. Unlike classic cron, this holds for wildcard schedules too: "*/15 * * * *" makes no run in the repeated hour's second pass.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL