Repository: noneplugin/nonebot-plugin-chatrecorder (language: python)

Issue:
消息记录时间的时区问题
现在的时间并不能保证是 UTC 时间，如果系统时区为其他时区，会出问题。（我错了，如果之前直接保存成时间戳就没这些问题了）

相关议题：<https://github.com/he0119/nonebot-plugin-wordcloud/issues/48>

```python
>>> datetime.utcfromtimestamp(1657163607)               
datetime.datetime(2022, 7, 7, 3, 13, 27)
```


Discussion / hints:

Fix patch:
diff --git a/nonebot_plugin_chatrecorder/__init__.py b/nonebot_plugin_chatrecorder/__init__.py
index fed37aa..72484ef 100644
--- a/nonebot_plugin_chatrecorder/__init__.py
+++ b/nonebot_plugin_chatrecorder/__init__.py
@@ -25,7 +25,7 @@ async def record_recv_msg(event: MessageEvent):
 
     record = MessageRecord(
         platform="qq",
-        time=datetime.fromtimestamp(event.time),
+        time=datetime.utcfromtimestamp(event.time),
         type="message",
         detail_type="group" if isinstance(event, GroupMessageEvent) else "private",
         message_id=str(event.message_id),


Test patch:
diff --git a/tests/test_chatrecorder.py b/tests/test_chatrecorder.py
index b75f2e4..18e9231 100644
--- a/tests/test_chatrecorder.py
+++ b/tests/test_chatrecorder.py
@@ -1,3 +1,4 @@
+from datetime import datetime
 import pytest
 from nonebug import App
 
@@ -27,7 +28,7 @@ async def test_record_recv_msg(app: App):
         message=Message(message),
     )
     await record_recv_msg(event)
-    await check_record(str(message_id), "group", message)
+    await check_record(str(message_id), "group", message, time=datetime(1970, 1, 12, 13, 46, 40))
 
     message_id = 11451422222
     message = "test private message"
@@ -37,7 +38,7 @@ async def test_record_recv_msg(app: App):
         message=Message(message),
     )
     await record_recv_msg(event)
-    await check_record(str(message_id), "private", message, group_id="")
+    await check_record(str(message_id), "private", message, group_id="", time=datetime(1970, 1, 12, 13, 46, 40))
 
 
 @pytest.mark.asyncio
@@ -101,6 +102,7 @@ async def check_record(
     message: str,
     user_id=str(USER_ID),
     group_id=str(GROUP_ID),
+    time=None,
 ):
     from typing import List
     from sqlmodel import select
@@ -123,3 +125,5 @@ async def check_record(
     assert record.alt_message == message
     assert record.user_id == user_id
     assert record.group_id == group_id
+    if time:
+        assert record.time == time