This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
A Go library for parsing cron expressions and computing the next matching time(s). Fork of github.com/gorhill/cronexpr. Module path is github.com/toba/cronexpr, requires Go 1.25+. Supports 5-field (standard), 6-field (with seconds), and 7-field (with seconds and year) cron expressions, plus predefined aliases (@yearly, @monthly, @weekly, @daily, @hourly).
go test ./... # run all tests
go test -run TestZero # run a single test by name
go test -bench . # run benchmarks
go test -v # verbose test outputTests are in-package (package cronexpr), so they have access to unexported types.
Three source files, one exported type (Expression), two entry points (Parse/MustParse):
- cronexpr.go — Public API. Defines the
Expressionstruct and theParse/MustParseconstructors, plusNext/NextNmethods.Nextwalks fields from year down to second usingslices.BinarySearchagainst pre-computed sorted value lists; on mismatch it delegates to the appropriatenext*function in cronexpr_next.go. - cronexpr_parse.go — Parsing engine. Tokenizes each cron field using regex patterns, handles special characters (
L,W,#), and populates theExpressionfields. UsesfieldDescriptorstructs to parameterize parsing per field type. Regex patterns are lazily compiled and cached in async.Map. - cronexpr_next.go — Time advancement. Contains
nextYearthroughnextSecondfunctions that cascade when a field overflows.calculateActualDaysOfMonthmerges day-of-month and day-of-week constraints per the crontab spec (if both are restricted, either match triggers).
- Day-of-week 7 is normalized to 0 (both mean Sunday)
- 5 fields → seconds default to 0, year defaults to wildcard
- 6 fields → seconds default to 0
- When both day-of-month and day-of-week are restricted (not
*), a day matches if either field matches (union, per crontab spec) W(nearest weekday) does not cross month boundaries- Year range is 1970–2099