Skip to content

Commit

Permalink
Fix wrap-range bug
Browse files Browse the repository at this point in the history
  • Loading branch information
ericpruitt authored and U-icebox\User committed Dec 7, 2010
1 parent 5c4edcd commit 867a130
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 8 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG
@@ -1,5 +1,8 @@
CHANGELOG

2010.12.07; Tuesday
Fixed bug in which wrap-around ranges sometimes skip values.

2010.11.29; Monday
Flawed implementation of the day of the week / day of the month changed
made on 2010.11.15 corrected and "test_dom_either_or_dow" made more
Expand Down
3 changes: 1 addition & 2 deletions README.markdown
Expand Up @@ -26,7 +26,7 @@ Examples
>>> job.check_trigger((2010, 5, 2, 1, 0), utc_offset=-6)
True

### Simple user-space cron in less than ten lines: ###
### Simple cron scheduler in less than ten lines: ###

import time
import os
Expand All @@ -40,4 +40,3 @@ Examples
os.system(job.comment)

time.sleep(60)

8 changes: 3 additions & 5 deletions cronex.py
Expand Up @@ -345,10 +345,8 @@ def parse_atom(parse, minmax):
return set(xrange(prefix, suffix + 1, increment))
else:
# Example: 12-4/2; (12, 12 + n, ..., 12 + m*n) U (n_0, ..., 4)
top = xrange(prefix, minmax[1] + 1, increment)
ceilvalue = increment - (minmax[1] - top[-1] - 1)
bottom = set(xrange(ceilvalue - minmax[0], suffix + 1, increment))
bottom.update(top)
return bottom
noskips = list(xrange(prefix, minmax[1] + 1))
noskips+= list(xrange(minmax[0], suffix + 1))
return set(noskips[::increment])
else:
raise ValueError("Atom \"%s\" not in a recognized format." % parse )
3 changes: 2 additions & 1 deletion test/test_cronex.py
Expand Up @@ -99,7 +99,8 @@ def test_parse_atom(self):
(('11-5/3',(1,14)),set([11, 14, 3])),
(('*',(1, 100)), set(xrange(1,101))),
(('*/5',(1,100)), set(xrange(1,101,5))),
(('666',(1,1000)), set([666]))]
(('666',(1,1000)), set([666])),
(('21-1',(0,23)), set([21,22,23,0,1]))]

for give_the_function, want_from_function in input_expect:
self.assertEqual(want_from_function,
Expand Down

0 comments on commit 867a130

Please sign in to comment.