| 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 |
|
| 30 |
start = self._component.get("DTSTART") |
| 31 |
if start is not None: |
| 32 |
return start.dt |
| 33 |
|
| 34 |
|
| 35 |
due = self._component.get("DUE") |
| 36 |
if due is not None: |
| 37 |
return due.dt |
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
return DATE_MIN_DT |
| 42 |
|
| 43 |
@property |
| 44 |
def raw_end(self) -> Time: |
| 45 |
"""Return DUE or DTSTART+DURATION or something""" |
| 46 |
|
| 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 |
|
| 54 |
duration = self._component.get("DURATION") |
| 55 |
|
| 56 |
|
| 57 |
|
| 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 |
|
| 65 |
|
| 66 |
|
| 67 |
if dtstart: |
| 68 |
return dtstart.dt |
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
return DATE_MAX_DT |
| 78 |
|
| 79 |
|
| 80 |
__all__ = ["TodoAdapter"] |