diff --git a/crontab/_crontab.py b/crontab/_crontab.py index 90ae45e..0eb2d26 100644 --- a/crontab/_crontab.py +++ b/crontab/_crontab.py @@ -3,6 +3,7 @@ crontab.py Written July 15, 2011 by Josiah Carlson +Copyright 2011-2018 Josiah Carlson Released under the GNU LGPL v2.1 and v3 available: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html @@ -433,16 +434,18 @@ class CronTab(object): "author with the following information:\n" \ "crontab: %r\n" \ "now: %r", ' '.join(m.input for m in self.matchers), now) + delay = future - now if tz: - delay += tz.utcoffset(now) - delay -= tz.utcoffset(future) + delay += onow.utcoffset() + delay -= tz.localize(future).utcoffset() if not delta: begin = datetime(1970, 1, 1) delay = future - begin if tz: - delay -= tz.utcoffset(future) + delay -= tz.localize(future).utcoffset() + return delay.days * 86400 + delay.seconds + delay.microseconds / 1000000. def previous(self, now=None, delta=True, default_utc=WARN_CHANGE): diff --git a/setup.py b/setup.py index b385f27..7347685 100644 --- a/setup.py +++ b/setup.py @@ -10,7 +10,7 @@ except: setup( name='crontab', - version='0.22.2', + version='0.22.3', description='Parse and use crontab schedules in Python', author='Josiah Carlson', author_email='josiah.carlson@gmail.com', diff --git a/tests/test_crontab.py b/tests/test_crontab.py index 5992bb0..4117173 100644 --- a/tests/test_crontab.py +++ b/tests/test_crontab.py @@ -179,6 +179,16 @@ class TestCrontab(unittest.TestCase): self.assertEqual(s.next(pytz.timezone('US/Eastern').localize(datetime.datetime(2016, 3, 13))), 28800) + t = CronTab('0 9 * * * 2018') + self.assertEqual(t.next(datetime.datetime(2018, 11, 4), default_utc=True), 32400) + + timezone = pytz.timezone("America/Los_Angeles") + self.assertEqual(t.next(timezone.localize(datetime.datetime(2018, 11, 4))), 36000) + before = pytz.utc.localize(datetime.datetime(2018, 11, 4, 8, 29)).astimezone(timezone) + self.assertEqual(CronTab('30 1 * * * 2018').next(before), 3660) + self.assertEqual(CronTab('30 1 * * * 2018').next(timezone.localize(datetime.datetime(2018, 11, 4, 1, 15))), 900) + self.assertEqual(CronTab('30 1 * * * 2018').next(timezone.localize(datetime.datetime(2018, 11, 4))), 9000) + if __name__ == '__main__': unittest.main()