Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion apps/web/src/components/SlowRpcRequestToastCoordinator.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { useClientSettings } from "../hooks/useSettings";
import { type SlowRpcAckRequest, subscribeSlowRpcAckRequests } from "../rpc/requestLatencyState";
import { formatShortTimestamp } from "../timestampFormat";
import { toastManager } from "./ui/toast";

function describeSlowRequests(requests: ReadonlyArray<SlowRpcAckRequest>): string {
Expand All @@ -11,6 +13,7 @@ function describeSlowRequests(requests: ReadonlyArray<SlowRpcAckRequest>): strin
}

function SlowRequestDetails({ requests }: { requests: ReadonlyArray<SlowRpcAckRequest> }) {
const timestampFormat = useClientSettings((settings) => settings.timestampFormat);
return (
<ul className="space-y-2.5 text-xs text-muted-foreground">
{requests.map((request) => (
Expand All @@ -20,7 +23,7 @@ function SlowRequestDetails({ requests }: { requests: ReadonlyArray<SlowRpcAckRe
>
<div className="wrap-break-word font-medium text-foreground">{request.tag}</div>
<div className="mt-0.5 text-3xs opacity-75">
Started {new Date(request.startedAt).toLocaleTimeString()}
Started {formatShortTimestamp(request.startedAt, timestampFormat, true)}
</div>
</li>
))}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import type { RelayClientDeviceRecord } from "@t3tools/contracts/relay";
import { type TimestampFormat } from "@t3tools/contracts/settings";

const mobileClientUpdatedAtFormatter = new Intl.DateTimeFormat(undefined, {
dateStyle: "medium",
timeStyle: "short",
});
import { formatDateTimeTimestamp } from "../../timestampFormat";

const NOTIFICATION_PREFERENCES = [
["notifyOnApproval", "approvals"],
Expand Down Expand Up @@ -37,9 +35,10 @@ export function mobileClientNotificationDetail(device: RelayClientDeviceRecord):
: "Push notifications are enabled, but no alert types are selected.";
}

export function mobileClientUpdatedAtLabel(updatedAt: string): string {
const date = new Date(updatedAt);
return Number.isNaN(date.getTime())
? "Update time unavailable"
: `Updated ${mobileClientUpdatedAtFormatter.format(date)}`;
export function mobileClientUpdatedAtLabel(
updatedAt: string,
timestampFormat: TimestampFormat,
): string {
const label = formatDateTimeTimestamp(updatedAt, timestampFormat);
return label ? `Updated ${label}` : "Update time unavailable";
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import type { RelayClientDeviceRecord } from "@t3tools/contracts/relay";
import { SmartphoneIcon } from "lucide-react";

import { useManagedRelayDevices } from "../../cloud/managedRelayState";
import { useClientSettings } from "../../hooks/useSettings";
import { Badge } from "../ui/badge";
import { Button } from "../ui/button";
import { Empty, EmptyDescription, EmptyHeader, EmptyMedia, EmptyTitle } from "../ui/empty";
Expand Down Expand Up @@ -34,6 +35,7 @@ function MobileClientStatusBadge({
}

function MobileClientRow({ device }: { readonly device: RelayClientDeviceRecord }) {
const timestampFormat = useClientSettings((settings) => settings.timestampFormat);
return (
<ClerkUserProfileRow icon={<SmartphoneIcon className="size-4" />}>
<div className="flex flex-col gap-0.5 sm:flex-row sm:items-start sm:justify-between sm:gap-3">
Expand All @@ -46,7 +48,7 @@ function MobileClientRow({ device }: { readonly device: RelayClientDeviceRecord
</p>
</div>
<p className="shrink-0 text-2xs leading-4 text-muted-foreground/75">
{mobileClientUpdatedAtLabel(device.updatedAt)}
{mobileClientUpdatedAtLabel(device.updatedAt, timestampFormat)}
</p>
</div>
<div className="mt-2 flex flex-wrap gap-1.5">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
} from "@t3tools/client-runtime/state/runtime";

import { useCopyToClipboard } from "../../hooks/useCopyToClipboard";
import { useClientSettings } from "../../hooks/useSettings";
import { cn } from "../../lib/utils";
import { formatElapsedDurationLabel, formatExpiresInLabel } from "../../timestampFormat";
import { resolveDesktopPairingUrl, resolveHostedPairingUrl } from "./pairingUrls";
Expand Down Expand Up @@ -151,6 +152,7 @@ const PairingLinkListRow = memo(function PairingLinkListRow({
canRevoke,
}: PairingLinkListRowProps) {
const nowMs = useNowSecond();
const timestampFormat = useClientSettings((settings) => settings.timestampFormat);
const expiresAtMs = new Date(pairingLink.expiresAt).getTime();
const [isRevealDialogOpen, setIsRevealDialogOpen] = useState(false);
const [isQrPanelOpen, setIsQrPanelOpen] = useState(defaultShareOpen);
Expand Down Expand Up @@ -248,7 +250,7 @@ const PairingLinkListRow = memo(function PairingLinkListRow({
if (credential) copyPairingValue(credential, "code");
};

const expiresAbsolute = formatAccessTimestamp(pairingLink.expiresAt);
const expiresAbsolute = formatAccessTimestamp(pairingLink.expiresAt, timestampFormat);

const primaryLabel = pairingLink.label ?? "Pairing link";
const selectedQrOption = selectQrEndpointOption(
Expand All @@ -268,7 +270,7 @@ const PairingLinkListRow = memo(function PairingLinkListRow({
<div className="min-w-0 flex-1 space-y-1">
<div className="flex min-h-5 items-center gap-1.5">
<ConnectionStatusDot
tooltipText={`Link created at ${formatAccessTimestamp(pairingLink.createdAt)}`}
tooltipText={`Link created at ${formatAccessTimestamp(pairingLink.createdAt, timestampFormat)}`}
dotClassName="bg-warning"
/>
<h3 className="text-sm font-medium text-foreground">{primaryLabel}</h3>
Expand Down Expand Up @@ -490,14 +492,15 @@ const ConnectedClientListRow = memo(function ConnectedClientListRow({
canRevoke,
}: ConnectedClientListRowProps) {
const nowMs = useNowSecond();
const timestampFormat = useClientSettings((settings) => settings.timestampFormat);
const isLive = clientSession.current || clientSession.connected;
const lastConnectedAt = clientSession.lastConnectedAt;
const statusTooltip = isLive
? lastConnectedAt
? `Connected for ${formatElapsedDurationLabel(lastConnectedAt, nowMs)}`
: "Connected"
: lastConnectedAt
? `Last connected at ${formatAccessTimestamp(lastConnectedAt)}`
? `Last connected at ${formatAccessTimestamp(lastConnectedAt, timestampFormat)}`
: "Not connected yet.";
const deviceInfoBits = [
clientSession.client.deviceType !== "unknown"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import * as DateTime from "effect/DateTime";
import { useState } from "react";

import type { ServerPairingLinkRecord } from "~/environments/primary";
import { useClientSettings } from "~/hooks/useSettings";
import { authEnvironment } from "~/state/auth";
import { useAtomCommand } from "~/state/use-atom-command";
import { Button } from "../ui/button";
Expand Down Expand Up @@ -49,6 +50,7 @@ export function ConnectDeviceApprovalSettings({
const deny = useAtomCommand(authEnvironment.revokePairingLink, { reportFailure: false });
const revoke = useAtomCommand(authEnvironment.revokeConnectDevice, { reportFailure: false });
const [busyId, setBusyId] = useState<string | null>(null);
const timestampFormat = useClientSettings((settings) => settings.timestampFormat);

const run = async (id: string, action: () => Promise<void>) => {
setBusyId(id);
Expand Down Expand Up @@ -122,7 +124,8 @@ export function ConnectDeviceApprovalSettings({
<p className="text-xs text-muted-foreground">
<span className="font-mono tabular-nums">{device.verificationCode}</span>
<span aria-hidden> · </span>
Trusted since {formatAccessTimestamp(DateTime.formatIso(device.approvedAt))}
Trusted since{" "}
{formatAccessTimestamp(DateTime.formatIso(device.approvedAt), timestampFormat)}
</p>
</div>
<div className="flex w-full shrink-0 items-center gap-2 sm:w-auto sm:justify-end">
Expand Down
18 changes: 18 additions & 0 deletions apps/web/src/components/settings/ConnectionsSettings.logic.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { type DesktopWslState, EnvironmentId } from "@t3tools/contracts";
import { describe, expect, it, vi } from "vite-plus/test";
import {
applyWslEnableSelection,
formatAccessTimestamp,
isServerNetworkAccessible,
parseManualDesktopSshTarget,
resolveAccessEnvironmentId,
Expand All @@ -10,6 +11,23 @@ import {
togglePairingScopeSelection,
} from "./ConnectionsSettings.logic";

describe("formatAccessTimestamp", () => {
const date = new Date(2026, 9, 20, 17, 30);

it.each([
["12-hour", true],
["24-hour", false],
] as const)("formats the time with the %s setting", (timestampFormat, hour12) => {
expect(formatAccessTimestamp(date.toISOString(), timestampFormat)).toBe(
new Intl.DateTimeFormat(undefined, {
dateStyle: "medium",
timeStyle: "short",
hour12,
}).format(date),
);
});
});

describe("togglePairingScopeSelection", () => {
it.each([
{
Expand Down
15 changes: 4 additions & 11 deletions apps/web/src/components/settings/ConnectionsSettings.logic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ import {
type ServerAuthPolicy,
type ServerDirectEndpoint,
} from "@t3tools/contracts";
import { type TimestampFormat } from "@t3tools/contracts/settings";
import { formatDateTimeTimestamp } from "../../timestampFormat";
import {
getDesktopUpdateDownloadedVersion,
resolveDesktopUpdateButtonAction,
Expand Down Expand Up @@ -162,17 +164,8 @@ export async function applyWslEnableSelection(input: {
return await bridge.setWslBackendEnabled(true);
}

const accessTimestampFormatter = new Intl.DateTimeFormat(undefined, {
dateStyle: "medium",
timeStyle: "short",
});

export function formatAccessTimestamp(value: string): string {
const parsed = new Date(value);
if (Number.isNaN(parsed.getTime())) {
return value;
}
return accessTimestampFormatter.format(parsed);
export function formatAccessTimestamp(value: string, timestampFormat: TimestampFormat): string {
return formatDateTimeTimestamp(value, timestampFormat) || value;
}

export function parseManualDesktopSshTarget(input: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ import { useState, type ReactNode } from "react";

import { T3AppIcon } from "~/components/T3AppIcon";
import { useCopyToClipboard } from "~/hooks/useCopyToClipboard";
import { useEnvironmentSettings } from "../../hooks/useSettings";
import { useClientSettings, useEnvironmentSettings } from "../../hooks/useSettings";
import { cn } from "../../lib/utils";
import { formatShortTimestamp } from "../../timestampFormat";
import { serverEnvironment } from "../../state/server";
import { sourceControlEnvironment } from "../../state/sourceControl";
import { useAtomCommand } from "../../state/use-atom-command";
Expand All @@ -31,9 +32,6 @@ const failureMessage = (cause: Cause.Cause<unknown>) => {
return error instanceof Error ? error.message : String(error);
};

const expiryTime = (expiresAt: number) =>
new Date(expiresAt).toLocaleTimeString(undefined, { hour: "numeric", minute: "2-digit" });

function ExternalLink(props: { readonly href: string; readonly children: ReactNode }) {
return (
<InlineButton render={<a href={props.href} target="_blank" rel="noreferrer noopener" />}>
Expand Down Expand Up @@ -98,6 +96,7 @@ export function SourceControlAppSignInSettings({
const { signIns, tokens } = useEnvironmentSettings(environmentId, (settings) =>
readHostCredentialSettings(settings, definition.kind),
);
const timestampFormat = useClientSettings((settings) => settings.timestampFormat);
const signedIn = (signIns[host] ?? "").length > 0;
const token = tokens[host];
// A token read from a secret provider overrides the sign-in like a saved one.
Expand Down Expand Up @@ -248,7 +247,8 @@ export function SourceControlAppSignInSettings({
</Button>
<p className="flex items-center gap-1.5 text-xs text-muted-foreground">
<span aria-hidden className="size-1.5 rounded-full bg-warning" />
Waiting for approval · code expires at {expiryTime(waiting.expiresAt)}
Waiting for approval · code expires at{" "}
{formatShortTimestamp(new Date(waiting.expiresAt).toISOString(), timestampFormat)}
</p>
</div>
</div>
Expand Down
26 changes: 24 additions & 2 deletions apps/web/src/timestampFormat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,32 @@ export function formatFullTimestamp(isoDate: string, timestampFormat: TimestampF
);
}

export function formatShortTimestamp(isoDate: string, timestampFormat: TimestampFormat): string {
export function formatShortTimestamp(
isoDate: string,
timestampFormat: TimestampFormat,
includeSeconds = false,
): string {
const date = parseTimestampDate(isoDate);
if (!date) return "";
return getTimestampFormatter(timestampFormat, false).format(date);
return getTimestampFormatter(timestampFormat, includeSeconds).format(date);
}

const dateTimeFormatterCache = new Map<TimestampFormat, Intl.DateTimeFormat>();

/** A date and time, such as "Oct 20, 2026, 5:30 PM". */
export function formatDateTimeTimestamp(isoDate: string, timestampFormat: TimestampFormat): string {
const date = parseTimestampDate(isoDate);
if (!date) return "";
let formatter = dateTimeFormatterCache.get(timestampFormat);
if (!formatter) {
formatter = new Intl.DateTimeFormat(timestampLocale, {
dateStyle: "medium",
timeStyle: "short",
...(timestampFormat === "locale" ? {} : { hour12: timestampFormat === "12-hour" }),
});
dateTimeFormatterCache.set(timestampFormat, formatter);
}
return formatter.format(date);
}

const numericDateOptions: Intl.DateTimeFormatOptions = { month: "numeric", day: "numeric" };
Expand Down
Loading