Files
dnsmasq-admin/lib/datetime.ts
T
jamo.siu@gmail.com 1e4f028685 refactor(db): switch records layer to Prisma
- Replace hand-written node:sqlite queries with a Prisma client using
  the better-sqlite3 driver adapter
- Version the schema with migrations: baseline table, timestamp
  normalisation, and WAL journal mode
- Store timestamps with an explicit UTC offset so they stop being parsed
  as local time
- Show created/updated times on the edit page, formatted with dayjs
- Move the root redirect into next.config to avoid a prerender error
- Run migrations from the container entrypoint before starting the server

BREAKING CHANGE: DNSMASQ_ADMIN_DB_PATH is replaced by DATABASE_URL, which
must be a Prisma connection URL (file:./data/dnsmasq-admin.db). Existing
database files are migrated in place and need no conversion.
2026-10-12 14:27:03 +08:00

22 lines
915 B
TypeScript

import dayjs from "dayjs"
/** Single format used everywhere a timestamp is rendered, so the UI stays consistent. */
const DISPLAY_FORMAT = "YYYY-MM-DD HH:mm:ss"
/**
* Format a stored timestamp for display.
*
* Every timestamp carries an explicit `+00:00` offset (see prisma/migrations/0002), so dayjs
* always resolves the correct instant; it then renders it in the viewer's local zone. Before
* that migration the values looked like `2026-10-09 08:55:10`, which JavaScript parses as
* *local* time even though SQLite stored it UTC — an eight-hour error on a UTC+8 machine.
*
* Timestamps travel through the app as ISO strings (see lib/db.ts), so this helper takes a
* string rather than a `Date`.
*/
export function formatDateTime(value: string | null | undefined): string {
if (!value) return "—"
const parsed = dayjs(value)
return parsed.isValid() ? parsed.format(DISPLAY_FORMAT) : value
}