修正北京时间并更换新闻候选源
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
from datetime import datetime, timezone
|
||||
|
||||
from app.core.timezone import beijing_now, beijing_today, to_beijing_naive
|
||||
|
||||
|
||||
def test_beijing_now_returns_naive_business_time() -> None:
|
||||
# 数据库存储无时区时间,业务层写入前统一生成北京时间。
|
||||
current = beijing_now()
|
||||
|
||||
assert current.tzinfo is None
|
||||
|
||||
|
||||
def test_beijing_today_returns_date() -> None:
|
||||
# 日报业务日期只需要日期部分,由北京时间统一决定。
|
||||
assert beijing_today().isoformat()
|
||||
|
||||
|
||||
def test_to_beijing_naive_converts_utc_time() -> None:
|
||||
# 外部UTC时间进入数据库前要先换算成北京时间,避免前端显示少8小时。
|
||||
current = to_beijing_naive(datetime(2026, 7, 8, 14, 46, tzinfo=timezone.utc))
|
||||
|
||||
assert current.tzinfo is None
|
||||
assert current.hour == 22
|
||||
Reference in New Issue
Block a user