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


Python pytz.all_timezones方法代码示例

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


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

示例1: parse_timezone

# 需要导入模块: import pytz [as 别名]
# 或者: from pytz import all_timezones [as 别名]
def parse_timezone(tzname, default=None):
    if tzname:
        # accept valid pytz names like US/Pacific
        try:
            return pytz_timezone(tzname)
        except UnknownTimeZoneError:
            pass
        # else check if it is a short name
        for zone in all_timezones:
            if tzname == zone.split('/')[-1]:
                return pytz_timezone(zone)
        # else check if it is one of out Timezone
        try:
            tz = TimeZone.objects.get(time_zone=tzname)
            return timezone(timedelta(seconds=tz.tzoffset))
        except TimeZone.DoesNotExist:
            pass

        logging.error('Unknown timezone {}'.format(tzname))
    if default:
        return pytz_timezone(default)
    return None 
开发者ID:opentaps,项目名称:opentaps_seas,代码行数:24,代码来源:utils.py

示例2: get_timezones_within_current_local_time_bounds

# 需要导入模块: import pytz [as 别名]
# 或者: from pytz import all_timezones [as 别名]
def get_timezones_within_current_local_time_bounds(start_hour, end_hour, isoweekdays=None):
    """Get a list of all timezone names whose current local time is within `start_hour` and `end_hour`

    If `isoweekdays` specified, also checks that it falls on one of the days of the week (Monday = 1, Sunday = 7)

    `start_hour` and `end_hour` are naive times
    """
    all_timezones = pytz.all_timezones
    timezone_names = []
    now = utcnow()
    def _is_within_time_bounds(tz_name):
        tz = pytz.timezone(tz_name)
        tz_datetime = now.astimezone(tz)
        result = start_hour <= tz_datetime.hour < end_hour and (isoweekdays is None or now.isoweekday() in isoweekdays)
        return result
    timezone_names = filter(_is_within_time_bounds, all_timezones)
    return timezone_names 
开发者ID:hacktoolkit,项目名称:django-htk,代码行数:19,代码来源:datetime_utils.py

示例3: update

# 需要导入模块: import pytz [as 别名]
# 或者: from pytz import all_timezones [as 别名]
def update(self, instance, validated_data):
        user_data = validated_data.pop('user')
        user = instance.user

        for key, value in user_data.iteritems():
            if key == 'password':
                raise serializers.ValidationError({'password': 'You do not have permission to perform this action'})

            if hasattr(user, key):
                setattr(user, key, value)

        timezone = validated_data.get('timezone', instance.timezone)
        if timezone not in pytz.all_timezones:
            # to avoid deadlock
            if instance.timezone not in pytz.all_timezones:
                instance.timezone = 'UTC'
                instance.save()
            raise serializers.ValidationError({'timezone': ['Not a valid choice.']})

        instance.timezone = timezone
        instance.save()

        user.save()
        return instance 
开发者ID:StamusNetworks,项目名称:scirius,代码行数:26,代码来源:rest_api.py

示例4: timezone

# 需要导入模块: import pytz [as 别名]
# 或者: from pytz import all_timezones [as 别名]
def timezone(self, ctx: commands.Context, timezone: str):
        """
        Set a timezone
        """

        if timezone not in pytz.all_timezones:
            matches = get_close_matches(timezone, pytz.all_timezones)
            if len(matches) > 0:
                embed = discord.Embed()
                embed.color = 0xeb3446
                embed.description = f"Did you mean: \n`{'`, `'.join(matches)}`"
                await ctx.send(embed=embed)
                return
            else:
                await ctx.send("Couldn't find the timezone.")
                return

        self.timezone = timezone
        await self._update_config()
        await ctx.send("Done")
        return 
开发者ID:officialpiyush,项目名称:modmail-plugins,代码行数:23,代码来源:birthday.py

示例5: possible_timezones

# 需要导入模块: import pytz [as 别名]
# 或者: from pytz import all_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

示例6: user_profile_page

# 需要导入模块: import pytz [as 别名]
# 或者: from pytz import all_timezones [as 别名]
def user_profile_page():
    the_tz = current_user.timezone if current_user.timezone else get_default_timezone()
    if current_user.social_id and current_user.social_id.startswith('phone$'):
        form = PhoneUserProfileForm(request.form, obj=current_user)
    else:
        form = UserProfileForm(request.form, obj=current_user)
    form.timezone.choices = [(x, x) for x in sorted([tz for tz in pytz.all_timezones])]
    form.timezone.default = the_tz
    if str(form.timezone.data) == 'None' or str(form.timezone.data) == '':
        form.timezone.data = the_tz
    if request.method == 'POST' and form.validate():
        form.populate_obj(current_user)
        db.session.commit()
        #docassemble.webapp.daredis.clear_user_cache()
        flash(word('Your information was saved.'), 'success')
        return redirect(url_for('interview_list'))
    response = make_response(render_template('users/user_profile_page.html', version_warning=None, page_title=word('User Profile'), tab_title=word('User Profile'), form=form, debug=debug_status()), 200)
    response.headers['Cache-Control'] = 'no-store, no-cache, must-revalidate, post-check=0, pre-check=0, max-age=0'
    return response 
开发者ID:jhpyle,项目名称:docassemble,代码行数:21,代码来源:views.py

示例7: __init__

