@@ -456,19 +456,10 @@ def get_due(self):
456456 """
457457 A VTODO may have due or duration set. Return or calculate due.
458458
459- WARNING: this method is likely to be deprecated and moved to
460- the icalendar library. If you decide to use it, please put
461- caldav<2.0 in the requirements.
459+ DEPRECATION WARNING: this method is likely to be removed in
460+ caldav v3.0. Use self.icalendar.end instead.
462461 """
463- i = self .icalendar_component
464- if "DUE" in i :
465- return i ["DUE" ].dt
466- elif "DTEND" in i :
467- return i ["DTEND" ].dt
468- elif "DURATION" in i and "DTSTART" in i :
469- return i ["DTSTART" ].dt + i ["DURATION" ].dt
470- else :
471- return None
462+ return self .icalendar_component .end
472463
473464 get_dtend = get_due
474465
@@ -976,7 +967,10 @@ def _get_icalendar_instance(self):
976967 )
977968
978969 def get_duration (self ) -> timedelta :
979- """According to the RFC, either DURATION or DUE should be set
970+ """
971+ DEPRECATION WARNING: This method may be removed in version 3.0
972+
973+ According to the RFC, either DURATION or DUE should be set
980974 for a task, but never both - implicitly meaning that DURATION
981975 is the difference between DTSTART and DUE (personally I
982976 believe that's stupid. If a task takes five minutes to
@@ -997,29 +991,11 @@ def get_duration(self) -> timedelta:
997991 the icalendar library. If you decide to use it, please put
998992 caldav<3.0 in the requirements.
999993 """
1000- i = self .icalendar_component
1001- return self ._get_duration (i )
1002-
1003- def _get_duration (self , i ):
1004- if "DURATION" in i :
1005- return i ["DURATION" ].dt
1006- elif "DTSTART" in i and self ._ENDPARAM in i :
1007- end = i [self ._ENDPARAM ].dt
1008- start = i ["DTSTART" ].dt
1009- ## We do have a problem here if one is a date and the other is a
1010- ## datetime. This is NOT explicitly defined as a technical
1011- ## breach in the RFC, so we need to work around it.
1012- if isinstance (end , datetime ) != isinstance (start , datetime ):
1013- start = datetime (start .year , start .month , start .day )
1014- end = datetime (end .year , end .month , end .day )
1015- return end - start
1016- elif "DTSTART" in i and not isinstance (i ["DTSTART" ], datetime ):
1017- return timedelta (days = 1 )
1018- else :
1019- return timedelta (0 )
994+ return self .icalendar_component .duration
1020995
996+ ## DEPRECATION WARNING:
1021997 ## for backward-compatibility - may be changed to
1022- ## icalendar_instance in version 1 .0
998+ ## icalendar_instance in version 3 .0
1023999 instance : VBase = vobject_instance
10241000
10251001
@@ -1168,7 +1144,7 @@ def _next(self, ts=None, i=None, dtstart=None, rrule=None, by=None, no_count=Tru
11681144 else :
11691145 dtstart = ts or datetime .now ()
11701146 else :
1171- dtstart = ts or datetime .now () - self . _get_duration ( i )
1147+ dtstart = ts or datetime .now () - i . duration
11721148 ## dtstart should be compared to the completion timestamp, which
11731149 ## is set in UTC in the complete() method. However, dtstart
11741150 ## may be a naïve or a floating timestamp
@@ -1303,7 +1279,7 @@ def _complete_recurring_thisandfuture(self, completion_timestamp) -> None:
13031279
13041280 rrule = rrule2 or rrule
13051281
1306- duration = self . _get_duration ( i = prev )
1282+ duration = prev . duration
13071283 thisandfuture .pop ("DTSTART" , None )
13081284 thisandfuture .pop ("DUE" , None )
13091285 next_dtstart = self ._next (i = prev , rrule = rrule , ts = completion_timestamp )
0 commit comments