Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def visitTimeZone(self, tz):
base_offset = xs_duration2timedelta(tz.get('t:BaseOffset'))
recurrences = self.accept(tz, 'recurrence')
print "got base_offset", base_offset
tz = ical.Timezone()
if len(recurrences) == 0:
std = ical.cal.Component()
std.name = 'STANDARD'
std.add('tzoffsetfrom', datetime.timedelta(0))
std.add('tzoffsetto', base_offset)
tz.add_component(std)
print tz.as_string()
#std.add
elif len(recurrences) == 1:
pass
elif len(recurrences) == 2:
pass
Possible Solutions:
As this information is not provided by pytz at all, there is no
easy solution, we'd really need to ship another version of the OLSON DB.
"""
if isinstance(tz, pytz.tzinfo.StaticTzInfo):
return _create_timezone_static(tz)
# TODO last_date = None, recurring to infinity
first_date = dt.datetime.today() if not first_date else to_naive_utc(first_date)
last_date = first_date + dt.timedelta(days=1) if not last_date else to_naive_utc(last_date)
timezone = icalendar.Timezone()
timezone.add('TZID', tz)
dst = {
one[2]: 'DST' in two.__repr__()
for one, two in iter(tz._tzinfos.items())
}
bst = {
one[2]: 'BST' in two.__repr__()
for one, two in iter(tz._tzinfos.items())
}
# looking for the first and last transition time we need to include
first_num, last_num = 0, len(tz._utc_transition_times) - 1
first_tt = tz._utc_transition_times[0]
last_tt = tz._utc_transition_times[-1]
for num, transtime in enumerate(tz._utc_transition_times):
acc = IEventAccessor(event)
tz = acc.timezone
# TODO: the standard wants each recurrence to have a valid timezone
# definition. sounds decent, but not realizable.
if not acc.whole_day: # whole day events are exported as dates without
# timezone information
if isinstance(tz, tuple):
tz_start, tz_end = tz
else:
tz_start = tz_end = tz
tzmap = add_to_zones_map(tzmap, tz_start, acc.start)
tzmap = add_to_zones_map(tzmap, tz_end, acc.end)
cal.add_component(IICalendarEventComponent(event).to_ical())
for (tzid, transitions) in tzmap.items():
cal_tz = icalendar.Timezone()
cal_tz.add('tzid', tzid)
cal_tz.add('x-lic-location', tzid)
for (transition, tzinfo) in transitions.items():
if tzinfo['dst']:
cal_tz_sub = icalendar.TimezoneDaylight()
else:
cal_tz_sub = icalendar.TimezoneStandard()
cal_tz_sub.add('tzname', tzinfo['name'])
cal_tz_sub.add('dtstart', transition)
cal_tz_sub.add('tzoffsetfrom', tzinfo['tzoffsetfrom'])
cal_tz_sub.add('tzoffsetto', tzinfo['tzoffsetto'])
# TODO: add rrule
# tzi.add('rrule',
def _create_timezone(self, tz):
"""
create an icalendar timezone from a pytz.tzinfo
:param tz: the timezone
:type tz: pytz.tzinfo
:returns: timezone information set
:rtype: icalendar.Timezone()
"""
timezone = icalendar.Timezone()
timezone.add('TZID', tz)
# FIXME should match year of the event, not this year
daylight, standard = [(num, dt) for num, dt in enumerate(tz._utc_transition_times) if dt.year == datetime.datetime.today().year]
timezone_daylight = icalendar.TimezoneDaylight()
timezone_daylight.add('TZNAME', tz._transition_info[daylight[0]][2])
timezone_daylight.add('DTSTART', daylight[1])
timezone_daylight.add('TZOFFSETFROM', tz._transition_info[daylight[0]][0])
timezone_daylight.add('TZOFFSETTO', tz._transition_info[standard[0]][0])
timezone_standard = icalendar.TimezoneStandard()
timezone_standard.add('TZNAME', tz._transition_info[standard[0]][2])
timezone_standard.add('DTSTART', standard[1])
timezone_standard.add('TZOFFSETFROM', tz._transition_info[standard[0]][0])
timezone_standard.add('TZOFFSETTO', tz._transition_info[daylight[0]][0])
def _create_timezone_static(tz):
"""create an icalendar vtimezone from a pytz.tzinfo.StaticTzInfo
:param tz: the timezone
:type tz: pytz.tzinfo.StaticTzInfo
:returns: timezone information
:rtype: icalendar.Timezone()
"""
timezone = icalendar.Timezone()
timezone.add('TZID', tz)
subcomp = icalendar.TimezoneStandard()
subcomp.add('TZNAME', tz)
subcomp.add('DTSTART', dt.datetime(1601, 1, 1))
subcomp.add('RDATE', dt.datetime(1601, 1, 1))
subcomp.add('TZOFFSETTO', tz._utcoffset)
subcomp.add('TZOFFSETFROM', tz._utcoffset)
timezone.add_component(subcomp)
return timezone