Help us shape the future of Go! Take the 2026 Go Developer Survey

recur

package
v0.7.0 Latest Latest
Warning

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

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

Documentation

Overview

Package recur describes when an automation runs: once, at a fixed interval, or at a local time of day on chosen weekdays in an IANA time zone. It validates requests, computes occurrences (including across daylight-saving transitions) and describes schedules for people.

Index

Constants

View Source
const (
	KindOnce     = "once"
	KindInterval = "interval"
	KindCalendar = "calendar"
)

Rule kinds.

View Source
const MinInterval = time.Minute

MinInterval is the shortest delay or interval.

Variables

This section is empty.

Functions

func FormatLocal

func FormatLocal(t time.Time, loc *time.Location) string

FormatLocal renders an instant for people and agents with its weekday, zone abbreviation and UTC offset, e.g. "Mon 2026-10-13 09:00 AEDT (+11:00)".

func ParseMoment

func ParseMoment(s string, loc *time.Location) (time.Time, error)

ParseMoment reads RFC 3339 with an offset, or a local wall-clock time ("2026-10-09T15:00", optionally with seconds or a space) in loc.

Types

type Request

type Request struct {
	// In is a delay from now, e.g. "20m".
	In string `json:"in,omitempty"`
	// At is a moment: RFC 3339 with an offset, or local wall-clock time
	// "2006-01-02T15:04" in Timezone.
	At string `json:"at,omitempty"`
	// Every is a fixed interval of elapsed time, at least MinInterval.
	Every string `json:"every,omitempty"`
	// Time is a local wall-clock time "15:04" repeated on Days in Timezone.
	Time string `json:"time,omitempty"`
	// Days are three-letter weekdays (mon..sun), "weekdays" or "weekends";
	// empty means every day.
	Days []string `json:"days,omitempty"`
	// Timezone is an IANA name; empty means the seat's time zone.
	Timezone string `json:"timezone,omitempty"`
}

Request is how an agent asks for a schedule. Exactly one of In, At, Every or Time is set; Days and Timezone qualify Time (and Timezone a local At).

type Rule

type Rule struct {
	Kind string `json:"kind"`
	// At is the one-off moment (once).
	At time.Time `json:"at,omitzero"`
	// Every and Anchor define an interval: runs at Anchor + n*Every.
	Every  string    `json:"every,omitempty"`
	Anchor time.Time `json:"anchor,omitzero"`
	// Time and Days define a calendar rule in Timezone.
	Time     string   `json:"time,omitempty"`
	Days     []string `json:"days,omitempty"`
	Timezone string   `json:"timezone"`
}

Rule is a validated, stored schedule.

func Parse

func Parse(req Request, defaultTZ string, now time.Time) (Rule, error)

Parse validates a request. defaultTZ applies when the request names no time zone; now anchors "in" and "every".

func (Rule) CountBetween

func (r Rule) CountBetween(from, to time.Time, limit int) int

CountBetween counts occurrences in (from, to], up to limit.

func (Rule) Location

func (r Rule) Location() *time.Location

Location returns the rule's time zone.

func (Rule) Next

func (r Rule) Next(t time.Time) (time.Time, bool)

Next returns the first occurrence strictly after t; ok is false when there is none.

func (Rule) Occurrences

func (r Rule) Occurrences(t time.Time, n int) []time.Time

Occurrences lists up to n occurrences strictly after t.

func (Rule) Summary

func (r Rule) Summary() string

Summary describes the rule for people, e.g. "every weekday at 09:00 (Australia/Melbourne)".

Jump to

Keyboard shortcuts

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