taichino / croniter

croniter is a python module to provide iteration for datetime object.
http://github.com/taichino/croniter
387 stars 105 forks source link

Incorrect "get_next" value in 0.3.22 #102

Closed manango closed 6 years ago

manango commented 6 years ago

In 0.3.20 version, the croniter.get_next() returns correct value.

>>> from datetime import datetime
>>> import croniter
>>>
>>> dt = datetime.strptime('2018/05/15 09:00:30+0000', '%Y/%m/%d %H:%M:%S%z')
>>> print(dt)
# outputs: 2018-05-15 09:00:30+00:00
>>> print(croniter.croniter('0,30 * * * *', dt).get_next(datetime))
# outputs: 2018-05-15 09:30:00+00:00

However, with 0.3.22, the croniter.get_next() returns incorrect value. Calling get_next() at 9:00:30 time with 0,30 * * * * cron returns 9:00:00:

>>> from datetime import datetime
>>> import croniter
>>>
>>> dt = datetime.strptime('2018/05/15 09:00:30+0000', '%Y/%m/%d %H:%M:%S%z')
>>> print(dt)
# outputs: 2018-05-15 09:00:30+00:00
>>> print(croniter.croniter('0,30 * * * *', dt).get_next(datetime))
# outputs: 2018-05-15 09:00:00+00:00
kiorky commented 6 years ago

Ok because of https://github.com/taichino/croniter/pull/97

MichelEdkrantz commented 6 years ago

This just broke a whole lot of code for us and caused a fair share of production issues. Is there a way to disable this "feature"?

kiorky commented 6 years ago

No, fix you requirement to 20 (croniter == 0.3.20). NO eta for having the time to fix it right now, maybe next week.

dawncold commented 6 years ago

I have to detect the result of get_next with the start_time, if it is less than start_time, I call get_next again. @MichelEdkrantz

MichelEdkrantz commented 6 years ago

Thanks, we have frozen to 0.3.20 in the meantime. It would make more sense to only activate the new behaviour with a flag, like croniter.croniter('0,30 ', dt, round_backwards=True) that should be false by default in order not to break existing applications. This is a breaking change in a minor version upgrade, just saying.

Also, this seems to have nothing to do with rounding to nearest 5 minutes in #97. It affects all patterns like "4 ".

kiorky commented 6 years ago

normally fixed by #103