Skip to content

Commit 738bc87

Browse files
feat(ui): add time and date format settings and message timestamps
1 parent 3f51e9d commit 738bc87

38 files changed

Lines changed: 1652 additions & 37 deletions

‎packages/types/src/global-settings.ts‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,21 @@ export const globalSettingsSchema = z.object({
280280
* When unset (or `null`), the webview inherits VS Code's `--vscode-font-size`.
281281
*/
282282
chatFontSize: z.number().int().min(8).max(32).nullish(),
283+
/**
284+
* Clock format used when rendering timestamps. "auto" follows the display language's locale.
285+
* @default "auto"
286+
*/
287+
timeFormat: z.enum(["auto", "12h", "24h"]).optional(),
288+
/**
289+
* How dates are written. "auto" follows the display language's locale.
290+
* @default "auto"
291+
*/
292+
dateFormat: z.enum(["auto", "mdy", "dmy", "ymd"]).optional(),
293+
/**
294+
* Show relative times ("5 min ago") in task history; when off, show the absolute date/time.
295+
* @default true
296+
*/
297+
showRelativeTimes: z.boolean().optional(),
283298
/**
284299
* Controls the keyboard behavior for sending messages in the chat input.
285300
* - "send": Enter sends message, Shift+Enter creates newline (default)

‎packages/types/src/vscode-extension-host.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,9 @@ export type ExtensionState = Pick<
339339
| "includeTaskHistoryInEnhance"
340340
| "reasoningBlockCollapsed"
341341
| "chatFontSize"
342+
| "timeFormat"
343+
| "dateFormat"
344+
| "showRelativeTimes"
342345
| "enterBehavior"
343346
| "includeCurrentTime"
344347
| "includeCurrentCost"

‎src/core/webview/ClineProvider.ts‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2860,6 +2860,9 @@ export class ClineProvider
28602860
historyPreviewCollapsed,
28612861
reasoningBlockCollapsed,
28622862
chatFontSize,
2863+
timeFormat,
2864+
dateFormat,
2865+
showRelativeTimes,
28632866
enterBehavior,
28642867
cloudUserInfo,
28652868
cloudIsAuthenticated,
@@ -3041,6 +3044,9 @@ export class ClineProvider
30413044
historyPreviewCollapsed: historyPreviewCollapsed ?? false,
30423045
reasoningBlockCollapsed: reasoningBlockCollapsed ?? true,
30433046
chatFontSize,
3047+
timeFormat: timeFormat ?? "auto",
3048+
dateFormat: dateFormat ?? "auto",
3049+
showRelativeTimes: showRelativeTimes ?? true,
30443050
enterBehavior: enterBehavior ?? "send",
30453051
cloudUserInfo,
30463052
cloudIsAuthenticated: cloudIsAuthenticated ?? false,
@@ -3274,6 +3280,9 @@ export class ClineProvider
32743280
historyPreviewCollapsed: stateValues.historyPreviewCollapsed ?? false,
32753281
reasoningBlockCollapsed: stateValues.reasoningBlockCollapsed ?? true,
32763282
chatFontSize: stateValues.chatFontSize,
3283+
timeFormat: stateValues.timeFormat ?? "auto",
3284+
dateFormat: stateValues.dateFormat ?? "auto",
3285+
showRelativeTimes: stateValues.showRelativeTimes ?? true,
32773286
enterBehavior: stateValues.enterBehavior ?? "send",
32783287
cloudUserInfo,
32793288
cloudIsAuthenticated,

‎webview-ui/src/__tests__/ContextWindowProgress.spec.tsx‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@ import { providerIdentifiers } from "@roo-code/types"
55

66
import TaskHeader from "@src/components/chat/TaskHeader"
77

8-
// Mock formatLargeNumber function
9-
vi.mock("@/utils/format", () => ({
8+
// Keep the real format helpers (other components in the tree use them) and override only formatLargeNumber.
9+
vi.mock("@/utils/format", async (importOriginal) => ({
10+
...(await importOriginal<typeof import("@/utils/format")>()),
1011
formatLargeNumber: vi.fn((num) => num.toString()),
1112
}))
1213

‎webview-ui/src/components/chat/ChatRow.tsx‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import WarningRow from "./WarningRow"
3838
import McpResourceRow from "../mcp/McpResourceRow"
3939

4040
import { Mention } from "./Mention"
41+
import { MessageTimestamp } from "./MessageTimestamp"
4142
import { CheckpointSaved } from "./checkpoints/CheckpointSaved"
4243
import { FollowUpSuggest } from "./FollowUpSuggest"
4344
import { BatchFilePermission } from "./BatchFilePermission"
@@ -196,6 +197,8 @@ export const ChatRowContent = ({
196197
clineMessages,
197198
currentTaskItem,
198199
enableCheckpoints,
200+
timeFormat,
201+
dateFormat,
199202
} = useExtensionState()
200203
const { info: model } = useSelectedModel(apiConfiguration)
201204
const [isEditing, setIsEditing] = useState(false)
@@ -1224,6 +1227,13 @@ export const ChatRowContent = ({
12241227
</div>
12251228
)}
12261229
</div>
1230+
{/* When the reply was sent. Held back while it streams, so the line does not appear and
1231+
shift as the text grows. */}
1232+
{!message.partial && (
1233+
<div className="ml-6 mt-1">
1234+
<MessageTimestamp ts={message.ts} timeFormat={timeFormat} dateFormat={dateFormat} />
1235+
</div>
1236+
)}
12271237
</div>
12281238
)
12291239
case "user_feedback":
@@ -1299,6 +1309,12 @@ export const ChatRowContent = ({
12991309
<Thumbnails images={message.images} style={{ marginTop: "8px" }} />
13001310
)}
13011311
</div>
1312+
{/* When the message was sent. Hidden while editing: the edit box replaces the bubble. */}
1313+
{!isEditing && (
1314+
<div className="ml-6 mt-1">
1315+
<MessageTimestamp ts={message.ts} timeFormat={timeFormat} dateFormat={dateFormat} />
1316+
</div>
1317+
)}
13021318
</div>
13031319
)
13041320
case "user_feedback_diff":
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import { Clock } from "lucide-react"
2+
3+
import { cn } from "@src/lib/utils"
4+
import { formatDateTime, formatMessageTime, type DateFormat, type TimeFormat } from "@/utils/format"
5+
6+
import { StandardTooltip } from "../ui/standard-tooltip"
7+
8+
interface MessageTimestampProps {
9+
/** Epoch ms the message was sent. */
10+
ts: number
11+
/** From the user's Language settings; both default to "auto". */
12+
timeFormat?: TimeFormat
13+
dateFormat?: DateFormat
14+
className?: string
15+
}
16+
17+
/**
18+
* "🕒 Yesterday 11:43 AM" under a sent message.
19+
*
20+
* Purely presentational: the caller supplies the user's time/date formats, so
21+
* the component has no dependency on extension state and renders anywhere. The
22+
* tooltip always carries the full date and time. A semantic <time> element
23+
* gives assistive tech and copy/paste the exact value.
24+
*/
25+
export const MessageTimestamp = ({ ts, timeFormat, dateFormat, className }: MessageTimestampProps) => {
26+
// Number.isFinite is not enough: a finite value beyond ±8.64e15 ms is an Invalid Date, and
27+
// toISOString() would throw during render and take the whole chat row down with it.
28+
const date = new Date(ts)
29+
if (!Number.isFinite(ts) || ts <= 0 || Number.isNaN(date.getTime())) return null
30+
31+
return (
32+
<StandardTooltip content={formatDateTime(ts, timeFormat, dateFormat)}>
33+
<time
34+
dateTime={date.toISOString()}
35+
className={cn(
36+
"inline-flex items-center gap-1.5 text-xs text-vscode-descriptionForeground select-none",
37+
className,
38+
)}
39+
data-testid="message-timestamp">
40+
<Clock className="size-3.5 shrink-0" aria-hidden="true" />
41+
{formatMessageTime(ts, { timeFormat, dateFormat })}
42+
</time>
43+
</StandardTooltip>
44+
)
45+
}

