Commit 810a24b0 authored by Bram Schoenmakers's avatar Bram Schoenmakers

Fix for relative dates not always being calculated properly.

Fell into the trap of calling a function as a default parameter. Because
of this, relative dates used with the 'add' or 'do' command (recurrence)
were based on an offset when topydo was started, not when the subcommand
was executed. Usually these two events occur in the same second and this
bug was unnoticed for a long time. But now with prompt mode, this bug
may surface if you leave running topydo for longer than a day.
parent 110e2fd7
......@@ -58,10 +58,11 @@ def _advance_recurring_todo_helper(p_todo, p_offset):
return todo
def advance_recurring_todo(p_todo, p_offset=date.today()):
def advance_recurring_todo(p_todo, p_offset=None):
p_offset = p_offset or date.today()
return _advance_recurring_todo_helper(p_todo, p_offset)
def strict_advance_recurring_todo(p_todo, p_offset=date.today()):
def strict_advance_recurring_todo(p_todo, p_offset=None):
"""
Given a Todo item, return a new instance of a Todo item with the dates
shifted according to the recurrence rule.
......@@ -74,5 +75,5 @@ def strict_advance_recurring_todo(p_todo, p_offset=date.today()):
When no recurrence tag is present, an exception is raised.
"""
offset = p_todo.due_date() or p_offset
offset = p_todo.due_date() or p_offset or date.today()
return _advance_recurring_todo_helper(p_todo, offset)
......@@ -35,13 +35,14 @@ def _add_months(p_sourcedate, p_months):
return date(year, month, day)
def _convert_pattern(p_length, p_periodunit, p_offset=date.today()):
def _convert_pattern(p_length, p_periodunit, p_offset=None):
"""
Converts a pattern in the form [0-9][dwmy] and returns a date from today
with the period of time added to it.
"""
result = None
p_offset = p_offset or date.today()
p_length = int(p_length)
if p_periodunit == 'd':
......@@ -80,7 +81,7 @@ def _convert_weekday_pattern(p_weekday):
shift = (target_day - day) % 7
return date.today() + timedelta(shift)
def relative_date_to_date(p_date, p_offset=date.today()):
def relative_date_to_date(p_date, p_offset=None):
"""
Transforms a relative date into a date object.
......@@ -93,6 +94,7 @@ def relative_date_to_date(p_date, p_offset=date.today()):
result = None
p_date = p_date.lower()
p_offset = p_offset or date.today()
relative = re.match('(?P<length>-?[0-9]+)(?P<period>[dwmy])$', p_date, re.I)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment