Skip to content

Commit 1f1b69c

Browse files
feat: add component to event (#172)
* feat: add component to event * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 32df274 commit 1f1b69c

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

icalevents/icalparser.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ def __init__(self):
7373
self.floating = None
7474
self.status = None
7575
self.url = None
76+
self.component = None
7677

7778
def time_left(self, time=None):
7879
"""
@@ -136,6 +137,7 @@ def copy_to(self, new_start=None, uid=None):
136137
uid = "%s_%d" % (self.uid, randint(0, 1000000))
137138

138139
ne = Event()
140+
ne.component = self.component
139141
ne.summary = self.summary
140142
ne.description = self.description
141143
ne.start = new_start
@@ -182,6 +184,8 @@ def create_event(component, strict):
182184

183185
event = Event()
184186

187+
event.component = component
188+
185189
event.start = component.get("dtstart").dt
186190
# The RFC specifies that the TZID parameter must be specified for datetime or time
187191
# Otherwise we set a default timezone (if only one is set with VTIMEZONE) or utc

test/test_icalevents.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from dateutil.tz import UTC, gettz
88

99
from icalevents import icalevents
10+
from icalendar.prop import vText
1011

1112

1213
class ICalEventsTests(unittest.TestCase):
@@ -1063,3 +1064,14 @@ def test_non_ascii_uid(self):
10631064

10641065
self.assertIsNot(event.uid, -1)
10651066
self.assertIsInstance(event.uid, str)
1067+
1068+
def test_component(self):
1069+
ical = "test/test_data/cest_every_day_for_one_year.ics"
1070+
start = date(2020, 1, 1)
1071+
end = date(2024, 12, 31)
1072+
1073+
evs = icalevents.events(file=ical, start=start, end=end)
1074+
event = evs[0]
1075+
1076+
self.assertEqual(str(event.component["X-MICROSOFT-CDO-BUSYSTATUS"]), "BUSY")
1077+
self.assertIsInstance(event.component["X-MICROSOFT-CDO-BUSYSTATUS"], vText)

0 commit comments

Comments
 (0)