clean code

This commit is contained in:
Cedric Boscher 2016-06-15 10:16:44 +02:00
parent 21ea648a44
commit 2957b40473

View File

@ -250,87 +250,88 @@ def _time_range_match(vobject_item, filter_, child_name):
else: else:
# Line 5 # Line 5
return start < dtstart + timedelta(days=1) and end > dtstart return start < dtstart + timedelta(days=1) and end > dtstart
elif child_name == "VTODO": elif child_name == "VTODO":
# TODO: implement this # TODO: implement this
dtstart = getattr(child, "dtstart", None) dtstart = getattr(child, "dtstart", None)
duration = getattr(child, "duration", None) duration = getattr(child, "duration", None)
due = getattr(child, "due", None) due = getattr(child, "due", None)
completed = getattr(child, "completed", None) completed = getattr(child, "completed", None)
created = getattr(child, "created", None) created = getattr(child, "created", None)
if dtstart is not None and duration is not None: if dtstart is not None and duration is not None:
#Line 1 # Line 1
dtstart = dtstart.value dtstart = dtstart.value
if not isinstance(dtstart, datetime): if not isinstance(dtstart, datetime):
dtstart = datetime.combine(dtstart, datetime.min.time()).replace( dtstart = (datetime.combine(dtstart, datetime.min.time())
tzinfo=timezone.utc) .replace(tzinfo=timezone.utc))
duration = duration.value duration = duration.value
return start <= dtstart + duration and ( end > dtstart or end >= dtstart + duration) return (start <= dtstart + duration and
(end > dtstart or end >= dtstart + duration))
elif dtstart is not None and due is not None: elif dtstart is not None and due is not None:
#Line 2 # Line 2
dtstart = dtstart.value dtstart = dtstart.value
if not isinstance(dtstart, datetime): if not isinstance(dtstart, datetime):
dtstart = datetime.combine(dtstart, datetime.min.time()).replace( dtstart = (datetime.combine(dtstart, datetime.min.time())
tzinfo=timezone.utc) .replace(tzinfo=timezone.utc))
due = due.value due = due.value
if not isinstance(due, datetime): if not isinstance(due, datetime):
due = datetime.combine(due, datetime.min.time()).replace( due = datetime.combine(due, datetime.min.time()).replace(
tzinfo=timezone.utc) tzinfo=timezone.utc)
return (start < due or start <= dtstart) and ( end > dtstart or end >= due) return ((start < due or start <= dtstart) and
elif dtstart is not None (end > dtstart or end >= due))
#Line 3 elif dtstart is not None:
# Line 3
dtstart = dtstart.value dtstart = dtstart.value
if not isinstance(dtstart, datetime): if not isinstance(dtstart, datetime):
dtstart = datetime.combine(dtstart, datetime.min.time()).replace( dtstart = (datetime.combine(dtstart, datetime.min.time())
tzinfo=timezone.utc) .replace(tzinfo=timezone.utc))
return start <= dtstart and end > dtstart return start <= dtstart and end > dtstart
elif due is not None: elif due is not None:
#Line 4 # Line 4
due = due.value due = due.value
if not isinstance(due, datetime): if not isinstance(due, datetime):
due = datetime.combine(due, datetime.min.time()).replace( due = datetime.combine(due, datetime.min.time()).replace(
tzinfo=timezone.utc) tzinfo=timezone.utc)
return start < due and end >= due return start < due and end >= due
elif completed is not None and created is not None: elif completed is not None and created is not None:
#Line 5 # Line 5
completed = completed.value completed = completed.value
created = created.value created = created.value
return (start <= created or start <= completed) and (end >= created or end >= completed) return ((start <= created or start <= completed) and
(end >= created or end >= completed))
elif completed is not None: elif completed is not None:
#Line 6 # Line 6
completed = completed.value completed = completed.value
return start <= completed and end >= completed return start <= completed and end >= completed
elif created is not None: elif created is not None:
created = created.value created = created.value
return end < created return end < created
else else:
return True return True
elif child_name == "VJOURNAL": elif child_name == "VJOURNAL":
dtstart = getattr(child, "dstart", None) dtstart = getattr(child, "dstart", None)
if dtstart is not None: if dtstart is not None:
dtstart = dtstart.value dtstart = dtstart.value
if not isinstance(dtstart, datetime): if not isinstance(dtstart, datetime):
dtstart_is_datetime = False dtstart_is_datetime = False
# TODO: changing dates to datetimes may be wrong because of tz # TODO: changing dates to datetimes may be wrong because of tz
dtstart = datetime.combine(dtstart, datetime.min.time()).replace( dtstart = (datetime.combine(dtstart, datetime.min.time())
tzinfo=timezone.utc) .replace(tzinfo=timezone.utc))
else: else:
dtstart_is_datetime = True dtstart_is_datetime = True
if dtstart_is_datetime: if dtstart_is_datetime:
# Line 1 # Line 1
return start <= dtstart and end > dtstart return start <= dtstart and end > dtstart
else: else:
# Line 2 # Line 2
return start < dtstart + timedelta(days=1) and end > dtstart return start < dtstart + timedelta(days=1) and end > dtstart
else: else:
# Line 3 # Line 3
return False return False
return True return True