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.

slack_message_conversion: Use datetime_to_global_time.

Anders Kaseorg389119e47507
diff --git a/zerver/data_import/slack_message_conversion.py b/zerver/data_import/slack_message_conversion.py
index 069685b6c5b..1eb2a132375 100644
--- a/zerver/data_import/slack_message_conversion.py
+++ b/zerver/data_import/slack_message_conversion.py
@@ -1,5 +1,6 @@
import json
import re
+from datetime import datetime, timezone
from itertools import zip_longest
from typing import Any, Literal, TypeAlias, TypedDict, cast
@@ -7,6 +8,7 @@ import regex
from django.core.exceptions import ValidationError
from requests.utils import requote_uri
+from zerver.lib.timestamp import datetime_to_global_time
from zerver.lib.types import Validator
from zerver.lib.validator import (
WildValue,
@@ -453,7 +455,7 @@ def render_attachment(attachment: WildValue) -> str:
raise e
time = int(ts_float)
- pieces.append(f"<time:{time}>")
+ pieces.append(datetime_to_global_time(datetime.fromtimestamp(time, timezone.utc)))
return "\n\n".join(piece.strip() for piece in pieces if piece.strip() != "")
diff --git a/zerver/webhooks/slack_incoming/tests.py b/zerver/webhooks/slack_incoming/tests.py
index b0c89854746..8dc571c2fdf 100644
--- a/zerver/webhooks/slack_incoming/tests.py
+++ b/zerver/webhooks/slack_incoming/tests.py
@@ -225,7 +225,7 @@ Value without title
[](https://pbs.twimg.com/profile_images/625633822235693056/lNGUneLX_400x400.jpg)
-<time:1655945306>
+<time:2022-06-23T00:48:26+00:00>
""".strip()
self.check_webhook(
@@ -253,7 +253,7 @@ Sample text.
Sample footer.
-<time:1655945306>
+<time:2022-06-23T00:48:26+00:00>
""".strip()
self.check_webhook(
@@ -273,7 +273,7 @@ Sample text.
Sample footer.
-<time:1655945306>
+<time:2022-06-23T00:48:26+00:00>
""".strip()
self.check_webhook(
@@ -313,7 +313,7 @@ Sample pretext.
Sample footer.
-<time:1655945306>
+<time:2022-06-23T00:48:26+00:00>
""".strip()
self.check_webhook(
@@ -333,7 +333,7 @@ Sample text.
Sample footer.
-<time:1655945306>
+<time:2022-06-23T00:48:26+00:00>
""".strip()
self.check_webhook(
@@ -353,7 +353,7 @@ Sample text.
[](https://pbs.twimg.com/profile_images/625633822235693056/lNGUneLX_400x400.jpg)
-<time:1655945306>
+<time:2022-06-23T00:48:26+00:00>
""".strip()
self.check_webhook(
@@ -375,7 +375,7 @@ Sample text.
Sample footer.
-<time:1655945306>
+<time:2022-06-23T00:48:26+00:00>
""".strip()
self.check_webhook(