‎webview-ui/src/components/chat/TaskHeader.tsx‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import { vscode } from "@src/utils/vscode"
2525
import Thumbnails from "../common/Thumbnails"
2626
import { TaskTitleEditor } from "../history/TaskTitleEditor"
2727
import { TaskActions } from "./TaskActions"
28+
import { MessageTimestamp } from "./MessageTimestamp"
2829
import { ContextWindowProgress } from "./ContextWindowProgress"
2930
import { Mention } from "./Mention"
3031
import { TodoListDisplay } from "./TodoListDisplay"
@@ -64,7 +65,7 @@ const TaskHeader = ({
6465
todos,
6566
}: TaskHeaderProps) => {
6667
const { t } = useTranslation()
67-
const { apiConfiguration, currentTaskItem } = useExtensionState()
68+
const { apiConfiguration, currentTaskItem, timeFormat, dateFormat } = useExtensionState()
6869
const { id: modelId, info: model } = useSelectedModel(apiConfiguration)
6970
const [isTaskExpanded, setIsTaskExpanded] = useState(false)
7071
const [isRenaming, setIsRenaming] = useState(false)
@@ -351,6 +352,11 @@ const TaskHeader = ({
351352
</div>
352353
{task.images && task.images.length > 0 && <Thumbnails images={task.images} />}
353354

355+
{/* When the task's first message was sent (follows the Time/Date format settings). */}
356+
<div onClick={(e) => e.stopPropagation()}>
357+
<MessageTimestamp ts={task.ts} timeFormat={timeFormat} dateFormat={dateFormat} />
358+
</div>
359+
354360
<div onClick={(e) => e.stopPropagation()}>
355361
<TaskActions
356362
item={currentTaskItem}
Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
import React from "react"
2+
import { render, screen } from "@/utils/test-utils"
3+
import type { ClineMessage } from "@roo-code/types"
4+
5+
import { ChatRowContent } from "../ChatRow"
6+
7+
vi.mock("@src/utils/vscode", () => ({ vscode: { postMessage: vi.fn() } }))
8+
9+
vi.mock("react-i18next", () => ({
10+
useTranslation: () => ({ t: (key: string) => key, i18n: { exists: () => true } }),
11+
Trans: ({ children }: { children?: React.ReactNode }) => <>{children}</>,
12+
initReactI18next: { type: "3rdParty", init: () => {} },
13+
}))
14+
15+
let mockState: Record<string, unknown> = {}
16+
vi.mock("@src/context/ExtensionStateContext", async (importOriginal) => ({
17+
...(await importOriginal<typeof import("@src/context/ExtensionStateContext")>()),
18+
useExtensionState: () => ({
19+
mcpServers: [],
20+
alwaysAllowMcp: false,
21+
currentCheckpoint: null,
22+
mode: "code",
23+
apiConfiguration: {},
24+
clineMessages: [],
25+
currentTaskItem: undefined,
26+
...mockState,
27+
}),
28+
}))
29+
30+
vi.mock("@src/components/ui/hooks/useSelectedModel", () => ({
31+
useSelectedModel: () => ({ info: { supportsImages: true } }),
32+
}))
33+
34+
const renderRow = (message: ClineMessage, isStreaming = false) =>
35+
render(
36+
<ChatRowContent
37+
message={message}
38+
isExpanded={false}
39+
isLast={false}
40+
isStreaming={isStreaming}
41+
onToggleExpand={() => {}}
42+
onSuggestionClick={() => {}}
43+
onBatchFileResponse={() => {}}
44+
onFollowUpUnmount={() => {}}
45+
isFollowUpAnswered={false}
46+
/>,
47+
)
48+
49+
describe("ChatRow – message timestamp", () => {
50+
beforeEach(() => {
51+
mockState = {}
52+
})
53+
54+
it("shows when a user message was sent", () => {
55+
renderRow({ ts: Date.now(), type: "say", say: "user_feedback", text: "hello there" })
56+
expect(screen.getByTestId("message-timestamp").textContent).toContain("Today")
57+
})
58+
59+
it("uses the message's own timestamp, not the current time", () => {
60+
const d = new Date()
61+
d.setDate(d.getDate() - 1)
62+
d.setHours(11, 43, 0, 0)
63+
renderRow({ ts: d.getTime(), type: "say", say: "user_feedback", text: "an older message" })
64+
expect(screen.getByTestId("message-timestamp").textContent).toContain("Yesterday")
65+
})
66+
67+
it("is rendered after the message bubble (under it), not before", () => {
68+
const { container } = renderRow({ ts: Date.now(), type: "say", say: "user_feedback", text: "ordering" })
69+
const html = container.innerHTML
70+
expect(html.indexOf("ordering")).toBeGreaterThan(-1)
71+
expect(html.indexOf("message-timestamp")).toBeGreaterThan(html.indexOf("ordering"))
72+
})
73+
74+
it("applies the user's time and date format settings", () => {
75+
const d = new Date()
76+
d.setHours(14, 41, 0, 0)
77+
mockState = { timeFormat: "24h", dateFormat: "ymd" }
78+
renderRow({ ts: d.getTime(), type: "say", say: "user_feedback", text: "formats" })
79+
expect(screen.getByTestId("message-timestamp").textContent).toContain("14:41")
80+
})
81+
82+
describe("assistant text", () => {
83+
it("shows when the reply was sent, under the reply", () => {
84+
const { container } = renderRow({ ts: Date.now(), type: "say", say: "text", text: "assistant reply" })
85+
expect(screen.getByTestId("message-timestamp").textContent).toContain("Today")
86+
const html = container.innerHTML
87+
expect(html.indexOf("message-timestamp")).toBeGreaterThan(html.indexOf("assistant reply"))
88+
})
89+
90+
it("uses the reply's own timestamp and the user's formats", () => {
91+
const d = new Date()
92+
d.setHours(14, 41, 0, 0)
93+
mockState = { timeFormat: "24h", dateFormat: "ymd" }
94+
renderRow({ ts: d.getTime(), type: "say", say: "text", text: "formatted reply" })
95+
expect(screen.getByTestId("message-timestamp").textContent).toContain("14:41")
96+
})
97+
98+
it("waits until the reply has finished streaming", () => {
99+
const { rerender } = renderRow({
100+
ts: Date.now(),
101+
type: "say",
102+
say: "text",
103+
text: "still typing",
104+
partial: true,
105+
})
106+
expect(screen.queryByTestId("message-timestamp")).toBeNull()
107+
108+
rerender(
109+
<ChatRowContent
110+
message={{ ts: Date.now(), type: "say", say: "text", text: "still typing", partial: false }}
111+
isExpanded={false}
112+
isLast={false}
113+
isStreaming={false}
114+
onToggleExpand={() => {}}
115+
onSuggestionClick={() => {}}
116+
onBatchFileResponse={() => {}}
117+
onFollowUpUnmount={() => {}}
118+
isFollowUpAnswered={false}
119+
/>,
120+
)
121+
expect(screen.getByTestId("message-timestamp")).toBeTruthy()
122+
})
123+
124+
it("shows nothing for an assistant message with an invalid timestamp", () => {
125+
renderRow({ ts: 0, type: "say", say: "text", text: "no time" })
126+
expect(screen.queryByTestId("message-timestamp")).toBeNull()
127+
})
128+
})
129+
130+
it("keeps the message visible while streaming", () => {
131+
renderRow({ ts: Date.now(), type: "say", say: "user_feedback", text: "streaming" }, true)
132+
expect(screen.getByTestId("message-timestamp")).toBeTruthy()
133+
})
134+
})

0 commit comments

Comments
 (0)