cron2date

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2026 License: MIT Imports: 7 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

Index

Constants

View Source
const DefaultVersion = "(devel)"

DefaultVersion is the fallback version string when build info is unavailable.

Variables

View Source
var ErrIteratorConfig = errors.New("IteratorConfig")

ErrIteratorConfig indicates an invalid iterator configuration.

Functions

func BuildVersion

func BuildVersion() string

BuildVersion returns the main module version from Go build info, or DefaultVersion.

func NewIterator

func NewIterator(nexter Nexter, cfg Config) (iter.Seq[time.Time], error)

NewIterator returns a reusable, stateless iterator yielding firing times from cfg.Start until the configured stop condition is reached.

func ParseStartTime

func ParseStartTime(s, layout string, loc *time.Location, explicitTZ bool, fallback time.Time) (time.Time, error)

ParseStartTime parses s in layout and loc, normalizing the resulting timestamp into loc when explicitTZ is true so cron evaluation uses the requested timezone even if s includes an offset.

func ParseTimeOrDefault

func ParseTimeOrDefault(s, layout string, loc *time.Location, fallback time.Time) (time.Time, error)

ParseTimeOrDefault parses s in layout and loc, returning fallback when s is empty.

func ResolveFormat

func ResolveFormat(format string) string

ResolveFormat expands named layout presets (datetime, date, time, rfc3339, rfc3339nano) and otherwise returns format verbatim as a Go time layout.

func ResolveLocation

func ResolveLocation(name string) (*time.Location, error)

ResolveLocation loads an IANA timezone by name, defaulting to time.Local when empty.

Types

type Config

type Config struct {
	Start     time.Time
	Count     int           // negative value is ignored
	Duration  time.Duration // negative value is ignored
	End       time.Time
	Inclusive bool
}

Config configures the firing-time iterator. Start is required, and at least one stop condition must be specified: Count >= 0, Duration >= 0, or a non-zero End. By default firing times are strictly after Start; set Inclusive to include Start when it matches.

func DefaultConfig

func DefaultConfig() Config

DefaultConfig returns a Config with unset Count and Duration.

type ExpandParams

type ExpandParams struct {
	Expr      string
	Start     string
	End       string
	Count     int           // negative value is ignored
	Duration  time.Duration // negative value is ignored
	Format    string
	Timezone  string
	Seconds   bool
	Inclusive bool
}

ExpandParams holds common expansion parameters shared by CLI and MCP adapters.

type NextFunc

type NextFunc func(time.Time) time.Time

NextFunc adapts a plain function to the Nexter interface.

func (NextFunc) Next

func (f NextFunc) Next(t time.Time) time.Time

type Nexter

type Nexter interface {
	// Next returns the next firing time strictly after t, or the zero Time if none exists.
	Next(t time.Time) time.Time
}

Nexter computes the next firing time after a given timestamp.

func NewNexter

func NewNexter(spec string) (Nexter, error)

NewNexter parses a standard 5-field cron expression or descriptor.

func NewNexterWithSeconds

func NewNexterWithSeconds(spec string) (Nexter, error)

NewNexterWithSeconds parses a 6-field cron expression (with leading seconds) or descriptor.

func ParseNexter

func ParseNexter(spec string, seconds bool) (Nexter, error)

ParseNexter parses spec as a 5-field standard cron expression or a 6-field seconds expression.

type PreparedExpand

type PreparedExpand struct {
	Seq      iter.Seq[time.Time]
	Format   string
	Location *time.Location
}

PreparedExpand holds the validated iterator and resolved formatting/location settings.

func PrepareExpand

func PrepareExpand(params ExpandParams, now func() time.Time) (PreparedExpand, error)

PrepareExpand resolves timezone, layout, timestamps, and cron expression into a ready-to-run iterator.

Jump to

Keyboard shortcuts

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