mirror of
https://github.com/csehviktor/status-monitor.git
synced 2026-04-28 08:17:35 +02:00
29 lines
933 B
TypeScript
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`;
|
|
}
|
|
};
|