cron

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 7, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package cron parses standard five-field cron expressions and works out when they next fire, in UTC or an IANA time zone.

Fields are minute, hour, day of month, month and day of week. Each takes *, a number, a range (1-5), a list (1,3,5) and a step (*/15 or 10-50/10). Months and weekdays also take three-letter names (JAN, MON), and 7 is Sunday as well as 0. The macros @yearly, @annually, @monthly, @weekly, @daily, @midnight and @hourly are accepted.

As in Vixie cron, when both day of month and day of week are restricted (neither starts with *), a day matches if either does.

Daylight saving: each wall-clock time fires at most once. A time that does not exist because the clocks went forward fires when it would have been, shifted by the jump (02:30 becomes 03:30 when 02:00 jumps to 03:00). A time that happens twice because the clocks went back fires the first time only.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Schedule

type Schedule struct {
	// contains filtered or unexported fields
}

Schedule is a parsed cron expression bound to a time zone.

func Parse

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

Parse reads a five-field expression. tz is an IANA zone name such as Europe/London; empty means UTC.

func (*Schedule) Location

func (s *Schedule) Location() *time.Location

Location is the schedule's time zone.

func (*Schedule) Next

func (s *Schedule) Next(after time.Time) time.Time

Next returns the first firing strictly after t, or the zero time if there is none within nine years.

func (*Schedule) NextN

func (s *Schedule) NextN(after time.Time, n int) []time.Time

NextN returns the next n firings after t.

func (*Schedule) String

func (s *Schedule) String() string

String returns the expression as given.

Jump to

Keyboard shortcuts

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