feat: 添加日期格式化功能,支持不同年份显示完整日期;在评论项中添加调试日志Close #18
All checks were successful
Push to Helm Chart Repository / build (push) Successful in 17s

This commit is contained in:
2025-09-24 09:54:44 +08:00
parent abf8d63607
commit e3e3384995
3 changed files with 12 additions and 5 deletions

View File

@ -51,6 +51,8 @@ export function CommentItem(
const [replies, setReplies] = useState<Comment[]>([]);
const [repliesLoaded, setRepliesLoaded] = useState(false);
console.log(comment)
const handleToggleLike = () => {
if (!canClickLike) {
return;
@ -175,6 +177,7 @@ export function CommentItem(
unitI18n: { secondsAgo: commonT("secondsAgo"), minutesAgo: commonT("minutesAgo"), hoursAgo: commonT("hoursAgo"), daysAgo: commonT("daysAgo") }
})}</span>
{commentState.createdAt !== commentState.updatedAt &&
(new Date(commentState.updatedAt).getTime() - new Date(commentState.createdAt).getTime()) > 10000 &&
<span className="text-xs">{t("edit_at", {
time: formatDateTime({
dateTimeString: commentState.updatedAt,

View File

View File

@ -40,13 +40,17 @@ export function formatDateTime({
return getAgoString(diff, unitI18n);
}
if (now.getFullYear() !== date.getFullYear()) {
// 不同年,显示完整日期时间
return date.toLocaleString(locale, {
year: 'numeric',
month: 'short',
day: 'numeric',
});
}
return date.toLocaleString(locale, {
year: 'numeric',
month: 'short',
day: 'numeric',
hour: '2-digit',
minute: '2-digit',
second: '2-digit',
hour12: false,
});
}