kiorky / croniter

MIT License
410 stars 40 forks source link

Unexpected result for "0 0 8-9 * 0#2" #2

Closed cuu508 closed 3 years ago

cuu508 commented 3 years ago

(originally reported in https://github.com/taichino/croniter/issues/177)

I'm working on an experimental cron expression evaluator, and am testing it against croniter. I came across something that might be a bug. The expression:

0 0 8-9 * 0#2

I read it as on midnight of every day that is either:

Here's a snippet that generates the first 20 matching datetimes, starting from 2021-01-01:

from datetime import datetime
from croniter import croniter

it = croniter("0 0 8-9 * 0#2", datetime(2021, 1, 1))

for i in range(0, 20):
    print(it.get_next(datetime).isoformat())

And here are the results:

2021-01-10T00:00:00
2021-02-14T00:00:00
2021-03-14T00:00:00
2021-04-11T00:00:00
2021-05-09T00:00:00
2021-06-13T00:00:00
2021-07-11T00:00:00
2021-08-08T00:00:00
2021-09-12T00:00:00
2021-10-10T00:00:00
2021-11-14T00:00:00
2021-12-12T00:00:00
2022-01-09T00:00:00
2022-02-13T00:00:00
2022-03-13T00:00:00
2022-04-10T00:00:00
2022-05-08T00:00:00
2022-06-12T00:00:00
2022-07-10T00:00:00
2022-08-14T00:00:00

Most 8ths and 9ths are missing from the output. I suspect this has something to do with the special handling of #2 in the expression. If I test with "0 0 8-9 * 0", I get the result I expected:

2021-01-03T00:00:00
2021-01-08T00:00:00
2021-01-09T00:00:00
2021-01-10T00:00:00
2021-01-17T00:00:00
2021-01-24T00:00:00
2021-01-31T00:00:00
2021-02-07T00:00:00
2021-02-08T00:00:00
2021-02-09T00:00:00
2021-02-14T00:00:00
2021-02-21T00:00:00
2021-02-28T00:00:00
2021-03-07T00:00:00
2021-03-08T00:00:00
2021-03-09T00:00:00
2021-03-14T00:00:00
2021-03-21T00:00:00
2021-03-28T00:00:00
2021-04-04T00:00:00
kiorky commented 3 years ago

croniter mostly stick with basic unix cron support and extra features are only community maintained.

I wont fix those bugs.

You can always (you will be welcome !) make a PR with additional support for those range topics with proper tests, and i wont see anything that would prevent me from merging them.