Esempio n. 1
0
def _advance_recurring_todo_helper(p_todo, p_offset):
    """
    Given a Todo item, return a new instance of a Todo item with the dates
    shifted according to the recurrence rule.

    The new date is calculated from the given p_offset value.

    When no recurrence tag is present, an exception is raised.
    """

    todo = Todo(p_todo.source())
    pattern = todo.tag_value('rec')

    if not pattern:
        raise NoRecurrenceException()

    length = todo.length()
    new_due = relative_date_to_date(pattern, p_offset)

    if not new_due:
        raise NoRecurrenceException()

    # pylint: disable=E1103
    todo.set_tag(config().tag_due(), new_due.isoformat())

    if todo.start_date():
        new_start = new_due - timedelta(length)
        todo.set_tag(config().tag_start(), new_start.isoformat())

    todo.set_creation_date(date.today())

    return todo
Esempio n. 2
0
def _advance_recurring_todo_helper(p_todo, p_offset):
    """
    Given a Todo item, return a new instance of a Todo item with the dates
    shifted according to the recurrence rule.

    The new date is calculated from the given p_offset value.

    When no recurrence tag is present, an exception is raised.
    """

    todo = Todo(p_todo.source())
    pattern = todo.tag_value('rec')

    if not pattern:
        raise NoRecurrenceException()

    length = todo.length()
    new_due = relative_date_to_date(pattern, p_offset)

    if not new_due:
        raise NoRecurrenceException()

    # pylint: disable=E1103
    todo.set_tag(config().tag_due(), new_due.isoformat())

    if todo.start_date():
        new_start = new_due - timedelta(length)
        todo.set_tag(config().tag_start(), new_start.isoformat())

    todo.set_creation_date(date.today())

    return todo
Esempio n. 3
0
def advance_recurring_todo(p_todo, p_offset=None, p_strict=False):
    """
    Given a Todo item, return a new instance of a Todo item with the dates
    shifted according to the recurrence rule.

    Strict means that the real due date is taken as a offset, not today or a
    future date to determine the offset.

    When the todo item has no due date, then the date is used passed by the
    caller (defaulting to today).

    When no recurrence tag is present, an exception is raised.
    """
    todo = Todo(p_todo.source())
    pattern = todo.tag_value('rec')

    if not pattern:
        raise NoRecurrenceException()
    elif pattern.startswith('+'):
        p_strict = True
        # strip off the +
        pattern = pattern[1:]

    if p_strict:
        offset = p_todo.due_date() or p_offset or date.today()
    else:
        offset = p_offset or date.today()

    length = todo.length()
    new_due = relative_date_to_date(pattern, offset)

    if not new_due:
        raise NoRecurrenceException()

    # pylint: disable=E1103
    todo.set_tag(config().tag_due(), new_due.isoformat())

    if todo.start_date():
        new_start = new_due - timedelta(length)
        todo.set_tag(config().tag_start(), new_start.isoformat())

    if config().auto_creation_date():
        todo.set_creation_date(date.today())

    return todo
Esempio n. 4
0
def advance_recurring_todo(p_todo, p_offset=None, p_strict=False):
    """
    Given a Todo item, return a new instance of a Todo item with the dates
    shifted according to the recurrence rule.

    Strict means that the real due date is taken as a offset, not today or a
    future date to determine the offset.

    When the todo item has no due date, then the date is used passed by the
    caller (defaulting to today).

    When no recurrence tag is present, an exception is raised.
    """
    todo = Todo(p_todo.source())
    pattern = todo.tag_value('rec')

    if not pattern:
        raise NoRecurrenceException()
    elif pattern.startswith('+'):
        p_strict = True
        # strip off the +
        pattern = pattern[1:]

    if p_strict:
        offset = p_todo.due_date() or p_offset or date.today()
    else:
        offset = p_offset or date.today()

    length = todo.length()
    new_due = relative_date_to_date(pattern, offset)

    if not new_due:
        raise NoRecurrenceException()

    # pylint: disable=E1103
    todo.set_tag(config().tag_due(), new_due.isoformat())

    if todo.start_date():
        new_start = new_due - timedelta(length)
        todo.set_tag(config().tag_start(), new_start.isoformat())

    todo.set_creation_date(date.today())

    return todo
