frontend: show Energy/DSMR/meter times in local timezone, 24h

Backend serializes SQLite-read (naive) UTC datetimes without a Z, so the browser
was parsing them as local time -> the UI effectively showed UTC values.

- New src/utils/datetime.ts: treats a tz-less timestamp as UTC, then formats in
  the browser's local timezone with hour12:false (no AM/PM).
- Applied to Energy tabs (contracts/prices/costs/DSMR), per-device readings &
  trends, and the meter readings table on the Records page.
- CostView Today/This month now use local day boundaries (queries stay UTC ISO).
- Untouched: location/poo (raw Zulu strings), the map, and query-window params.
- Tests are timezone-independent (verified under TZ=America/Los_Angeles).
This commit is contained in:
2026-06-24 13:22:07 +02:00
parent 9d3e28a529
commit effe434637
9 changed files with 301 additions and 37 deletions
+3 -6
View File
@@ -35,6 +35,7 @@ import type { PooRecord, LocationRecord } from '../records'
import { useDevices, useMetrics, useReadings } from '../energy/hooks'
import type { ModbusDevice, MetricInfo } from '../energy/hooks'
import { formatMetricValue } from '../energy/format'
import { formatLocalDateTime } from '../utils/datetime'
// ---------------------------------------------------------------------------
// Constants
@@ -359,13 +360,9 @@ interface MeterReadingsTableProps {
device: ModbusDevice
}
/** Format an ISO timestamp for display. */
/** Format an ISO timestamp for display (local timezone, 24-hour). */
function formatRecordedAt(iso: string): string {
try {
return new Date(iso).toLocaleString()
} catch {
return iso
}
return formatLocalDateTime(iso)
}
function MeterReadingsTable({ device }: MeterReadingsTableProps) {