mirror of
https://github.com/hansjone/netx.git
synced 2026-10-18 17:20:44 +08:00
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:
parent
5b77c6f327
commit
71ec3385d2
2 changed files with 25 additions and 3 deletions
|
|
@ -349,7 +349,11 @@ export function NePage() {
|
||||||
{row.connect_status}
|
{row.connect_status}
|
||||||
</span>
|
</span>
|
||||||
</td>
|
</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">
|
<td className="table-actions">
|
||||||
<button type="button" className="link-btn" onClick={() => openEdit(row)}>
|
<button type="button" className="link-btn" onClick={() => openEdit(row)}>
|
||||||
{t("managedNe.edit")}
|
{t("managedNe.edit")}
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,26 @@
|
||||||
const systemTimeZone = Intl.DateTimeFormat().resolvedOptions().timeZone;
|
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 "";
|
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);
|
if (Number.isNaN(d.getTime())) return String(value);
|
||||||
return d.toLocaleString(undefined, {
|
return d.toLocaleString(undefined, {
|
||||||
hour12: false,
|
hour12: false,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue