Initial commit: Memind H5 portal with MindSpace, Plaza, and agent jobs.
Track application source and tests; exclude local env, user workspaces, and runtime data via .gitignore. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
const pad = (n: number) => String(n).padStart(2, '0');
|
||||
|
||||
function sameDay(a: Date, b: Date) {
|
||||
return (
|
||||
a.getFullYear() === b.getFullYear() &&
|
||||
a.getMonth() === b.getMonth() &&
|
||||
a.getDate() === b.getDate()
|
||||
);
|
||||
}
|
||||
|
||||
export function formatChatTime(timestampSec: number): string {
|
||||
const date = new Date(timestampSec * 1000);
|
||||
const now = new Date();
|
||||
const time = `${pad(date.getHours())}:${pad(date.getMinutes())}`;
|
||||
|
||||
if (sameDay(date, now)) {
|
||||
return time;
|
||||
}
|
||||
|
||||
const yesterday = new Date(now);
|
||||
yesterday.setDate(yesterday.getDate() - 1);
|
||||
if (sameDay(date, yesterday)) {
|
||||
return `昨天 ${time}`;
|
||||
}
|
||||
|
||||
if (date.getFullYear() === now.getFullYear()) {
|
||||
return `${date.getMonth() + 1}月${date.getDate()}日 ${time}`;
|
||||
}
|
||||
|
||||
return `${date.getFullYear()}年${date.getMonth() + 1}月${date.getDate()}日 ${time}`;
|
||||
}
|
||||
|
||||
export function shouldShowTimestamp(currentSec: number, previousSec?: number): boolean {
|
||||
if (previousSec === undefined) return true;
|
||||
return currentSec - previousSec > 5 * 60;
|
||||
}
|
||||
Reference in New Issue
Block a user