def utcoffset2vDDD(utcoffset, negate=False): td = utcoffset.td if negate: td = -td # This is a workaround for a bug in the iCalendar package. See # http://codespeak.net/pipermail/icalendar-dev/2008-May/000099.html # for information if td < timedelta(0): return '-' + vDDDTypes(-td).ical() else: return vDDDTypes(td).ical()
def test_tzinfo_dateutil(self): # Test for issues #77, #63 # references: #73,7430b66862346fe3a6a100ab25e35a8711446717 date = dateutil.parser.parse('2012-08-30T22:41:00Z') date2 = dateutil.parser.parse('2012-08-30T22:41:00 +02:00') self.assertTrue(date.tzinfo.__module__ == 'dateutil.tz') self.assertTrue(date2.tzinfo.__module__ == 'dateutil.tz') # make sure, it's parsed properly and doesn't throw an error self.assertTrue(icalendar.vDDDTypes(date).to_ical() == b'20120830T224100Z') self.assertTrue(icalendar.vDDDTypes(date2).to_ical() == b'20120830T224100')
def test_tzinfo_dateutil(self): # Test for issues #77, #63 # references: #73,7430b66862346fe3a6a100ab25e35a8711446717 date = dateutil.parser.parse('2012-08-30T22:41:00Z') date2 = dateutil.parser.parse('2012-08-30T22:41:00 +02:00') self.assertTrue(date.tzinfo.__module__.startswith('dateutil.tz')) self.assertTrue(date2.tzinfo.__module__.startswith('dateutil.tz')) # make sure, it's parsed properly and doesn't throw an error self.assertTrue(icalendar.vDDDTypes(date).to_ical() == b'20120830T224100Z') self.assertTrue(icalendar.vDDDTypes(date2).to_ical() == b'20120830T224100')
def add_datetime(component, name, time): """一个跳过带时区的时间中 VALUE 属性的 workaround 某些日历软件无法正常解析同时带 TZID 和 VALUE 属性的时间。 详见 https://github.com/collective/icalendar/issues/75 。 """ vdatetime = vDDDTypes(time) if 'VALUE' in vdatetime.params and 'TZID' in vdatetime.params: vdatetime.params.pop('VALUE') component.add(name, vdatetime)
# Define the date of the race in the input calendar INPUT_RACE_DATE = date(2015,04,26) # Define the date of the new race NEW_RACE_DATE = date(2015,04,26) # Calculate the adjustment needed to the dates DT_DELTA = NEW_RACE_DATE - INPUT_RACE_DATE def date_add(dt, delta=DT_DELTA): if not isinstance(dt, date): raise ValueError('Value passed must be an object of type date') return dt + delta f = open('./input.ics', 'rb') gcal = Calendar.from_ical(f.read()) for component in gcal.walk(): if component.name == 'VEVENT': component['dtstart'] = vDDDTypes(date_add(component.get('dtstart').dt)) component['dtend'] = vDDDTypes(date_add(component.get('dtend').dt)) f.close() f = open('./race-cal-' + NEW_RACE_DATE.strftime('%Y%m%d') + '.ics', 'wb') f.write(gcal.to_ical()) f.close()
def _add_datetime(component, name, time): vdatetime = vDDDTypes(time) if "VALUE" in vdatetime.params and "TZID" in vdatetime.params: vdatetime.params.pop("VALUE") component.add(name, vdatetime)
def contacts_ics(): cal = Calendar() cal.add('prodid', vText('-//choochootrain//Auto-generated//EN')) cal.add('version', vText('2.0')) cal.add('calscale', vText('gregorian')) cal.add('method', vText('publish')) cal.add('x-wr-calname', vText('Birthdays')) cal.add('x-wr-timezone', vText('America/Los_Angeles')) cal.add('x-wr-caldesc', vText('Autogenerated calendar of birthday events')) conn = sqlite3.connect("data/contacts.db") cursor = conn.cursor() cursor.execute("SELECT * FROM contacts order by birthyear, birthmonth, birthday") for id, name, day, month, year in cursor.fetchall(): event = Event() event.add('summary', "%s's birthday" % name) start = datetime.datetime(day=day, month=month, year=year if year is not None else 2014) event.add('dtstart', vDDDTypes(start)) event.add('dtend', vDDDTypes(start + datetime.timedelta(days=1))) event.add('rrule', vRecur(freq='yearly')) cal.add_component(event) return Response(cal.to_ical(), mimetype="text/calendar")