1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
|
"""Adapter for VEVENT."""
from __future__ import annotations
import datetime
from typing import TYPE_CHECKING
from recurring_ical_events.adapters.component import ComponentAdapter
from recurring_ical_events.util import (
convert_to_datetime,
is_date,
normalize_pytz,
)
if TYPE_CHECKING:
from recurring_ical_events.types import Time
class EventAdapter(ComponentAdapter):
"""An icalendar event adapter."""
@staticmethod
def component_name() -> str:
"""The icalendar component name."""
return "VEVENT"
@property
def end_property(self) -> str:
"""DTEND"""
return "DTEND"
@property
def raw_start(self) -> Time:
"""Return DTSTART"""
# Arguably, it may be considered a feature that this breaks
# if no DTSTART is set
return self._component["DTSTART"].dt
@property
def raw_end(self) -> Time:
"""Yield DTEND or calculate the end of the event based on
DTSTART and DURATION.
"""
## an even may have DTEND or DURATION, but not both
end = self._component.get("DTEND")
if end is not None:
return end.dt
duration = self._component.get("DURATION")
if duration is not None:
start = self._component["DTSTART"].dt
if duration.dt.seconds != 0 and is_date(start):
start = convert_to_datetime(start, None)
return normalize_pytz(start + duration.dt)
start = self._component["DTSTART"].dt
if is_date(start):
return start + datetime.timedelta(days=1)
return start
__all__ = ["EventAdapter"]
|