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:
@@ -43,6 +43,7 @@ import {
|
||||
import { useReadings, useMetrics } from './hooks'
|
||||
import type { MetricInfo, AutoRefreshOptions } from './hooks'
|
||||
import { formatMetricValue } from './format'
|
||||
import { formatLocalTime, formatLocalDateTime } from '../utils/datetime'
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Constants
|
||||
@@ -107,12 +108,7 @@ function lineColor(index: number): string {
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
function formatTimeTick(isoString: string): string {
|
||||
try {
|
||||
const d = new Date(isoString)
|
||||
return d.toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' })
|
||||
} catch {
|
||||
return isoString
|
||||
}
|
||||
return formatLocalTime(isoString)
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
@@ -300,11 +296,7 @@ export function EnergyCharts({ uuid, deviceName, autoRefresh }: EnergyChartsProp
|
||||
] as [string, string]
|
||||
}}
|
||||
labelFormatter={(label) => {
|
||||
try {
|
||||
return new Date(String(label)).toLocaleString()
|
||||
} catch {
|
||||
return String(label)
|
||||
}
|
||||
return formatLocalDateTime(String(label))
|
||||
}}
|
||||
/>
|
||||
<Legend />
|
||||
|
||||
Reference in New Issue
Block a user