cronspec

package
v0.315.0 Latest Latest
Warning

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

Go to latest
Published: Nov 30, 2026 License: MIT Imports: 4 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 cronspec is muster's ONE cron grammar: the five-field UTC expression a builtin officer's schedule (internal/officers/builtin) and a scheduled host job (internal/hostjobs, docs/host-jobs.md) both take, so the two cannot disagree about what an expression means. A leaf of the standard library alone, so the host binary (muster-mirror) checks its own jobs file with it without linking the server's stores.

Index

Constants

View Source
const CustomWords = "On a custom timetable (UTC)"

CustomWords is Describe's answer for a timetable it does not put in words.

Variables

This section is empty.

Functions

func Describe added in v0.301.0

func Describe(expr string) string

Describe is expr in plain words, for a person: "Weekdays at 09:00 UTC", "Every 15 minutes". It names only what it is sure of — a common shape it recognises exactly — and answers CustomWords for anything else (or for an expression Parse refuses), so a schedule is never described as something it is not. Times are UTC, as every cron here is, and say so.

Recognised, field by field (minute hour day-of-month month day-of-week):

  • minute `*` or `*/n` with n dividing 60, every other field `*`: "Every minute" / "Every n minutes". A step that does not divide 60 (`*/7`) does NOT fire evenly across the hour (…:56, then :00), so it is custom.
  • minute a number m, hour `*`: "Every hour, on the hour" / "Every hour at m minutes past".
  • minute m, hour `*/n` with n dividing 24: "Every n hours from 00:mm UTC".
  • minute m, hour h or a list h1,h2,…: "<days> at HH:MM UTC" (several: "at 09:00 and 17:00 UTC"); hour a range a-b: "<days>, every hour from HH:MM to HH:MM UTC".
  • days: both day fields `*` "Every day"; day-of-week `1-5` "Weekdays", `0,6` / `6,0` / `6,7` "Weekends", one day "Mondays", a list "Mondays, Wednesdays and Fridays"; day-of-month one number n with day-of-week `*` "On the nth of every month". The month field must be `*`.

Types

type Cron

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

Cron is a parsed five-field cron expression — minute hour day-of-month month day-of-week — evaluated in UTC. Each field takes `*`, a number, a range `a-b`, a list `a,b,c` and a step `*/n` or `a-b/n`; day-of-week is 0–6 with 0 (or 7) Sunday. When BOTH day fields are restricted a day matches if EITHER does; a field counts as unrestricted only when it is a bare `*` — so `*/2` restricts (robfig/cron's rule; Vixie cron treats any field starting with `*` as unrestricted). No names (MON, JAN), no `@daily` macros, no seconds: 0118's CHECK already holds an officer schedule's column to five fields, and 0166's a host job's.

func Parse

func Parse(expr string) (Cron, error)

Parse parses expr, refusing (naming the field) anything outside the grammar above.

func (Cron) Next

func (c Cron) Next(t time.Time) (time.Time, bool)

Next is the first minute strictly after t (in UTC) that c matches, and false when there is none within cronHorizon.

func (Cron) ShortestInterval

func (c Cron) ShortestInterval(from time.Time) time.Duration

ShortestInterval is the shortest gap between two consecutive fires of c in the eight days after from (0 when it fires at most once there): what a host officer's spawn budget is sized from (officers.SpawnBudgetFor).

Jump to

Keyboard shortcuts

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