mirror of
https://github.com/snowykami/neo-blog.git
synced 2025-09-26 02:56:22 +00:00
feat: 添加日期格式化功能,支持不同年份显示完整日期;在评论项中添加调试日志Close #18
All checks were successful
Push to Helm Chart Repository / build (push) Successful in 17s
All checks were successful
Push to Helm Chart Repository / build (push) Successful in 17s
This commit is contained in:
@ -51,6 +51,8 @@ export function CommentItem(
|
|||||||
const [replies, setReplies] = useState<Comment[]>([]);
|
const [replies, setReplies] = useState<Comment[]>([]);
|
||||||
const [repliesLoaded, setRepliesLoaded] = useState(false);
|
const [repliesLoaded, setRepliesLoaded] = useState(false);
|
||||||
|
|
||||||
|
console.log(comment)
|
||||||
|
|
||||||
const handleToggleLike = () => {
|
const handleToggleLike = () => {
|
||||||
if (!canClickLike) {
|
if (!canClickLike) {
|
||||||
return;
|
return;
|
||||||
@ -175,6 +177,7 @@ export function CommentItem(
|
|||||||
unitI18n: { secondsAgo: commonT("secondsAgo"), minutesAgo: commonT("minutesAgo"), hoursAgo: commonT("hoursAgo"), daysAgo: commonT("daysAgo") }
|
unitI18n: { secondsAgo: commonT("secondsAgo"), minutesAgo: commonT("minutesAgo"), hoursAgo: commonT("hoursAgo"), daysAgo: commonT("daysAgo") }
|
||||||
})}</span>
|
})}</span>
|
||||||
{commentState.createdAt !== commentState.updatedAt &&
|
{commentState.createdAt !== commentState.updatedAt &&
|
||||||
|
(new Date(commentState.updatedAt).getTime() - new Date(commentState.createdAt).getTime()) > 10000 &&
|
||||||
<span className="text-xs">{t("edit_at", {
|
<span className="text-xs">{t("edit_at", {
|
||||||
time: formatDateTime({
|
time: formatDateTime({
|
||||||
dateTimeString: commentState.updatedAt,
|
dateTimeString: commentState.updatedAt,
|
||||||
|
0
web/src/types/datetime.ts
Normal file
0
web/src/types/datetime.ts
Normal file
@ -40,13 +40,17 @@ export function formatDateTime({
|
|||||||
return getAgoString(diff, unitI18n);
|
return getAgoString(diff, unitI18n);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (now.getFullYear() !== date.getFullYear()) {
|
||||||
|
// 不同年,显示完整日期时间
|
||||||
return date.toLocaleString(locale, {
|
return date.toLocaleString(locale, {
|
||||||
year: 'numeric',
|
year: 'numeric',
|
||||||
month: 'short',
|
month: 'short',
|
||||||
day: 'numeric',
|
day: 'numeric',
|
||||||
hour: '2-digit',
|
});
|
||||||
minute: '2-digit',
|
}
|
||||||
second: '2-digit',
|
|
||||||
hour12: false,
|
return date.toLocaleString(locale, {
|
||||||
|
month: 'short',
|
||||||
|
day: 'numeric',
|
||||||
});
|
});
|
||||||
}
|
}
|
Reference in New Issue
Block a user