diff --git a/src/icalendar/cal.py b/src/icalendar/cal.py index a91819dc..95c081ee 100644 --- a/src/icalendar/cal.py +++ b/src/icalendar/cal.py @@ -1312,6 +1312,15 @@ def TRIGGER_RELATED(self) -> str: A value of START will set the alarm to trigger off the start of the associated event or to-do. A value of END will set the alarm to trigger off the end of the associated event or to-do. + + In this example, we create an alarm that triggers two hours after the + end of its parent component: + + >>> from icalendar import Alarm + >>> from datetime import timedelta + >>> alarm = Alarm() + >>> alarm.TRIGGER = timedelta(hours=2) + >>> alarm.TRIGGER_RELATED = "END" """ trigger = self.get("TRIGGER") if trigger is None: @@ -1329,11 +1338,11 @@ def TRIGGER_RELATED(self, value: str): class Triggers(NamedTuple): """The computed times of alarm triggers. - start - relative to the start of the Event or Todo (timedelta) + start - triggers relative to the start of the Event or Todo (timedelta) - end - relateive to the end of the Event or Todo (timedelta) + end - triggers relative to the end of the Event or Todo (timedelta) - absolute - datetime in UTC + absolute - triggers at a datetime in UTC """ start: tuple[timedelta] end: tuple[timedelta] @@ -1351,7 +1360,7 @@ def triggers(self): >>> from icalendar import Alarm >>> from datetime import timedelta >>> alarm = Alarm() - >>> alarm.TRIGGER = timedelta(hours=-4) # trigger 4 hours after + >>> alarm.TRIGGER = timedelta(hours=-4) # trigger 4 hours before START >>> alarm.DURATION = timedelta(hours=1) # after 1 hour trigger again >>> alarm.REPEAT = 2 # trigger 2 more times >>> alarm.triggers.start == (timedelta(hours=-4), timedelta(hours=-3), timedelta(hours=-2)) @@ -1376,8 +1385,9 @@ def triggers(self): end.append(trigger) add = end duration = self.DURATION - for _ in range(self.REPEAT): - add.append(add[-1] + duration) + if duration is not None: + for _ in range(self.REPEAT): + add.append(add[-1] + duration) return self.Triggers(start=tuple(start), end=tuple(end), absolute=tuple(absolute)) class Calendar(Component): diff --git a/src/icalendar/tests/test_issue_662_component_properties.py b/src/icalendar/tests/test_issue_662_component_properties.py index 8fa6957a..b524c95a 100644 --- a/src/icalendar/tests/test_issue_662_component_properties.py +++ b/src/icalendar/tests/test_issue_662_component_properties.py @@ -557,20 +557,20 @@ def test_get_alarm_triggers(alarms, file, triggers): assert alarm.triggers == triggers -def triggers_emtpy_alarm(): +def test_triggers_emtpy_alarm(): """An alarm with no trigger has no triggers.""" assert Alarm().triggers == ((), (), ()) h1 = timedelta(hours=1) -def triggers_emtpy_with_no_repeat(): +def test_triggers_emtpy_with_no_repeat(): """Check incomplete values.""" a = Alarm() a.TRIGGER = h1 a.DURATION = h1 assert a.triggers == ((h1,), (), ()) -def triggers_emtpy_with_no_duration(): +def test_triggers_emtpy_with_no_duration(): """Check incomplete values.""" a = Alarm() a.TRIGGER = h1