diff --git a/homeassistant/components/calendar/__init__.py b/homeassistant/components/calendar/__init__.py index 594964c129c076e135f7c95f151b252ef5284ebe..2445c054c6d1d225eece7971cdfbc6c40dd53b16 100644 --- a/homeassistant/components/calendar/__init__.py +++ b/homeassistant/components/calendar/__init__.py @@ -140,26 +140,6 @@ def _has_min_duration( return validate -def _has_all_day_event_duration( - start_key: str, - end_key: str, -) -> Callable[[dict[str, Any]], dict[str, Any]]: - """Modify all day events to have a duration of one day.""" - - def validate(obj: dict[str, Any]) -> dict[str, Any]: - if ( - (start := obj.get(start_key)) - and (end := obj.get(end_key)) - and not isinstance(start, datetime.datetime) - and not isinstance(end, datetime.datetime) - and start == end - ): - obj[end_key] = start + datetime.timedelta(days=1) - return obj - - return validate - - def _has_same_type(*keys: Any) -> Callable[[dict[str, Any]], dict[str, Any]]: """Verify that all values are of the same type.""" @@ -267,7 +247,6 @@ CALENDAR_EVENT_SCHEMA = vol.Schema( _has_consistent_timezone("start", "end"), _as_local_timezone("start", "end"), _has_min_duration("start", "end", MIN_EVENT_DURATION), - _has_all_day_event_duration("start", "end"), ), extra=vol.ALLOW_EXTRA, ) @@ -375,6 +354,16 @@ class CalendarEvent: f"Failed to validate CalendarEvent: {err}" ) from err + # It is common to set a start an end date to be the same thing for + # an all day event, but that is not a valid duration. Fix to have a + # duration of one day. + if ( + not isinstance(self.start, datetime.datetime) + and not isinstance(self.end, datetime.datetime) + and self.start == self.end + ): + self.end = self.start + datetime.timedelta(days=1) + def _event_dict_factory(obj: Iterable[tuple[str, Any]]) -> dict[str, str]: """Convert CalendarEvent dataclass items to dictionary of attributes.""" diff --git a/homeassistant/components/local_calendar/calendar.py b/homeassistant/components/local_calendar/calendar.py index 6cfcaec61d055fb17b83e5c1ef404288c8c89e0e..423be8143b85db5ac8f9bd0f9a6243e53818154d 100644 --- a/homeassistant/components/local_calendar/calendar.py +++ b/homeassistant/components/local_calendar/calendar.py @@ -196,7 +196,7 @@ def _get_calendar_event(event: Event) -> CalendarEvent: else: start = event.start end = event.end - if (end - start) <= timedelta(days=0): + if (end - start) < timedelta(days=0): end = start + timedelta(days=1) return CalendarEvent(