Python pytz 模块,country_timezones() 实例源码

我们从Python开源项目中,提取了以下4个代码示例,用于说明如何使用pytz.country_timezones()

项目:PySIGNFe    作者:thiagopena    | 项目源码 | 文件源码
def set_fuso_horaro(self, novo_valor):
        if novo_valor in pytz.country_timezones['br']:
            self._fuso_horario = pytz.timezone(novo_valor)

        #
        # Nos valores abaixo, não entendi ainda até agora, mas para o resultado
        # correto é preciso usar GMT+ (mais), não (menos) como seria de se
        # esperar...
        #
        elif novo_valor == '-04:00' or novo_valor == '-0400':
            self._fuso_horario = pytz.timezone('Etc/GMT+4')
        elif novo_valor == '-03:00' or novo_valor == '-0300':
            self._fuso_horario = pytz.timezone('Etc/GMT+3')
        elif novo_valor == '-02:00' or novo_valor == '-0200':
            self._fuso_horario = pytz.timezone('Etc/GMT+2')
        elif novo_valor == '-01:00' or novo_valor == '-0100':
            self._fuso_horario = pytz.timezone('Etc/GMT+1')
项目:MultiMAuS    作者:lmzintgraf    | 项目源码 | 文件源码
def get_local_datetime(self):
        # convert global to local date (first add global timezone info, then convert to local)
        local_datetime = self.model.curr_global_date
        local_datetime = local_datetime.astimezone(timezone(country_timezones(self.country)[0]))
        return local_datetime
项目:esdc-ce    作者:erigones    | 项目源码 | 文件源码
def get_time_zone(country_code):
    """
    Return time zone for country.
    """
    try:
        return country_timezones[country_code][0]
    except KeyError:
        return None
项目:server    作者:viur-framework    | 项目源码 | 文件源码
def guessTimeZone(self):
        """
        Guess the timezone the user is supposed to be in.
        If it cant be guessed, a safe default (UTC) is used
        """
        timeZone = "UTC" # Default fallback
        try:
            # Check the local cache first
            if "timeZone" in request.current.requestData().keys():
                return( request.current.requestData()["timeZone"] )
            headers = request.current.get().request.headers
            if "X-Appengine-Country" in headers.keys():
                country = headers["X-Appengine-Country"]
            else:  # Maybe local development Server - no way to guess it here
                return( timeZone )
            tzList = pytz.country_timezones[ country ]
        except:  # Non-User generated request (deferred call; task queue etc), or no pytz
            return( timeZone )
        if len( tzList ) == 1:  # Fine - the country has exactly one timezone
            timeZone = tzList[ 0 ]
        elif country.lower()=="us":  # Fallback for the US
            timeZone = "EST"
        elif country.lower() == "de":  # For some freaking reason Germany is listed with two timezones
            timeZone = "Europe/Berlin"
        else:  # The user is in a Country which has more than one timezone
            # Fixme: Is there any equivalent of EST for australia?
            pass
        request.current.requestData()["timeZone"] = timeZone #Cache the result
        return( timeZone )