Debian Codegraph @

recurring_ical_events/adapters/todo.py

raw symbols SCIP
1 """Adapter for VTODO."""
2
3 from recurring_ical_events.adapters.component import ComponentAdapter
4 from recurring_ical_events.constants import DATE_MAX_DT, DATE_MIN_DT
5 from recurring_ical_events.types import Time
6 from recurring_ical_events.util import (
7 convert_to_datetime,
8 is_date,
9 normalize_pytz,
10 )
11
12
13 class TodoAdapter(ComponentAdapter):
14 """Unified access to TODOs."""
15
16 @staticmethod
17 def component_name() -> str:
18 """The icalendar component name."""
19 return "VTODO"
20
21 @property
22 def end_property(self) -> str:
23 """DUE"""
24 return "DUE"
25
26 @property
27 def raw_start(self) -> Time:
28 """Return DTSTART if it set, do not panic if it's not set."""
29 ## easy case - DTSTART set
30 start = self._component.get("DTSTART")
31 if start is not None:
32 return start.dt
33 ## Tasks may have DUE set, but no DTSTART.
34 ## Let's assume 0 duration and return the DUE
35 due = self._component.get("DUE")
36 if due is not None:
37 return due.dt
38
39 ## Assume infinite time span if neither is given
40 ## (see the comments under _get_event_end)
41 return DATE_MIN_DT
42
43 @property
44 def raw_end(self) -> Time:
45 """Return DUE or DTSTART+DURATION or something"""
46 ## Easy case - DUE is set
47 end = self._component.get("DUE")
48 if end is not None:
49 return end.dt
50
51 dtstart = self._component.get("DTSTART")
52
53 ## DURATION can be specified instead of DUE.
54 duration = self._component.get("DURATION")
55 ## It is no requirement that DTSTART is set.
56 ## Perhaps duration is a time estimate rather than an indirect
57 ## way to set DUE.
58 if duration is not None and dtstart is not None:
59 start = dtstart.dt
60 if duration.dt.seconds != 0 and is_date(start):
61 start = convert_to_datetime(start, None)
62 return normalize_pytz(start + duration.dt)
63
64 ## According to the RFC, a VEVENT without an end/duration
65 ## is to be considered to have zero duration. Assuming the
66 ## same applies to VTODO.
67 if dtstart:
68 return dtstart.dt
69
70 ## The RFC says this about VTODO:
71 ## > A "VTODO" calendar component without the "DTSTART" and "DUE" (or
72 ## > "DURATION") properties specifies a to-do that will be associated
73 ## > with each successive calendar date, until it is completed.
74 ## It can be interpreted in different ways, though probably it may
75 ## be considered equivalent with a DTSTART in the infinite past and DUE
76 ## in the infinite future?
77 return DATE_MAX_DT
78
79
80 __all__ = ["TodoAdapter"]