store-instants-as-utc
Use when a timestamp is written to a database, log line or API payload — persist the instant in UTC with an explicit offset, never a bare local wall-clock string.
- License 许可
- MIT
- 最近更新
- 2026-11-14
- Stars
- ★ 81
- Forks
- 17
01 前言 Front Matter
- name
- store-instants-as-utc
- description
- Use when a timestamp is written to a database, log line or API payload — persist the instant in UTC with an explicit offset, never a bare local wall-clock string.
02 资源文件 3
- 许可证LICENSE1.0 KB
- 参考文档SOURCE.md347 B
- 参考文档TRUST.auto.yaml2.2 KB
03 SKILL.md 正文
Store instants as UTC
An instant is a point on the world timeline; a wall-clock reading is not. A UTC (or offset-bearing) value lets two hosts, two timezones and two DST regimes agree about what happened and in what order.
Procedure
- Declare the column type, not just the value. In Postgres use
TIMESTAMPTZ; a plainTIMESTAMPsilently drops the offset:
ALTER TABLE events ALTER COLUMN created_at TYPE timestamptz USING created_at AT TIME ZONE 'UTC';
- Serialize as ISO-8601 with an offset.
2026-03-01T14:00:00Z, never2026-03-01 14:00:00:
date -u +%Y-%m-%dT%H:%M:%SZ
- In the application layer, produce aware objects and convert only when formatting:
from datetime import datetime, timezone
now = datetime.now(timezone.utc) # aware, UTC
row = now.isoformat().replace("+00:00", "Z") # 2026-03-01T14:00:00Z
- Store the original zone name separately if you ever need to redisplay in the user's local time — UTC loses it. Keep
created_at timestamptzpluscreated_tz text('America/New_York'). - Reject writes that carry no offset at the API boundary. A regex gate on ingress:
rg -n '\d{4}-\d{2}-\d{2}[T ]\d{2}:\d{2}:\d{2}(?!Z|[+-]\d{2}:?\d{2})' payloads/ # finds bare local stamps
- Migrate legacy local strings by pinning the zone they were written in, not by assuming UTC:
UPDATE events SET created_at = created_at AT TIME ZONE 'America/New_York' WHERE created_at_was_local;
- Verify round-trip: write an instant, read it back, and confirm the offset survives.
Pitfalls
--A naiveTIMESTAMPcolumn read by a driver set to a differentTimeZonereturns a different wall clock for the same row. The bug looks like "the date changed" with no code change.new Date("2026-03-01")in JavaScript parses date-only as UTC midnight;new Date("2026-03-01T00:00")parses as local. Two spellings, two instants.- Emitting UTC but truncating the
Zproduces a string that a downstream parser reads as local. Keep the offset suffix. - Sorting a mixed column of
Zand+05:00strings lexically reorders events across zones; sort parsed instants, not text.
Verification
psql -c "SELECT count(*) FROM events WHERE created_at IS NOT NULL AND pg_typeof(created_at)::text <> 'timestamp with time zone';"
Returns 0 = every stored timestamp is offset-aware. Report: "events.created_at is timestamptz, 0 naive rows; API rejects offset-less strings."
04 同仓库更多 Skills
recipe-performance
Diagnose a specific MetaMask user flow's real-app performance and Sentry critical-user-flow telemetry with deterministic mm-harness recipes. Use for CUF boundaries, cold/warm/background-resume behavior, latency regressions, lifecycle tags, duplicate or blocking network requests, long tasks, layout/paint cost, screen redraws, React rerenders, or browser trace analysis where tests alone cannot prove the real app.
mexc-spot-websocket
MEXC Spot WebSocket workflows for public streams, protobuf handling, depth maintenance, listen keys, and private streams without exposing API keys.
mexc-spot-rest
MEXC Spot REST workflows for public data, signed account requests, orders, wallet/admin actions, and secure signing without exposing API keys.
mexc-futures-websocket
MEXC Futures WebSocket workflows for public streams, private account/order/position streams, ping/pong, subscriptions, and depth maintenance.
0xklen-version-and-refresh-sanctions-lists
暂无简介
verify-tests-cover-changed-lines
Use when a PR adds code that the existing suite may not exercise. Measures patch coverage — the share of newly changed lines hit by tests — before approving.