Skip to content

Error parsing day-of-month combined with day-of-week #68

@dswhite42

Description

@dswhite42

Hello. Thank you very much for this library. It seems to be working well, except for a couple of corner-case issues. Here's some code:

import cron_descriptor
cron = '30 4 1,15 * FRI'
print(f'Description for [{cron}] is: {cron_descriptor.get_description(cron)}')

Output:

Description for [30 4 1,15 * FRI] is: At 04:30 AM, on day 1 and 15 of the month, only on Friday

This should actually be something like:

Description for [30 4 1,15 * FRI] is: At 04:30 AM, on day 1 and 15 of the month, plus every Friday

This is in keeping with the crontab(5) man page which indicates the day-of-month and day-of-week criteria should be combined with OR rather than AND.

Note: The day of a command's execution can be specified by two fields — day of month, and day of week. If both fields are restricted (i.e., aren't *), the command will be run when either field matches the current time. For example,
``30 4 1,15 * 5'' would cause a command to be run at 4:30 am on the 1st and 15th of each month, plus every Friday.

However, there is an exception to this due to a bug in Vixie cron/ISC cron/cronie. Because cron fails to parse asterisk fields that contain more than just a single asterisk (for example, */2), it will join the criteria together with AND rather than OR for those entries, in violation of its own man page. So for this code:

cron = '30 4 */2 * FRI'
print(f'Description for [{cron}] is: {cron_descriptor.get_description(cron)}')

cron-descriptor actually evaluates the code the same way the buggy cron does:

Description for [30 4 */2 * FRI] is: At 04:30 AM, every 2 days, only on Friday

(more details on the asterisk bug in cron is here: https://crontab.guru/cron-bug.html The consensus seems to be that this bug should not be fixed due to its having been around for decades now.)

So, could the incorrect evaluation of cron entries like "30 4 1,5 * FRI" be fixed, while still keeping consistency with the buggy versions of cron for entries like "30 4 */2 * FRI"?

Thanks for looking into it, and for your work on this tool.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions