fix(web): display NE tested time in system timezone

Treat timezone-less ISO timestamps from connect_tested_at as UTC before formatting so NE test time renders correctly in the user's system timezone.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
oliver 2026-05-28 14:39:15 +08:00
parent 5b77c6f327
commit 71ec3385d2
2 changed files with 25 additions and 3 deletions

View file

@ -349,7 +349,11 @@ export function NePage() {
{row.connect_status}
</span>
</td>
<td>{row.connect_tested_at ? formatSystemTime(row.connect_tested_at) : t("common.empty")}</td>
<td>
{row.connect_tested_at
? formatSystemTime(row.connect_tested_at, { assumeUtcNaive: true })
: t("common.empty")}
</td>
<td className="table-actions">
<button type="button" className="link-btn" onClick={() => openEdit(row)}>
{t("managedNe.edit")}

View file

@ -1,8 +1,26 @@
const systemTimeZone = Intl.DateTimeFormat().resolvedOptions().timeZone;
export function formatSystemTime(value: string | number | Date | null | undefined): string {
type FormatTimeOptions = {
/** Treat timezone-less ISO timestamp strings as UTC. */
assumeUtcNaive?: boolean;
};
function normalizeTimeInput(value: string | number | Date, options?: FormatTimeOptions): string | number | Date {
if (!options?.assumeUtcNaive || typeof value !== "string") return value;
const text = value.trim();
if (!text) return value;
// Match "YYYY-MM-DDTHH:mm:ss(.sss)" without explicit timezone offset.
const isIsoLike = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d+)?$/.test(text);
return isIsoLike ? `${text}Z` : value;
}
export function formatSystemTime(
value: string | number | Date | null | undefined,
options?: FormatTimeOptions,
): string {
if (value === null || value === undefined) return "";
const d = value instanceof Date ? value : new Date(value);
const normalized = normalizeTimeInput(value, options);
const d = normalized instanceof Date ? normalized : new Date(normalized);
if (Number.isNaN(d.getTime())) return String(value);
return d.toLocaleString(undefined, {
hour12: false,