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

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

项目:true_review    作者:lucadealfaro    | 项目源码 | 文件源码
def set_timezone():
    """Ajax call to set the timezone information for the session."""
    tz_name = request.vars.name
    # Validates the name.
    from pytz import all_timezones_set
    if tz_name in all_timezones_set:
        session.user_timezone = tz_name
        # If the user is logged in, sets also the timezone for the user.
        # Otherwise, it can happen that a user expires a cookie, then click on edit.
        # When the user is presented the edit page, the translation is done according to UTC,
        # but when the user is done editing, due to autodetection, the user is then in
        # it's own time zone, and the dates of an assignment change.
        # This really happened.
        if auth.user is not None:
            db.auth_user[auth.user.id] = dict(user_timezone = tz_name)
        logger.info("Set timezone to: %r" % tz_name)
    else:
        logger.warning("Invalid timezone received: %r" % tz_name)
项目:true_review    作者:lucadealfaro    | 项目源码 | 文件源码
def set_timezone():
    """Ajax call to set the timezone information for the session."""
    tz_name = request.vars.name
    # Validates the name.
    from pytz import all_timezones_set
    if tz_name in all_timezones_set:
        session.user_timezone = tz_name
        # If the user is logged in, sets also the timezone for the user.
        # Otherwise, it can happen that a user expires a cookie, then click on edit.
        # When the user is presented the edit page, the translation is done according to UTC,
        # but when the user is done editing, due to autodetection, the user is then in
        # it's own time zone, and the dates of an assignment change.
        # This really happened.
        if auth.user is not None:
            db.auth_user[auth.user.id] = dict(user_timezone = tz_name)
        logger.info("Set timezone to: %r" % tz_name)
    else:
        logger.warning("Invalid timezone received: %r" % tz_name)

# TODO: use vue.js
项目:trustedsleepbot    作者:gumblex    | 项目源码 | 文件源码
def cmd_time(expr, chatid, replyid, msg):
    '''/time - Get time for various timezones'''
    tzs = list(filter(lambda x: x in pytz.all_timezones_set, expr.split()))
    if not tzs:
        if chatid > 0:
            tzs = [USER_CACHE[msg['from']['id']]['timezone']]
        else:
            tzs = [row[0] for row in CONN.execute(
                'SELECT users.timezone FROM users'
                ' INNER JOIN user_chats ON users.id = user_chats.user'
                ' WHERE user_chats.chat = ? GROUP BY users.timezone'
                ' ORDER BY count(users.timezone) DESC, users.timezone ASC',
                (msg['chat']['id'],))]
    if tzs:
        text = [_('The time is:')]
        for tz in tzs:
            usertime = datetime.datetime.now(pytz.timezone(tz))
            text.append(' '.join((
               '??' if tz_is_day(usertime, tz) else '??',
                usertime.strftime('%H:%M'), tz
            )))
        sendmsg('\n'.join(text), chatid, replyid)
    else:
        sendmsg(_("No timezone specified."), chatid, replyid)
项目:sndlatr    作者:Schibum    | 项目源码 | 文件源码
def test_belfast(self):
        # Belfast uses London time.
        self.assertTrue('Europe/Belfast' in pytz.all_timezones_set)
        self.assertFalse('Europe/Belfast' in pytz.common_timezones)
        self.assertFalse('Europe/Belfast' in pytz.common_timezones_set)
项目:arisu    作者:Appleman1234    | 项目源码 | 文件源码
def find_tz(self,place):
        for x in pytz.all_timezones_set:
            if place in x:
                return x
        return None
项目:epg-dk.bundle    作者:ukdtom    | 项目源码 | 文件源码
def test_belfast(self):
        # Belfast uses London time.
        self.assertTrue('Europe/Belfast' in pytz.all_timezones_set)
        self.assertFalse('Europe/Belfast' in pytz.common_timezones)
        self.assertFalse('Europe/Belfast' in pytz.common_timezones_set)
项目:respeaker_virtualenv    作者:respeaker    | 项目源码 | 文件源码
def _get_localzone():
    pipe = subprocess.Popen(
        "systemsetup -gettimezone",
        shell=True,
        stderr=subprocess.PIPE,
        stdout=subprocess.PIPE
    )
    tzname = pipe.stdout.read().replace(b'Time Zone: ', b'').strip()

    if not tzname or tzname not in pytz.all_timezones_set:
        # link will be something like /usr/share/zoneinfo/America/Los_Angeles.
        link = os.readlink("/etc/localtime")
        tzname = link[link.rfind("zoneinfo/") + 9:]
    return pytz.timezone(tzname)
项目:start    作者:argeweb    | 项目源码 | 文件源码
def test_belfast(self):
        # Belfast uses London time.
        self.assertTrue('Europe/Belfast' in pytz.all_timezones_set)
        self.assertFalse('Europe/Belfast' in pytz.common_timezones)
        self.assertFalse('Europe/Belfast' in pytz.common_timezones_set)
