diff --git a/desktop/src/components/chat/MessageActionBar.tsx b/desktop/src/components/chat/MessageActionBar.tsx
index 4d39c377..7a8b0b1e 100644
--- a/desktop/src/components/chat/MessageActionBar.tsx
+++ b/desktop/src/components/chat/MessageActionBar.tsx
@@ -1,7 +1,6 @@
import { Check, Copy, GitFork } from 'lucide-react'
-import { useTranslation } from '../../i18n'
import { useSettingsStore } from '../../stores/settingsStore'
-import { formatExactMessageTimestamp, formatMessageTimestamp } from '../../lib/formatMessageTimestamp'
+import { formatExactMessageTimestamp, formatMessageHoverTime } from '../../lib/formatMessageTimestamp'
import { CopyButton } from '../shared/CopyButton'
export type MessageBranchAction = {
@@ -25,11 +24,10 @@ export function MessageActionBar({
align = 'start',
timestamp,
}: Props) {
- const t = useTranslation()
const locale = useSettingsStore((state) => state.locale)
const hasCopy = Boolean(copyText?.trim())
- const timeLabel = typeof timestamp === 'number'
- ? formatMessageTimestamp(timestamp, t, locale)
+ const hoverTimeLabel = typeof timestamp === 'number'
+ ? formatMessageHoverTime(timestamp, locale)
: ''
const exactTimeLabel = typeof timestamp === 'number'
? formatExactMessageTimestamp(timestamp, locale)
@@ -69,12 +67,12 @@ export function MessageActionBar({
) : null}
- {timeLabel ? (
+ {hoverTimeLabel ? (
- {timeLabel}
+ {hoverTimeLabel}
) : null}
diff --git a/desktop/src/lib/formatMessageTimestamp.ts b/desktop/src/lib/formatMessageTimestamp.ts
index 65d71877..2ff72d77 100644
--- a/desktop/src/lib/formatMessageTimestamp.ts
+++ b/desktop/src/lib/formatMessageTimestamp.ts
@@ -46,6 +46,18 @@ export function formatExactMessageTimestamp(value: number | string | Date, local
}).format(date)
}
+export function formatMessageHoverTime(
+ value: number | string | Date,
+ locale: Locale,
+ now = Date.now(),
+): string {
+ const date = coerceDate(value)
+ if (!date) return ''
+ return isSameLocalYear(date, new Date(now))
+ ? formatMonthDayTime(date, locale)
+ : formatYearMonthDayTime(date, locale)
+}
+
function coerceDate(value: number | string | Date): Date | null {
const date = value instanceof Date ? value : new Date(value)
return Number.isFinite(date.getTime()) ? date : null