mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-18 14:07:27 +00:00
Centralize date/time formatting utilities (#11831)
This commit is contained in:
@@ -1,25 +1,6 @@
|
||||
export function formatRelativeTime(timestamp: number): string {
|
||||
const now = Date.now();
|
||||
const diff = now - timestamp;
|
||||
const seconds = Math.floor(diff / 1000);
|
||||
const minutes = Math.floor(seconds / 60);
|
||||
const hours = Math.floor(minutes / 60);
|
||||
const days = Math.floor(hours / 24);
|
||||
import { formatRelativeTimestamp } from "../infra/format-time/format-relative.ts";
|
||||
|
||||
if (seconds < 60) {
|
||||
return "just now";
|
||||
}
|
||||
if (minutes < 60) {
|
||||
return `${minutes}m ago`;
|
||||
}
|
||||
if (hours < 24) {
|
||||
return `${hours}h ago`;
|
||||
}
|
||||
if (days === 1) {
|
||||
return "Yesterday";
|
||||
}
|
||||
if (days < 7) {
|
||||
return `${days}d ago`;
|
||||
}
|
||||
return new Date(timestamp).toLocaleDateString(undefined, { month: "short", day: "numeric" });
|
||||
/** Delegates to centralized formatRelativeTimestamp with date fallback for >7d. */
|
||||
export function formatRelativeTime(timestamp: number): string {
|
||||
return formatRelativeTimestamp(timestamp, { dateFallback: true, fallback: "unknown" });
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user