🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.
TypeScript analyticsautogenevaluationlangchainlarge-language-modelsllama-indexllmllm-evaluationllm-observabilityllmopsmonitoringobservabilityopen-sourceopenaiplaygroundprompt-engineeringprompt-managementself-hostedycombinator
fix(dashboards): label chart date axes in UTC (#16625)
Mark Salpeter1c8c434a42ba
diff --git a/web/src/features/widgets/chart-library/prepareTimeAxis.clienttest.ts b/web/src/features/widgets/chart-library/prepareTimeAxis.clienttest.tsindex 673775a229..ce3298c5e8 100644--- a/web/src/features/widgets/chart-library/prepareTimeAxis.clienttest.ts+++ b/web/src/features/widgets/chart-library/prepareTimeAxis.clienttest.ts@@ -257,4 +257,52 @@ describe("prepareTimeAxis", () => {);expect(parseChartTimestamp("not a date")).toBeNull();});++ describe("UTC calendar labels when the browser is west of UTC", () => {+ const previousTz = process.env.TZ;++ beforeEach(() => {+ process.env.TZ = "America/Los_Angeles";+ });++ afterEach(() => {+ if (previousTz === undefined) {+ delete process.env.TZ;+ } else {+ process.env.TZ = previousTz;+ }+ });++ it("date ticks and tooltips use the UTC calendar day, not the local previous evening", () => {+ // UTC midnight Jun 28 is still Jun 27 evening in PT. Formatting in local+ // time made the axis read one day early.+ const values = Array.from({ length: 14 }, (_, d) =>+ iso(Date.UTC(2026, 5, 28) + d * DAY),+ );+ const axis = prepareTimeAxis(values, 6);+ expect(axis.mode).toBe("date");+ expect(axis.formatTick(values[0])).toBe("Jun 28");+ expect(axis.formatTooltip(values[0])).toBe("Jun 28, 2026");+ expect(axis.formatTick("2026-06-28")).toBe("Jun 28");+ });++ it("month ticks use the UTC month (UTC midnight Jun 1 is still May locally)", () => {+ const values = Array.from({ length: 200 }, (_, d) =>+ iso(Date.UTC(2026, 5, 1) + d * DAY),+ );+ const axis = prepareTimeAxis(values, 6);+ expect(axis.mode).toBe("month");+ expect(axis.formatTick(values[0])).toBe("Jun 2026");+ });++ it("intraday time ticks stay in local time", () => {+ const start = Date.UTC(2026, 5, 28, 18); // 11 AM PT+ const values = Array.from({ length: 12 }, (_, h) =>+ iso(start + h * HOUR),+ );+ const axis = prepareTimeAxis(values, 6);+ expect(axis.mode).toBe("time");+ expect(axis.formatTick(values[0])).toMatch(/11\s?AM/i);+ });+ });});diff --git a/web/src/features/widgets/chart-library/prepareTimeAxis.ts b/web/src/features/widgets/chart-library/prepareTimeAxis.tsindex 7df08943ca..f4c42af067 100644--- a/web/src/features/widgets/chart-library/prepareTimeAxis.ts+++ b/web/src/features/widgets/chart-library/prepareTimeAxis.ts@@ -268,10 +268,11 @@ export function prepareTimeAxis(const span = count >= 2 ? maxTs - minTs : 0;// Date ticks normally omit the year (one unit per scale), but show it when the// range straddles a year boundary so "Dec 29 → Jan 5" stays unambiguous.- // Use LOCAL year to match the tick formatter (toLocaleDateString renders in- // local time), so a range that crosses Jan 1 locally still shows the year.+ // UTC year to match date/month formatters (buckets are UTC-aligned; local+ // midnight would otherwise drop the year on a range that only crosses Jan 1+ // in the browser timezone).const crossesYear =- new Date(minTs).getFullYear() !== new Date(maxTs).getFullYear();+ new Date(minTs).getUTCFullYear() !== new Date(maxTs).getUTCFullYear();const mode: AxisMode =span > 0 && span <= TIME_SCALE_MAX@@ -297,6 +298,10 @@ export function prepareTimeAxis(const subHour = bucketMs > 0 && bucketMs < HOUR;const subDay = bucketMs > 0 && bucketMs < DAY;+ // Date/month labels use UTC so a UTC-midnight bucket is not formatted as the+ // previous local evening. Intraday time ticks stay in the browser timezone.+ const calendarTimeZone = mode === "time" ? undefined : "UTC";+const formatTick = (raw: unknown): string => {const date = parseChartTimestamp(raw);if (!date) return typeof raw === "string" ? raw : "";@@ -308,11 +313,13 @@ export function prepareTimeAxis(}if (mode === "month") {return date.toLocaleDateString("en-US", {+ timeZone: calendarTimeZone,month: "short",year: "numeric",});}return date.toLocaleDateString("en-US", {+ timeZone: calendarTimeZone,month: "short",day: "numeric",...(crossesYear ? { year: "numeric" } : {}),@@ -327,6 +334,7 @@ export function prepareTimeAxis(const date = parseChartTimestamp(raw);if (!date) return typeof raw === "string" ? raw : "";return date.toLocaleString("en-US", {+ ...(calendarTimeZone ? { timeZone: calendarTimeZone } : {}),month: "short",day: "numeric",year: "numeric",