Esempio n. 5
0
class RecurrenceTest(TopydoTest):
    def setUp(self):
        super().setUp()
        self.todo = Todo("Test rec:1w")
        self.stricttodo = Todo("Test rec:+1w")

    def test_duedate1(self):
        """ Where due date is in the future. """
        future = date.today() + timedelta(1)
        new_due = date.today() + timedelta(7)

        self.todo.set_tag(config().tag_due(), future.isoformat())
        new_todo = advance_recurring_todo(self.todo)

        self.assertEqual(new_todo.due_date(), new_due)

    def test_duedate2(self):
        """ Where due date is today. """
        today = date.today()
        new_due = date.today() + timedelta(7)

        self.todo.set_tag(config().tag_due(), today.isoformat())
        new_todo = advance_recurring_todo(self.todo)

        self.assertEqual(new_todo.due_date(), new_due)

    def test_duedate3(self):
        """ Where due date is in the past. """
        past = date.today() - timedelta(8)
        new_due = date.today() + timedelta(7)

        self.todo.set_tag(config().tag_due(), past.isoformat())
        new_todo = advance_recurring_todo(self.todo)

        self.assertEqual(new_todo.due_date(), new_due)

    def test_duedate4(self):
        """ Where due date is in the past. """
        past = date.today() - timedelta(8)
        new_due = date.today() - timedelta(1)

        self.todo.set_tag(config().tag_due(), past.isoformat())
        new_todo = advance_recurring_todo(self.todo, p_strict=True)

        self.assertEqual(new_todo.due_date(), new_due)

    def test_duedate5(self):
        """ Where due date is in the future. """
        future = date.today() + timedelta(1)
        new_due = date.today() + timedelta(8)

        self.todo.set_tag(config().tag_due(), future.isoformat())
        new_todo = advance_recurring_todo(self.todo, p_strict=True)

        self.assertEqual(new_todo.due_date(), new_due)

    def test_duedate6(self):
        """ Where due date is today. """
        today = date.today()
        new_due = date.today() + timedelta(7)

        self.todo.set_tag(config().tag_due(), today.isoformat())
        new_todo = advance_recurring_todo(self.todo, p_strict=True)

        self.assertEqual(new_todo.due_date(), new_due)

    def test_noduedate1(self):
        new_due = date.today() + timedelta(7)
        new_todo = advance_recurring_todo(self.todo)

        self.assertTrue(new_todo.has_tag(config().tag_due()))
        self.assertEqual(new_todo.due_date(), new_due)

    def test_noduedate2(self):
        new_due = date.today() + timedelta(7)
        new_todo = advance_recurring_todo(self.todo, p_strict=True)

        self.assertTrue(new_todo.has_tag(config().tag_due()))
        self.assertEqual(new_todo.due_date(), new_due)

    def test_startdate1(self):
        """ Start date is before due date. """
        self.todo.set_tag(config().tag_due(), date.today().isoformat())
        yesterday = date.today() - timedelta(1)
        self.todo.set_tag(config().tag_start(), yesterday.isoformat())

        new_start = date.today() + timedelta(6)
        new_todo = advance_recurring_todo(self.todo)

        self.assertEqual(new_todo.start_date(), new_start)

    def test_startdate2(self):
        """ Strict recurrence. Start date is before due date. """
        due = date.today() - timedelta(1)
        self.todo.set_tag(config().tag_due(), date.today().isoformat())
        yesterday = due - timedelta(1)
        # pylint: disable=E1103
        self.todo.set_tag(config().tag_start(), yesterday.isoformat())

        new_start = date.today() + timedelta(5)
        new_todo = advance_recurring_todo(self.todo, p_strict=True)

        self.assertEqual(new_todo.start_date(), new_start)

    def test_startdate3(self):
        """ Start date equals due date. """
        self.todo.set_tag(config().tag_due(), date.today().isoformat())
        self.todo.set_tag(config().tag_start(), date.today().isoformat())

        new_start = date.today() + timedelta(7)
        new_todo = advance_recurring_todo(self.todo)

        self.assertEqual(new_todo.start_date(), new_start)

    def test_strict_recurrence1(self):
        """
        Strict recurrence where due date is in the past, using + notation in
        expression.
        """
        past = date.today() - timedelta(8)
        new_due = date.today() - timedelta(1)

        self.stricttodo.set_tag(config().tag_due(), past.isoformat())
        new_todo = advance_recurring_todo(self.stricttodo, p_strict=True)

        self.assertEqual(new_todo.due_date(), new_due)

    def test_strict_recurrence2(self):
        """
        Strict recurrence where due date is in the future, using + notation in
        expression.
        """
        future = date.today() + timedelta(1)
        new_due = date.today() + timedelta(8)

        self.stricttodo.set_tag(config().tag_due(), future.isoformat())
        new_todo = advance_recurring_todo(self.stricttodo, p_strict=True)

        self.assertEqual(new_todo.due_date(), new_due)

    def test_no_recurrence(self):
        self.todo.remove_tag('rec')
        self.assertRaises(NoRecurrenceException, advance_recurring_todo,
                          self.todo)

    def test_invalid_recurrence(self):
        """ Throw exception when 'rec' tag has an invalid value. """
        self.todo.set_tag('rec', '1')
        self.assertRaises(NoRecurrenceException, advance_recurring_todo,
                          self.todo)
