Skip to content

Open-source status page, incident response and uptime monitoring

feat(status-page): render bars and timestamps in the page's time zone (#2983)

Takaaki Abe734d10a4ee99
diff --git a/apps/status-page/src/app/(status-page)/[domain]/[locale]/(public)/client.tsx b/apps/status-page/src/app/(status-page)/[domain]/[locale]/(public)/client.tsx
index 5d80fbcb2..f918c2b5f 100644
--- a/apps/status-page/src/app/(status-page)/[domain]/[locale]/(public)/client.tsx
+++ b/apps/status-page/src/app/(status-page)/[domain]/[locale]/(public)/client.tsx
@@ -31,6 +31,7 @@ import { notFound, useParams } from "next/navigation";
import { useMemo } from "react";
import { Link } from "../../../../../components/common/link";
+import { StatusBlocksProvider } from "../../../../../components/i18n/status-blocks-provider";
import { useStatusPage } from "../../../../../components/status-page/floating-button";
import {
StatusBanner,
@@ -331,7 +332,7 @@ export function Client() {
const uptimeRow = uptimeData?.find(
(u) => u.pageComponentId === component.id,
);
- const { data, uptime } = uptimeRow ?? {};
+ const { data, uptime, timeZone } = uptimeRow ?? {};
return (
<ComponentCard
@@ -341,6 +342,7 @@ export function Client() {
status={component.status}
data={data}
uptime={uptime}
+ timeZone={timeZone}
showUptime={showUptime}
isLoading={isLoading}
latency={buildLatency(uptimeRow)}
@@ -359,7 +361,7 @@ export function Client() {
const uptimeRow = uptimeData?.find(
(u) => u.pageComponentId === component.id,
);
- const { data, uptime } = uptimeRow ?? {};
+ const { data, uptime, timeZone } = uptimeRow ?? {};
return (
<ComponentCard
@@ -369,6 +371,7 @@ export function Client() {
status={component.status}
data={data}
uptime={uptime}
+ timeZone={timeZone}
showUptime={showUptime}
isLoading={isLoading}
latency={buildLatency(uptimeRow)}
@@ -427,6 +430,7 @@ function ComponentCard({
status,
data,
uptime,
+ timeZone,
showUptime,
isLoading,
latency,
@@ -436,6 +440,8 @@ function ComponentCard({
status: "success" | "degraded" | "error" | "info";
data?: ComponentCardData;
uptime?: string;
+ /** The zone the bars' days are grouped in. */
+ timeZone?: string;
showUptime?: boolean;
isLoading?: boolean;
latency?: { label: string; isLoading: boolean; value?: string; href: string };
@@ -481,10 +487,12 @@ function ComponentCard({
)}
</StatusComponentHeaderRight>
</StatusComponentHeader>
- <StatusComponentBody>
- {isLoading ? <StatusBarSkeleton /> : <StatusBar data={data ?? []} />}
- <StatusComponentFooter data={data ?? []} isLoading={isLoading} />
- </StatusComponentBody>
+ <StatusBlocksProvider timezone={timeZone}>
+ <StatusComponentBody>
+ {isLoading ? <StatusBarSkeleton /> : <StatusBar data={data ?? []} />}
+ <StatusComponentFooter data={data ?? []} isLoading={isLoading} />
+ </StatusComponentBody>
+ </StatusBlocksProvider>
</StatusComponent>
);
}
diff --git a/apps/status-page/src/app/(status-page)/[domain]/[locale]/(public)/monitors/[id]/page.tsx b/apps/status-page/src/app/(status-page)/[domain]/[locale]/(public)/monitors/[id]/page.tsx
index a55be4996..07724c313 100644
--- a/apps/status-page/src/app/(status-page)/[domain]/[locale]/(public)/monitors/[id]/page.tsx
+++ b/apps/status-page/src/app/(status-page)/[domain]/[locale]/(public)/monitors/[id]/page.tsx
@@ -29,6 +29,7 @@ import {
ChartLineRegions,
ChartLineRegionsSkeleton,
} from "../../../../../../../components/chart/chart-line-regions";
+import { useStatusPage } from "../../../../../../../components/status-page/floating-button";
import { StatusBlankMonitors } from "../../../../../../../components/status-page/status-blank";
import {
StatusChartContent,
@@ -57,6 +58,7 @@ export default function Page() {
const t = useExtracted();
const [{ tab }, setSearchParams] = useQueryStates(searchParamsParsers);
const trpc = useTRPC();
+ const { timezone } = useStatusPage();
const { id, domain } = useParams<{ id: string; domain: string }>();
const { data: page } = useQuery(
trpc.statusPage.get.queryOptions({ slug: domain }),
@@ -85,9 +87,10 @@ export default function Page() {
hour: "numeric",
minute: "numeric",
timeZoneName: "short",
+ timeZone: timezone,
}),
}));
- }, [monitor?.data.latency?.data]);
+ }, [monitor?.data.latency?.data, timezone]);
const regionLatencyData = useMemo(() => {
if (!monitor?.data.regions?.data) return [];
@@ -102,6 +105,7 @@ export default function Page() {
hour: "numeric",
minute: "numeric",
timeZoneName: "short",
+ timeZone: timezone,
});
if (!acc[timestamp]) {
@@ -117,7 +121,7 @@ export default function Page() {
);
return Object.values(grouped);
- }, [monitor?.data.regions?.data]);
+ }, [monitor?.data.regions?.data, timezone]);
const uptimeData = useMemo(() => {
if (!monitor?.data.uptime?.data) return [];
@@ -130,10 +134,11 @@ export default function Page() {
hour: "numeric",
minute: "numeric",
timeZoneName: "short",
+ timeZone: timezone,
}),
...item,
}));
- }, [monitor?.data.uptime?.data]);
+ }, [monitor?.data.uptime?.data, timezone]);
const { totalChecks, uptimePercentage, slowestRegion, p75Range } =
useMemo(() => {
diff --git a/apps/status-page/src/app/(status-page)/[domain]/[locale]/(public)/monitors/page.tsx b/apps/status-page/src/app/(status-page)/[domain]/[locale]/(public)/monitors/page.tsx
index f3babab26..80a2e0d09 100644
--- a/apps/status-page/src/app/(status-page)/[domain]/[locale]/(public)/monitors/page.tsx
+++ b/apps/status-page/src/app/(status-page)/[domain]/[locale]/(public)/monitors/page.tsx
@@ -19,12 +19,14 @@ import {
ChartAreaPercentiles,
ChartAreaPercentilesSkeleton,
} from "../../../../../../components/chart/chart-area-percentiles";
+import { useStatusPage } from "../../../../../../components/status-page/floating-button";
import { StatusBlankMonitors } from "../../../../../../components/status-page/status-blank";
import { useTRPC } from "../../../../../../lib/trpc/client";
export default function Page() {
const { domain } = useParams<{ domain: string }>();
const trpc = useTRPC();
+ const { timezone } = useStatusPage();
const { data: page } = useQuery(
trpc.statusPage.get.queryOptions({ slug: domain }),
);
@@ -60,6 +62,7 @@ export default function Page() {
hour: "numeric",
minute: "numeric",
timeZoneName: "short",
+ timeZone: timezone,
},
),
})) ?? [];
diff --git a/apps/status-page/src/app/(status-page)/[domain]/layout.tsx b/apps/status-page/src/app/(status-page)/[domain]/layout.tsx
index 626a3ad4b..71db1a94a 100644
--- a/apps/status-page/src/app/(status-page)/[domain]/layout.tsx
+++ b/apps/status-page/src/app/(status-page)/[domain]/layout.tsx
@@ -68,6 +68,7 @@ export default async function Layout({
defaultNumberOfDays={cfg.days}
defaultCommunityTheme={cfg.theme}
customTheme={page.customTheme}
+ timezone={page.defaultTimezone}
>
{children}
<FloatingButton
diff --git a/apps/status-page/src/components/content/timestamp-hover-card.tsx b/apps/status-page/src/components/content/timestamp-hover-card.tsx
index e70ecf23d..7b722a92d 100644
--- a/apps/status-page/src/components/content/timestamp-hover-card.tsx
+++ b/apps/status-page/src/components/content/timestamp-hover-card.tsx
@@ -1,6 +1,5 @@
"use client";
-import { UTCDate } from "@date-fns/utc";
import { Check, Copy } from "@openstatus/icons";
import {
HoverCard,
@@ -13,11 +12,13 @@ import {
type HoverCardContentProps,
HoverCardPortal,
} from "@radix-ui/react-hover-card";
-import { format } from "date-fns";
import { formatDistanceToNowStrict } from "date-fns";
import { useExtracted } from "next-intl";
import { useEffect, useState } from "react";
+import { formatTimestamp } from "../../lib/formatter";
+import { useStatusPage } from "../status-page/floating-button";
+
export function TimestampHoverCard({
date,
side = "right",
@@ -39,10 +40,12 @@ export function TimestampHoverCard({
const isTouch = useMediaQuery("(hover: none)");
const [_, setRerender] = useState(0);
- const timezone = Intl.DateTimeFormat().resolvedOptions().timeZone;
+ const { timezone: pageTimezone } = useStatusPage();
+ const viewerTimezone = Intl.DateTimeFormat().resolvedOptions().timeZone;
+ // a non-UTC page zone leads, as the visible text is in it; each zone once
+ const lead = pageTimezone === "UTC" ? viewerTimezone : pageTimezone;
+ const timezones = [...new Set([lead, viewerTimezone, "UTC"])];
const relative = formatDistanceToNowStrict(date, { addSuffix: true });
- const formatted = format(date, "LLL dd, y HH:mm:ss");
- const utc = format(new UTCDate(date), "LLL dd, y HH:mm:ss");
useEffect(() => {
// only setInterval if open
@@ -74,8 +77,13 @@ export function TimestampHoverCard({
{...{ side, align, alignOffset, sideOffset }}
>
<dl className="flex flex-col gap-1">
- <Row value={formatted} label={timezone} />
- <Row value={utc} label="UTC" />
+ {timezones.map((timezone) => (
+ <Row
+ key={timezone}
+ value={formatTimestamp(date, timezone, true)}
+ label={timezone}
+ />
+ ))}
{/* <Row value={date.toISOString()} label="ISO" /> */}
{/* <Row value={String(date.getTime())} label="Timestamp" /> */}
<Row value={relative} label={t("Relative")} />
diff --git a/apps/status-page/src/components/i18n/status-blocks-provider.tsx b/apps/status-page/src/components/i18n/status-blocks-provider.tsx
index 4d8573c42..46d41861b 100644
--- a/apps/status-page/src/components/i18n/status-blocks-provider.tsx
+++ b/apps/status-page/src/components/i18n/status-blocks-provider.tsx
@@ -4,6 +4,11 @@ import {
StatusBlocksI18nProvider,
type StatusBlocksLabels,
} from "@openstatus/ui/components/blocks/status-i18n";
+import {
+ resolveTimeZone,
+ timeZoneShortName,
+ timeZoneShortNames,
+} from "@openstatus/utils";
import { useExtracted, useLocale } from "next-intl";
import { useMemo } from "react";
@@ -12,10 +17,9 @@ import {
formatDateRange,
formatDateRangeParts,
formatDateTime,
+ formatTimestamp,
} from "../../lib/formatter";
-
-// Status-page timestamps render in UTC; the suffix tells viewers which zone.
-const withUTC = (value: string) => `${value} (UTC)`;
+import { useStatusPage } from "../status-page/floating-button";
/**
* StatusBlocksProvider
@@ -30,14 +34,25 @@ const withUTC = (value: string) => `${value} (UTC)`;
*/
export function StatusBlocksProvider({
children,
+ timezone: timezoneOverride,
}: {
children: React.ReactNode;
+ /** Defaults to the page's zone. */
+ timezone?: string;
}) {
const t = useExtracted();
const locale = useLocale();
+ const { timezone: pageTimezone } = useStatusPage();
+ const timezone = timezoneOverride
+ ? resolveTimeZone(timezoneOverride)
+ : pageTimezone;
- const value = useMemo<StatusBlocksLabels>(
- () => ({
+ const value = useMemo<StatusBlocksLabels>(() => {
+ // timestamps render in the page zone; the suffix names the zone as of
+ // each instant, since DST zones change their short name through the year
+ const withZone = (value: string, ...instants: Date[]) =>
+ `${value} (${timeZoneShortNames(timezone, locale, instants)})`;
+ return {
systemStatus: {
success: {
long: t("All Systems Operational"),
@@ -113,20 +128,35 @@ export function StatusBlocksProvider({
durationAcross: (duration: string) =>
t("across {duration}", { duration }),
- formatDate: (d: Date) => withUTC(formatDate(d, { locale })),
- formatDateShort: (d: Date) => formatDate(d, { month: "short", locale }),
- formatDateTime: (d: Date) => withUTC(formatDateTime(d, locale)),
+ formatDate: (d: Date) =>
+ withZone(formatDate(d, { locale, timeZone: timezone }), d),
+ formatDateShort: (d: Date) =>
+ formatDate(d, { month: "short", locale, timeZone: timezone }),
+ formatDateTime: (d: Date) =>
+ withZone(formatDateTime(d, locale, timezone), d),
+ // bar keys are calendar dates stored as UTC midnight, so no zone here
+ formatDay: (day: string) =>
+ formatDate(new Date(day), { month: "short", locale }),
+ timeZone: timezone,
+ // the banner stamp is en-US throughout, zone name included
+ formatTimestamp: (d: Date) =>
+ `${formatTimestamp(d, timezone)} (${timeZoneShortName(timezone, "en-US", d)})`,
formatDateRange: (from?: Date, to?: Date) => {
- const range = formatDateRange(from, to, locale);
- return from || to ? withUTC(range) : range;
+ const range = formatDateRange(from, to, locale, timezone);
+ const instants = [from, to].filter((d): d is Date => d !== undefined);
+ return instants.length > 0 ? withZone(range, ...instants) : range;
},
formatDateRangeParts: (from: Date, to: Date) => {
- const { from: start, to: end } = formatDateRangeParts(from, to, locale);
- return { from: start, to: withUTC(end) };
+ const { from: start, to: end } = formatDateRangeParts(
+ from,
+ to,
+ locale,
+ timezone,
+ );
+ return { from: start, to: withZone(end, from, to) };
},
- }),
- [t, locale],
- );
+ };
+ }, [t, locale, timezone]);
return (
<StatusBlocksI18nProvider value={value}>
diff --git a/apps/status-page/src/components/nav/footer.tsx b/apps/status-page/src/components/nav/footer.tsx
index a74f26eb1..f4bd94cd9 100644
--- a/apps/status-page/src/components/nav/footer.tsx
+++ b/apps/status-page/src/components/nav/footer.tsx
@@ -7,17 +7,16 @@ import {
StatusPageFooterContent,
StatusPagePoweredBy,
} from "@openstatus/ui/components/blocks/status-page-footer";
-import { Skeleton } from "@openstatus/ui/components/ui/skeleton";
import { cn } from "@openstatus/ui/lib/utils";
import { useQuery } from "@tanstack/react-query";
import { useParams } from "next/navigation";
-import { useEffect, useState } from "react";
import { useEmbed } from "../../hooks/use-embed";
import { useTRPC } from "../../lib/trpc/client";
import { Link } from "../common/link";
import { TimestampHoverCard } from "../content/timestamp-hover-card";
import { LocaleSwitcher } from "../locale-switcher";
+import { useStatusPage } from "../status-page/floating-button";
import { ThemeSwitcher } from "../themes/theme-switcher";
export function Footer({
@@ -25,17 +24,13 @@ export function Footer({
...props
}: React.ComponentProps<"footer">) {
const { domain } = useParams<{ domain: string }>();
- const [isMounted, setIsMounted] = useState(false);
const trpc = useTRPC();
const { data: page, dataUpdatedAt } = useQuery({
...trpc.statusPage.get.queryOptions({ slug: domain }),
});
const embed = useEmbed();
- const timezone = Intl.DateTimeFormat().resolvedOptions().timeZone;
-
- useEffect(() => {
- setIsMounted(true);
- }, []);
+ // the zone the page's days and timestamps render in, not the viewer's
+ const { timezone } = useStatusPage();
if (!page) return null;
@@ -69,14 +64,8 @@ export function Footer({
align="end"
className="text-muted-foreground/70 mr-2 flex items-center gap-1.5"
>
- {isMounted ? (
- <>
- <Clock className="size-3" />
- <span className="font-mono text-xs">{timezone}</span>
- </>
- ) : (
- <Skeleton className="h-4 w-28" />
- )}
+ <Clock className="size-3" />
+ <span className="font-mono text-xs">{timezone}</span>
</TimestampHoverCard>
<LocaleSwitcher
pageLocales={page.locales}
diff --git a/apps/status-page/src/components/status-page/floating-button.tsx b/apps/status-page/src/components/status-page/floating-button.tsx
index 3b8c3baaa..4457e6b7f 100644
--- a/apps/status-page/src/components/status-page/floating-button.tsx
+++ b/apps/status-page/src/components/status-page/floating-button.tsx
@@ -35,9 +35,10 @@ import {
} from "@openstatus/ui/components/ui/select";
import { Separator } from "@openstatus/ui/components/ui/separator";
import { cn } from "@openstatus/ui/lib/utils";
+import { resolveTimeZone } from "@openstatus/utils";
import { parseAsString, useQueryState } from "nuqs";
import type React from "react";
-import { createContext, useContext, useEffect, useState } from "react";
+import { createContext, useContext, useEffect, useMemo, useState } from "react";
import { clearThemeDraft } from "../../lib/theme-draft";
import { ThemeSelect } from "../themes/theme-select";
@@ -83,6 +84,8 @@ interface StatusPageContextType {
/** Unregistered theme previewed from the explorer's builder. */
draftTheme: Theme | null;
setDraftTheme: (draftTheme: Theme | null) => void;
+ /** IANA zone the page's days and timestamps are rendered in. */
+ timezone: string;
}
const StatusPageContext = createContext<StatusPageContextType | null>(null);
@@ -103,6 +106,7 @@ export function StatusPageProvider({
defaultNumberOfDays = 45,
defaultCommunityTheme = "default",
customTheme,
+ timezone: pageTimezone = "UTC",
}: {
children: React.ReactNode;
defaultCardType?: CardType;
@@ -111,6 +115,7 @@ export function StatusPageProvider({
defaultNumberOfDays?: NumberOfDays;
defaultCommunityTheme?: CommunityTheme;
customTheme?: CustomTheme | null;
+ timezone?: string;
}) {
const [cardType, setCardType] = useState<CardType>(defaultCardType);
const [barType, setBarType] = useState<BarType>(defaultBarType);
@@ -121,6 +126,9 @@ export function StatusPageProvider({
defaultCommunityTheme,
);
const [draftTheme, setDraftTheme] = useState<Theme | null>(null);
+ // the server vetted the zone against Node; an older browser may still not
+ // know it and would throw on every formatter
+ const timezone = useMemo(() => resolveTimeZone(pageTimezone), [pageTimezone]);
// a draft shadows the community theme, so picking one discards the draft
function setCommunityTheme(theme: CommunityTheme) {
@@ -167,6 +175,7 @@ export function StatusPageProvider({
setCommunityTheme,
draftTheme,
setDraftTheme,
+ timezone,
}}
>
{children}
diff --git a/apps/status-page/src/lib/formatter.test.ts b/apps/status-page/src/lib/formatter.test.ts
index 9ca20f914..32f225355 100644
--- a/apps/status-page/src/lib/formatter.test.ts
+++ b/apps/status-page/src/lib/formatter.test.ts
@@ -8,10 +8,11 @@ import {
formatMilliseconds,
formatMillisecondsRange,
formatTime,
+ formatTimestamp,
} from "./formatter";
-// Timestamps must render in UTC so every viewer sees the authored time,
-// independent of their local timezone (see #2302).
+// Timestamps render in UTC unless a zone is given, never in the viewer's
+// local timezone, so every viewer sees the same time (see #2302).
describe("formatter UTC rendering", () => {
describe("formatDate", () => {
test("renders the UTC day with a long month", () => {
@@ -32,13 +33,13 @@ describe("formatter UTC rendering", () => {
);
});
- test("ignores a caller attempt to override the timezone", () => {
- // 01:00 UTC is still Jan 14 in New York, so a leaked override would read "January 14".
+ test("renders the day of the requested zone", () => {
+ // 22:30 UTC on the 15th is already the 16th in Tokyo
expect(
- formatDate(new Date("2024-01-15T01:00:00Z"), {
- timeZone: "America/New_York",
+ formatDate(new Date("2024-01-15T22:30:00Z"), {
+ timeZone: "Asia/Tokyo",
}),
- ).toBe("January 15, 2024");
+ ).toBe("January 16, 2024");
});
});
@@ -48,6 +49,16 @@ describe("formatter UTC rendering", () => {
"January 15 at 2:30 PM",
);
});
+
+ test("renders the wall-clock time of the requested zone", () => {
+ expect(
+ formatDateTime(
+ new Date("2024-01-15T22:30:00Z"),
+ undefined,
+ "Asia/Tokyo",
+ ),
+ ).toBe("January 16 at 7:30 AM");
+ });
});
describe("formatTime", () => {
@@ -61,6 +72,28 @@ describe("formatter UTC rendering", () => {
});
});
+describe("formatTimestamp", () => {
+ const date = new Date("2024-01-15T22:30:00Z");
+
+ test("renders the compact banner stamp in UTC by default", () => {
+ expect(formatTimestamp(date)).toBe("Jan 15, 2024 22:30");
+ });
+
+ test("renders the wall-clock time of the requested zone", () => {
+ expect(formatTimestamp(date, "Asia/Tokyo")).toBe("Jan 16, 2024 07:30");
+ expect(formatTimestamp(date, "America/New_York")).toBe(
+ "Jan 15, 2024 17:30",
+ );
+ });
+
+ test("appends seconds for the hover card rows", () => {
+ const at = new Date("2024-01-15T22:30:05Z");
+ expect(formatTimestamp(at, "Asia/Tokyo", true)).toBe(
+ "Jan 16, 2024 07:30:05",
+ );
+ });
+});
+
describe("formatMilliseconds", () => {
test("renders sub-second values with the millisecond unit", () => {
expect(formatMilliseconds(111)).toBe("111 ms");
@@ -139,6 +172,30 @@ describe("formatDateRange", () => {
test("renders `All time` when no bounds are given", () => {
expect(formatDateRange()).toBe("All time");
});
+
+ describe("in a time zone", () => {
+ // 01:00-05:00 on Jan 16 in Tokyo, still Jan 15 in UTC
+ const from = new Date("2024-01-15T16:00:00Z");
+ const to = new Date("2024-01-15T20:00:00Z");
+
+ test("collapses a range that is one day in the zone", () => {
+ expect(formatDateRange(from, to, undefined, "Asia/Tokyo")).toBe(
+ "January 16 at 1:00 AM - 5:00 AM",
+ );
+ expect(formatDateRange(from, to)).toBe("January 15 at 4:00 PM - 8:00 PM");
+ });
+
+ test("renders date-only when the range spans whole days in the zone", () => {
+ expect(
+ formatDateRange(
+ new Date("2024-01-14T15:00:00.000Z"),
+ new Date("2024-01-17T14:59:59.999Z"),
+ undefined,
+ "Asia/Tokyo",
+ ),
+ ).toBe("January 15, 2024 - January 17, 2024");
+ });
+ });
});
describe("formatDateRangeParts", () => {
diff --git a/apps/status-page/src/lib/formatter.ts b/apps/status-page/src/lib/formatter.ts
index ccad1bfd4..3aa158176 100644
--- a/apps/status-page/src/lib/formatter.ts
+++ b/apps/status-page/src/lib/formatter.ts
@@ -1,5 +1,4 @@
-import { UTCDate } from "@date-fns/utc";
-import { endOfDay, isSameDay, startOfDay } from "date-fns";
+import { TZDate } from "@date-fns/tz";
export function formatMilliseconds(ms: number) {
if (ms > 1000) {
@@ -50,42 +49,88 @@ export function formatNumber(
// TODO: think of supporting custom formats
-// All status-page timestamps render in UTC for consistency across viewers; the
-// StatusTimestamp hover card surfaces the viewer's local timezone on demand.
+// All status-page timestamps render in the page's zone (UTC unless the page
+// says otherwise) so every viewer sees the same time; the StatusTimestamp hover
+// card surfaces the viewer's local timezone on demand.
+
+// Day boundaries are built with TZDate directly: date-fns 3.6 helpers work in
+// the machine's zone.
+function dayStartMs(date: Date, timeZone: string, dayOffset = 0): number {
+ const d = new TZDate(date, timeZone);
+ return new TZDate(
+ d.getFullYear(),
+ d.getMonth(),
+ d.getDate() + dayOffset,
+ timeZone,
+ ).getTime();
+}
+
+function isStartOfDay(date: Date, timeZone: string) {
+ return dayStartMs(date, timeZone) === date.getTime();
+}
+
+function isEndOfDay(date: Date, timeZone: string) {
+ return dayStartMs(date, timeZone, 1) - 1 === date.getTime();
+}
+
+function isSameDay(a: Date, b: Date, timeZone: string) {
+ return dayStartMs(a, timeZone) === dayStartMs(b, timeZone);
+}
export function formatDate(
date: Date,
options?: Intl.DateTimeFormatOptions & { locale?: string },
) {
- const { locale, ...rest } = options ?? {};
+ const { locale, timeZone = "UTC", ...rest } = options ?? {};
return date.toLocaleDateString(locale, {
year: "numeric",
month: "long",
day: "numeric",
...rest,
- // last so callers can't override away from UTC (the "(UTC)" label depends on it)
- timeZone: "UTC",
+ timeZone,
});
}
-export function formatDateTime(date: Date, locale?: string) {
+export function formatDateTime(date: Date, locale?: string, timeZone = "UTC") {
return date.toLocaleDateString(locale, {
month: "long",
day: "numeric",
hour: "numeric",
minute: "numeric",
- timeZone: "UTC",
+ timeZone,
});
}
-export function formatTime(date: Date, locale?: string) {
+export function formatTime(date: Date, locale?: string, timeZone = "UTC") {
return date.toLocaleTimeString(locale, {
hour: "numeric",
minute: "numeric",
- timeZone: "UTC",
+ timeZone,
});
}
+/** Compact banner stamp, `Oct 03, 2026 14:41` (`:05` with seconds), in `timeZone`. */
+export function formatTimestamp(
+ date: Date,
+ timeZone = "UTC",
+ withSeconds = false,
+) {
+ const parts = new Intl.DateTimeFormat("en-US", {
+ timeZone,
+ hourCycle: "h23",
+ month: "short",
+ day: "2-digit",
+ year: "numeric",
+ hour: "2-digit",
+ minute: "2-digit",
+ ...(withSeconds && { second: "2-digit" }),
+ }).formatToParts(date);
+ const part = (type: Intl.DateTimeFormatPartTypes) =>
+ parts.find((p) => p.type === type)?.value ?? "";
+ const stamp = `${part("month")} ${part("day")}, ${part("year")} ${part("hour")}:${part("minute")}`;
+ return withSeconds ? `${stamp}:${part("second")}` : stamp;
+}
+
/**
* Returns the start/end of a closed range as separate strings, collapsing the
* `to` side to a time-only render when `from` and `to` fall on the same day.
@@ -95,56 +140,60 @@ export function formatDateRangeParts(
from: Date,
to: Date,
locale?: string,
+ timeZone = "UTC",
): { from: string; to: string } {
- if (isSameDay(new UTCDate(from), new UTCDate(to))) {
+ if (isSameDay(from, to, timeZone)) {
return {
- from: formatDateTime(from, locale),
- to: formatTime(to, locale),
+ from: formatDateTime(from, locale, timeZone),
+ to: formatTime(to, locale, timeZone),
};
}
- const isFromStartDay =
- startOfDay(new UTCDate(from)).getTime() === from.getTime();
- const isToEndDay = endOfDay(new UTCDate(to)).getTime() === to.getTime();
+ const isFromStartDay = isStartOfDay(from, timeZone);
+ const isToEndDay = isEndOfDay(to, timeZone);
if (isFromStartDay && isToEndDay) {
return {
- from: formatDate(from, { locale }),
- to: formatDate(to, { locale }),
+ from: formatDate(from, { locale, timeZone }),
+ to: formatDate(to, { locale, timeZone }),
};
}
return {
- from: formatDateTime(from, locale),
- to: formatDateTime(to, locale),
+ from: formatDateTime(from, locale, timeZone),
+ to: formatDateTime(to, locale, timeZone),
};
}
-export function formatDateRange(from?: Date, to?: Date, locale?: string) {
- const sameDay = from && to && isSameDay(new UTCDate(from), new UTCDate(to));
- const isFromStartDay =
- from && startOfDay(new UTCDate(from)).getTime() === from.getTime();
- const isToEndDay = to && endOfDay(new UTCDate(to)).getTime() === to.getTime();
+export function formatDateRange(
+ from?: Date,
+ to?: Date,
+ locale?: string,
+ timeZone = "UTC",
+) {
+ const sameDay = from && to && isSameDay(from, to, timeZone);
+ const isFromStartDay = from && isStartOfDay(from, timeZone);
+ const isToEndDay = to && isEndOfDay(to, timeZone);
if (sameDay) {
if (from.getTime() === to.getTime()) {
- return formatDateTime(from, locale);
+ return formatDateTime(from, locale, timeZone);
}
if (from && to) {
- return `${formatDateTime(from, locale)} - ${formatTime(to, locale)}`;
+ return `${formatDateTime(from, locale, timeZone)} - ${formatTime(to, locale, timeZone)}`;
}
}
if (from && to) {
if (isFromStartDay && isToEndDay) {
- return `${formatDate(from, { locale })} - ${formatDate(to, { locale })}`;
+ return `${formatDate(from, { locale, timeZone })} - ${formatDate(to, { locale, timeZone })}`;
}
- return `${formatDateTime(from, locale)} - ${formatDateTime(to, locale)}`;
+ return `${formatDateTime(from, locale, timeZone)} - ${formatDateTime(to, locale, timeZone)}`;
}
if (to) {
- return `Until ${formatDateTime(to, locale)}`;
+ return `Until ${formatDateTime(to, locale, timeZone)}`;
}
if (from) {
- return `Since ${formatDateTime(from, locale)}`;
+ return `Since ${formatDateTime(from, locale, timeZone)}`;
}
return "All time";
diff --git a/apps/status-page/src/lib/status-blocks-labels.test.ts b/apps/status-page/src/lib/status-blocks-labels.test.ts
index 67a53d76d..b0e8097e2 100644
--- a/apps/status-page/src/lib/status-blocks-labels.test.ts
+++ b/apps/status-page/src/lib/status-blocks-labels.test.ts
@@ -14,6 +14,14 @@ describe("defaultStatusBlocksLabels UTC suffix", () => {
expect(labels.formatDateShort(date)).toBe("Jan 15, 2024");
});
+ test("formatDay renders the bar's calendar date without shifting it", () => {
+ expect(labels.formatDay("2026-10-16T00:00:00.000Z")).toBe("Oct 16, 2026");
+ });
+
+ test("formatTimestamp keeps the compact banner shape", () => {
+ expect(labels.formatTimestamp(date)).toBe("Jan 15, 2024 14:30 (UTC)");
+ });
+
test("formatDateTime appends the UTC suffix", () => {
expect(labels.formatDateTime(date)).toBe("January 15 at 2:30 PM (UTC)");
});
diff --git a/packages/api/src/router/statusPage.ts b/packages/api/src/router/statusPage.ts
index 36e412aa1..583d442d0 100644
--- a/packages/api/src/router/statusPage.ts
+++ b/packages/api/src/router/statusPage.ts
@@ -15,6 +15,7 @@ import {
selectStatusReportPageSchema,
selectWorkspaceSchema,
statusReport,
+ timeZoneSchema,
} from "@openstatus/db/src/schema";
import { getStatusUpdateTypes } from "@openstatus/services/page";
import { constantTimeEqual } from "@openstatus/services/page-access";
@@ -54,6 +55,7 @@ import {
getMetricsLatencyMultiProcedure,
getMetricsLatencyProcedure,
getMetricsRegionsProcedure,
+ getStatusInTimeZoneProcedure,
getStatusProcedure,
getUptimeProcedure,
} from "./tinybird";
@@ -85,6 +87,42 @@ const queryPasswordSchema = z.string().nullish();
const bySlugOrDomain = (slug: string) =>
sql`lower(${page.slug}) = ${slug} OR lower(${page.customDomain}) = ${slug}`;
+// Status rows grouped into `timeZone` days, with the zone they ended up in.
+async function fetchStatusDays(
+ monitors: Parameters<typeof fetchByJobType>[0],
+ timeZone: string,
+) {
+ const readUtc = async () => ({
+ timeZone: "UTC",
+ rows: await fetchByJobType(monitors, (type) =>
+ getStatusProcedure("45d", type),
+ ),
+ });
+ // UTC pages keep the 45d pipes; other zones regroup 15m buckets into their days
+ if (timeZone === "UTC") return readUtc();
+ try {
+ const rows = await fetchByJobType(
+ monitors,
+ (type) =>
+ ({ monitorIds }) =>
+ getStatusInTimeZoneProcedure(type)({
+ monitorIds,
+ timezone: timeZone,
+ }),
+ );
+ return { timeZone, rows };
+ } catch (err) {
+ // ClickHouse's tz database can reject a zone Node accepts: keep real bars
+ // in UTC days; other errors still drop the page to manual mode
+ if (!(err instanceof Error) || !/time ?zone/i.test(err.message)) throw err;
+ console.error(
+ `[status-page] zone ${timeZone} failed, using UTC days:`,
+ err,
+ );
+ return readUtc();
+ }
+}
+
export const statusPageRouter = createTRPCRouter({
get: publicProcedure
.input(
@@ -794,17 +832,24 @@ export const statusPageRouter = createTRPCRouter({
const monitors = pageComponents.filter(isMonitorComponent);
+ // a zone this runtime cannot resolve renders the page in UTC instead of failing it
+ const pageTimeZone = timeZoneSchema
+ .catch("UTC")
+ .parse(_page.defaultTimezone);
+
// Manual mode never touches Tinybird. Otherwise race the reads against
// the fallback budget: a slow (>5s) or erroring Tinybird degrades the
// whole page to manual mode so bars still render from DB events.
const tinybird = await withTinybirdFallback(() =>
input.barType === "manual"
? Promise.resolve(null)
- : fetchByJobType(monitors, (type) => getStatusProcedure("45d", type)),
+ : fetchStatusDays(monitors, pageTimeZone),
);
const tinybirdUnhealthy = !tinybird.ok;
- const statusDataByMonitorId = tinybird.data ?? new Map<string, never[]>();
+ const timeZone = tinybird.data?.timeZone ?? pageTimeZone;
+ const statusDataByMonitorId =
+ tinybird.data?.rows ?? new Map<string, never[]>();
const parsedConfiguration = pageConfigurationSchema.safeParse(
_page.configuration ?? {},
@@ -861,6 +906,7 @@ export const statusPageRouter = createTRPCRouter({
rawData,
monitorId,
lookbackPeriod,
+ timeZone,
);
} else {
// Static components, manual mode, or NOOP mode: use synthetic data
@@ -868,6 +914,7 @@ export const statusPageRouter = createTRPCRouter({
errorDays: [],
degradedDays: [],
lookbackPeriod,
+ timeZone,
});
}
@@ -882,12 +929,14 @@ export const statusPageRouter = createTRPCRouter({
data: filledData,
cardType: effectiveCardType,
barType: effectiveBarType,
+ timeZone,
});
const uptime = getUptime({
data: filledData,
events,
barType: effectiveBarType,
cardType: effectiveCardType,
+ timeZone,
privateLocationOnly:
c.monitor != null && privateOnlyMonitorIds.has(c.monitor.id),
});
@@ -902,6 +951,8 @@ export const statusPageRouter = createTRPCRouter({
...(c.monitor ? { monitor: c.monitor } : {}),
data: processedData,
uptime,
+ // the zone the days were grouped in, UTC if the page's was rejected
+ timeZone,
};
});
}),
diff --git a/packages/api/src/router/tinybird/index.ts b/packages/api/src/router/tinybird/index.ts
index df88b0f86..7a31df8f7 100644
--- a/packages/api/src/router/tinybird/index.ts
+++ b/packages/api/src/router/tinybird/index.ts
@@ -196,6 +196,16 @@ export function getStatusProcedure(_period: "45d", type: Type) {
throw new TRPCError({ code: "NOT_FOUND", message: "Invalid type" });
}
+/** 15m buckets regrouped into the days of a time zone; the 45d pipes are UTC only. */
+export function getStatusInTimeZoneProcedure(type: Type) {
+ if (type === "dns") return tb.dnsStatus15m;
+ if (type === "http") return tb.httpStatus15m;
+ if (type === "tcp") return tb.tcpStatus15m;
+ if (type === "icmp") return tb.icmpStatus15m;
+ if (type === "grpc") return tb.grpcStatus15m;
+ throw new TRPCError({ code: "NOT_FOUND", message: "Invalid type" });
+}
+
export function getGetProcedure(period: "14d", type: Type) {
switch (period) {
case "14d":
diff --git a/packages/db/src/schema/pages/validation.ts b/packages/db/src/schema/pages/validation.ts
index 8b3e040e4..d26db98ba 100644
--- a/packages/db/src/schema/pages/validation.ts
+++ b/packages/db/src/schema/pages/validation.ts
@@ -6,6 +6,7 @@ import {
THEME_KEYS,
validateCustomTheme,
} from "@openstatus/theme-store";
+import { isKnownTimeZone } from "@openstatus/utils";
import { createInsertSchema, createSelectSchema } from "drizzle-zod";
import { z } from "zod";
@@ -33,16 +34,6 @@ export const customDomainSchema = z
)
.or(z.enum([""]));
-function isKnownTimeZone(value: string): boolean {
- try {
- new Intl.DateTimeFormat("en-US", { timeZone: value });
- return true;
- } catch (error) {
- if (error instanceof RangeError) return false;
- throw error;
- }
-}
-
// ClickHouse rejects offsets like "+09:00" that Intl accepts.
export const timeZoneSchema = z
.string()
diff --git a/packages/ui/registry.json b/packages/ui/registry.json
index e877e2b17..6f877a238 100644
--- a/packages/ui/registry.json
+++ b/packages/ui/registry.json
@@ -67,7 +67,7 @@
"type": "registry:lib",
"title": "Status Utilities",
"description": "Utility functions for status formatting and display",
- "dependencies": ["date-fns"],
+ "dependencies": ["date-fns", "@date-fns/[email protected]"],
"cssVars": {
"theme": {
"color-success": "var(--success)",
@@ -172,6 +172,7 @@
"title": "Status Timestamp",
"description": "Interactive timestamp display with tooltip (simple) or hover-card (rich) variants showing multiple timezone formats",
"registryDependencies": [
+ "status-i18n",
"hover-card",
"tooltip",
"use-copy-to-clipboard",
@@ -180,7 +181,6 @@
"dependencies": [
"@radix-ui/react-hover-card",
"date-fns",
- "@date-fns/[email protected]",
"lucide-react"
],
"files": [
diff --git a/packages/ui/src/components/blocks/README.md b/packages/ui/src/components/blocks/README.md
index 5d4211184..3186bdf77 100644
--- a/packages/ui/src/components/blocks/README.md
+++ b/packages/ui/src/components/blocks/README.md
@@ -460,7 +460,7 @@ Internally, `useStatusBlocksLabels()` returns `defaultStatusBlocksLabels` (expor
### Localizing in your app
-Mount `<StatusBlocksI18nProvider>` once near the root of your tree and pass a `StatusBlocksLabels` object:
+Mount `<StatusBlocksI18nProvider>` once near the root of your tree and pass a `StatusBlocksLabelsInput` object (`StatusBlocksLabels` with `formatDay` and `formatTimestamp` optional; missing ones fall back to the defaults):
```tsx
"use client";
@@ -469,14 +469,14 @@ import { useMemo } from "react";
import { useTranslations, useLocale } from "next-intl"; // or any i18n library
import {
StatusBlocksI18nProvider,
- type StatusBlocksLabels,
+ type StatusBlocksLabelsInput,
} from "@openstatus/ui/components/blocks/status-i18n";
export function MyStatusBlocksProvider({ children }: { children: React.ReactNode }) {
const t = useTranslations();
const locale = useLocale();
- const labels = useMemo<StatusBlocksLabels>(() => {
+ const labels = useMemo<StatusBlocksLabelsInput>(() => {
const dateFmt = new Intl.DateTimeFormat(locale, { dateStyle: "long" });
const dateShortFmt = new Intl.DateTimeFormat(locale, { dateStyle: "medium" });
const dateTimeFmt = new Intl.DateTimeFormat(locale, {
@@ -560,6 +560,21 @@ const labels: StatusBlocksLabels = {
};
```
+### Rendering in a time zone
+
+Pass `timeZone` to every instant formatter and set `timeZone` on the labels so the rich timestamp hover card lists it first, ahead of the viewer's zone and UTC. `formatDay` receives a bar's `YYYY-MM-DD` key, a calendar date already in that zone, so it must format without shifting it. The example shows two formatters; give every other instant formatter (`formatDate`, `formatTimestamp`, the ranges) the same `timeZone`:
+
+```tsx
+const labels: StatusBlocksLabelsInput = {
+ ...defaultStatusBlocksLabels,
+ timeZone: "Asia/Tokyo",
+ formatDateTime: (d) =>
+ new Intl.DateTimeFormat(locale, { dateStyle: "medium", timeStyle: "short", timeZone: "Asia/Tokyo" }).format(d),
+ formatDay: (day) =>
+ new Intl.DateTimeFormat(locale, { dateStyle: "medium", timeZone: "UTC" }).format(new Date(day)),
+};
+```
+
## Extension Slots
Blocks expose slot props so app-specific concerns (Next.js `<Link>`, markdown rendering, etc.) stay out of the registry while still being injectable by consumers.
diff --git a/packages/ui/src/components/blocks/status-bar.tsx b/packages/ui/src/components/blocks/status-bar.tsx
index 9aee794c8..94d7e07cd 100644
--- a/packages/ui/src/components/blocks/status-bar.tsx
+++ b/packages/ui/src/components/blocks/status-bar.tsx
@@ -612,9 +612,7 @@ export function StatusBarCard({
const labels = useStatusBlocksLabels();
return (
<div data-slot="status-bar-card">
- <div className="p-2 text-xs">
- {labels.formatDateShort(new Date(item.day))}
- </div>
+ <div className="p-2 text-xs">{labels.formatDay(item.day)}</div>
{item.card.length > 0 && (
<>
<Separator />
diff --git a/packages/ui/src/components/blocks/status-i18n.tsx b/packages/ui/src/components/blocks/status-i18n.tsx
index ffb213d5e..c90d9ac58 100644
--- a/packages/ui/src/components/blocks/status-i18n.tsx
+++ b/packages/ui/src/components/blocks/status-i18n.tsx
@@ -7,7 +7,7 @@ import type {
ThemeValue,
} from "@openstatus/ui/components/blocks/status.types";
import { defaultStatusBlocksLabels } from "@openstatus/ui/components/blocks/status.utils";
-import { createContext, useContext } from "react";
+import { createContext, useContext, useMemo } from "react";
/**
* Labels and locale-aware formatters consumed by block components.
@@ -61,6 +61,18 @@ export type StatusBlocksLabels = {
formatDate: (d: Date) => string;
formatDateShort: (d: Date) => string;
formatDateTime: (d: Date) => string;
+ /**
+ * A status bar's calendar day from its `YYYY-MM-DD` key. Unlike the
+ * instant formatters above it must not shift the date into a time zone.
+ */
+ formatDay: (day: string) => string;
+ /** Compact banner stamp such as `Oct 03, 2026 14:41 (UTC)`. */
+ formatTimestamp: (d: Date) => string;
+ /**
+ * IANA zone the formatters render in, when not UTC. The rich timestamp
+ * hover card adds a row for it next to the viewer's zone and UTC.
+ */
+ timeZone?: string;
formatDateRange: (from?: Date, to?: Date) => string;
/**
* Returns the start/end of a closed range as separate strings, so callers
@@ -76,6 +88,13 @@ export type StatusBlocksLabels = {
formatDateRangeParts: (from: Date, to: Date) => { from: string; to: string };
};
+/** Provider input: formatters added after the first release fall back to the defaults. */
+export type StatusBlocksLabelsInput = Omit<
+ StatusBlocksLabels,
+ "formatDay" | "formatTimestamp"
+> &
+ Partial<Pick<StatusBlocksLabels, "formatDay" | "formatTimestamp">>;
+
const StatusBlocksLabelsContext = createContext<StatusBlocksLabels | null>(
null,
);
@@ -84,11 +103,20 @@ export function StatusBlocksI18nProvider({
value,
children,
}: {
- value: StatusBlocksLabels;
+ value: StatusBlocksLabelsInput;
children: React.ReactNode;
}) {
+ const labels = useMemo<StatusBlocksLabels>(
+ () => ({
+ ...value,
+ formatDay: value.formatDay ?? defaultStatusBlocksLabels.formatDay,
+ formatTimestamp:
+ value.formatTimestamp ?? defaultStatusBlocksLabels.formatTimestamp,
+ }),
+ [value],
+ );
return (
- <StatusBlocksLabelsContext.Provider value={value}>
+ <StatusBlocksLabelsContext.Provider value={labels}>
{children}
</StatusBlocksLabelsContext.Provider>
);
diff --git a/packages/ui/src/components/blocks/status-timestamp.tsx b/packages/ui/src/components/blocks/status-timestamp.tsx
index 1f9e5338a..39b3ff764 100644
--- a/packages/ui/src/components/blocks/status-timestamp.tsx
+++ b/packages/ui/src/components/blocks/status-timestamp.tsx
@@ -1,6 +1,6 @@
"use client";
-import { UTCDate } from "@date-fns/utc";
+import { useStatusBlocksLabels } from "@openstatus/ui/components/blocks/status-i18n";
import {
HoverCard,
HoverCardContent,
@@ -160,12 +160,12 @@ StatusTimestamp.displayName = "StatusTimestamp";
* the full formatted date in a tooltip on hover. The timestamp is shown in monospace
* font with muted foreground color.
*
- * If no children are provided, displays the date in UTC format. If children are
- * provided, they are used as the trigger text while the tooltip still shows the
- * formatted date in the user's local timezone.
+ * If no children are provided, displays the date with the labels' `formatTimestamp`
+ * (UTC by default). If children are provided, they are used as the trigger text
+ * while the tooltip still shows the formatted date in the user's local timezone.
*
* @param date - The date to display
- * @param children - Optional custom text to display (falls back to formatted UTC date)
+ * @param children - Optional custom text to display (falls back to `formatTimestamp`)
*
* @example
* ```tsx
@@ -180,6 +180,7 @@ function SimpleTimestamp({
children,
...props
}: Omit<SimpleVariantProps, "variant">) {
+ const labels = useStatusBlocksLabels();
return (
<TooltipProvider>
<Tooltip>
@@ -190,7 +191,7 @@ function SimpleTimestamp({
)}
{...props}
>
- {children || format(new UTCDate(date), "LLL dd, y HH:mm '(UTC)'")}
+ {children || labels.formatTimestamp(date)}
</TooltipTrigger>
<TooltipContent data-slot="status-timestamp-content">
<p className="font-mono">{format(date, "LLL dd, y HH:mm (z)")}</p>
@@ -205,8 +206,9 @@ SimpleTimestamp.displayName = "SimpleTimestamp";
* RichTimestamp - Internal hover card timestamp display with timezone details
*
* Displays a hover card with comprehensive timestamp information:
- * - Local timezone timestamp with timezone abbreviation (e.g., "PST", "EST")
- * - UTC timestamp
+ * - The labels' `timeZone`, when set and not UTC, as the visible text is in it
+ * - The viewer's local timezone
+ * - UTC (each zone listed once)
* - Relative time ("2 hours ago") that updates every second while open
*
* Each row in the hover card is clickable to copy the value to clipboard, with
@@ -251,10 +253,12 @@ function RichTimestamp({
const isTouch = useMediaQuery("(hover: none)");
const [_, setRerender] = useState(0);
+ const { timeZone: pageTimeZone } = useStatusBlocksLabels();
const timezone = Intl.DateTimeFormat().resolvedOptions().timeZone;
+ // a non-UTC page zone leads, as the visible text is in it; each zone once
+ const lead = pageTimeZone && pageTimeZone !== "UTC" ? pageTimeZone : timezone;
+ const timezones = [...new Set([lead, timezone, "UTC"])];
const relative = formatDistanceToNowStrict(date, { addSuffix: true });
- const formatted = format(date, "LLL dd, y HH:mm:ss");
- const utc = format(new UTCDate(date), "LLL dd, y HH:mm:ss");
useEffect(() => {
// only setInterval if open
@@ -286,8 +290,13 @@ function RichTimestamp({
{...{ side, align, alignOffset, sideOffset }}
>
<dl className="flex flex-col gap-1">
- <StatusTimestampRow value={formatted} label={timezone} />
- <StatusTimestampRow value={utc} label="UTC" />
+ {timezones.map((zone) => (
+ <StatusTimestampRow
+ key={zone}
+ value={formatInTimeZone(date, zone)}
+ label={zone}
+ />
+ ))}
<StatusTimestampRow value={relative} label="Relative" />
</dl>
</HoverCardContent>
@@ -296,6 +305,23 @@ function RichTimestamp({
}
RichTimestamp.displayName = "RichTimestamp";
+/** `LLL dd, y HH:mm:ss` like the other rows, in `timeZone`. */
+function formatInTimeZone(date: Date, timeZone: string) {
+ const parts = new Intl.DateTimeFormat("en-US", {
+ timeZone,
+ hourCycle: "h23",
+ month: "short",
+ day: "2-digit",
+ year: "numeric",
+ hour: "2-digit",
+ minute: "2-digit",
+ second: "2-digit",
+ }).formatToParts(date);
+ const part = (type: Intl.DateTimeFormatPartTypes) =>
+ parts.find((p) => p.type === type)?.value ?? "";
+ return `${part("month")} ${part("day")}, ${part("year")} ${part("hour")}:${part("minute")}:${part("second")}`;
+}
+
/**
* StatusTimestampRow - Internal component for hover card timestamp rows
*
diff --git a/packages/ui/src/components/blocks/status.utils.ts b/packages/ui/src/components/blocks/status.utils.ts
index 86e95b845..7bdb7228b 100644
--- a/packages/ui/src/components/blocks/status.utils.ts
+++ b/packages/ui/src/components/blocks/status.utils.ts
@@ -1,6 +1,6 @@
import { UTCDate } from "@date-fns/utc";
import type { StatusBlocksLabels } from "@openstatus/ui/components/blocks/status-i18n";
-import { endOfDay, isSameDay, startOfDay } from "date-fns";
+import { endOfDay, format, isSameDay, startOfDay } from "date-fns";
/**
* Formats a date range in a human-readable format.
@@ -347,6 +347,9 @@ export const defaultStatusBlocksLabels = {
formatDate: (d: Date) => withUTC(formatDate(d)),
formatDateShort: (d: Date) => formatDateShort(d),
formatDateTime: (d: Date) => withUTC(formatDateTime(d)),
+ formatDay: (day: string) => formatDateShort(new Date(day)),
+ formatTimestamp: (d: Date) =>
+ format(new UTCDate(d), "LLL dd, y HH:mm '(UTC)'"),
formatDateRange: (from?: Date, to?: Date) => {
const range = formatDateRange(from, to);
return from || to ? withUTC(range) : range;
diff --git a/packages/utils/src/index.ts b/packages/utils/src/index.ts
index 4cec9f557..0bbebe956 100644
--- a/packages/utils/src/index.ts
+++ b/packages/utils/src/index.ts
@@ -33,3 +33,9 @@ export {
export { personName } from "./person-name";
export { iteratorToStream, yieldMany } from "./stream";
export { type PageUpdateStatus, statusLabel } from "./status";
+export {
+ isKnownTimeZone,
+ resolveTimeZone,
+ timeZoneShortName,
+ timeZoneShortNames,
+} from "./timezone";
diff --git a/packages/utils/src/timezone.test.ts b/packages/utils/src/timezone.test.ts
new file mode 100644
index 000000000..957eb7bb7
--- /dev/null
+++ b/packages/utils/src/timezone.test.ts
@@ -0,0 +1,64 @@
+import { describe, expect, it } from "vitest";
+
+import {
+ resolveTimeZone,
+ timeZoneShortName,
+ timeZoneShortNames,
+} from "./timezone";
+
+describe("resolveTimeZone", () => {
+ it("keeps a zone the runtime knows", () => {
+ expect(resolveTimeZone("Asia/Tokyo")).toBe("Asia/Tokyo");
+ });
+
+ it("collapses UTC aliases", () => {
+ expect(resolveTimeZone("Etc/UTC")).toBe("UTC");
+ expect(resolveTimeZone("GMT")).toBe("UTC");
+ });
+
+ it("keeps a zone Intl would rename", () => {
+ expect(resolveTimeZone("Asia/Kolkata")).toBe("Asia/Kolkata");
+ });
+
+ it("falls back to UTC for an unknown zone", () => {
+ expect(resolveTimeZone("Mars/Olympus")).toBe("UTC");
+ });
+});
+
+describe("timeZoneShortName", () => {
+ it("keeps UTC as is", () => {
+ expect(timeZoneShortName("UTC")).toBe("UTC");
+ });
+
+ it("renders the locale's short name", () => {
+ expect(timeZoneShortName("Asia/Tokyo")).toBe("GMT+9");
+ expect(timeZoneShortName("Asia/Tokyo", "ja")).toBe("JST");
+ });
+
+ it("names the zone as of the given instant", () => {
+ const winter = new Date("2026-01-15T12:00:00Z");
+ const summer = new Date("2026-07-15T12:00:00Z");
+ expect(timeZoneShortName("America/New_York", "en-US", winter)).toBe("EST");
+ expect(timeZoneShortName("America/New_York", "en-US", summer)).toBe("EDT");
+ expect(timeZoneShortName("Europe/Berlin", "en-US", winter)).toBe("GMT+1");
+ expect(timeZoneShortName("Europe/Berlin", "en-US", summer)).toBe("GMT+2");
+ });
+});
+
+describe("timeZoneShortNames", () => {
+ it("names a span once when it stays in one offset", () => {
+ const from = new Date("2026-01-15T12:00:00Z");
+ const to = new Date("2026-01-15T14:00:00Z");
+ expect(timeZoneShortNames("America/New_York", "en-US", [from, to])).toBe(
+ "EST",
+ );
+ });
+
+ it("names both ends of a span that crosses a DST change", () => {
+ const from = new Date("2026-03-08T06:00:00Z");
+ const to = new Date("2026-03-08T08:00:00Z");
+ expect(timeZoneShortNames("America/New_York", "en-US", [from, to])).toBe(
+ "EST/EDT",
+ );
+ });
+});
diff --git a/packages/utils/src/timezone.ts b/packages/utils/src/timezone.ts
new file mode 100644
index 000000000..90d939171
--- /dev/null
+++ b/packages/utils/src/timezone.ts
@@ -0,0 +1,60 @@
+/** Whether this runtime's Intl knows `timeZone`; browsers can lag behind Node. */
+export function isKnownTimeZone(timeZone: string): boolean {
+ try {
+ new Intl.DateTimeFormat("en-US", { timeZone });
+ return true;
+ } catch (error) {
+ if (error instanceof RangeError) return false;
+ throw error;
+ }
+}
+
+/** `timeZone` if this runtime can format in it, otherwise UTC. */
+export function resolveTimeZone(timeZone: string): string {
+ if (!isKnownTimeZone(timeZone)) return "UTC";
+ // UTC aliases (Etc/UTC, GMT) collapse so callers can compare with "UTC";
+ // other zones keep their name, as Intl renames some (Asia/Kolkata)
+ const resolved = new Intl.DateTimeFormat("en-US", {
+ timeZone,
+ }).resolvedOptions().timeZone;
+ return resolved === "UTC" ? "UTC" : timeZone;
+}
+
+// formatters are costly to build and labels ask for one per instant
+const shortNameFormatters = new Map<string, Intl.DateTimeFormat>();
+
+/**
+ * Short zone name as Intl renders it ("UTC", "JST", "GMT+9", "EST") for the
+ * given instant: zones with daylight saving time change name through the year.
+ */
+export function timeZoneShortName(
+ timeZone: string,
+ locale = "en-US",
+ at = new Date(),
+) {
+ if (timeZone === "UTC") return "UTC";
+ const key = `${locale}|${timeZone}`;
+ let formatter = shortNameFormatters.get(key);
+ if (!formatter) {
+ formatter = new Intl.DateTimeFormat(locale, {
+ timeZone,
+ timeZoneName: "short",
+ });
+ shortNameFormatters.set(key, formatter);
+ }
+ return (
+ formatter.formatToParts(at).find((part) => part.type === "timeZoneName")
+ ?.value ?? timeZone
+ );
+}
+
+/** "EST" for a span in one offset, "EST/EDT" for one that crosses a DST change. */
+export function timeZoneShortNames(
+ timeZone: string,
+ locale: string,
+ instants: Date[],
+) {
+ return [
+ ...new Set(instants.map((at) => timeZoneShortName(timeZone, locale, at))),
+ ].join("/");
+}
diff --git a/scripts/screenshot.mjs b/scripts/screenshot.mjs
index e01005b89..20c68180b 100644
--- a/scripts/screenshot.mjs
+++ b/scripts/screenshot.mjs
@@ -170,7 +170,7 @@ function cookies(token, slug) {
}
// Three apps, two default ports, and on this machine any of them may sit on
-// :3001. Only the dashboard serves a form at /login; use that to tell them apart.
+// :3001. Only the dashboard titles /login "Sign In"; use that to tell them apart.
const probe = await fetch(base + (app.probe ?? paths[0])).catch(() => null);
if (!probe || probe.status === 404 || probe.status >= 500) {
console.error(
@@ -182,7 +182,14 @@ if (!app.auth) {
const login = await fetch(`${base}/login`, { redirect: "manual" }).catch(
() => null,
);
- if (login?.status === 200) {
+ // a status page in dev answers /login too when a page has that slug
+ const html =
+ login?.status === 200 ? await login.text().catch(() => null) : "";
+ if (html === null) {
+ console.error(`could not read ${base}/login to identify the app; retry`);
+ process.exit(1);
+ }
+ if (/<title>Sign In \|/.test(html)) {
console.error(
`${base} serves the dashboard, not ${flags.app}; pass --base`,
);