예제 #1
0
    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
예제 #2
0
    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
예제 #3
0
    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)
예제 #4
0
    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)
예제 #5
0
    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)