项目:alexa-apple-calendar    作者:zanderxyz    | 项目源码 | 文件源码
def _get_localzone():
    pipe = subprocess.Popen(
        "systemsetup -gettimezone",
        shell=True,
        stderr=subprocess.PIPE,
        stdout=subprocess.PIPE
    )
    tzname = pipe.stdout.read().replace(b'Time Zone: ', b'').strip()

    if not tzname or tzname not in pytz.all_timezones_set:
        # link will be something like /usr/share/zoneinfo/America/Los_Angeles.
        link = os.readlink("/etc/localtime")
        tzname = link[link.rfind("zoneinfo/") + 9:]
    return pytz.timezone(tzname)
项目:metrics    作者:Jeremy-Friedman    | 项目源码 | 文件源码
def _get_localzone():
    pipe = subprocess.Popen(
        "systemsetup -gettimezone",
        shell=True,
        stderr=subprocess.PIPE,
        stdout=subprocess.PIPE
    )
    tzname = pipe.stdout.read().replace(b'Time Zone: ', b'').strip()

    if not tzname or tzname not in pytz.all_timezones_set:
        # link will be something like /usr/share/zoneinfo/America/Los_Angeles.
        link = os.readlink("/etc/localtime")
        tzname = link[link.rfind("zoneinfo/") + 9:]
    return pytz.timezone(tzname)
项目:metrics    作者:Jeremy-Friedman    | 项目源码 | 文件源码
def _get_localzone():
    pipe = subprocess.Popen(
        "systemsetup -gettimezone",
        shell=True,
        stderr=subprocess.PIPE,
        stdout=subprocess.PIPE
    )
    tzname = pipe.stdout.read().replace(b'Time Zone: ', b'').strip()

    if not tzname or tzname not in pytz.all_timezones_set:
        # link will be something like /usr/share/zoneinfo/America/Los_Angeles.
        link = os.readlink("/etc/localtime")
        tzname = link[link.rfind("zoneinfo/") + 9:]
    return pytz.timezone(tzname)
项目:cloud-memory    作者:onejgordon    | 项目源码 | 文件源码
def test_belfast(self):
        # Belfast uses London time.
        self.assertTrue('Europe/Belfast' in pytz.all_timezones_set)
        self.assertFalse('Europe/Belfast' in pytz.common_timezones)
        self.assertFalse('Europe/Belfast' in pytz.common_timezones_set)
项目:FMoviesPlus.bundle    作者:coder-alpha    | 项目源码 | 文件源码
def _get_localzone(_root='/'):
    with Popen(
        "systemsetup -gettimezone",
        shell=True,
        stderr=subprocess.PIPE,
        stdout=subprocess.PIPE
    ) as pipe:
        tzname = pipe.stdout.read().replace(b'Time Zone: ', b'').strip()

    if not tzname or tzname not in pytz.all_timezones_set:
        # link will be something like /usr/share/zoneinfo/America/Los_Angeles.
        link = os.readlink(os.path.join(_root, "etc/localtime"))
        tzname = link[link.rfind("zoneinfo/") + 9:]

    return pytz.timezone(tzname)
项目:FMoviesPlus.bundle    作者:coder-alpha    | 项目源码 | 文件源码
def test_belfast(self):
        # Belfast uses London time.
        self.assertTrue('Europe/Belfast' in pytz.all_timezones_set)
        self.assertFalse('Europe/Belfast' in pytz.common_timezones)
        self.assertFalse('Europe/Belfast' in pytz.common_timezones_set)
项目:trustedsleepbot    作者:gumblex    | 项目源码 | 文件源码
def cmd_settz(expr, chatid, replyid, msg):
    '''/settz - Set your timezone'''
    if expr and expr in pytz.all_timezones_set:
        update_user(msg['from'], timezone=expr)
        sendmsg(_("Your timezone is %s now.") % expr, chatid, replyid)
    else:
        try:
            current = USER_CACHE[msg['from']['id']]['timezone']
        except KeyError:
            current = CFG['defaulttz']
        sendmsg(_("Invalid timezone. Your current timezone is %s.") % current, chatid, replyid)
项目:pyfiddleio    作者:priyankcommits    | 项目源码 | 文件源码
def test_belfast(self):
        # Belfast uses London time.
        self.assertTrue('Europe/Belfast' in pytz.all_timezones_set)
        self.assertFalse('Europe/Belfast' in pytz.common_timezones)
        self.assertFalse('Europe/Belfast' in pytz.common_timezones_set)
项目:LSTM-GA-StockTrader    作者:MartinLidy    | 项目源码 | 文件源码
def test_belfast(self):
        # Belfast uses London time.
        self.assertTrue('Europe/Belfast' in pytz.all_timezones_set)
        self.assertFalse('Europe/Belfast' in pytz.common_timezones)
        self.assertFalse('Europe/Belfast' in pytz.common_timezones_set)
项目:Alfred    作者:jkachhadia    | 项目源码 | 文件源码
def _get_localzone():
    pipe = subprocess.Popen(
        "systemsetup -gettimezone",
        shell=True,
        stderr=subprocess.PIPE,
        stdout=subprocess.PIPE
    )
    tzname = pipe.stdout.read().replace(b'Time Zone: ', b'').strip()

    if not tzname or tzname not in pytz.all_timezones_set:
        # link will be something like /usr/share/zoneinfo/America/Los_Angeles.
        link = os.readlink("/etc/localtime")
        tzname = link[link.rfind("zoneinfo/") + 9:]
    return pytz.timezone(tzname)