Documentation
¶
Overview ¶
Package recur parses and projects interval repeater cookies.
Index ¶
- Variables
- func Calendar(value string) bool
- func Cookie(value string) bool
- func Humanize(value string) *string
- func NextTemporalDate(value string, stamp temporal.Value, kind Kind, context temporal.Context, ...) (temporal.Date, error)
- type CivilDate
- func NewCheckedCivilDate(year *big.Int, month, day int) (CivilDate, error)
- func NewCivilDate(year int64, month, day int) CivilDate
- func NextDate(value string, from, today CivilDate) (CivilDate, error)
- func Occurrences(value string, from, today CivilDate, count int) ([]CivilDate, error)
- func Step(date CivilDate, count *big.Int, unit string) CivilDate
- type Explanation
- type Kind
- type Result
Constants ¶
This section is empty.
Variables ¶
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.
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 NextDate ¶
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 ¶
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.
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.
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.
type Result ¶
Result is Parse's outcome. Canonical is either a stored cookie or "off". Error is intentionally an observable Ruby-compatible rejection category.
func Parse ¶
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.