本文整理汇总了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
示例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)
示例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
示例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)
示例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)
示例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)
示例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)
示例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)
示例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)
示例10: _timezones
# 需要导入模块: import pytz [as 别名]
# 或者: from pytz import common_timezones [as 别名]
def _timezones():
return [(tz, tz) for tz in common_timezones][::-1]
示例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
示例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
示例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)
示例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)
示例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]))