# 需要导入模块: import pytz [as 别名]
# 或者: from pytz import all_timezones [as 别名]
def __init__(self, context=None, logger=None):
        """
        Initializes the instance
        :param context: Lambda context
        :param logger: Optional logger for warnings, if None then warnings are printed to console
        """
        self._logger = logger
        self._this_account = None
        self._context = context
        self._all_timezones = {tz.lower(): tz for tz in pytz.all_timezones}
        self._all_actions = actions.all_actions()
        self._s3_client = None
        self._s3_configured_cross_account_roles = None
        self._ssm_client = None 
开发者ID:awslabs,项目名称:aws-ops-automator,代码行数:16,代码来源:task_configuration.py

示例8: get_timezone

# 需要导入模块: import pytz [as 别名]
# 或者: from pytz import all_timezones [as 别名]
def get_timezone(tz):
	"""
	Look up a timezone by name, case-insensitively
	"""
	try:
		return pytz.timezone(tz)
	except pytz.exceptions.UnknownTimeZoneError:
		tznames = {i.lower(): i for i in pytz.all_timezones}
		tz = tz.lower()
		if tz in tznames:
			return pytz.timezone(tznames[tz])
		else:
			raise 
开发者ID:mrphlip,项目名称:lrrbot,代码行数:15,代码来源:time.py

示例9: testRoundtrip

# 需要导入模块: import pytz [as 别名]
# 或者: from pytz import all_timezones [as 别名]
def testRoundtrip(self):
        dt = datetime(2004, 2, 1, 0, 0, 0)
        for zone in pytz.all_timezones:
            tz = pytz.timezone(zone)
            self._roundtrip_tzinfo(tz) 
开发者ID:Schibum,项目名称:sndlatr,代码行数:7,代码来源:test_tzinfo.py

示例10: timezones

# 需要导入模块: import pytz [as 别名]
# 或者: from pytz import all_timezones [as 别名]
def timezones(self, request, pk=None):
        """List all accepted timezones"""
        return Response(self.get_serializer({'all_timezones': pytz.all_timezones}).data) 
开发者ID:yunity,项目名称:karrot-backend,代码行数:5,代码来源:api.py

示例11: allTimeZones

# 需要导入模块: import pytz [as 别名]
# 或者: from pytz import all_timezones [as 别名]
def allTimeZones(self):
        for tz in all_timezones:
            self.scr.insert(tk.INSERT, tz + '\n')

    # TZ Local Button callback 
开发者ID:PacktPublishing,项目名称:Python-GUI-Programming-Cookbook-Second-Edition,代码行数:7,代码来源:GUI.py

示例12: allTimeZones

# 需要导入模块: import pytz [as 别名]
# 或者: from pytz import all_timezones [as 别名]
def allTimeZones(self):
        for tz in all_timezones:
            self.oop.scr.insert(tk.INSERT, tz + '\n')

    # TZ Local Button callback 
开发者ID:PacktPublishing,项目名称:Python-GUI-Programming-Cookbook-Second-Edition,代码行数:7,代码来源:Callbacks_Refactored.py

示例13: get_all_timezones

# 需要导入模块: import pytz [as 别名]
# 或者: from pytz import all_timezones [as 别名]
def get_all_timezones() -> List[str]:
    return sorted(pytz.all_timezones) 
开发者ID:zulip,项目名称:zulip,代码行数:4,代码来源:timezone.py

示例14: _calculate_timezones

# 需要导入模块: import pytz [as 别名]
# 或者: from pytz import all_timezones [as 别名]
def _calculate_timezones() -> Dict[str, Union[int, Any]]:
    tzdata = {}
    normal = datetime.datetime(2009, 9, 1)  # Any random date is fine here.
    for str in pytz.all_timezones:
        tz = pytz.timezone(str)
        timedelta = tz.utcoffset(normal)
        if not timedelta:
            continue
        offset = timedelta.seconds
        tz_name = tz.tzname(normal)
        tzdata[tz_name] = offset
        # Handle known duplicates/exceptions.
        # IST: Asia/Kolkata and Europe/Dublin.
        if tz_name == 'IST':
            tzdata[tz_name] = 19800  # Asia/Kolkata
        # CDT: America/AlmostAll and America/Havana.
        if tz_name == 'CDT':
            tzdata[tz_name] = -68400  # America/AlmostAll
        # CST America/Belize -64800
        # CST America/Costa_Rica -64800
        # CST America/El_Salvador -64800
        # CST America/Guatemala -64800
        # CST America/Managua -64800
        # CST America/Regina -64800
        # CST America/Swift_Current -64800
        # CST America/Tegucigalpa -64800
        # CST Asia/Macau 28800
        # CST Asia/Shanghai 28800
        # CST Asia/Taipei 28800
        if tz_name == 'CST':
            tzdata[tz_name] = -64800  # America/All
    return tzdata 
开发者ID:zulip,项目名称:zulip,代码行数:34,代码来源:timezone.py

示例15: _tz_get

# 需要导入模块: import pytz [as 别名]
# 或者: from pytz import all_timezones [as 别名]
def _tz_get(self):
    # put POSIX 'Etc/*' entries at the end to avoid confusing users - see bug 1086728
    return [(tz,tz) for tz in sorted(pytz.all_timezones, key=lambda tz: tz if not tz.startswith('Etc/') else '_')] 
开发者ID:vertelab,项目名称:odoo-payroll,代码行数:5,代码来源:resource.py


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