Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

settings: Show UTC offsets in timezone dropdown.

Amaan-pathanb0844109ca67
diff --git a/tools/setup/build_timezone_values b/tools/setup/build_timezone_values
index 53456b45cc7..735d0c1a20e 100755
--- a/tools/setup/build_timezone_values
+++ b/tools/setup/build_timezone_values
@@ -3,6 +3,7 @@ import json
import os
import sys
import zoneinfo
+from datetime import datetime, timedelta
ZULIP_PATH = os.path.join(os.path.dirname(os.path.abspath(__file__)), "../../")
sys.path.insert(0, ZULIP_PATH)
@@ -11,14 +12,35 @@ from zerver.lib.timezone import get_canonical_timezone_map
OUT_PATH = os.path.join(ZULIP_PATH, "web", "generated", "timezones.json")
+
+def get_utc_offset(tz_name: str) -> str:
+ """Get UTC offset for a timezone in the format UTC(+HH:MM)."""
+ try:
+ now = datetime.now(zoneinfo.ZoneInfo(tz_name))
+ offset: timedelta | None = now.utcoffset()
+
+ if offset is None:
+ return "UTC(+00:00)"
+
+ offset_seconds = offset.total_seconds()
+ hours, remainder = divmod(offset_seconds, 3600)
+ minutes = remainder // 60
+ if minutes == 0:
+ return f"UTC{int(hours):+d}"
+ return f"UTC{int(hours):+d}:{int(minutes):02d}"
+
+ except Exception as e:
+ print(f"Error processing {tz_name}: {e}")
+ return "UTC(?)"
+
+
+timezones = sorted(
+ zoneinfo.available_timezones() - {"Factory", "localtime"} - set(get_canonical_timezone_map())
+)
+
+
+timezone_data = [{"name": tz, "utc_offset": get_utc_offset(tz)} for tz in timezones]
+
+
with open(OUT_PATH, "w") as f:
- json.dump(
- {
- "timezones": sorted(
- zoneinfo.available_timezones()
- - {"Factory", "localtime"}
- - set(get_canonical_timezone_map())
- )
- },
- f,
- )
+ json.dump({"timezones": timezone_data}, f)
diff --git a/version.py b/version.py
index 4301f450143..6135f0f9780 100644
--- a/version.py
+++ b/version.py
@@ -49,4 +49,4 @@ API_FEATURE_LEVEL = 371 # Last bumped for Zulip 10.0 release.
# historical commits sharing the same major version, in which case a
# minor version bump suffices.
-PROVISION_VERSION = (321, 1) # bumped 2025-03-26 to generate static/generated/integrations files.
+PROVISION_VERSION = (322, 0) # bumped 2025-03-26 for updated build_timezone_values.
diff --git a/web/templates/settings/profile_settings.hbs b/web/templates/settings/profile_settings.hbs
index ea6f86f4e73..5df9145529f 100644
--- a/web/templates/settings/profile_settings.hbs
+++ b/web/templates/settings/profile_settings.hbs
@@ -27,7 +27,8 @@
{{/unless}}
{{#each timezones}}
- <option value="{{ this }}">{{ this }}</option>
+ <option value="{{ this.name }}">{{ this.name }} ({{ this.utc_offset }})</option>
+
{{/each}}
</select>
</div>