Skip to content

Commit

Permalink
Merge "Add UTC offset information to the timezone" into stable/folsom
Browse files Browse the repository at this point in the history
  • Loading branch information
Jenkins authored and openstack-gerrit committed Feb 18, 2013
2 parents 1af5e78 + aa369b0 commit 0a42fa0
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 1 deletion.
17 changes: 16 additions & 1 deletion horizon/dashboards/settings/user/forms.py
Expand Up @@ -14,6 +14,7 @@
# License for the specific language governing permissions and limitations
# under the License.

from datetime import datetime
import pytz

from django import shortcuts
Expand All @@ -38,7 +39,21 @@ def __init__(self, *args, **kwargs):
self.fields['language'].choices = languages

# Timezones
timezones = [(tz, tz) for tz in pytz.common_timezones]
d = datetime(datetime.today().year, 1, 1)
timezones = []
for tz in pytz.common_timezones:
try:
utc_offset = pytz.timezone(tz).localize(d).strftime('%z')
utc_offset = " (UTC %s:%s)" % (utc_offset[:3], utc_offset[3:])
except:
utc_offset = ""

if tz != "UTC":
tz_name = "%s%s" % (tz, utc_offset)
else:
tz_name = tz
timezones.append((tz, tz_name))

self.fields['timezone'].choices = timezones

def handle(self, request, data):
Expand Down
31 changes: 31 additions & 0 deletions horizon/dashboards/settings/user/tests.py
@@ -0,0 +1,31 @@
# vim: tabstop=4 shiftwidth=4 softtabstop=4

# Copyright 2013 Red Hat, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.

from django.core.urlresolvers import reverse

from horizon import test


INDEX_URL = reverse("horizon:settings:user:index")


class UserSettingsTest(test.TestCase):

def test_timezone_offset_is_displayed(self):
res = self.client.get(INDEX_URL)

self.assertContains(res, "Australia/Melbourne (UTC +11:00)")
self.assertContains(res, "Canada/Newfoundland (UTC -03:30)")

0 comments on commit 0a42fa0

Please sign in to comment.