24 lines
798 B
Python
24 lines
798 B
Python
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
|