Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
: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])
timezone.add_component(timezone_daylight)
timezone.add_component(timezone_standard)
return timezone
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',
# {'freq': 'yearly', 'bymonth': 10, 'byday': '-1su'})
cal_tz.add_component(cal_tz_sub)
cal.add_component(cal_tz)
return cal
def __init__(self, tz_name=None):
"""
:param str tz_name: The timezone to represent, if not specified it
defaults to the local timezone.
"""
super(Timezone, self).__init__()
if tz_name is None:
tz_name = tzlocal.get_localzone().zone
self.add('tzid', tz_name)
tz_details = parse_tz_posix_env_var(get_tz_posix_env_var(tz_name))
timezone_standard = icalendar.TimezoneStandard()
timezone_standard.add('dtstart', datetime.datetime(1601, 1, 1, 2, 0, tzinfo=dateutil.tz.tzutc()))
timezone_standard.add('tzoffsetfrom', tz_details.offset + datetime.timedelta(0, SECONDS_IN_ONE_HOUR))
timezone_standard.add('tzoffsetto', tz_details.offset)
if tz_details.offset_dst:
timezone_standard.add('rrule', tz_details.dst_end)
timezone_daylight = icalendar.TimezoneDaylight()
timezone_daylight.add('dtstart', datetime.datetime(1601, 1, 1, 2, 0, tzinfo=dateutil.tz.tzutc()))
timezone_daylight.add('tzoffsetfrom', tz_details.offset)
timezone_daylight.add('tzoffsetto', tz_details.offset + datetime.timedelta(0, SECONDS_IN_ONE_HOUR))
timezone_daylight.add('rrule', tz_details.dst_start)
self.add_component(timezone_daylight)
self.add_component(timezone_standard)
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
timezones = dict()
for num in range(first_num, last_num + 1):
name = tz._transition_info[num][2]
if name in timezones:
ttime = tz.fromutc(tz._utc_transition_times[num]).replace(tzinfo=None)
if 'RDATE' in timezones[name]:
timezones[name]['RDATE'].dts.append(
icalendar.prop.vDDDTypes(ttime))
else:
timezones[name].add('RDATE', ttime)
continue
if dst[name] or bst[name]:
subcomp = icalendar.TimezoneDaylight()
else:
subcomp = icalendar.TimezoneStandard()
subcomp.add('TZNAME', tz._transition_info[num][2])
subcomp.add(
'DTSTART',
tz.fromutc(tz._utc_transition_times[num]).replace(tzinfo=None))
subcomp.add('TZOFFSETTO', tz._transition_info[num][0])
subcomp.add('TZOFFSETFROM', tz._transition_info[num - 1][0])
timezones[name] = subcomp
for subcomp in timezones.values():
timezone.add_component(subcomp)
return timezone