Open WebCRT in its own module tab and fix UTC naive time display.

Config/NE/topology links now focus the webcrt window instead of replacing network routes; formatSystemTime treats naive API timestamps as UTC.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
oliver 2026-07-31 11:13:22 +08:00
parent 3fc80f55bc
commit 68883d1a84
4 changed files with 27 additions and 13 deletions

View file

@ -1,17 +1,24 @@
const systemTimeZone = Intl.DateTimeFormat().resolvedOptions().timeZone;
type FormatTimeOptions = {
/** Treat timezone-less ISO timestamp strings as UTC. */
/**
* Treat timezone-less timestamps as UTC (DB/API default).
* Defaults to true so naive ISO strings show in the browser system timezone.
*/
assumeUtcNaive?: boolean;
};
function normalizeTimeInput(value: string | number | Date, options?: FormatTimeOptions): string | number | Date {
if (!options?.assumeUtcNaive || typeof value !== "string") return value;
const assumeUtc = options?.assumeUtcNaive !== false;
if (!assumeUtc || 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;
// Already has explicit offset / Z.
if (/[zZ]$|[+-]\d{2}:\d{2}$/.test(text)) return value;
// "YYYY-MM-DDTHH:mm:ss(.sss)" or "YYYY-MM-DD HH:mm:ss(.sss)"
const isoLike = /^\d{4}-\d{2}-\d{2}[T ]\d{2}:\d{2}:\d{2}(?:\.\d+)?$/.test(text);
if (!isoLike) return value;
return `${text.replace(" ", "T")}Z`;
}
export function formatSystemTime(
@ -27,4 +34,3 @@ export function formatSystemTime(
timeZone: systemTimeZone,
});
}