Skip to content

Support natural language offsets - #123

Merged
jmettraux merged 1 commit into
floraison:masterfrom
jeromedalbert:add-nat-offset
Jul 14, 2026
Merged

Support natural language offsets#123
jmettraux merged 1 commit into
floraison:masterfrom
jeromedalbert:add-nat-offset

Conversation

@jeromedalbert

@jeromedalbert jeromedalbert commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

At work we have a cron job that runs every 15 minutes (minutes 0, 15, 30, 45). The corresponding natural language expression is easy to write: every 15 minutes.
But we also have a second job that runs 1 minute after the first job (minutes 1, 16, 31, 46). There is currently no nice way to express this in natural language besides listing all the minutes: at minutes 1,16,31,46.

I thought it might be nice if the natural language parser could support offsets, so the second job's schedule could be rewritten to every 15 minutes starting at minute 1 or every 15 minutes from minute 1.

This PR is an attempt to support such offsets. If this looks useful, I am happy to tweak this further. For example I sort of like the expressiveness of "starting at", but it might look too wordy.

@jeromedalbert
jeromedalbert force-pushed the add-nat-offset branch 6 times, most recently from 84f33da to 6b58267 Compare July 9, 2026 18:17
@jmettraux jmettraux self-assigned this Jul 9, 2026
@jmettraux

Copy link
Copy Markdown
Member

Salut, thanks for the PR, looking good, let me sleep and marinate over it...

@jeromedalbert

jeromedalbert commented Jul 10, 2026

Copy link
Copy Markdown
Contributor Author

Merci pour ta considération et pour cette gem très utile que j'utilises depuis des années !

Some extra info:

  • the word "minute" is repeated in every 15 minutes starting at minute 1 because it looks more natural to me than every 15 minutes starting at 1, but I can add support for omitting the second "minute" word. I can also add support for a sentence like every 15 minutes with offset 1.
  • I am not currently validating that the second "minute" word matches the first one. In the incorrect sentence every 15 minutes starting at hour 1, the offset is still interpreted as a minute offset. This may feel like an edge case so I kept the PR simple, but I can add some validation if desired.
  • The PR's initial focus was offsets, but looking at your exploration in 21cb1c9 we could support ranges like every 15 minutes from minute 1 to 31. In that case what I call offset is just a subset of the notion of ranges, which is the official term according to man 5 crontab. So we could refactor the PR with names like range instead of offset, with an optional range end. This is probably the cleaner way to go.

@jeromedalbert
jeromedalbert force-pushed the add-nat-offset branch 2 times, most recently from a168d40 to 113fded Compare July 10, 2026 10:09
@jmettraux

Copy link
Copy Markdown
Member

Salut,

I'm taking it in, I might tweak it a little bit, but overall I like your work.

Merci beaucoup !

@jmettraux
jmettraux merged commit 8485343 into floraison:master Jul 14, 2026
11 checks passed
@jeromedalbert
jeromedalbert deleted the add-nat-offset branch July 14, 2026 08:37
jmettraux added a commit that referenced this pull request Jul 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants