Python pytz.common_timezones() Examples
The following are 28
code examples of pytz.common_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: views.py From pynab with GNU General Public License v3.0 | 6 votes |
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)
Example #2
Source File: misc.py From pollmaster with MIT License | 6 votes |
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
Example #3
Source File: 0002_create_services_and_set_timezone_enm.py From baobab with GNU General Public License v3.0 | 5 votes |
def forwards(self, orm): # create service for name, description in Service.SERVICE_CHOICES: orm.Service.objects.create(name=name, description=description) # set timezone for timezone in pytz.common_timezones: orm.TimeZoneEnum.objects.create(name=timezone) timezone_id = orm.TimeZoneEnum.objects.get(name=settings.TIME_ZONE).id for user in User.objects.all(): orm.TimeZone.objects.create( user_id=user.id, timezone_id=timezone_id, )
Example #4
Source File: views.py From pynab with GNU General Public License v3.0 | 5 votes |
def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) context["config"] = Config.load() context["timezones"] = common_timezones context["current_timezone"] = self.get_system_tz() return context
Example #5
Source File: forms.py From avos with Apache License 2.0 | 5 votes |
def _sorted_zones(): d = datetime(datetime.today().year, 1, 1) zones = [(tz, pytz.timezone(tz).localize(d).strftime('%z')) for tz in pytz.common_timezones] zones.sort(key=lambda zone: int(zone[1])) return zones
Example #6
Source File: test_choices.py From django-timezone-utils with MIT License | 5 votes |
def test_GROUPED_COMMON_TIMEZONES_CHOICES_values(self): for name, display in map( lambda v: v[0], map(lambda x: x[1], GROUPED_COMMON_TIMEZONES_CHOICES) ): self.assertIn( name, pytz.common_timezones ) self.assertIn( display, pytz.common_timezones )
Example #7
Source File: test_choices.py From django-timezone-utils with MIT License | 5 votes |
def test_PRETTY_COMMON_TIMEZONES_CHOICES_values(self): values = map(itemgetter(0), PRETTY_COMMON_TIMEZONES_CHOICES) for value in values: self.assertIn( value, pytz.common_timezones, 'The value "{0}" from PRETTY_COMMON_TIMEZONES_CHOICES was not ' 'found in pytz.common_timezones.'.format( value ) )
Example #8
Source File: test_choices.py From django-timezone-utils with MIT License | 5 votes |
def test_PRETTY_COMMON_TIMEZONES_CHOICES_length(self): self.assertEqual( len(PRETTY_COMMON_TIMEZONES_CHOICES), len(pytz.common_timezones), 'The length of PRETTY_COMMON_TIMEZONES_CHOICES does not match ' 'pytz.common_timezones.' )
Example #9
Source File: test_choices.py From django-timezone-utils with MIT License | 5 votes |
def test_COMMON_TIMEZONES_CHOICES_values(self): values = map(itemgetter(0), COMMON_TIMEZONES_CHOICES) for value in values: self.assertIn( value, pytz.common_timezones, 'The value "{0}" from COMMON_TIMEZONES_CHOICES was not found ' 'in pytz.common_timezones.'.format( value ) )
Example #10
Source File: test_choices.py From django-timezone-utils with MIT License | 5 votes |
def test_COMMON_TIMEZONES_CHOICES_length(self): self.assertEqual( len(COMMON_TIMEZONES_CHOICES), len(pytz.common_timezones), 'The length of COMMON_TIMEZONES_CHOICES does not match ' 'pytz.common_timezones.' )
Example #11
Source File: test_timezones.py From elasticintel with GNU General Public License v3.0 | 5 votes |
def test_cache_keys_are_distinct_for_pytz_vs_dateutil(self): tzs = pytz.common_timezones for tz_name in tzs: if tz_name == 'UTC': # skip utc as it's a special case in dateutil continue tz_p = timezones.maybe_get_tz(tz_name) tz_d = timezones.maybe_get_tz('dateutil/' + tz_name) if tz_d is None: # skip timezones that dateutil doesn't know about. continue assert (timezones._p_tz_cache_key(tz_p) != timezones._p_tz_cache_key(tz_d))
Example #12
Source File: account.py From tekton with MIT License | 5 votes |
def index(_logged_user): _logged_user.locale = _logged_user.locale or settings.DEFAULT_LOCALE _logged_user.timezone = _logged_user.timezone or settings.DEFAULT_TIMEZONE context = {'user': _logged_user, 'timezones': common_timezones, 'save_path': router.to_path(edit)} return TemplateResponse(context, 'permission/account_form.html')
Example #13
Source File: fields.py From travelcrm with GNU General Public License v3.0 | 5 votes |
def timezones_field( name, value=None, data_options=None, **kwargs ): _data_options="panelHeight:'120',editable:false" if data_options: _data_options += ",%s" % data_options choices = [tz for tz in common_timezones] return tags.select( name, value, choices, class_='easyui-combobox text w20', data_options=_data_options, **kwargs )
Example #14
Source File: fetcher.py From Penny-Dreadful-Tools with GNU General Public License v3.0 | 5 votes |
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
Example #15
Source File: cmd_baobab.py From baobab with GNU General Public License v3.0 | 5 votes |
def default_user(): from django.contrib.auth.models import User from baobab.backoffice.models import TimeZoneEnum argv = sys.argv if not User.objects.exists(): if not TimeZoneEnum.objects.exists(): print 'Creating the TimeZoneEnum ...' for timezone in pytz.common_timezones: TimeZoneEnum.objects.create(name=timezone) login = getattr(settings, 'DEFAULT_USER_LOGIN', None) pwd = getattr(settings, 'DEFAULT_USER_PWD', None) mail = getattr(settings, 'DEFAULT_USER_MAIL', None) if not mail: mail = '%s@gandi.net' % login if login and pwd: execute_from_command_line([argv[0], 'createsuperuser', '--username=%s' % login, '--email=%s' % mail, '--noinput']) user = User.objects.get(username=login) user.set_password(pwd) user.save() else: create_user = '' while create_user not in ['y', 'n']: create_user = raw_input('Do you want to create ' 'a user: y/n? ') print create_user if create_user == 'y': execute_from_command_line([argv[0], 'createsuperuser'])
Example #16
Source File: timezone.py From Spirit with MIT License | 5 votes |
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]))
Example #17
Source File: test_account_management.py From wagtail with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_available_admin_time_zones_by_default(self): self.assertListEqual(get_available_admin_time_zones(), pytz.common_timezones)
Example #18
Source File: localization.py From wagtail with BSD 3-Clause "New" or "Revised" License | 5 votes |
def get_available_admin_time_zones(): return getattr(settings, 'WAGTAIL_USER_TIME_ZONES', pytz.common_timezones)
Example #19
Source File: countries.py From lux with BSD 3-Clause "New" or "Revised" License | 5 votes |
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
Example #20
Source File: dates.py From riko with MIT License | 5 votes |
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
Example #21
Source File: new_appointment.py From appointment-reminders-flask with MIT License | 5 votes |
def _timezones(): return [(tz, tz) for tz in common_timezones][::-1]
Example #22
Source File: forms.py From django-aws-template with MIT License | 5 votes |
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)
Example #23
Source File: __init__.py From gamification-engine with MIT License | 5 votes |
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)
Example #24
Source File: test_tzinfo.py From sndlatr with Apache License 2.0 | 5 votes |
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)
Example #25
Source File: test_tzinfo.py From sndlatr with Apache License 2.0 | 5 votes |
def test_us_eastern(self): self.assertTrue('US/Eastern' in pytz.common_timezones) self.assertTrue('US/Eastern' in pytz.common_timezones_set)
Example #26
Source File: test_tzinfo.py From sndlatr with Apache License 2.0 | 5 votes |
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)
Example #27
Source File: views.py From ACE with Apache License 2.0 | 5 votes |
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)
Example #28
Source File: forms.py From allura with Apache License 2.0 | 4 votes |
def fields(self): # Since @property is readonly we can't modify field values in display() method # Returns fields modified by display() if self._fields: return self._fields list_of_fields = [ ew.SingleSelectField( name='sex', label='Gender', options=[ew.Option(py_value=v, label=v, selected=False) for v in ['Male', 'Female', 'Unknown', 'Other']], validator=formencode.All( V.OneOfValidator(['Male', 'Female', 'Unknown', 'Other']), V.UnicodeString(not_empty=True))), ew.SingleSelectField( name='country', label='Country of residence', validator=V.MapValidator(country_names, not_empty=False), options=[ew.Option(py_value=" ", label=" -- Unknown -- ", selected=False)] + [ew.Option(py_value=c, label=n, selected=False) for c, n in sorted(list(country_names.items()), key=lambda k_v: k_v[1])], attrs={'onchange': 'selectTimezone(this.value)'}), ew.TextField( name='city', label='City of residence', attrs=dict(value=None), validator=V.UnicodeString(not_empty=False)), ew.SingleSelectField( name='timezone', label='Timezone', attrs={'id': 'tz'}, validator=V.OneOfValidator(common_timezones, not_empty=False), options=[ew.Option(py_value=" ", label=" -- Unknown -- ")] + [ew.Option(py_value=n, label=n) for n in sorted(common_timezones)]) ] if asbool(tg.config.get('auth.allow_birth_date', True)): list_of_fields[1:1] = self.birth_date_fields return list_of_fields