示例#1
0
 def setUp(self):
     TestIcalBouncerRunning.setUp(self)
     # Beijing is UTC+8
     self.beijing_tz = tz.gettz('Asia/Shanghai')
     if self.beijing_tz is None:
         raise unittest.SkipTest("Could not find tzinfo data "
                                 "for the Asia/Shanghai timezone")
     # Guatemala is UTC+8
     self.guatemala_tz = tz.gettz('America/Guatemala')
     if self.guatemala_tz is None:
         raise unittest.SkipTest("Could not find tzinfo data "
                                 "for the America/Guatemala timezone")
示例#2
0
def vDDDToDatetime(v, timezones):
    """
    Convert a vDDDType to a datetime, respecting timezones.

    @param v: the time to convert
    @type  v: L{icalendar.prop.vDDDTypes}

    @param timezones: Defined timezones in the calendar

    """
    if v is None:
        return None
    dt = _toDateTime(v.dt)
    if dt.tzinfo is None:
        # We might have a "floating" DATE-TIME value here, in
        # which case we will not have a TZID parameter; see
        # 4.3.5, FORM #3
        tzid = v.params.get('TZID')
        if tzid is None:
            timezone = tz.LOCAL
        else:
            # If the timezone is not in the calendar, try one last time
            # with the system's timezones
            timezone = timezones.get(tzid, tz.gettz(tzid))
            if timezone is None:
                raise NotCompilantError("You are trying to use a timezone\
                    that is not defined in this calendar")
            elif isinstance(timezone, tz.DSTTimezone):
                timezone = timezone.copy()
        dt = datetime.datetime(dt.year, dt.month, dt.day,
                               dt.hour, dt.minute, dt.second,
                               dt.microsecond, timezone)
    return dt
 def testGetPoints(self):
     start = datetime(2007, 12, 22, 9, 0, 0, 0, LOCAL)
     end = datetime(2007, 12, 22, 11, 0, 0, 0, LOCAL)
     eventSet1 = eventcalendar.EventSet('uid1')
     eventSet2 = eventcalendar.EventSet('uid2')
     event1 = eventcalendar.Event('uid1', start, end, 'content')
     eventSet1.addEvent(event1)
     event2 = eventcalendar.Event('uid2', start, end, 'content')
     eventSet2.addEvent(event2)
     rid = self._events[0].get('RECURRENCE-ID')
     self.failUnless(rid)
     riddatetime = parser.parse(str(rid))
     self.failUnless(str(rid).endswith('Z'))
     start = self._events[1].decoded('dtstart')
     self.failUnless(start)
     if start.tzinfo is None:
         tzinfo = tz.gettz(
             self._events[1]['dtstart'].params['TZID'])
         start = datetime(start.year, start.month, start.day,
             start.hour, start.minute, start.second,
             start.microsecond, tzinfo)
     rrulestr = str(self._events[1].get('RRULE'))
     self.failUnless(rrulestr)
     r = rrule.rrulestr(rrulestr, dtstart=start)
     self.failUnless(riddatetime in r)
