schedparse

package
v0.0.53 Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2026 License: Apache-2.0 Imports: 7 Imported by: 1 module, 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 schedparse compiles finite scheduling phrases and validates client-side cron previews. Compile retains the legacy phrase-only interface; Validate is the timezone-aware validation boundary for preview and submission.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Preview added in v0.0.52

type Preview struct {
	Result
	Timezone string
	Next     time.Time // strictly after now, in the chosen timezone
}

Preview is a validated trigger and local estimate, not a server acceptance promise. Re-run Validate at Create with a fresh now, especially for relative phrases.

func Validate added in v0.0.52

func Validate(input, timezone string, now time.Time) (Preview, error)

Validate accepts finite phrases or backend-standard five-field cron/@ macros. The explicit timezone is authoritative. now is supplied by the caller, never read here. On error no usable trigger is returned.

type Result

type Result struct {
	Cron    string    // a 5-field cron expression, set when the phrase is recurring
	OneShot time.Time // a wall-clock instant, set when the phrase is a one-shot (zero otherwise)
}

Result is the outcome of Compile: exactly one of Cron or OneShot is set. The caller decides which kind of trigger to build (a cron schedule vs a one-shot schedule) — Compile only produces the value.

func Compile

func Compile(nl string, now time.Time) (Result, bool)

Compile parses a natural-language scheduling phrase into a trigger result. If the phrase matches a known pattern, exactly one of Cron or OneShot is set and ok is true. If no pattern matches, ok is false and the caller should treat the input verbatim as a raw cron expression.

now is the reference instant for the one-shot patterns ("next monday 9am", "in 30 minutes", "tomorrow at 9am"); it is ignored by the recurring (cron) patterns.

type ValidationError added in v0.0.52

type ValidationError struct {
	Field   string // "timing" or "timezone"
	Message string
}

ValidationError identifies the form field that needs correction.

func (*ValidationError) Error added in v0.0.52

func (e *ValidationError) Error() string

Jump to

Keyboard shortcuts

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