recur

package
v1.8.1 Latest Latest
Warning

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

Go to latest
Published: Aug 14, 2026 License: MIT Imports: 11 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 recur parses and projects interval repeater cookies.

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidDate = errors.New("invalid date")

ErrInvalidDate is the Go spelling of the Date::Error Ruby raises for a well-formed but non-existent civil date. Its text is Ruby's message verbatim because the probe reports it where Ruby reports the rescued message.

View Source
var ErrNoValidOccurrence = errors.New("recurrence could not find a valid local date/time")

ErrNoValidOccurrence is the exhaustion of the candidate walk: every date the schedule offered was unwritable or vetoed.

Functions

func Calendar

func Calendar(value string) bool

Calendar reports whether a value is a stored calendar schedule in its exact canonical spelling. That round trip is the whole test: a schedule that means something but is spelled differently is not a STORED value, and accepting it would let two spellings of one schedule sit in the file.

func Cookie(value string) bool

Cookie reports whether value is already a STORED recurrence value: an interval cookie or a calendar schedule, each in its exact canonical spelling. Both halves matter — a store holds one spelling per schedule, so "w:monday" is readable input and not a stored value.

func Humanize

func Humanize(value string) *string

Humanize renders an interval cookie as Ruby does. It returns nil for blank input and the trimmed value when it is not an interval cookie, allowing the calendar package to own its own rendering later.

func NextTemporalDate

func NextTemporalDate(value string, stamp temporal.Value, kind Kind, context temporal.Context,
	veto func(temporal.Date) bool) (temporal.Date, error)

NextTemporalDate is the date a stored recurrence rolls a stamp to. `veto` may be nil; when supplied it rejects a candidate the caller cannot accept (a paired field that would land in a DST gap, say) and the walk continues.

Types

type CivilDate

type CivilDate struct {
	Year  *big.Int
	Month int
	Day   int
}

CivilDate is an unzoned Ruby Date-compatible civil date. Its year is arbitrary precision because Ruby Date accepts interval projections beyond time.Time's range. Ruby Date's default Date::ITALY start means dates before 1582-10-15 use the Julian calendar, with the ten reform days omitted.

func NewCheckedCivilDate

func NewCheckedCivilDate(year *big.Int, month, day int) (CivilDate, error)

NewCheckedCivilDate applies Ruby Date's validity rule under Date::ITALY: month 1..12, day within the month's length on the calendar in force for that year, and none of the ten days the 1582 reform omitted.

func NewCivilDate

func NewCivilDate(year int64, month, day int) CivilDate

func NextDate

func NextDate(value string, from, today CivilDate) (CivilDate, error)

NextDate projects a STORED value — an interval cookie or a calendar schedule — from its stamp's current date and today's date.

A catch-up projection intentionally may land on today rather than past it: that is exactly where the completion path's own fast-forward stops, and a candidate landing on today can still be in the future by its end-of-day boundary. A date-only projection has no time to compare, so it must name the same day the write would produce.

func Occurrences

func Occurrences(value string, from, today CivilDate, count int) ([]CivilDate, error)

Occurrences is the next `count` dates a stored value fires on. Each landing becomes the anchor for the next, so an every-Nth series keeps its parity and a from-completion cookie keeps stepping.

func Step

func Step(date CivilDate, count *big.Int, unit string) CivilDate

Step advances a civil date. Month and year units clamp overflowing days; time.Time.AddDate cannot be used because it normalizes Jan 31 + one month into March instead of Ruby Date#>>'s February clamp.

func (CivilDate) Before

func (d CivilDate) Before(other CivilDate) bool

func (CivilDate) Compare

func (d CivilDate) Compare(other CivilDate) int

func (CivilDate) Equal

func (d CivilDate) Equal(other CivilDate) bool

func (CivilDate) String

func (d CivilDate) String() string

type Explanation

type Explanation struct {
	Input        string
	Canonical    string
	HasCanonical bool
	Human        string
	Next         []CivilDate
	HasNext      bool
	Error        string
}

Explanation is the discoverability payload every surface renders: what was typed, what it stores as, how it reads, and when it next fires.

Three shapes, and the middle one is why this is a struct rather than a pair:

understood and projected   Canonical, Human, Next
understood, never fires    Canonical, Human, empty Next, Error
not understood             Input and Error only

Whether a schedule ever fires depends on the ANCHOR, not on the schedule alone, so a projection failure must still identify what was typed rather than masquerading as a parse error.

func Explain

func Explain(input string, today CivilDate, count int, from string) Explanation

Explain parses, normalizes, and projects without touching the store. `from` is the stamp the projection is anchored on, in the stored spelling; empty means today.

type Kind

type Kind int

Kind says which boundary a candidate is judged by, because an all-day deadline and an all-day available-from date do not release at the same instant.

const (
	// Deadline judges a candidate by when it stops being on time.
	Deadline Kind = iota
	// Scheduled judges a candidate by when it becomes available.
	Scheduled
)

type Result

type Result struct {
	Canonical string
	Error     string
}

Result is Parse's outcome. Canonical is either a stored cookie or "off". Error is intentionally an observable Ruby-compatible rejection category.

func Parse

func Parse(input, defaultPrefix string) Result

Parse normalizes any accepted spelling into the one canonical stored value, "off" to clear recurrence, or a refusal naming the reason.

".+1w" "+2d" "++1m"          passthrough (validated)
"weekly" "2w" "every 3 days" ".+…" — a bare interval takes defaultPrefix
"w:mon" "every monday"       "w:mon"
"off" / "none" / "never"     off

defaultPrefix picks the semantics for a bare INTERVAL: ".+" (from completion) normally, "+" when the caller wants the date-anchored form. Calendar schedules carry their own prefix and ignore it — bare calendar input is catch-up.

Jump to

Keyboard shortcuts

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