Should now be usable with all timezone libs

* Fixed unittest runner to return nonzero status on failure
This commit is contained in:
Josiah Carlson 2016-03-21 21:19:49 -07:00
parent e9426e934e
commit 112109d017
3 changed files with 9 additions and 11 deletions

View file

@ -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):

View file

@ -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',

View file

@ -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()