timezone: Only look up canonical time zones from the system.

Legacy time zone aliases were removed from the Debian tzdata package
in tzdata 2023c-8.

https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1040997

Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
Anders Kaseorg 2024-02-27 16:36:17 -08:00 committed by Tim Abbott
parent 119900120e
commit 59b0548433
4 changed files with 11 additions and 5 deletions

View File

@ -29,6 +29,7 @@ from zerver.lib.queue import queue_json_publish
from zerver.lib.send_email import FromAddress, send_future_email from zerver.lib.send_email import FromAddress, send_future_email
from zerver.lib.soft_deactivation import soft_reactivate_if_personal_notification from zerver.lib.soft_deactivation import soft_reactivate_if_personal_notification
from zerver.lib.tex import change_katex_to_raw_latex from zerver.lib.tex import change_katex_to_raw_latex
from zerver.lib.timezone import canonicalize_timezone
from zerver.lib.topic import get_topic_resolution_and_bare_name from zerver.lib.topic import get_topic_resolution_and_bare_name
from zerver.lib.url_encoding import ( from zerver.lib.url_encoding import (
huddle_narrow_url, huddle_narrow_url,
@ -686,7 +687,9 @@ def get_onboarding_email_schedule(user: UserProfile) -> Dict[str, timedelta]:
user_tz = user.timezone user_tz = user.timezone
if user_tz == "": if user_tz == "":
user_tz = "UTC" user_tz = "UTC"
signup_day = user.date_joined.astimezone(zoneinfo.ZoneInfo(user_tz)).isoweekday() signup_day = user.date_joined.astimezone(
zoneinfo.ZoneInfo(canonicalize_timezone(user_tz))
).isoweekday()
# General rules for scheduling welcome emails flow: # General rules for scheduling welcome emails flow:
# -Do not send emails on Saturday or Sunday # -Do not send emails on Saturday or Sunday

View File

@ -140,7 +140,7 @@ def check_long_string(var_name: str, val: object) -> str:
def check_timezone(var_name: str, val: object) -> str: def check_timezone(var_name: str, val: object) -> str:
s = check_string(var_name, val) s = check_string(var_name, val)
try: try:
zoneinfo.ZoneInfo(s) zoneinfo.ZoneInfo(canonicalize_timezone(s))
except (ValueError, zoneinfo.ZoneInfoNotFoundError): except (ValueError, zoneinfo.ZoneInfoNotFoundError):
raise ValidationError( raise ValidationError(
_("{var_name} is not a recognized time zone").format(var_name=var_name) _("{var_name} is not a recognized time zone").format(var_name=var_name)
@ -603,11 +603,12 @@ def to_decimal(var_name: str, s: str) -> Decimal:
def to_timezone_or_empty(var_name: str, s: str) -> str: def to_timezone_or_empty(var_name: str, s: str) -> str:
try: try:
s = canonicalize_timezone(s)
zoneinfo.ZoneInfo(s) zoneinfo.ZoneInfo(s)
except (ValueError, zoneinfo.ZoneInfoNotFoundError): except (ValueError, zoneinfo.ZoneInfoNotFoundError):
return "" return ""
else: else:
return canonicalize_timezone(s) return s
def to_converted_or_fallback( def to_converted_or_fallback(

View File

@ -11,6 +11,7 @@ from django.utils.translation import gettext as _
from confirmation.models import one_click_unsubscribe_link from confirmation.models import one_click_unsubscribe_link
from zerver.lib.queue import queue_json_publish from zerver.lib.queue import queue_json_publish
from zerver.lib.send_email import FromAddress from zerver.lib.send_email import FromAddress
from zerver.lib.timezone import canonicalize_timezone
from zerver.models import UserProfile from zerver.models import UserProfile
if sys.version_info < (3, 9): # nocoverage if sys.version_info < (3, 9): # nocoverage
@ -96,7 +97,7 @@ def email_on_new_login(sender: Any, user: UserProfile, request: Any, **kwargs: A
user_tz = user.timezone user_tz = user.timezone
if user_tz == "": if user_tz == "":
user_tz = timezone_get_current_timezone_name() user_tz = timezone_get_current_timezone_name()
local_time = timezone_now().astimezone(zoneinfo.ZoneInfo(user_tz)) local_time = timezone_now().astimezone(zoneinfo.ZoneInfo(canonicalize_timezone(user_tz)))
if user.twenty_four_hour_time: if user.twenty_four_hour_time:
hhmm_string = local_time.strftime("%H:%M") hhmm_string = local_time.strftime("%H:%M")
else: else:

View File

@ -13,6 +13,7 @@ from zerver.actions.create_user import notify_new_user
from zerver.actions.user_settings import do_change_user_setting from zerver.actions.user_settings import do_change_user_setting
from zerver.lib.initial_password import initial_password from zerver.lib.initial_password import initial_password
from zerver.lib.test_classes import ZulipTestCase from zerver.lib.test_classes import ZulipTestCase
from zerver.lib.timezone import canonicalize_timezone
from zerver.models import Message, Realm, Recipient, Stream, UserProfile from zerver.models import Message, Realm, Recipient, Stream, UserProfile
from zerver.models.realms import get_realm from zerver.models.realms import get_realm
from zerver.signals import JUST_CREATED_THRESHOLD, get_device_browser, get_device_os from zerver.signals import JUST_CREATED_THRESHOLD, get_device_browser, get_device_os
@ -53,7 +54,7 @@ class SendLoginEmailTest(ZulipTestCase):
firefox_windows = ( firefox_windows = (
"Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:47.0) Gecko/20100101 Firefox/47.0" "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:47.0) Gecko/20100101 Firefox/47.0"
) )
user_tz = zoneinfo.ZoneInfo(user.timezone) user_tz = zoneinfo.ZoneInfo(canonicalize_timezone(user.timezone))
mock_time = datetime(year=2018, month=1, day=1, tzinfo=timezone.utc) mock_time = datetime(year=2018, month=1, day=1, tzinfo=timezone.utc)
reference_time = mock_time.astimezone(user_tz).strftime("%A, %B %d, %Y at %I:%M %p %Z") reference_time = mock_time.astimezone(user_tz).strftime("%A, %B %d, %Y at %I:%M %p %Z")
with time_machine.travel(mock_time, tick=False): with time_machine.travel(mock_time, tick=False):