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
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export function DialogForkFromTimeline(props: { sessionID: string; onMove: (mess
result.push({
title: part.text.replace(/\n/g, " "),
value: message.id,
footer: Locale.time(message.time.created),
footer: Locale.shortDateTime(message.time.created),
onSelect: async (dialog) => {
const forked = await sdk.client.session.fork({
sessionID: props.sessionID,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export function DialogTimeline(props: {
result.push({
title: part.text.replace(/\n/g, " "),
value: message.id,
footer: Locale.time(message.time.created),
footer: Locale.shortDateTime(message.time.created),
onSelect: (dialog) => {
dialog.replace(() => (
<DialogMessage messageID={message.id} sessionID={props.sessionID} setPrompt={props.setPrompt} />
Expand Down
21 changes: 21 additions & 0 deletions packages/opencode/src/util/locale.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
export namespace Locale {
const MONTHS = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]

export function titlecase(str: string) {
return str.replace(/\b\w/g, (c) => c.toUpperCase())
}
Expand Down Expand Up @@ -28,6 +30,25 @@ export namespace Locale {
}
}

export function shortDateTime(input: number): string {
const date = new Date(input)
const now = new Date()
const isToday =
date.getFullYear() === now.getFullYear() &&
date.getMonth() === now.getMonth() &&
date.getDate() === now.getDate()

const timeStr = time(input)

if (isToday) {
return timeStr
} else {
const month = MONTHS[date.getMonth()]
const day = date.getDate()
return `${month} ${day} ${timeStr}`
}
}

export function number(num: number): string {
if (num >= 1000000) {
return (num / 1000000).toFixed(1) + "M"
Expand Down