Files
memind/src/utils/time.ts
T
John 2e14873f2d 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>
2026-06-15 15:04:43 -07:00

37 lines
1.0 KiB
TypeScript

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;
}