Bug fix: The get_prev API crashed when last day of month token was used. Some essential logic was missing.
This commit is contained in:
parent
7cfd1818c1
commit
d611e66093
@ -271,6 +271,8 @@ class croniter(object):
|
|||||||
days = DAYS[month - 1]
|
days = DAYS[month - 1]
|
||||||
if month == 2 and self.is_leap(year) is True:
|
if month == 2 and self.is_leap(year) is True:
|
||||||
days += 1
|
days += 1
|
||||||
|
if 'l' in expanded[2] and days==d.day:
|
||||||
|
return False, d
|
||||||
|
|
||||||
if is_prev:
|
if is_prev:
|
||||||
days_in_prev_month = DAYS[
|
days_in_prev_month = DAYS[
|
||||||
@ -387,8 +389,10 @@ class croniter(object):
|
|||||||
candidates = to_check[:]
|
candidates = to_check[:]
|
||||||
candidates.reverse()
|
candidates.reverse()
|
||||||
for d in candidates:
|
for d in candidates:
|
||||||
if d <= x:
|
if d != 'l' and d <= x:
|
||||||
return d - x
|
return d - x
|
||||||
|
if 'l' in candidates:
|
||||||
|
return -x
|
||||||
candidate = candidates[0]
|
candidate = candidates[0]
|
||||||
for c in candidates:
|
for c in candidates:
|
||||||
if c < range_val:
|
if c < range_val:
|
||||||
|
@ -180,6 +180,49 @@ class CroniterTest(base.TestCase):
|
|||||||
self.assertEqual(n4.month, 12)
|
self.assertEqual(n4.month, 12)
|
||||||
self.assertEqual(n4.day, 31)
|
self.assertEqual(n4.day, 31)
|
||||||
|
|
||||||
|
def testPrevLastDayOfMonth(self):
|
||||||
|
base = datetime(2009, 12, 31, hour=20)
|
||||||
|
itr = croniter('0 0 l * *', base)
|
||||||
|
n1 = itr.get_prev(datetime)
|
||||||
|
self.assertEqual(n1.month, 12)
|
||||||
|
self.assertEqual(n1.day, 31)
|
||||||
|
|
||||||
|
base = datetime(2009, 12, 31)
|
||||||
|
itr = croniter('0 0 l * *', base)
|
||||||
|
n1 = itr.get_prev(datetime)
|
||||||
|
self.assertEqual(n1.month, 11)
|
||||||
|
self.assertEqual(n1.day, 30)
|
||||||
|
|
||||||
|
base = datetime(2010, 1, 5)
|
||||||
|
itr = croniter('0 0 l * *', base)
|
||||||
|
n1 = itr.get_prev(datetime)
|
||||||
|
self.assertEqual(n1.month, 12)
|
||||||
|
self.assertEqual(n1.day, 31)
|
||||||
|
n1 = itr.get_prev(datetime)
|
||||||
|
self.assertEqual(n1.month, 11)
|
||||||
|
self.assertEqual(n1.day, 30)
|
||||||
|
n1 = itr.get_prev(datetime)
|
||||||
|
self.assertEqual(n1.month, 10)
|
||||||
|
self.assertEqual(n1.day, 31)
|
||||||
|
n1 = itr.get_prev(datetime)
|
||||||
|
self.assertEqual(n1.month, 9)
|
||||||
|
self.assertEqual(n1.day, 30)
|
||||||
|
|
||||||
|
base = datetime(2010, 1, 31, minute=2)
|
||||||
|
itr = croniter('* * l * *', base)
|
||||||
|
n1 = itr.get_prev(datetime)
|
||||||
|
self.assertEqual(n1.month, 1)
|
||||||
|
self.assertEqual(n1.day, 31)
|
||||||
|
n1 = itr.get_prev(datetime)
|
||||||
|
self.assertEqual(n1.month, 1)
|
||||||
|
self.assertEqual(n1.day, 31)
|
||||||
|
n1 = itr.get_prev(datetime)
|
||||||
|
self.assertEqual(n1.month, 12)
|
||||||
|
self.assertEqual(n1.day, 31)
|
||||||
|
n1 = itr.get_prev(datetime)
|
||||||
|
self.assertEqual(n1.month, 12)
|
||||||
|
self.assertEqual(n1.day, 31)
|
||||||
|
|
||||||
def testError(self):
|
def testError(self):
|
||||||
itr = croniter('* * * * *')
|
itr = croniter('* * * * *')
|
||||||
self.assertRaises(TypeError, itr.get_next, str)
|
self.assertRaises(TypeError, itr.get_next, str)
|
||||||
|
Loading…
Reference in New Issue
Block a user