Fixes bug with crontab's previous() calculation
* When looking for a previous entry, sometimes the initial pass for the previous() method would effectively double-decrement the current time, which can cause previous() to skip over the correct previous time if it was within 1 minute of now (or the time passed as now) * Bug report thanks to David Siera
This commit is contained in:
parent
06ed7eef04
commit
86b15138fd
3 changed files with 18 additions and 3 deletions
|
@ -134,6 +134,17 @@ class TestCrontab(unittest.TestCase):
|
|||
self.assertRaises(ValueError, lambda: CronTab('L * * * *'))
|
||||
self.assertRaises(ValueError, lambda: CronTab('* 1, * * *'))
|
||||
|
||||
def test_previous(self):
|
||||
schedule = CronTab('0 * * * *')
|
||||
ts = datetime.datetime(2014, 6, 6, 9, 0, 0)
|
||||
for i in range(70):
|
||||
next = schedule.next(ts)
|
||||
self.assertTrue(0 <= next <= 3600, next)
|
||||
previous = schedule.previous(ts)
|
||||
self.assertTrue(-3600 <= previous <= 0, previous)
|
||||
ts += datetime.timedelta(seconds=1)
|
||||
|
||||
|
||||
def test():
|
||||
suite = unittest.TestLoader().loadTestsFromTestCase(TestCrontab)
|
||||
unittest.TextTestRunner(verbosity=2).run(suite)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue