kiorky / croniter

MIT License
410 stars 40 forks source link

.next loses timezone info after v0.3.35 and shows wrong value #11

Closed mayghalV closed 2 years ago

mayghalV commented 2 years ago

Hi thank you for your work on this.

I noticed that calling .next in the way below seems to lose the timezone information after v0.3.35 It also seems to go backwards instead of forward

Any idea why this could be?

from datetime import datetime
import pytz
from croniter import croniter

if __name__ == '__main__':
    now = pytz.timezone('America/New_York').localize(datetime.utcnow())

    cron_schedule = croniter('* * * * *')

    print(now)
    print(cron_schedule.next(datetime, now))

v0.3.34

2022-02-15 05:07:31.216199-05:00
2022-02-15 05:08:00-05:00

v0.3.35 / v1.2.0

2022-02-15 10:13:29.604991-05:00
2022-02-15 10:13:00
kiorky commented 2 years ago

That's not how croniter was supposed to be used, but i just added something that will let you to do it.

IOW, you can do both the two ways (old and new) to achieve the same thing:

before the 1.3.0 i just released, you could do only this way

nextnow2 = croniter('* * * * * ', now).next(datetime)

from 1.3.0

# note that it will work without the `start_time` kwarg
# but you really should add this extra kwarg to ensure compat in case of an API change
nextnow = croniter('* * * * * ').next(datetime, start_time=now)