20 lines
691 B
Python
20 lines
691 B
Python
"""Telegram timestamps should display Beijing local time."""
|
|
|
|
from datetime import datetime
|
|
from zoneinfo import ZoneInfo
|
|
|
|
from server.infrastructure.telegram import _now_cn
|
|
from server.utils.display_time import format_beijing_now
|
|
|
|
|
|
def test_now_cn_uses_beijing_timezone_label():
|
|
text = _now_cn()
|
|
assert text == format_beijing_now()
|
|
assert text.endswith("北京时间")
|
|
assert "UTC" not in text
|
|
wall = text.replace(" 北京时间", "")
|
|
parsed = datetime.strptime(wall, "%Y-%m-%d %H:%M:%S").replace(tzinfo=ZoneInfo("Asia/Shanghai"))
|
|
utc_now = datetime.now(ZoneInfo("UTC"))
|
|
delta_seconds = abs((parsed - utc_now).total_seconds())
|
|
assert delta_seconds < 120
|