当前位置: 首页>>代码示例>>Python>>正文


Python pytz.common_timezones方法代码示例

本文整理汇总了Python中pytz.common_timezones方法的典型用法代码示例。如果您正苦于以下问题:Python pytz.common_timezones方法的具体用法?Python pytz.common_timezones怎么用?Python pytz.common_timezones使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pytz的用法示例。


在下文中一共展示了pytz.common_timezones方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: possible_timezones

# 需要导入模块: import pytz [as 别名]
# 或者: from pytz import common_timezones [as 别名]
def possible_timezones(tz_offset, common_only=True):
    # pick one of the timezone collections
    timezones = pytz.common_timezones if common_only else pytz.all_timezones

    # convert the float hours offset to a timedelta
    offset_days, offset_seconds = 0, int(tz_offset * 3600)
    if offset_seconds < 0:
        offset_days = -1
        offset_seconds += 24 * 3600
    desired_delta = dt.timedelta(offset_days, offset_seconds)

    # Loop through the timezones and find any with matching offsets
    null_delta = dt.timedelta(0, 0)
    results = []
    for tz_name in timezones:
        tz = pytz.timezone(tz_name)
        non_dst_offset = getattr(tz, '_transition_info', [[null_delta]])[-1]
        if desired_delta == non_dst_offset[0]:
            results.append(tz_name)

    return results 
开发者ID:matnad,项目名称:pollmaster,代码行数:23,代码来源:misc.py

示例2: post

# 需要导入模块: import pytz [as 别名]
# 或者: from pytz import common_timezones [as 别名]
def post(self, request, *args, **kwargs):
        config = Config.load()
        if "chime_hour" in request.POST:
            config.chime_hour = request.POST["chime_hour"] == "true"
        if "wakeup_time" in request.POST:
            (hour, min) = self.parse_time(request.POST["wakeup_time"])
            config.wakeup_hour = hour
            config.wakeup_min = min
        if "sleep_time" in request.POST:
            (hour, min) = self.parse_time(request.POST["sleep_time"])
            config.sleep_hour = hour
            config.sleep_min = min
        if "timezone" in request.POST:
            selected_tz = request.POST["timezone"]
            if selected_tz in common_timezones:
                self.set_system_tz(selected_tz)
        config.save()
        NabClockd.signal_daemon()
        context = self.get_context_data(**kwargs)
        return render(request, SettingsView.template_name, context=context) 
开发者ID:nabaztag2018,项目名称:pynab,代码行数:22,代码来源:views.py

示例3: times_from_timezone_code

# 需要导入模块: import pytz [as 别名]
# 或者: from pytz import common_timezones [as 别名]
def times_from_timezone_code(q: str, twentyfour: bool) ->  Dict[str, List[str]]:
    possibles = list(filter(lambda x: datetime.datetime.now(pytz.timezone(x)).strftime('%Z') == q.upper(), pytz.common_timezones))
    if not possibles:
        raise TooFewItemsException(f'Not a recognized timezone: {q.upper()}')
    results: Dict[str, List[str]] = {}
    for possible in possibles:
        timezone = dtutil.timezone(possible)
        t = current_time(timezone, twentyfour)
        results[t] = results.get(t, []) + [possible]
    return results 
开发者ID:PennyDreadfulMTG,项目名称:Penny-Dreadful-Tools,代码行数:12,代码来源:fetcher.py

示例4: file

# 需要导入模块: import pytz [as 别名]
# 或者: from pytz import common_timezones [as 别名]
def file(db, c):
    # get the list of available nodes (for all companies)
    sql = """
SELECT
    nodes.id,
    nodes.name, 
    nodes.location,
    company.id,
    company.name
FROM
    nodes LEFT JOIN node_modes ON nodes.id = node_modes.node_id
    JOIN company ON nodes.company_id = company.id
WHERE
    nodes.is_local = 0
    AND ( nodes.any_mode OR node_modes.analysis_mode = %s )
ORDER BY
    company.name,
    nodes.location
"""
    c.execute(sql, (ANALYSIS_MODE_CORRELATION,))
    available_nodes = c.fetchall()
    date = datetime.datetime.now().strftime("%m-%d-%Y %H:%M:%S")
    return render_template('analysis/analyze_file.html', 
                           observable_types=VALID_OBSERVABLE_TYPES,
                           date=date, 
                           available_nodes=available_nodes,
                           timezones=pytz.common_timezones) 
开发者ID:IntegralDefense,项目名称:ACE,代码行数:29,代码来源:views.py

示例5: test_bratislava

# 需要导入模块: import pytz [as 别名]
# 或者: from pytz import common_timezones [as 别名]
def test_bratislava(self):
        # Bratislava is the default timezone for Slovakia, but our
        # heuristics where not adding it to common_timezones. Ideally,
        # common_timezones should be populated from zone.tab at runtime,
        # but I'm hesitant to pay the startup cost as loading the list
        # on demand whilst remaining backwards compatible seems
        # difficult.
        self.assertTrue('Europe/Bratislava' in pytz.common_timezones)
        self.assertTrue('Europe/Bratislava' in pytz.common_timezones_set) 
