From 7de63f8335999b77de5f74f642ff7ac5b6eeca1c Mon Sep 17 00:00:00 2001 From: Cedric Boscher Date: Wed, 15 Jun 2016 09:56:05 +0200 Subject: [PATCH] VTODO first implementation --- radicale/xmlutils.py | 55 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 54 insertions(+), 1 deletion(-) diff --git a/radicale/xmlutils.py b/radicale/xmlutils.py index 4f6a84c..8692783 100644 --- a/radicale/xmlutils.py +++ b/radicale/xmlutils.py @@ -252,7 +252,60 @@ def _time_range_match(vobject_item, filter_, child_name): return start < dtstart + timedelta(days=1) and end > dtstart elif child_name == "VTODO": # TODO: implement this - pass + dtstart = getattr(child, "dtstart", None) + duration = getattr(child, "duration", None) + due = getattr(child, "due", None) + completed = getattr(child, "completed", None) + created = getattr(child, "created", None) + + if dtstart is not None and duration is not None: + #Line 1 + dtstart = dtstart.value + if not isinstance(dtstart, datetime): + dtstart = datetime.combine(dtstart, datetime.min.time()).replace( + tzinfo=timezone.utc) + duration = duration.value + return start <= dtstart + duration and ( end > dtstart or end >= dtstart + duration) + elif dtstart is not None and due is not None: + #Line 2 + dtstart = dtstart.value + if not isinstance(dtstart, datetime): + dtstart = datetime.combine(dtstart, datetime.min.time()).replace( + tzinfo=timezone.utc) + due = due.value + if not isinstance(due, datetime): + due = datetime.combine(due, datetime.min.time()).replace( + tzinfo=timezone.utc) + return (start < due or start <= dtstart) and ( end > dtstart or end >= due) + elif dtstart is not None + #Line 3 + dtstart = dtstart.value + if not isinstance(dtstart, datetime): + dtstart = datetime.combine(dtstart, datetime.min.time()).replace( + tzinfo=timezone.utc) + return start <= dtstart and end > dtstart + elif due is not None: + #Line 4 + due = due.value + if not isinstance(due, datetime): + due = datetime.combine(due, datetime.min.time()).replace( + tzinfo=timezone.utc) + return start < due and end >= due + elif completed is not None and created is not None: + #Line 5 + completed = completed.value + created = created.value + return (start <= created or start <= completed) and (end >= created or end >= completed) + elif completed is not None: + #Line 6 + completed = completed.value + return start <= completed and end >= completed + elif created is not None: + created = created.value + return end < created + else + return True + elif child_name == "VJOURNAL": # TODO: implement this pass