Skip to content

Commit 3965292

Browse files
committed
started deprecating some methods that have been moved to icalendar library
1 parent b679919 commit 3965292

2 files changed

Lines changed: 12 additions & 40 deletions

File tree

caldav/calendarobjectresource.py

Lines changed: 11 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -510,19 +510,10 @@ def get_due(self):
510510
"""
511511
A VTODO may have due or duration set. Return or calculate due.
512512
513-
WARNING: this method is likely to be deprecated and moved to
514-
the icalendar library. If you decide to use it, please put
515-
caldav<3.0 in the requirements.
513+
DEPRECATION WARNING: this method is likely to be removed in
514+
caldav v3.0. Use self.icalendar_component.end instead.
516515
"""
517-
i = self.icalendar_component
518-
if "DUE" in i:
519-
return i["DUE"].dt
520-
elif "DTEND" in i:
521-
return i["DTEND"].dt
522-
elif "DURATION" in i and "DTSTART" in i:
523-
return i["DTSTART"].dt + i["DURATION"].dt
524-
else:
525-
return None
516+
return self.icalendar_component.end
526517

527518
get_dtend = get_due
528519

@@ -1426,7 +1417,11 @@ def _has_data(self) -> bool:
14261417
## ===================================================================
14271418

14281419
def get_duration(self) -> timedelta:
1429-
"""According to the RFC, either DURATION or DUE should be set
1420+
"""
1421+
DEPRECATION WARNING: This method may be removed in version 3.0.
1422+
Use self.icalendar_component.duration instead.
1423+
1424+
According to the RFC, either DURATION or DUE should be set
14301425
for a task, but never both - implicitly meaning that DURATION
14311426
is the difference between DTSTART and DUE (personally I
14321427
believe that's stupid. If a task takes five minutes to
@@ -1442,31 +1437,8 @@ def get_duration(self) -> timedelta:
14421437
TODO: should be fixed for Event class as well (only difference
14431438
is that DTEND is used rather than DUE) and possibly also for
14441439
Journal (defaults to one day, probably?)
1445-
1446-
WARNING: this method is likely to be deprecated and moved to
1447-
the icalendar library. If you decide to use it, please put
1448-
caldav<3.0 in the requirements.
14491440
"""
1450-
i = self.icalendar_component
1451-
return self._get_duration(i)
1452-
1453-
def _get_duration(self, i):
1454-
if "DURATION" in i:
1455-
return i["DURATION"].dt
1456-
elif "DTSTART" in i and self._ENDPARAM in i:
1457-
end = i[self._ENDPARAM].dt
1458-
start = i["DTSTART"].dt
1459-
## We do have a problem here if one is a date and the other is a
1460-
## datetime. This is NOT explicitly defined as a technical
1461-
## breach in the RFC, so we need to work around it.
1462-
if isinstance(end, datetime) != isinstance(start, datetime):
1463-
start = datetime(start.year, start.month, start.day)
1464-
end = datetime(end.year, end.month, end.day)
1465-
return end - start
1466-
elif "DTSTART" in i and not isinstance(i["DTSTART"], datetime):
1467-
return timedelta(days=1)
1468-
else:
1469-
return timedelta(0)
1441+
return self.icalendar_component.duration
14701442

14711443

14721444
class Event(CalendarObjectResource):
@@ -1616,7 +1588,7 @@ def _next(self, ts=None, i=None, dtstart=None, rrule=None, by=None, no_count=Tru
16161588
else:
16171589
dtstart = ts or datetime.now()
16181590
else:
1619-
dtstart = ts or datetime.now() - self._get_duration(i)
1591+
dtstart = ts or datetime.now() - i.duration
16201592
## dtstart should be compared to the completion timestamp, which
16211593
## is set in UTC in the complete() method. However, dtstart
16221594
## may be a naïve or a floating timestamp
@@ -1747,7 +1719,7 @@ def _complete_recurring_thisandfuture(self, completion_timestamp) -> None:
17471719

17481720
rrule = rrule2 or rrule
17491721

1750-
duration = self._get_duration(i=prev)
1722+
duration = prev.duration
17511723
thisandfuture.pop("DTSTART", None)
17521724
thisandfuture.pop("DUE", None)
17531725
next_dtstart = self._next(i=prev, rrule=rrule, ts=completion_timestamp)

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ dependencies = [
5656
"niquests",
5757
"recurring-ical-events>=2.0.0",
5858
"typing_extensions;python_version<'3.11'",
59-
"icalendar>6.0.0",
59+
"icalendar>=7.0.0a2",
6060
"icalendar-searcher>=1.0.0,<2",
6161
"dnspython",
6262
"python-dateutil",

0 commit comments

Comments
 (0)