Esempio n. 1
0
    def occurrence(self, entryid):
        entryid = _bdec(entryid)
        pos = 2 + _utils.unpack_short(entryid, 0)
        basedate_val = _utils.unpack_long(entryid, pos)

        for exc in self.exceptions:  # TODO subject etc
            if exc['original_start_date'] in (
                    basedate_val,
                    basedate_val - self.starttime_offset):  # TODO pick one
                start = datetime.datetime.fromtimestamp(
                    _utils.rectime_to_unixtime(exc['start_datetime']))
                start = _utils._to_gmt(start, self.tz)
                break
        else:
            # TODO check that date is (still) valid
            start = datetime.datetime.fromtimestamp(
                _utils.rectime_to_unixtime(basedate_val))
            start = _utils._to_gmt(start, self.tz)

        return Occurrence(
            self.item,
            start,
            start + datetime.timedelta(minutes=self.endtime_offset -
                                       self.starttime_offset),
            basedate_val=basedate_val,
        )
Esempio n. 2
0
    def occurrences(self, start=None, end=None):  # XXX fit-to-period
        tz = self.item.get_value(PidLidTimeZoneStruct)

        recurrences = self.recurrences
        if start and end:
            recurrences = recurrences.between(_utils._from_gmt(start, tz),
                                              _utils._from_gmt(end, tz))

        start_exc_ext = {}
        for exc, ext in zip(self.exceptions, self.extended_exceptions):
            start_exc_ext[exc['start_datetime']] = exc, ext

        for d in recurrences:
            startdatetime_val = _utils.unixtime_to_rectime(
                time.mktime(d.timetuple()))

            subject = self.item.subject
            location = self.item.location
            if startdatetime_val in start_exc_ext:
                exc, ext = start_exc_ext[startdatetime_val]
                minutes = exc['end_datetime'] - startdatetime_val
                subject = ext.get('subject', subject)
                location = ext.get('location', location)
            else:
                minutes = self.endtime_offset - self.starttime_offset

            d = _utils._to_gmt(d, tz)

            occ = Occurrence(self.item, d,
                             d + datetime.timedelta(minutes=minutes), subject,
                             location)
            if (not start or occ.end > start) and (not end or occ.start < end):
                yield occ
Esempio n. 3
0
    def basedate(self):
        """ Exception date """

        blob = self.item.get_value(PidLidGlobalObjectId)
        if blob is not None:
            y, m, d = struct.unpack_from('>HBB', blob, 16)
            if (y, m, d) != (0, 0, 0):
                ts = timegm(datetime.datetime(y, m, d).timetuple())
                tz = self.item.get_value(PidLidTimeZoneStruct)
                return _utils._to_gmt(datetime.datetime.fromtimestamp(ts), tz)
Esempio n. 4
0
    def _update(self, **kwargs):
        if self.item.recurring:
            rec = self.item.recurrence
            basedate = datetime.datetime.fromtimestamp(
                _utils.rectime_to_unixtime(self._basedate_val))
            basedate = _utils._to_gmt(basedate, rec.tz)

            if rec.is_exception(basedate):
                rec.modify_exception2(basedate, **kwargs)
            else:
                rec.create_exception2(basedate)
                rec.modify_exception2(basedate, **kwargs)
        else:
            for (k, v) in kwargs.items():
                setattr(self.item, k, v)