Repository: jaraco/tempora (language: python)

Issue:
test failure in test_command_at_noon
hi,
a recent build of tempora in [debian reproducibility testing](https://tests.reproducible-builds.org/debian/rb-pkg/bullseye/amd64/python-tempora.html) failed. Reproducibility testing aims to ensure rebuilds of packages are bit by bit identical by doing two builds, introducing [variations](https://tests.reproducible-builds.org/debian/index_variations.html) in paths, language settings, time/timezones and so on.

In a build with the timezone set to UTC+14, 'test_command_at_noon' failed:
```
collected 10 items

tests/test_schedule.py ....F...                                          [ 80%]
tests/test_timing.py ..                                                  [100%]

=================================== FAILURES ===================================
______________________ TestCommands.test_command_at_noon _______________________

self = <test_schedule.TestCommands object at 0x7f7331fe6750>

    def test_command_at_noon(self):
    	"""
    	Create a periodic command that's run at noon every day.
    	"""
    	when = datetime.time(12, 0, tzinfo=pytz.utc)
    	cmd = schedule.PeriodicCommandFixedDelay.daily_at(when, target=None)
    	assert cmd.due() is False
    	next_cmd = cmd.next()
    	daily = datetime.timedelta(days=1)
    	day_from_now = schedule.now() + daily
    	two_days_from_now = day_from_now + daily
>   	assert day_from_now < next_cmd < two_days_from_now
E    assert PeriodicCommandFixedDelay(2019, 12, 10, 12, 0, tzinfo=<UTC>) < datetime.datetime(2019, 12, 10, 11, 26, 53, 555895, tzinfo=<UTC>)

tests/test_schedule.py:83: AssertionError
```
I suspect the above may be triggered by the combination of the timezone used and the time 
just before noon UTC. The other build, which had the time set to January 2021 with tz UTC-12, worked fine.

Full build logs attached, the failure is in "build2".
[python-tempora_1.14.1-2.build2.log](https://github.com/jaraco/tempora/files/3957187/python-tempora_1.14.1-2.build2.log)
[python-tempora_1.14.1-2.rbuild.log](https://github.com/jaraco/tempora/files/3957190/python-tempora_1.14.1-2.rbuild.log)


Discussion / hints:

Fix patch:
diff --git a/CHANGES.rst b/CHANGES.rst
index bd15297..dcd39f2 100644
--- a/CHANGES.rst
+++ b/CHANGES.rst
@@ -1,3 +1,9 @@
+v2.1.1
+======
+
+- #8: Fixed error in ``PeriodicCommandFixedDelay.daily_at``
+  when timezone is more than 12 hours from UTC.
+
 v2.1.0
 ======
 
diff --git a/tempora/schedule.py b/tempora/schedule.py
index 031437f..d0b6a15 100644
--- a/tempora/schedule.py
+++ b/tempora/schedule.py
@@ -158,7 +158,8 @@ def daily_at(cls, at, target):
         daily = datetime.timedelta(days=1)
         # convert when to the next datetime matching this time
         when = datetime.datetime.combine(datetime.date.today(), at)
-        if when < now():
+        when -= daily
+        while when < now():
             when += daily
         return cls.at_time(cls._localize(when), daily, target)
 


Test patch:
diff --git a/tempora/tests/test_schedule.py b/tempora/tests/test_schedule.py
index 740909a..84bf2e8 100644
--- a/tempora/tests/test_schedule.py
+++ b/tempora/tests/test_schedule.py
@@ -64,6 +64,16 @@ def test_command_at_noon(self):
         two_days_from_now = day_from_now + daily
         assert day_from_now < next_cmd < two_days_from_now
 
+    @pytest.mark.parametrize("hour", range(10, 14))
+    @pytest.mark.parametrize("tz_offset", (14, -14))
+    def test_command_at_noon_distant_local(self, hour, tz_offset):
+        """
+        Run test_command_at_noon, but with the local timezone
+        more than 12 hours away from UTC.
+        """
+        with freezegun.freeze_time(f"2020-01-10 {hour:02}:01", tz_offset=tz_offset):
+            self.test_command_at_noon()
+
 
 class TestTimezones:
     def test_alternate_timezone_west(self):