开发者ID:Schibum,项目名称:sndlatr,代码行数:11,代码来源:test_tzinfo.py

示例6: test_us_eastern

# 需要导入模块: import pytz [as 别名]
# 或者: from pytz import common_timezones [as 别名]
def test_us_eastern(self):
        self.assertTrue('US/Eastern' in pytz.common_timezones)
        self.assertTrue('US/Eastern' in pytz.common_timezones_set) 
开发者ID:Schibum,项目名称:sndlatr,代码行数:5,代码来源:test_tzinfo.py

示例7: test_belfast

# 需要导入模块: import pytz [as 别名]
# 或者: from pytz import common_timezones [as 别名]
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) 
开发者ID:Schibum,项目名称:sndlatr,代码行数:7,代码来源:test_tzinfo.py

示例8: timezones_list

# 需要导入模块: import pytz [as 别名]
# 或者: from pytz import common_timezones [as 别名]
def timezones_list(request, *args, **kw):
    context = request.context
    timezones = pytz.common_timezones

    if not request.has_perm(perm_global_list_timezones):
        raise APIError(403, "forbidden")

    ret = {
        "timezones": [{
            "name": st,
        } for st in timezones]
    }

    return r_timezonelist.output(ret) 
开发者ID:ActiDoo,项目名称:gamification-engine,代码行数:16,代码来源:__init__.py

示例9: __init__

# 需要导入模块: import pytz [as 别名]
# 或者: from pytz import common_timezones [as 别名]
def __init__(self, *args, **kwargs):

        def coerce_to_pytz(val):
            try:
                return pytz.timezone(val)
            except pytz.UnknownTimeZoneError:
                raise ValidationError("Unknown time zone: '%s'" % val)

        defaults = {
            'coerce': coerce_to_pytz,
            'choices': [(tz, tz) for tz in pytz.common_timezones],
            'empty_value': None,
        }
        defaults.update(kwargs)
        super(TimeZoneFormField, self).__init__(*args, **defaults) 
开发者ID:dkarchmer,项目名称:django-aws-template,代码行数:17,代码来源:forms.py

示例10: _timezones

# 需要导入模块: import pytz [as 别名]
# 或者: from pytz import common_timezones [as 别名]
def _timezones():
    return [(tz, tz) for tz in common_timezones][::-1] 
开发者ID:TwilioDevEd,项目名称:appointment-reminders-flask,代码行数:4,代码来源:new_appointment.py

示例11: gen_tzinfos

# 需要导入模块: import pytz [as 别名]
# 或者: from pytz import common_timezones [as 别名]
def gen_tzinfos():
    for zone in pytz.common_timezones:
        try:
            tzdate = pytz.timezone(zone).localize(dt.utcnow(), is_dst=None)
        except pytz.NonExistentTimeError:
            pass
        else:
            tzinfo = gettz(zone)

            if tzinfo:
                yield tzdate.tzname(), tzinfo 
开发者ID:nerevu,项目名称:riko,代码行数:13,代码来源:dates.py

示例12: _timezones

# 需要导入模块: import pytz [as 别名]
# 或者: from pytz import common_timezones [as 别名]
def _timezones():
    """Yield timezone name, gap to UTC and UTC
    """
    for item in pytz.common_timezones:
        dt = datetime.now(pytz.timezone(item)).strftime('%z')
        utc = '(UTC%s:%s)' % (dt[:-2], dt[-2:])
        gap = int(dt)
        yield item, gap, utc 
开发者ID:quantmind,项目名称:lux,代码行数:10,代码来源:countries.py

示例13: get_available_admin_time_zones

# 需要导入模块: import pytz [as 别名]
# 或者: from pytz import common_timezones [as 别名]
def get_available_admin_time_zones():
    return getattr(settings, 'WAGTAIL_USER_TIME_ZONES', pytz.common_timezones) 
开发者ID:wagtail,项目名称:wagtail,代码行数:4,代码来源:localization.py

示例14: test_available_admin_time_zones_by_default

# 需要导入模块: import pytz [as 别名]
# 或者: from pytz import common_timezones [as 别名]
def test_available_admin_time_zones_by_default(self):
        self.assertListEqual(get_available_admin_time_zones(), pytz.common_timezones) 
开发者ID:wagtail,项目名称:wagtail,代码行数:4,代码来源:test_account_management.py

示例15: timezones_by_offset

# 需要导入模块: import pytz [as 别名]
# 或者: from pytz import common_timezones [as 别名]
def timezones_by_offset():
    return sorted(
        ((utc_offset(tz), tz)
         for tz in pytz.common_timezones),
        key=lambda x: (offset_to_int(x[0]), x[1])) 
开发者ID:nitely,项目名称:Spirit,代码行数:7,代码来源:timezone.py


注:本文中的pytz.common_timezones方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。