From 112109d017af1785264d23f2ef71041013fcd508 Mon Sep 17 00:00:00 2001 From: Josiah Carlson Date: Mon, 21 Mar 2016 21:19:49 -0700 Subject: [PATCH] Should now be usable with all timezone libs * Fixed unittest runner to return nonzero status on failure --- crontab/_crontab.py | 12 +++++++----- setup.py | 2 +- tests/test_crontab.py | 6 +----- 3 files changed, 9 insertions(+), 11 deletions(-) diff --git a/crontab/_crontab.py b/crontab/_crontab.py index 500ddeb..537871e 100644 --- a/crontab/_crontab.py +++ b/crontab/_crontab.py @@ -374,6 +374,7 @@ class CronTab(object): # handle timezones if the datetime object has a timezone and get a # reasonable future/past start time onow, now = now, now.replace(tzinfo=None) + tz = onow.tzinfo future = now.replace(second=0, microsecond=0) + increments[0]() if future < now: # we are going backwards... @@ -409,15 +410,16 @@ class CronTab(object): "author with the following information:\n" \ "crontab: %r\n" \ "now: %r", ' '.join(m.input for m in self.matchers), now) - if onow.tzinfo: - future = onow.tzinfo.localize(future) + delay = future - now + if tz: + delay += tz.utcoffset(now) + delay -= tz.utcoffset(future) - delay = future - onow if not delta: begin = datetime(1970, 1, 1) - if onow.tzinfo: - begin = onow.tzinfo.localize(begin) delay = future - begin + if tz: + delay -= tz.utcoffset(future) 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 d0b6f11..4d32c4c 100644 --- a/setup.py +++ b/setup.py @@ -10,7 +10,7 @@ except: setup( name='crontab', - version='0.21.1', + version='0.21.2', 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 8ad1f73..5ad355e 100644 --- a/tests/test_crontab.py +++ b/tests/test_crontab.py @@ -172,9 +172,5 @@ class TestCrontab(unittest.TestCase): self.assertEquals(s.next(pytz.timezone('US/Eastern').localize(datetime.datetime(2016, 3, 13))), 28800) -def test(): - suite = unittest.TestLoader().loadTestsFromTestCase(TestCrontab) - unittest.TextTestRunner(verbosity=2).run(suite) - if __name__ == '__main__': - test() + unittest.main()