Skip to content

cron: accept a step over a range (e.g. 1-5/2) - #482

Open
itzzdev09 wants to merge 1 commit into
python-validators:masterfrom
itzzdev09:cron-range-step
Open

itzzdev09 wants to merge 1 commit into
python-validators:masterfrom
itzzdev09:cron-range-step

Conversation

@itzzdev09

Copy link
Copy Markdown

cron() rejects a step applied to a range, e.g. 1-5/2, which is valid cron (every 2nd value from 1 to 5). It also rejects any comma-list whose items use a range or step, e.g. 15,45 6-18/3 * * *.

_validate_cron_component looked for /, - and , in a fixed order. For 1-5/2 it split on / first, so the base became "1-5", which is neither * nor a decimal, and the item was refused. A field like 6-18/3 never reached the range branch at all. The test file already noted this:

# "5-10/2 * * * *", # this is valid, but not supported yet

This splits each field on , first, then parses each item as an optional base (*, a number, or an n-m range) followed by an optional /step. Behaviour is unchanged for every currently-passing case: */61 (step wider than the range) still passes, */0 and reversed ranges like 30-20 still fail, and out-of-range list members like 0,6,12,24 in the hours field still fail.

Uncommented the noted 5-10/2 case and added 1-30/2 and 15,45 6-18/3 to the valid tests. The 3 new cases fail on master and pass here; the full test_cron.py passes (29).

_validate_cron_component checked for /, - and , in a fixed order, so a
stepped range like "1-5/2" (valid cron) was rejected, as was any
comma-list whose items used ranges or steps. Split each field on ","
first, then parse each item as an optional base ("*", a number or a
range) followed by an optional step.
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.

1 participant