Beispiel #1
0
    def from_ical(ical, timezone=None):
        """ Parses the data format from ical text format.

        """
        # TODO: ical string should better contain also the TZID property.deleter(

        if timezone:
            timezone = timezone_from_string(timezone)

        try:
            timetuple = map(int, ((
                ical[:4],       # year
                ical[4:6],      # month
                ical[6:8],      # day
                ical[9:11],     # hour
                ical[11:13],    # minute
                ical[13:15],    # second
                )))
            if timezone:
                return datetime(tzinfo=timezone, *timetuple)
            elif not ical[15:]:
                return datetime(*timetuple)
            elif ical[15:16] == 'Z':
                timetuple += [0, UTC]
                return datetime(*timetuple)
            else:
                raise ValueError, ical
        except:
            raise ValueError, 'Wrong datetime format: %s' % ical
Beispiel #2
0
 def add(self, name, value, encode=1):
     "If property exists append, else create and set it"
     if name in self:
         oldval = self[name]
         value = self._encode(name, value, encode)
         if type(oldval) == ListType:
             oldval.append(value)
         else:
             self.set(name, [oldval, value], encode=0)
     else:
         self.set(name, value, encode)
     if getattr(value, 'tzinfo', False):
         timezone = timezone_from_string(value.tzinfo)
         self[name].params.update({'TZID': str(timezone)})