Skip to content

Commit

Permalink
make sure the .get_duration altgorithm accepts dates vs time in due/d…
Browse files Browse the repository at this point in the history
…tstart
  • Loading branch information
tobixen committed Apr 7, 2024
1 parent a0ff944 commit 0b9f91a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ This project should more or less adhere to [Semantic Versioning](https://semver.

### Fixed

* `get_duration`: make sure the algorithm doesn't raise an exception comparing dates with timestamps
* `set_due`: make sure the algorithm doesn't raise an exception comparing naive timestamps with timezone timestamps
* Code formatting / style fixes.
* Search method did some logic handling non-conformant servers (loading data from the server if the search response didn't include the icalendar data, ignoring trash from the Google server when it returns data without a VTODO/VEVENT/VJOURNAL component.
Expand Down
16 changes: 10 additions & 6 deletions caldav/objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -2662,7 +2662,7 @@ def get_duration(self) -> timedelta:
WARNING: this method is likely to be deprecated and moved to
the icalendar library. If you decide to use it, please put
caldav<2.0 in the requirements.
caldav<3.0 in the requirements.
"""
i = self.icalendar_component
return self._get_duration(i)
Expand All @@ -2671,11 +2671,15 @@ def _get_duration(self, i):
if "DURATION" in i:
return i["DURATION"].dt
elif "DTSTART" in i and self._ENDPARAM in i:
## if we get an exception here it may be that one of the
## timestamps is a date and the other is a datetime.
## This is a breach of the standard.
## We may want to implement a workaround in lib.vcal.fix
return i[self._ENDPARAM].dt - i["DTSTART"].dt
end = i[self._ENDPARAM].dt
start = i["DTSTART"].dt
## We do have a problem here if one is a date and the other is a
## datetime. This is NOT explicitly defined as a technical
## breach in the RFC, so we need to work around it.
if isinstance(end, datetime) != isinstance(start, datetime):
start = datetime(start.year, start.month, start.day)
end = datetime(end.year, end.month, end.day)
return end - start
elif "DTSTART" in i and not isinstance(i["DTSTART"], datetime):
return timedelta(days=1)
else:
Expand Down

0 comments on commit 0b9f91a

Please sign in to comment.