mirror of
https://gitee.com/wanwujie/deer-flow
synced 2026-04-21 05:14:45 +08:00
feat: add memory settings page
This commit is contained in:
@@ -1,7 +1,27 @@
|
||||
import { formatDistanceToNow } from "date-fns";
|
||||
import { enUS as dateFnsEnUS, zhCN as dateFnsZhCN } from "date-fns/locale";
|
||||
|
||||
export function formatTimeAgo(date: Date | string | number) {
|
||||
import { detectLocale, type Locale } from "@/core/i18n";
|
||||
import { getLocaleFromCookie } from "@/core/i18n/cookies";
|
||||
|
||||
function getDateFnsLocale(locale: Locale) {
|
||||
switch (locale) {
|
||||
case "zh-CN":
|
||||
return dateFnsZhCN;
|
||||
case "en-US":
|
||||
default:
|
||||
return dateFnsEnUS;
|
||||
}
|
||||
}
|
||||
|
||||
export function formatTimeAgo(date: Date | string | number, locale?: Locale) {
|
||||
const effectiveLocale =
|
||||
locale ??
|
||||
(getLocaleFromCookie() as Locale | null) ??
|
||||
// Fallback when cookie is missing (or on first render)
|
||||
detectLocale();
|
||||
return formatDistanceToNow(date, {
|
||||
addSuffix: true,
|
||||
locale: getDateFnsLocale(effectiveLocale),
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user