Python pytz.country_timezones() Examples

The following are 6 code examples of pytz.country_timezones(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module pytz , or try the search function .
Example #1
Source File: timezone.py    From SML-Cogs with MIT License 7 votes vote down vote up
def timezone_country(self, ctx, country):
        """Commonly used timezones with ISO 3166 country codes.

        Example:
        [p]timezone country nz
        """
        timezones = pytz.country_timezones(country)
        if not len(timezones):
            await self.bot.say(
                "{} does not appear to be a "
                "valid ISO 3166 country code.".format(country))
            return
        name = pytz.country_names[country]
        await self.bot.say(
            "Commonly used timezones in {}: {}.".format(
                name, ", ".join(timezones))) 
Example #2
Source File: base.py    From PySIGNFe with GNU Lesser General Public License v2.1 6 votes vote down vote up
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') 
Example #3
Source File: forms.py    From allura with Apache License 2.0 6 votes vote down vote up
def resources(self):
        def _append(x, y):
            return x + y

        yield ew.JSScript('''
var $allTimezones = $("#tz").clone();
var $t = {};
''' +
                          reduce(_append, [
                              '$t["' + el + '"] = ' + str([name.encode('utf-8')
                                                           for name in country_timezones[el]]) + ";\n"
                              for el in country_timezones]) + '''
function selectTimezone($country){
     if($country == " "){
         $("#tz").replaceWith($allTimezones);
     }
     else{
         $("#tz option:gt(0)").remove();
         $.each($t[$country], function(index, value){
             $("#tz").append($("<option></option>").attr("value", value).text(value))
         })
     }
}''') 
Example #4
Source File: timestamp.py    From recsys2019 with Apache License 2.0 5 votes vote down vote up
def convert_dt_to_timezone(row):
    try:
        timezone = pytz.country_timezones[row["platform"]]
    except:
        timezone = [timezones[row["platform"]]]
    return row["datetime"].to(timezone[0]) 
Example #5
Source File: utils.py    From esdc-ce with Apache License 2.0 5 votes vote down vote up
def get_time_zone(country_code):
    """
    Return time zone for country.
    """
    try:
        return country_timezones[country_code][0]
    except KeyError:
        return None 
Example #6
Source File: __init__.py    From Greynir with GNU General Public License v3.0 5 votes vote down vote up
def timezone4loc(loc, fallback=None):
    """ Returns timezone string given a tuple of coordinates. 
        Fallback argument should be an ISO country code."""
    if loc:
        return tzwhere_singleton().tzNameAt(loc[0], loc[1], forceTZ=True)
    if fallback and fallback in country_timezones:
        return country_timezones[fallback][0]
    return None