Files
status-monitor/ui/src/services/utils.ts
T
2025-07-06 03:33:41 +02:00

29 lines
933 B
TypeScript

import { UptimeMessage } from "@/services/types";
export function isAgentOnline(data: UptimeMessage): boolean {
const timeDiff = new Date().getTime() - new Date(data.last_seen).getTime();
return timeDiff < 10000;
}
export const formatRelativeTime = (timestamp: string): string => {
const now = new Date();
const past = new Date(timestamp);
const diffInSeconds = Math.floor((now.getTime() - past.getTime()) / 1000);
if (diffInSeconds < 5) {
return "now";
} else if (diffInSeconds < 60) {
return `${diffInSeconds}s ago`;
} else if (diffInSeconds < 3600) {
const minutes = Math.floor(diffInSeconds / 60);
return `${minutes}m ago`;
} else if (diffInSeconds < 86400) {
const hours = Math.floor(diffInSeconds / 3600);
return `${hours}h ago`;
} else {
const days = Math.floor(diffInSeconds / 86400);
return `${days}d ago`;
}
};