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 @@ -31,7 +31,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
32 changes: 30 additions & 2 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 All @@ -11,8 +13,13 @@ export namespace Locale {
export function datetime(input: number): string {
const date = new Date(input)
const localTime = time(input)
const localDate = date.toLocaleDateString()
return `${localTime} · ${localDate}`
const month = date.getMonth() + 1
const day = date.getDate()
const year = date.getFullYear()
// Pad day with leading space if single digit for alignment
const paddedDay = day < 10 ? ` ${day}` : day.toString()
const localDate = `${month}/${paddedDay}/${year}`
return `${localTime} ${localDate}`
}

export function todayTimeOrDateTime(input: number): string {
Expand All @@ -28,6 +35,27 @@ 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()
// Pad day with leading space if single digit for alignment
const paddedDay = day < 10 ? ` ${day}` : day.toString()
return `${month} ${paddedDay} ${timeStr}`
}
}

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