Skip to content

Commit

Permalink
chore: add test for per-event timezone where required
Browse files Browse the repository at this point in the history
  • Loading branch information
eigenmannmartin committed Sep 9, 2024
1 parent d1c11aa commit 9829e80
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 4 deletions.
7 changes: 3 additions & 4 deletions icalevents/icalparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,11 +167,12 @@ def encode(value: Optional[vText]) -> Optional[str]:
return str(value.encode("utf-8"))


def create_event(component, utc_default, strict):
def create_event(component, strict):
"""
Create an event from its iCal representation.
:param component: iCal component
:param strict:
:return: event
"""

Expand Down Expand Up @@ -323,11 +324,9 @@ def parse_events(

# If there's exactly one timezone in the file,
# assume it applies globally, otherwise UTC
utc_default = False
if len(timezones) == 1:
cal_tz = get_timezone(list(timezones)[0])
else:
utc_default = True
cal_tz = UTC
# < ==========================================

Expand Down Expand Up @@ -358,7 +357,7 @@ def is_not_exception(date):
exceptions[exdate[0:8]] = exdate

if component.name == "VEVENT":
e = create_event(component, utc_default, strict)
e = create_event(component, strict)

# make rule.between happy and provide from, to points in time that have the same format as dtstart
s = component["dtstart"].dt
Expand Down
50 changes: 50 additions & 0 deletions test/test_data/per_event_timezone.ics
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
BEGIN:VCALENDAR
PRODID:-//Google Inc//Google Calendar 70.9054//EN
VERSION:2.0
CALSCALE:GREGORIAN
METHOD:PUBLISH
X-WR-CALNAME:test
X-WR-TIMEZONE:Europe/Zurich
BEGIN:VTIMEZONE
TZID:Europe/Zurich
X-LIC-LOCATION:Europe/Zurich
BEGIN:DAYLIGHT
TZOFFSETFROM:+0100
TZOFFSETTO:+0200
TZNAME:GMT+2
DTSTART:19700329T020000
RRULE:FREQ=YEARLY;BYMONTH=3;BYDAY=-1SU
END:DAYLIGHT
BEGIN:STANDARD
TZOFFSETFROM:+0200
TZOFFSETTO:+0100
TZNAME:GMT+1
DTSTART:19701025T030000
RRULE:FREQ=YEARLY;BYMONTH=10;BYDAY=-1SU
END:STANDARD
END:VTIMEZONE
BEGIN:VEVENT
DTSTART;TZID=Europe/Zurich:20240325T070000
DTEND;TZID=Europe/Zurich:20240325T080000
DTSTAMP:20240908T134310Z
UID:[email protected]
CREATED:20240908T134239Z
LAST-MODIFIED:20240908T134239Z
SEQUENCE:0
STATUS:CONFIRMED
SUMMARY:Zürich
TRANSP:OPAQUE
END:VEVENT
BEGIN:VEVENT
DTSTART;TZID=Australia/Perth:20240325T070000
DTEND;TZID=Australia/Perth:20240325T080000
DTSTAMP:20240908T134310Z
UID:[email protected]
CREATED:20240908T134239Z
LAST-MODIFIED:20240908T134239Z
SEQUENCE:0
STATUS:CONFIRMED
SUMMARY:Perth
TRANSP:OPAQUE
END:VEVENT
END:VCALENDAR
13 changes: 13 additions & 0 deletions test/test_icalevents.py
Original file line number Diff line number Diff line change
Expand Up @@ -902,6 +902,19 @@ def test_recurr_id_dtstart_missmatch(self):
self.assertEqual(evs[3].start, datetime(2022, 6, 8, 13, 00, 0, tzinfo=tz))
self.assertEqual(evs[3].summary, "Recurring Event")

def test_per_event_timezone(self):
ical = "test/test_data/per_event_timezone.ics"
start = date(2024, 1, 1)
end = date(2024, 12, 30)

events = icalevents.events(file=ical, start=start, end=end, strict=True)
self.assertEqual(
events[0].start.tzname(), "CET", "check tz as specified in calendar"
)
self.assertEqual(
events[1].start.tzname(), "AWST", "check tz as specified in calendar"
)

def test_regression_repeating_events_raise_an_error(self):
ical = "test/test_data/recurrence_tzinfo.ics"
start = date(2023, 1, 1)
Expand Down

0 comments on commit 9829e80

Please sign in to comment.