Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conflict between "Day of Month" & "Day of Week" #13

Closed
CooledCoffee opened this issue Dec 31, 2014 · 2 comments
Closed

Conflict between "Day of Month" & "Day of Week" #13

CooledCoffee opened this issue Dec 31, 2014 · 2 comments
Labels

Comments

@CooledCoffee
Copy link

Cron expressions such as "0 0 1-7 * 4" (first thursday of every month) is not supported by your library.
The error is caused by these code:

    if not matchers.day.any:
        _assert(matchers.weekday.any,
            "missing a wildcard specifier for weekday")
    if not matchers.weekday.any:
        _assert(matchers.day.any,
            "missing a wildcard specifier for day")

in the CronTab._make_matchers method.

@grahambell
Copy link
Contributor

Wouldn't "0 0 1-7 * 4" mean days 1-7 and also any Thursdays? The wikipedia page given in the parse-crontab README instead mentions the # symbol for expressions such as "the first Thursday".

The crontab(5) manual on my system says:

Note: The day of a command's execution can be specified in the following two fields — 'day of month', and 'day of week'. If both fields are restricted (i.e., do not contain the "*" character), 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.

@josiahcarlson
Copy link
Owner

As @grahambell mentioned, the '#' specifier is supposed to handle that behavior, but this module explicitly excludes that functionality. And as @grahambell quoted, when both day of month and week are restricted, cron expressions don't work the way you would expect.

To address this limitation, I would suggest using the "0 0 1-7 * *" variant, then verifying upon trigger that the date/time is on the day of week that you want. I do a similar thing to handle timezones and DST changes in my own code that uses this package.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants