Skip to main content

Module legacy_time

Module legacy_time 

Source
Expand description

DB 时间列(TIMESTAMP UTC)与 API 的直通层

§约定

  • PostgreSQL 列类型:TIMESTAMP WITHOUT TIME ZONE,会话 SET TIME ZONE 'UTC'
  • 库内值为 UTC 墙钟;后端读写不做 ±8h 等业务偏移
  • API 以 RFC3339 UTC(...Z)输出;展示时区由前端 WebFront-end/src/utils/datetime.ts 处理

§使用

  • 读行:try_dt(row, "updateTime")naive_db_to_api_utc(naive)
  • 写入:api_to_db_naive(Utc::now())api_to_db_naive(instant)

Functions§

api_to_db_naive
API UTC 写入 TIMESTAMP
api_to_db_utc
API UTC 写入 DB(TIMESTAMPTZ 列时保留)
db_to_api_utc
DB DateTime<Utc> → API(恒等)
db_to_api_utc_opt
可选 DB 时间 → API
naive_db_to_api_utc
TIMESTAMP 列读出的 naive 值视为 UTC
naive_db_to_api_utc_opt
可选 naive → API UTC
try_dt
从 PG 行读取时间列(优先 TIMESTAMP naive,兼容 TIMESTAMPTZ)