]> git.giacomolli.uk - onechat/commit
Parse cron expressions and find the next time
authorAnderson A. Giacomolli <redacted>
Mon, 9 Nov 2026 00:20:15 +0000 (21:20 -0300)
committerAnderson A. Giacomolli <redacted>
Mon, 9 Nov 2026 00:20:15 +0000 (21:20 -0300)
commit03ef0cf2e8b23ae3954a89883bde4bb557b9ccee
treec7bcf3d53dc924c950ef01094210afa66256d1da
parentb1095a9efc2d57d0c13a043f3feaddbdec789512
Parse cron expressions and find the next time

The schedules of the agent repeat by a five-field cron expression, so
OneChat parses one with a small parser and no new dependency. A field is
a comma list of *, N, and N-M, where * and N-M can have a step. When
both day fields are restricted, a day matches when either one matches,
as in classic cron. The parser refuses names, macros, the characters ? L
W #, a seconds field, N/S, values out of range, and an expression that
matches no day in 8 years, each with an error that names the problem.

It also refuses an expression whose runs can be less than 5 minutes
apart, also across the end of an hour and across midnight. Each run is a
full turn, so a run every minute would use the weekly quota in hours.
The error gives the limit, so that the agent can ask the user.

The next time is the first matching wall time in the local zone. A wall
time that the clock skips runs later by the length of the skip, and a
wall time that the clock repeats runs once, at its first occurrence.

Issue: 60e4e4f
schedule_cron.go [new file with mode: 0644]
schedule_cron_test.go [new file with mode: 0644]