Repository: kiorky/croniter

Issue:
`get_next` behaviour seems to have changed in 1.3.0
Hi, i'm using croniter through [Procrastinate](https://procrastinate.readthedocs.io/en/stable/howto/cron.html), an asynchronous task scheduler and executor. Procrastinate relies on croniter to trigger recurring jobs.

My recurring jobs have stopped triggering today, and I've pinpointed the issue to this croniter commit: https://github.com/kiorky/croniter/commit/1ea781aa1936214088fa6451c5d62537045869dd

If I run my procrastinate worker with this croniter version, recurring jobs are not triggered. If I run my procrastinate worker with commit https://github.com/kiorky/croniter/commit/5298c6a3f365503f7c8d25b773d65c2e27b3ac9b (the previous one), everything works as expected.

Internally, [Procrastinate uses the `get_next()` method](https://github.com/procrastinate-org/procrastinate/blob/781cbdf0ce272f9bc449acbccc8caa65108c6649/procrastinate/periodic.py#L118-L128) to decide how much time to wait before trigerring a recurring job. This is the method that was modified in 1ea781aa1936214088fa6451c5d62537045869dd.

Do you you think 1ea781aa1936214088fa6451c5d62537045869dd could have introduced a backward incompatible change, or does the issue lies in Procrastinate itself (latest release was on 2021-12-19)?

Discussion:

Patch:
diff --git a/src/croniter/croniter.py b/src/croniter/croniter.py
index 061e35a..c3f69ba 100644
--- a/src/croniter/croniter.py
+++ b/src/croniter/croniter.py
@@ -175,7 +175,7 @@ class croniter(object):
             return self._timestamp_to_datetime(self.cur)
         return self.cur
 
-    def set_current(self, start_time, force=False):
+    def set_current(self, start_time, force=True):
         if (force or (self.cur is None)) and start_time is not None:
             if isinstance(start_time, datetime.datetime):
                 self.tzinfo = start_time.tzinfo


Test patch:
diff --git a/src/croniter/tests/test_croniter.py b/src/croniter/tests/test_croniter.py
index a4bdb1e..b509921 100755
--- a/src/croniter/tests/test_croniter.py
+++ b/src/croniter/tests/test_croniter.py
@@ -2,7 +2,7 @@
 # -*- coding: utf-8 -*-
 
 import unittest
-from datetime import datetime, timedelta
+from datetime import datetime, timedelta, timezone
 from functools import partial
 from time import sleep
 import pytz
@@ -1451,6 +1451,13 @@ class CroniterTest(base.TestCase):
             self.assertEqual(nt.tzinfo.zone, 'America/New_York')
             self.assertEqual(int(croniter._datetime_to_timestamp(nt)), 1547481660)
 
+    def test_issue_12(self):
+        base = datetime(2010, 1, 23, 12, 18, tzinfo=timezone.utc)
+        itr = croniter('* * * * *')
+        itr.set_current(start_time=base)
+        n1 = itr.get_next()   # 19
+
+        self.assertEqual(n1, base.timestamp() + 60)
 
 if __name__ == '__main__':
     unittest.main()