Skip to content

Commit

Permalink
Fix handling of VTIMEZONEs with subcomponents with the same DTSTARTs
Browse files Browse the repository at this point in the history
For VTIMEZONE subcomponents without a TZNAME we would construct a
TZNAME from their shared TZID and DTSTART, if their DTSTART was equal,
this would lead to the same TZNAME and with that to a broken timezone
object.

Fixes #217.
  • Loading branch information
geier committed Mar 22, 2017
1 parent 4c0d95b commit 901a309
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 15 deletions.
3 changes: 3 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ New features:

Bug fixes:

- Fix handling of VTIMEZONEs with subcomponents with the same DTSTARTs.
[geier]

- *add item here*


Expand Down
22 changes: 7 additions & 15 deletions src/icalendar/cal.py
Original file line number Diff line number Diff line change
Expand Up @@ -517,19 +517,11 @@ class Timezone(Component):
singletons = ('TZID', 'LAST-MODIFIED', 'TZURL',)

@staticmethod
def _extract_offsets(component, zone):
def _extract_offsets(component, tzname):
"""extract offsets and transition times from a VTIMEZONE component
:param component: a STANDARD or DAYLIGHT component
:param zone: the name of the zone, used for constructing a TZNAME if
this component has none
:param tzname: the name of the zone
"""
try:
tzname = str(component['TZNAME'])
except KeyError:
tzname = '{0}_{1}'.format(
zone,
component['DTSTART'].to_ical().decode('utf-8')
)
offsetfrom = component['TZOFFSETFROM'].td
offsetto = component['TZOFFSETTO'].td
dtstart = component['DTSTART'].dt
Expand Down Expand Up @@ -586,12 +578,11 @@ def to_tz(self):
try:
tzname = str(component['TZNAME'])
except KeyError:
tzname = '{0}_{1}'.format(
zone,
component['DTSTART'].to_ical().decode('utf-8')
)
# yes, this is an awful TZNAME, but at least it's unique
tzname = component.to_ical().decode('utf-8')
assert tzname not in dst
dst[tzname], component_transitions = self._extract_offsets(
component, zone
component, tzname
)
transitions.extend(component_transitions)

Expand Down Expand Up @@ -622,6 +613,7 @@ def to_tz(self):
if not dst[transitions[index][3]]: # [3] is the name
dst_offset = osto - transitions[index][2] # [2] is osto # noqa
break
assert dst_offset is not False
transition_info.append((osto, dst_offset, name))

cls = type(zone, (DstTzInfo,), {
Expand Down

0 comments on commit 901a309

Please sign in to comment.