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 行读取时间列(优先
TIMESTAMPnaive,兼容 TIMESTAMPTZ)