def stripStandardTimezones(self): """ Remove VTIMEZONE components from this L{Calendar} if the corresponding TZIDs are in the timezone database. @return: L{True} if changes were made, L{False} otherwise @rtype: L{bool} """ from pycalendar.timezonedb import TimezoneDatabase changed = False for component in self.getComponents(definitions.cICalComponent_VTIMEZONE): tz = TimezoneDatabase.getTimezone(component.getID()) if tz is not None and TimezoneDatabase.isStandardTimezone(component.getID()): self.removeComponent(component) changed = True return changed
def test_getTimezone(self): """ L{TimezoneDatabase.getTimezone} returns correct result. """ data = ( ("America/New_York", True), ("America/Los_Angeles", True), ("America/Cupertino", True), ("America/FooBar", False), ) for tzid, result in data: tz = TimezoneDatabase.getTimezone(tzid) if result: self.assertTrue(tz is not None) self.assertEqual(tz.getID(), tzid) else: self.assertTrue(tz is None)
def includeMissingTimezones(self, includeTimezones=None): """ For each timezone referenced in this L{Calendar}, if the corresponding VTIMEZONE component is not present, then add the matching component from the timezone database. L{includeTimezones} indicates what set of timezones should be automatically included. If set to L{None} the default is L{Calendar.NO_TIMEZONES}. Otherwise, one of L{Calendar.ALL_TIMEZONES}, L{Calendar.NONSTD_TIMEZONES}, or L{Calendar.NO_TIMEZONES} must be used. @param includeTimezones: indicated whether all, only non-standard or no timezones are included @type includeTimezones: L{int} or L{None} """ # Don't add anything in this case if includeTimezones == Calendar.NO_TIMEZONES: return if includeTimezones is None: includeTimezones = Calendar.NONSTD_TIMEZONES # Get timezone names from each component tzids = set() for component in self.mComponents: if component.getType() != definitions.cICalComponent_VTIMEZONE: component.getTimezones(tzids) # Make sure each timezone is in current calendar from pycalendar.timezonedb import TimezoneDatabase for tzid in tzids: # Skip standard timezones if requested if includeTimezones == Calendar.NONSTD_TIMEZONES and TimezoneDatabase.isStandardTimezone( tzid): continue tz = self.getTimezone(tzid) if tz is None: # Find it in the static object tz = TimezoneDatabase.getTimezone(tzid) if tz is not None: dup = tz.duplicate() self.addComponent(dup)
def includeMissingTimezones(self, includeTimezones=None): """ For each timezone referenced in this L{Calendar}, if the corresponding VTIMEZONE component is not present, then add the matching component from the timezone database. L{includeTimezones} indicates what set of timezones should be automatically included. If set to L{None} the default is L{Calendar.NO_TIMEZONES}. Otherwise, one of L{Calendar.ALL_TIMEZONES}, L{Calendar.NONSTD_TIMEZONES}, or L{Calendar.NO_TIMEZONES} must be used. @param includeTimezones: indicated whether all, only non-standard or no timezones are included @type includeTimezones: L{int} or L{None} """ # Don't add anything in this case if includeTimezones == Calendar.NO_TIMEZONES: return if includeTimezones is None: includeTimezones = Calendar.NONSTD_TIMEZONES # Get timezone names from each component tzids = set() for component in self.mComponents: if component.getType() != definitions.cICalComponent_VTIMEZONE: component.getTimezones(tzids) # Make sure each timezone is in current calendar from pycalendar.timezonedb import TimezoneDatabase for tzid in tzids: # Skip standard timezones if requested if includeTimezones == Calendar.NONSTD_TIMEZONES and TimezoneDatabase.isStandardTimezone(tzid): continue tz = self.getTimezone(tzid) if tz is None: # Find it in the static object tz = TimezoneDatabase.getTimezone(tzid) if tz is not None: dup = tz.duplicate() self.addComponent(dup)