cronexpr

package
v0.2.0-beta Latest Latest
Warning

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

Go to latest
Published: Sep 12, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package cronexpr parses and evaluates standard 5-field cron expressions ("minute hour day-of-month month day-of-week", e.g. "0 3 * * *"), the exact format internal/spec.Backup.Schedule and app.yaml's own databases[].backup.schedule field document (see the worked example in the repo plan's section 4.9).

This is a small, purpose-built parser, not a vendored dependency: go.mod carries no cron library today, and standard 5-field cron (literals, "*", comma-separated lists, "a-b" ranges, and "/step" steps, plus the classic "day matches if EITHER day-of-month OR day-of-week matches, when both are restricted" quirk every real cron implementation shares) is a small, well-understood grammar that fits comfortably in one file with table-driven tests, matching this project's own stated preference for a handful of well-tested internal primitives over pulling in a framework for something this narrow (repo plan section 4.1's "do not pull in a heavy framework" rule, applied here one layer down from the HTTP framework it was written about). Nothing here schedules anything or runs a goroutine: that is internal/backup.Scheduler's job, built on top of the Next method this package exposes, the same "parser is a pure value, the loop lives elsewhere" split internal/spec keeps between Parse and every package that actually acts on a Spec.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Schedule

type Schedule struct {
	// contains filtered or unexported fields
}

Schedule is a parsed, immutable 5-field cron expression, safe for concurrent use by multiple goroutines (every method only reads its own fields, computed once at Parse time).

func Parse

func Parse(expr string) (*Schedule, error)

Parse parses a standard 5-field cron expression. Fields are separated by whitespace; each field is one of "*", a single integer, an "a-b" range, or any of those with a "/step" suffix (e.g. "*/15", "10-20/5"), optionally comma-separating multiple such terms in one field (e.g. "1,15,30"). day-of-week accepts 7 as an alias for 0 (Sunday), the common convention several real cron implementations also accept, though this parser does not accept month or day names (JAN, MON, ...): app.yaml's own schedule field is documented purely as a cron expression, and every worked example in this codebase uses numeric fields only, so name support would be untested surface with no current caller.

func (*Schedule) Next

func (s *Schedule) Next(t time.Time) time.Time

Next returns the earliest minute-aligned UTC time strictly after t that this Schedule matches, or the zero time.Time if no match exists within searchHorizon. Cron fields have no timezone concept of their own; every caller in this codebase (internal/backup.Scheduler) works in UTC exclusively, the same "everything server-side is UTC, a client converts for display" convention store.BackupHistory's own RFC3339-in-UTC timestamps already establish, so t is converted to UTC here rather than accepting an implicit local-time assumption.

Jump to

Keyboard shortcuts

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