From 75b39866c7551c294714721f469cfc19bf6e644e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yago=20Gonz=C3=A1lez?= Date: Sat, 4 Aug 2018 11:05:12 +0200 Subject: [PATCH] emails: Display the timezone's name on login notifications. Show the timezone's name instead of the UTC offset, since it's easier to infer where does the login come from that way. --- zerver/signals.py | 3 +-- zerver/tests/test_new_users.py | 4 ++-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/zerver/signals.py b/zerver/signals.py index 7d3a9aed02..74e88f2294 100644 --- a/zerver/signals.py +++ b/zerver/signals.py @@ -79,8 +79,7 @@ def email_on_new_login(sender: Any, user: UserProfile, request: Any, **kwargs: A if user_tz == '': user_tz = timezone_get_current_timezone_name() local_time = timezone_now().astimezone(get_timezone(user_tz)) - utc_offset = local_time.strftime('%z') - context['login_time'] = local_time.strftime('%A, %B %d, %Y at %I:%M%p ') + utc_offset + context['login_time'] = local_time.strftime('%A, %B %d, %Y at %I:%M%p %Z') context['device_ip'] = request.META.get('REMOTE_ADDR') or _("Unknown IP address") context['device_os'] = get_device_os(user_agent) context['device_browser'] = get_device_browser(user_agent) diff --git a/zerver/tests/test_new_users.py b/zerver/tests/test_new_users.py index e48f7b53ab..4ad50f260a 100644 --- a/zerver/tests/test_new_users.py +++ b/zerver/tests/test_new_users.py @@ -35,8 +35,8 @@ class SendLoginEmailTest(ZulipTestCase): password = initial_password(user.email) firefox_windows = "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:47.0) Gecko/20100101 Firefox/47.0" user_tz = get_timezone(user.timezone) - utc_offset = mock_time.astimezone(user_tz).strftime('%z') - reference_time = mock_time.astimezone(user_tz).strftime('%A, %B %d, %Y at %I:%M%p ') + utc_offset + mock_time = datetime.datetime(year=2018, month=1, day=1, tzinfo=utc) + reference_time = mock_time.astimezone(user_tz).strftime('%A, %B %d, %Y at %I:%M%p %Z') with mock.patch('zerver.signals.timezone_now', return_value=mock_time): self.client_post("/accounts/login/", info={"username": user.email, "password": password}, HTTP_USER_AGENT=firefox_windows)