Open-source Grok Bot alternative for named AI teammates. Local-first desktop, web, and mobile clients with per-bot tools, instructions, and memory. Independent fork of T3 Code.
fix(shared): degrade an unknown system time zone to UTC in usage windows (#6670)
Rishet11684d703b0a8a
diff --git a/packages/shared/src/usageFormat.test.ts b/packages/shared/src/usageFormat.test.tsindex cecc07c6e..fb231fbac 100644--- a/packages/shared/src/usageFormat.test.ts+++ b/packages/shared/src/usageFormat.test.ts@@ -1,5 +1,5 @@// @effect-diagnostics globalDate:off -- A fixed instant keeps calendar-window assertions deterministic.-import { describe, expect, it } from "vite-plus/test";+import { describe, expect, it, vi } from "vite-plus/test";import {enumerateHourStarts,@@ -54,4 +54,20 @@ describe("hourly usage formatting", () => {expect(window.sinceTime).toBe("2026-08-10T12:37:00.000Z");expect(window.untilTime).toBe("2026-08-11T12:37:00.000Z");});++ it("degrades an unknown resolved zone to UTC instead of crashing", () => {+ const resolved = new Intl.DateTimeFormat().resolvedOptions();+ const resolvedOptions = vi+ .spyOn(Intl.DateTimeFormat.prototype, "resolvedOptions")+ .mockReturnValue({ ...resolved, timeZone: "Etc/Unknown" });++ try {+ const now = new Date("2026-08-11T12:37:42.123Z");++ expect(makeWindow(1, now, "hour").timeZone).toBe("UTC");+ expect(makeWindow(30, now).timeZone).toBe("UTC");+ } finally {+ resolvedOptions.mockRestore();+ }+ });});diff --git a/packages/shared/src/usageFormat.ts b/packages/shared/src/usageFormat.tsindex ef2b2bcf2..bd751829d 100644--- a/packages/shared/src/usageFormat.ts+++ b/packages/shared/src/usageFormat.ts@@ -179,13 +179,25 @@ export function makeWindow(now = new Date(),resolution: UsageResolution = "day",): UsageSummaryInput {- const timeZone = Intl.DateTimeFormat().resolvedOptions().timeZone || "UTC";- const format = new Intl.DateTimeFormat("en-CA", {- timeZone,- year: "numeric",- month: "2-digit",- day: "2-digit",- });+ let timeZone = Intl.DateTimeFormat().resolvedOptions().timeZone || "UTC";+ let format: Intl.DateTimeFormat;+ try {+ format = new Intl.DateTimeFormat("en-CA", {+ timeZone,+ year: "numeric",+ month: "2-digit",+ day: "2-digit",+ });+ } catch {+ // An unknown zone should degrade to UTC rather than crash the page.+ timeZone = "UTC";+ format = new Intl.DateTimeFormat("en-CA", {+ timeZone: "UTC",+ year: "numeric",+ month: "2-digit",+ day: "2-digit",+ });+ }const untilDay = format.format(now);if (resolution === "hour") {// Minute-aligned bounds keep labels readable while still representing an