Fix off by one issues in todo templates
This commit is contained in:
parent
8a0ea86e75
commit
d53a21b235
1 changed files with 21 additions and 20 deletions
|
|
@ -38,15 +38,16 @@ def renderTodos(todosRaw, args):
|
||||||
return todosRaw
|
return todosRaw
|
||||||
else:
|
else:
|
||||||
step = args.todo_step if args.todo_step is not None else todosRaw['step']
|
step = args.todo_step if args.todo_step is not None else todosRaw['step']
|
||||||
|
step -= 1
|
||||||
start = args.todo_start if args.todo_start is not None else todosRaw['start']
|
start = args.todo_start if args.todo_start is not None else todosRaw['start']
|
||||||
end = args.todo_end if args.todo_end is not None else todosRaw['end']
|
end = args.todo_end if args.todo_end is not None else todosRaw['end']
|
||||||
template = args.todo_template if args.todo_template is not None else todosRaw['template']
|
template = args.todo_template if args.todo_template is not None else todosRaw['template']
|
||||||
unrolled = [template.format(i, i + step - 1) for i in range(start, end, step)]
|
unrolled = []
|
||||||
remaining = ((end + 1) - start) % step
|
while start + step < end:
|
||||||
if remaining > 0:
|
unrolled.append(template.format(start, start + step))
|
||||||
unrolled.append(template.format((end + 1) - remaining, end))
|
start += step + 1
|
||||||
if step == 1:
|
if start <= end:
|
||||||
unrolled.append(template.format(end, end))
|
unrolled.append(template.format(start, end))
|
||||||
return unrolled
|
return unrolled
|
||||||
|
|
||||||
def createThings3Project(template, args):
|
def createThings3Project(template, args):
|
||||||
|
|
@ -79,7 +80,7 @@ def createThings3Template(template, args):
|
||||||
else:
|
else:
|
||||||
raise Exception('Unknown template type: {}'.format(template.type))
|
raise Exception('Unknown template type: {}'.format(template.type))
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
ARGS = parser.parse_args()
|
ARGS = parser.parse_args()
|
||||||
|
|
||||||
if ARGS.template:
|
if ARGS.template:
|
||||||
|
|
|
||||||
Reference in a new issue