mirror of
https://github.com/zulip/zulip.git
synced 2025-10-22 20:42:14 +00:00
signals: Extract function to convert datetime to readable string.
This commit is contained in:
@@ -47,3 +47,11 @@ def timestamp_to_datetime(timestamp: float) -> datetime:
|
||||
def datetime_to_timestamp(dt: datetime) -> int:
|
||||
verify_UTC(dt)
|
||||
return int(dt.timestamp())
|
||||
|
||||
|
||||
def format_datetime_to_string(dt: datetime, use_twenty_four_hour_time: bool) -> str:
|
||||
if use_twenty_four_hour_time:
|
||||
hhmm_string = dt.strftime("%H:%M")
|
||||
else:
|
||||
hhmm_string = dt.strftime("%I:%M %p")
|
||||
return dt.strftime(f"%A, %B %d, %Y at {hhmm_string} %Z")
|
||||
|
@@ -11,6 +11,7 @@ from django.utils.translation import gettext as _
|
||||
from confirmation.models import one_click_unsubscribe_link
|
||||
from zerver.lib.queue import queue_json_publish_rollback_unsafe
|
||||
from zerver.lib.send_email import EMAIL_DATE_FORMAT, FromAddress
|
||||
from zerver.lib.timestamp import format_datetime_to_string
|
||||
from zerver.lib.timezone import canonicalize_timezone
|
||||
from zerver.models import UserProfile
|
||||
|
||||
@@ -93,11 +94,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(zoneinfo.ZoneInfo(canonicalize_timezone(user_tz)))
|
||||
if user.twenty_four_hour_time:
|
||||
hhmm_string = local_time.strftime("%H:%M")
|
||||
else:
|
||||
hhmm_string = local_time.strftime("%I:%M %p")
|
||||
context["login_time"] = local_time.strftime(f"%A, %B %d, %Y at {hhmm_string} %Z")
|
||||
context["login_time"] = format_datetime_to_string(local_time, user.twenty_four_hour_time)
|
||||
context["device_ip"] = request.META.get("REMOTE_ADDR") or _("Unknown IP address")
|
||||
context["device_os"] = get_device_os(user_agent) or _("an unknown operating system")
|
||||
context["device_browser"] = get_device_browser(user_agent) or _("An unknown browser")
|
||||
|
Reference in New Issue
Block a user