mirror of
https://github.com/hansjone/netx.git
synced 2026-10-09 09:30:45 +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
|
|
@ -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,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue