feat: formatRelativeTime add seconds

This commit is contained in:
hamster1963 2024-10-20 00:36:08 +08:00
parent 3413c73889
commit 57c7a60860

View File

@ -90,17 +90,19 @@ export function formatRelativeTime(timestamp: number): string {
const diff = now - timestamp; const diff = now - timestamp;
const hours = Math.floor(diff / (1000 * 60 * 60)); const hours = Math.floor(diff / (1000 * 60 * 60));
const minutes = Math.floor((diff % (1000 * 60 * 60)) / (1000 * 60)); const minutes = Math.floor((diff % (1000 * 60 * 60)) / (1000 * 60));
const seconds = Math.floor((diff % (1000 * 60)) / 1000);
if (hours > 24) { if (hours > 24) {
const days = Math.floor(hours / 24); const days = Math.floor(hours / 24);
return `${days}d`; return `${days}d`;
} else if (hours > 0) { } else if (hours > 0) {
return `${hours}h`; return `${hours}h`;
} else if (minutes >= 0) { } else if (minutes > 0) {
return `${minutes}m`; return `${minutes}m`;
} else { } else if (seconds >= 0) {
return "just now"; return `${seconds}s`;
} }
return "0s";
} }
export function formatTime(timestamp: number): string { export function formatTime(timestamp: number): string {