Fixes issue with timezones, more tests
This commit is contained in:
parent
68e47df736
commit
c033a5c6f6
3 changed files with 17 additions and 4 deletions
|
@ -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):
|
||||
|
|
2
setup.py
2
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',
|
||||
|
|
|
@ -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()
|
||||
|
|
Loading…
Reference in a new issue