Skip to content

Commit

Permalink
Merge pull request #467 from collective/fix_466
Browse files Browse the repository at this point in the history
Fix #466
  • Loading branch information
niccokunzmann committed Oct 20, 2022
2 parents 2528641 + e882a4b commit 68b1804
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/icalendar/prop.py
Original file line number Diff line number Diff line change
Expand Up @@ -414,10 +414,10 @@ def from_ical(ical, timezone=None):
tzinfo = None
if timezone:
try:
tzinfo = pytz.timezone(timezone)
tzinfo = pytz.timezone(timezone.strip('/'))
except pytz.UnknownTimeZoneError:
if timezone in WINDOWS_TO_OLSON:
tzinfo = pytz.timezone(WINDOWS_TO_OLSON.get(timezone))
tzinfo = pytz.timezone(WINDOWS_TO_OLSON.get(timezone.strip('/')))
else:
tzinfo = _timezone_cache.get(timezone, None)

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
BEGIN:VCALENDAR
BEGIN:VTIMEZONE
TZID:/Europe/CUSTOM
BEGIN:DAYLIGHT
TZOFFSETFROM:+0100
TZOFFSETTO:+0200
TZNAME:CEST
DTSTART:19700329T020000
RRULE:FREQ=YEARLY;BYMONTH=3;BYDAY=-1SU
END:DAYLIGHT
BEGIN:STANDARD
TZOFFSETFROM:+0200
TZOFFSETTO:+0100
TZNAME:CET
DTSTART:19701025T030000
RRULE:FREQ=YEARLY;BYMONTH=10;BYDAY=-1SU
END:STANDARD
END:VTIMEZONE
BEGIN:VEVENT
UID:0cab49a0-1167-40f0-bfed-ecb4d117047d
DTSTAMP:20221019T102950Z
DTSTART;TZID=/Europe/CUSTOM:20221021T200000
DTEND;TZID=/Europe/CUSTOM:20221021T210000
SUMMARY:Just chatting
DESCRIPTION:Just Chatting.
CATEGORIES:Just Chatting
RRULE:FREQ=WEEKLY;BYDAY=FR
END:VEVENT
END:VCALENDAR
10 changes: 10 additions & 0 deletions src/icalendar/tests/events/issue_466_convert_tzid_with_slash.ics
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
BEGIN:VEVENT
UID:0cab49a0-1167-40f0-bfed-ecb4d117047d
DTSTAMP:20221019T102950Z
DTSTART;TZID=/Europe/Stockholm:20221021T200000
DTEND;TZID=/Europe/Stockholm:20221021T210000
SUMMARY:Just chatting
DESCRIPTION:Just Chatting.
CATEGORIES:Just Chatting
RRULE:FREQ=WEEKLY;BYDAY=FR
END:VEVENT
19 changes: 19 additions & 0 deletions src/icalendar/tests/test_parsing.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,3 +160,22 @@ def test_creates_event_with_base64_encoded_attachment_issue_82(events):
event = Event()
event.add('ATTACH', b)
assert event.to_ical() == events.issue_82_expected_output.raw_ics

def test_converts_unqiue_tzid_if_no_timezone(events, in_timezone):
''' Issue #466 - [BUG] TZID timezone is ignored when forward-slash is used
https://github.com/collective/icalendar/issues/466
'''
start_dt = events.issue_466_convert_tzid_with_slash['dtstart'].dt
end_dt = events.issue_466_convert_tzid_with_slash['dtend'].dt
assert start_dt == in_timezone(datetime(2022, 10, 21, 20, 0, 0), 'Europe/Stockholm')
assert end_dt == in_timezone(datetime(2022, 10, 21, 21, 0, 0), 'Europe/Stockholm')

def test_respects_unique_tzid(calendars, in_timezone):
''' Issue #466 - [BUG] TZID timezone is ignored when forward-slash is used
https://github.com/collective/icalendar/issues/466
'''
start_dt = calendars.issue_466_respect_unique_timezone.walk('VEVENT')[0]['dtstart'].dt
end_dt = calendars.issue_466_respect_unique_timezone.walk('VEVENT')[0]['dtend'].dt
assert start_dt == in_timezone(datetime(2022, 10, 21, 20, 0, 0), 'Europe/Stockholm')
assert end_dt == in_timezone(datetime(2022, 10, 21, 21, 0, 0), 'Europe/Stockholm')

0 comments on commit 68b1804

Please sign in to comment.