maennchen / crontab

Parse Cron Expressions, Compose Cron Expression Strings and Caluclate Execution Dates.
https://hex.pm/packages/crontab
MIT License
91 stars 32 forks source link

Fail to parse expressions with non-range step values #123

Closed shaolang closed 7 months ago

shaolang commented 7 months ago

hi,

The current version fails to parse expressions with non-range step values, even though the library's examples page suggest otherwise. For example, the following all return {:error, "Can't parse 0 as a range"}

Crontab.CronExpression.Parser.parse "0 0/5 14 * * *"    # example from library's example page
Crontab.CronExpression.Parse.parse "0/2 * * * *"

I can get around the issue by using ranges, e.g., 0-23/5 and 0-59/2 respectively for the examples above.

I can help in submitting a fix, if supporting such expressions is expected.

maennchen commented 7 months ago

Oh, you're right. A PR would be welcome.

I think it's suppused to work as follows: REMAINDER/DIVIDER and evaluates as truthy if INTERVAL % DIVIDER == REMAINDER

shaolang commented 7 months ago

Oh, you're right. A PR would be welcome.

I think it's suppused to work as follows: REMAINDER/DIVIDER and evaluates as truthy if INTERVAL % DIVIDER == REMAINDER

I think START/INTERVAL means run on START + INTERVAL N where N begins at 0; for example, if `0 0 2/5 ` (i.e., for the day of month field) and today is 2024-01-30, that expression's next few run dates would be:

Not sure whether I've misinterpreted your reply, so we may be talking about the same thing. :D

maennchen commented 7 months ago

@shaolang Exactly what I meant :)