Esempio n. 6
0
class RecurrenceTest(TopydoTest):
    def setUp(self):
        super().setUp()
        self.todo = Todo("Test rec:1w")
        self.stricttodo = Todo("Test rec:+1w")

    def test_duedate1(self):
        """ Where due date is in the future. """
        future = date.today() + timedelta(1)
        new_due = date.today() + timedelta(7)

        self.todo.set_tag(config().tag_due(), future.isoformat())
        new_todo = advance_recurring_todo(self.todo)

        self.assertEqual(new_todo.due_date(), new_due)

    def test_duedate2(self):
        """ Where due date is today. """
        today = date.today()
        new_due = date.today() + timedelta(7)

        self.todo.set_tag(config().tag_due(), today.isoformat())
        new_todo = advance_recurring_todo(self.todo)

        self.assertEqual(new_todo.due_date(), new_due)

    def test_duedate3(self):
        """ Where due date is in the past. """
        past = date.today() - timedelta(8)
        new_due = date.today() + timedelta(7)

        self.todo.set_tag(config().tag_due(), past.isoformat())
        new_todo = advance_recurring_todo(self.todo)

        self.assertEqual(new_todo.due_date(), new_due)

    def test_duedate4(self):
        """ Where due date is in the past. """
        past = date.today() - timedelta(8)
        new_due = date.today() - timedelta(1)

        self.todo.set_tag(config().tag_due(), past.isoformat())
        new_todo = advance_recurring_todo(self.todo, p_strict=True)

        self.assertEqual(new_todo.due_date(), new_due)

    def test_duedate5(self):
        """ Where due date is in the future. """
        future = date.today() + timedelta(1)
        new_due = date.today() + timedelta(8)

        self.todo.set_tag(config().tag_due(), future.isoformat())
        new_todo = advance_recurring_todo(self.todo, p_strict=True)

        self.assertEqual(new_todo.due_date(), new_due)

    def test_duedate6(self):
        """ Where due date is today. """
        today = date.today()
        new_due = date.today() + timedelta(7)

        self.todo.set_tag(config().tag_due(), today.isoformat())
        new_todo = advance_recurring_todo(self.todo, p_strict=True)

        self.assertEqual(new_todo.due_date(), new_due)

    def test_noduedate1(self):
        new_due = date.today() + timedelta(7)
        new_todo = advance_recurring_todo(self.todo)

        self.assertTrue(new_todo.has_tag(config().tag_due()))
        self.assertEqual(new_todo.due_date(), new_due)

    def test_noduedate2(self):
        new_due = date.today() + timedelta(7)
        new_todo = advance_recurring_todo(self.todo, p_strict=True)

        self.assertTrue(new_todo.has_tag(config().tag_due()))
        self.assertEqual(new_todo.due_date(), new_due)

    def test_startdate1(self):
        """ Start date is before due date. """
        self.todo.set_tag(config().tag_due(), date.today().isoformat())
        yesterday = date.today() - timedelta(1)
        self.todo.set_tag(config().tag_start(), yesterday.isoformat())

        new_start = date.today() + timedelta(6)
        new_todo = advance_recurring_todo(self.todo)

        self.assertEqual(new_todo.start_date(), new_start)

    def test_startdate2(self):
        """ Strict recurrence. Start date is before due date. """
        due = date.today() - timedelta(1)
        self.todo.set_tag(config().tag_due(), date.today().isoformat())
        yesterday = due - timedelta(1)
        # pylint: disable=E1103
        self.todo.set_tag(config().tag_start(), yesterday.isoformat())

        new_start = date.today() + timedelta(5)
        new_todo = advance_recurring_todo(self.todo, p_strict=True)

        self.assertEqual(new_todo.start_date(), new_start)

    def test_startdate3(self):
        """ Start date equals due date. """
        self.todo.set_tag(config().tag_due(), date.today().isoformat())
        self.todo.set_tag(config().tag_start(), date.today().isoformat())

        new_start = date.today() + timedelta(7)
        new_todo = advance_recurring_todo(self.todo)

        self.assertEqual(new_todo.start_date(), new_start)

    def test_strict_recurrence1(self):
        """
        Strict recurrence where due date is in the past, using + notation in
        expression.
        """
        past = date.today() - timedelta(8)
        new_due = date.today() - timedelta(1)

        self.stricttodo.set_tag(config().tag_due(), past.isoformat())
        new_todo = advance_recurring_todo(self.stricttodo, p_strict=True)

        self.assertEqual(new_todo.due_date(), new_due)

    def test_strict_recurrence2(self):
        """
        Strict recurrence where due date is in the future, using + notation in
        expression.
        """
        future = date.today() + timedelta(1)
        new_due = date.today() + timedelta(8)

        self.stricttodo.set_tag(config().tag_due(), future.isoformat())
        new_todo = advance_recurring_todo(self.stricttodo, p_strict=True)

        self.assertEqual(new_todo.due_date(), new_due)

    def test_no_recurrence(self):
        self.todo.remove_tag('rec')
        self.assertRaises(NoRecurrenceException, advance_recurring_todo,
                          self.todo)

    def test_invalid_recurrence(self):
        """ Throw exception when 'rec' tag has an invalid value. """
        self.todo.set_tag('rec', '1')
        self.assertRaises(NoRecurrenceException, advance_recurring_todo,
                          self.todo)