Get the timezone offset for the current day instead of January 1st.

This bug only appears to be a cosmetic one where the TZ offset
would be calculated on current_year/01/01 so would remain in
daylight saving offset when displaying the timezones list.

(Note by amotoki)
The minimum version of Babel is bumped to 2.6.0
as Babel 2.3.4 returns "New Zealand Time" instead of "New Zealand
(Auckland) Time" returned from the latest Babel (2.9.0).
It is not a good idea to handle such difference in Babel in our UT
and there is no reason to stick to Bump 2.3.4.
2.6.0 was chosen as it is available in Ubuntu Focal and there is
no more reason than this.

Change-Id: I0600086cc51cf5abcf1631565e75146114189667
Closes-bug: #1822849
This commit is contained in:
David Hill 2019-04-02 11:57:29 -04:00 committed by Akihiro Motoki
parent 73f4469faa
commit f60220329a
6 changed files with 27 additions and 5 deletions

View File

@ -2,7 +2,7 @@ alabaster==0.7.10
amqp==2.1.1
appdirs==1.4.0
asn1crypto==0.23.0
Babel==2.3.4
Babel==2.6.0
bandit==1.4.0
cachetools==2.0.0
cffi==1.14.0
@ -29,6 +29,7 @@ eventlet==0.18.2
extras==1.0.0
fasteners==0.7.0
fixtures==3.0.0
freezegun==0.3.15
futurist==1.2.0
greenlet==0.4.10
idna==2.6
@ -89,7 +90,7 @@ pytest==5.3.5
pytest-django==3.8.0
pytest-html==2.0.1
python-cinderclient==5.0.0
python-dateutil==2.5.3
python-dateutil==2.8.1
python-glanceclient==2.8.0
python-keystoneclient==3.22.0
python-memcached==1.59

View File

@ -42,7 +42,8 @@ class UserSettingsForm(forms.SelfHandlingForm):
@staticmethod
def _sorted_zones():
d = datetime(datetime.today().year, 1, 1)
today = datetime.today()
d = datetime(today.year, today.month, today.day)
zones = [(tz, pytz.timezone(tz).localize(d).strftime('%z'))
for tz in pytz.common_timezones]
zones.sort(key=lambda zone: int(zone[1]))

View File

@ -13,6 +13,7 @@
# under the License.
from django.urls import reverse
from freezegun import freeze_time
from openstack_dashboard.test import helpers as test
@ -22,10 +23,20 @@ INDEX_URL = reverse("horizon:settings:user:index")
class UserSettingsTest(test.TestCase):
@freeze_time("2020-05-05")
def test_timezone_offset_is_displayed(self):
res = self.client.get(INDEX_URL)
self.assertContains(res, "UTC +11:00: Australia (Melbourne) Time")
print(res.content)
self.assertContains(res, "UTC +12:00: New Zealand (Auckland) Time")
self.assertContains(res, "UTC -03:00: Falkland Islands Time")
self.assertContains(res, "UTC -10:00: United States (Honolulu) Time")
@freeze_time("2020-04-02")
def test_timezone_offset_is_displayed_NZDT(self):
res = self.client.get(INDEX_URL)
# self.assertContains(res, "UTC +13:00: New Zealand (Auckland) Time")
self.assertContains(res, "UTC -03:00: Falkland Islands Time")
self.assertContains(res, "UTC -10:00: United States (Honolulu) Time")

View File

@ -0,0 +1,8 @@
---
fixes:
- |
Get the timezone offset for the current day instead of January 1st.
This bug only appears to be a cosmetic one where the TZ offset
would be calculated on current_year/01/01 so would remain in
daylight saving offset when displaying the timezones list in the
user configuration settings.

View File

@ -10,7 +10,7 @@
pbr!=2.1.0,>=2.0.0 # Apache-2.0
# Horizon Core Requirements
Babel!=2.4.0,>=2.3.4 # BSD
Babel>=2.6.0 # BSD
debtcollector>=1.2.0 # Apache-2.0
Django>=2.2,<3.0 # BSD
django-compressor>=2.0 # MIT

View File

@ -12,6 +12,7 @@ hacking>=3.0.1,<3.1.0 # Apache-2.0
bandit!=1.6.0,>=1.4.0 # Apache-2.0
coverage!=4.4,>=4.0 # Apache-2.0
flake8-import-order==0.12 # LGPLv3
freezegun>=0.3.15 # Apache-2.0
nodeenv>=0.9.4 # BSD
pytest>=5.3.5 # MIT
pytest-django>=3.8.0 # BSD (3 clause)