clean code
This commit is contained in:
parent
21ea648a44
commit
2957b40473
@ -262,27 +262,29 @@ def _time_range_match(vobject_item, filter_, child_name):
|
|||||||
# 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))
|
||||||
|
elif dtstart is not None:
|
||||||
# Line 3
|
# 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
|
||||||
@ -295,7 +297,8 @@ def _time_range_match(vobject_item, filter_, child_name):
|
|||||||
# 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
|
||||||
@ -303,7 +306,7 @@ def _time_range_match(vobject_item, filter_, child_name):
|
|||||||
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":
|
||||||
@ -314,19 +317,17 @@ def _time_range_match(vobject_item, filter_, child_name):
|
|||||||
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
|
||||||
|
Loading…
Reference in New Issue
Block a user