feat(ui-chat): respect locale and bucket message bubble timestamps by today/yesterday/earlier

Replace hardcoded zh-CN locale with vue-i18n locale.value, add a yesterday bucket reusing the security.activity.yesterday key, and fall back to YYYY/MM/DD HH:mm for older messages. Computes the previous day with setDate(getDate()-1) so DST transitions stay correct, and short-circuits invalid Date inputs.
This commit is contained in:
DayByDay 2026-05-10 22:30:35 +08:00 committed by GitHub
parent d09b9de8a6
commit 7b9ec75137
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -423,7 +423,7 @@ import type { Message, MessageSegment, ChatAttachment, ToolCallMeta, PlanMeta }
import type { ChatErrorInfo } from '@/types/chatError'
const { renderMarkdown } = useMarkdownRenderer()
const { t } = useI18n()
const { t,locale} = useI18n()
const { getToolLabel } = useToolLabel()
const { blobUrls, loadAllImages, loadAllVideos, loadAllAudios, loadAllModels, downloadFile, openImage, getDisplayUrl, revokeAll } = useAuthenticatedAttachment()
@ -747,8 +747,39 @@ watch(model3dAttachments, (atts) => {
// --- ---
const formattedTime = computed(() => {
if (!props.message.createTime) return ''
return new Date(props.message.createTime).toLocaleTimeString('zh-CN', {
const createTime = props.message.createTime
if (!createTime) return ''
const date = new Date(createTime)
if (Number.isNaN(date.getTime())) return ''
const now = new Date()
const sameDay = (a: Date, b: Date) =>
a.getFullYear() === b.getFullYear() &&
a.getMonth() === b.getMonth() &&
a.getDate() === b.getDate()
const currentLocale = locale.value
const time = date.toLocaleTimeString(currentLocale, {
hour: '2-digit',
minute: '2-digit',
})
if (sameDay(date, now)) return time
const yesterday = new Date(now)
yesterday.setDate(now.getDate() - 1)
if (sameDay(date, yesterday)) {
return `${t('security.activity.yesterday')} ${time}`
}
return date.toLocaleString(currentLocale, {
year: 'numeric',
month: '2-digit',
day: '2-digit',
hour: '2-digit',
minute: '2-digit',
})