def test_isStandardTimezone(self): """ L{TimezoneDatabase.isStandardTimezone} returns correct result when the database cache is initially empty. """ data = ( ("America/New_York", True), ("America/Los_Angeles", True), ("America/Cupertino", False), ("America/FooBar", False), ) TimezoneDatabase.getTimezoneDatabase().clear() # Do twice to excersise the cache for _ in range(2): for tzid, result in data: self.assertEqual(TimezoneDatabase.isStandardTimezone(tzid), result, "Failed {}".format(tzid)) self.assertTrue("America/New_York" in TimezoneDatabase.getTimezoneDatabase().stdtzcache) self.assertTrue("America/Los_Angeles" in TimezoneDatabase.getTimezoneDatabase().stdtzcache) self.assertFalse("America/Cupertino" in TimezoneDatabase.getTimezoneDatabase().stdtzcache) self.assertFalse("America/FooBar" in TimezoneDatabase.getTimezoneDatabase().stdtzcache) self.assertFalse("America/New_York" in TimezoneDatabase.getTimezoneDatabase().notstdtzcache) self.assertFalse("America/Los_Angeles" in TimezoneDatabase.getTimezoneDatabase().notstdtzcache) self.assertTrue("America/Cupertino" in TimezoneDatabase.getTimezoneDatabase().notstdtzcache) self.assertTrue("America/FooBar" in TimezoneDatabase.getTimezoneDatabase().notstdtzcache)
def test_isStandardTimezone(self): """ L{TimezoneDatabase.isStandardTimezone} returns correct result. """ data = ( ("America/New_York", True), ("America/Los_Angeles", True), ("America/Cupertino", False), ("America/FooBar", False), ) for tzid, result in data: self.assertEqual(TimezoneDatabase.isStandardTimezone(tzid), result, "Failed {}".format(tzid))
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 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)