示例#4
0
def vDDDToDatetime(v, timezones):
    """
    Convert a vDDDType to a datetime, respecting timezones.

    @param v: the time to convert
    @type  v: L{icalendar.prop.vDDDTypes}

    @param timezones: Defined timezones in the calendar

    """
    if v is None:
        return None
    dt = _toDateTime(v.dt)
    if dt.tzinfo is None:
        # We might have a "floating" DATE-TIME value here, in
        # which case we will not have a TZID parameter; see
        # 4.3.5, FORM #3
        tzid = v.params.get('TZID')
        if tzid is None:
            timezone = tz.LOCAL
        else:
            # If the timezone is not in the calendar, try one last time
            # with the system's timezones
            timezone = timezones.get(tzid, tz.gettz(tzid))
            if timezone is None:
                raise NotCompilantError("You are trying to use a timezone\
                    that is not defined in this calendar")
            elif isinstance(timezone, tz.DSTTimezone):
                timezone = timezone.copy()
        dt = datetime.datetime(dt.year, dt.month, dt.day, dt.hour, dt.minute,
                               dt.second, dt.microsecond, timezone)
    return dt
 def testExDate(self):
     TZMADRID = tz.gettz('Europe/Madrid')
     start = datetime(2007, 11, 1, 0, 0, 0, 0, TZMADRID)
     end = datetime(2008, 1, 1, 0, 0, 0, 0, TZMADRID)
     calendar = eventcalendar.fromFile(open(self._path, 'r'))
     sets = calendar._eventSets.values()
     self.assertEquals(len(sets), 1)
     set = sets[0]
     self.assertEquals(set.uid, '*****@*****.**')
     points = set.getPoints(start, end - start)
     self.assertEquals(len(points), 44)
     exdatetime = datetime(2007, 11, 12, 20, 0, 0, 0, TZMADRID)
     for p in points:
         self.assertNotEquals(p.dt, exdatetime)
 def testExDate(self):
     TZMADRID = tz.gettz('Europe/Madrid')
     start = datetime(2007, 11, 1, 0, 0, 0, 0, TZMADRID)
     end = datetime(2008, 1, 1, 0, 0, 0, 0, TZMADRID)
     calendar = eventcalendar.fromFile(open(self._path, 'r'))
     sets = calendar._eventSets.values()
     self.assertEquals(len(sets), 1)
     set = sets[0]
     self.assertEquals(set.uid, '*****@*****.**')
     points = set.getPoints(start, end - start)
     self.assertEquals(len(points), 44)
     exdatetime = datetime(2007, 11, 12, 20, 0, 0, 0, TZMADRID)
     for p in points:
         self.assertNotEquals(p.dt, exdatetime)
 def testRecurrenceId(self):
     rid = self._events[0].get('RECURRENCE-ID')
     self.failUnless(rid)
     riddatetime = parser.parse(str(rid))
     self.failUnless(str(rid).endswith('Z'))
     start = self._events[1].decoded('dtstart')
     self.failUnless(start)
     if start.tzinfo is None:
         tzinfo = tz.gettz(self._events[1]['dtstart'].params['TZID'])
         start = datetime(start.year, start.month, start.day, start.hour,
                          start.minute, start.second, start.microsecond,
                          tzinfo)
     rrulestr = str(self._events[1].get('RRULE'))
     self.failUnless(rrulestr)
     r = rrule.rrulestr(rrulestr, dtstart=start)
     self.failUnless(riddatetime in r)
 def testRecurrenceId(self):
     rid = self._events[0].get("RECURRENCE-ID")
     self.failUnless(rid)
     riddatetime = parser.parse(str(rid))
     self.failUnless(str(rid).endswith("Z"))
     start = self._events[1].decoded("dtstart")
     self.failUnless(start)
     if start.tzinfo is None:
         tzinfo = tz.gettz(self._events[1]["dtstart"].params["TZID"])
         start = datetime(
             start.year, start.month, start.day, start.hour, start.minute, start.second, start.microsecond, tzinfo
         )
     rrulestr = str(self._events[1].get("RRULE"))
     self.failUnless(rrulestr)
     r = rrule.rrulestr(rrulestr, dtstart=start)
     self.failUnless(riddatetime in r)
 def testGetPoints(self):
     start = datetime(2007, 12, 22, 9, 0, 0, 0, LOCAL)
     end = datetime(2007, 12, 22, 11, 0, 0, 0, LOCAL)
     eventSet1 = eventcalendar.EventSet('uid1')
     eventSet2 = eventcalendar.EventSet('uid2')
     event1 = eventcalendar.Event('uid1', start, end, 'content')
     eventSet1.addEvent(event1)
     event2 = eventcalendar.Event('uid2', start, end, 'content')
     eventSet2.addEvent(event2)
     rid = self._events[0].get('RECURRENCE-ID')
     self.failUnless(rid)
     riddatetime = parser.parse(str(rid))
     self.failUnless(str(rid).endswith('Z'))
     start = self._events[1].decoded('dtstart')
     self.failUnless(start)
     if start.tzinfo is None:
         tzinfo = tz.gettz(self._events[1]['dtstart'].params['TZID'])
         start = datetime(start.year, start.month, start.day, start.hour,
                          start.minute, start.second, start.microsecond,
                          tzinfo)
     rrulestr = str(self._events[1].get('RRULE'))
     self.failUnless(rrulestr)
     r = rrule.rrulestr(rrulestr, dtstart=start)
     self.failUnless(riddatetime in r)
 def testGetPoints(self):
     start = datetime(2007, 12, 22, 9, 0, 0, 0, LOCAL)
     end = datetime(2007, 12, 22, 11, 0, 0, 0, LOCAL)
     eventSet1 = eventcalendar.EventSet("uid1")
     eventSet2 = eventcalendar.EventSet("uid2")
     event1 = eventcalendar.Event("uid1", start, end, "content")
     eventSet1.addEvent(event1)
     event2 = eventcalendar.Event("uid2", start, end, "content")
     eventSet2.addEvent(event2)
     rid = self._events[0].get("RECURRENCE-ID")
     self.failUnless(rid)
     riddatetime = parser.parse(str(rid))
     self.failUnless(str(rid).endswith("Z"))
     start = self._events[1].decoded("dtstart")
     self.failUnless(start)
     if start.tzinfo is None:
         tzinfo = tz.gettz(self._events[1]["dtstart"].params["TZID"])
         start = datetime(
             start.year, start.month, start.day, start.hour, start.minute, start.second, start.microsecond, tzinfo
         )
     rrulestr = str(self._events[1].get("RRULE"))
     self.failUnless(rrulestr)
     r = rrule.rrulestr(rrulestr, dtstart=start)
     self.failUnless(riddatetime in r)