kiorky / croniter

MIT License
410 stars 40 forks source link

croniter.match unexpected output #29

Closed TaridaGeorge closed 1 year ago

TaridaGeorge commented 1 year ago

I'm trying to understand why does this croniter.match call returns True:

    iter = croniter("* * * * * 2,4", datetime(2023, 1, 1, 0, 0, 1))
    print(iter.get_next(datetime))
    print(iter.get_next(datetime))
    print(iter.get_next(datetime))
    print(iter.get_next(datetime))

    print(croniter.match("* * * * * 2,4", datetime(2023, 1, 1, 0, 0, 1)))

Output is:

    2023-01-01 00:00:02
    2023-01-01 00:00:04
    2023-01-01 00:01:02
    2023-01-01 00:01:04
    True

You can see that I'm matching it against a datetime that has 1 in the seconds place. Is this the indented behavior or is it a bug?

waltervos commented 1 year ago

As far as I can tell, your cron expression says "every second", as you're using the six positions syntax.

TaridaGeorge commented 1 year ago

But then why does iter.get_next(datetime) returns 00:00:02 then 00:00:04 then again 00:01:02, 00:01:04?

waltervos commented 1 year ago

I'm sorry, I didn't look close enough. I've always thought that the seconds field was the first field (when using seconds).

waltervos commented 1 year ago

I had a closer look now. croniter only matches for minute precision cron expressions. Refer to line 806: https://github.com/kiorky/croniter/blob/master/src/croniter/croniter.py#L806

I'm not sure if this is something that has been overlooked or if it's intentional.

TaridaGeorge commented 1 year ago

Yes. That seems to be the problem. It only matches for minute precision.

kiorky commented 1 year ago

as said on #18

Sorry but i'm afraid croniter mostly stick with UNIX like cron.

You may submit a PR to add the support, through.

waltervos commented 1 year ago

@kiorky Shouldn't croniter just choose more definitively whether it supports seconds or not? The functionality is kind of half-implemented now. Would you welcome a PR that fixes this?

kiorky commented 1 year ago

Its on the README: croniter iterates along with cron_format from start_time. cron_format is min hour day month day_of_week,

kiorky commented 1 year ago

(And yes, as always, i would greatly appreciate a PR where things may be clearer)

PR are always welcome !