Refine device inventory layout and last-seen details
Build and Deploy Gateway / build-and-push (push) Successful in 11s
Build and Deploy Gateway / deploy (push) Successful in 6s

This commit is contained in:
2026-08-07 13:39:25 +03:00
parent 158aaadd23
commit 44367e0ef3
5 changed files with 291 additions and 119 deletions
+35
View File
@@ -29,3 +29,38 @@ export function formatTime(iso) {
if (!iso) return "";
return new Date(iso).toLocaleTimeString("ru-RU", { hour12: false });
}
export function formatLastSeen(iso, now = new Date()) {
const date = new Date(iso);
if (Number.isNaN(date.getTime())) return { label: "Нет данных", tooltip: "Нет данных" };
const current = new Date(now);
const day = (value) => Date.UTC(value.getFullYear(), value.getMonth(), value.getDate());
const daysAgo = Math.round((day(current) - day(date)) / 86_400_000);
const time = date.toLocaleTimeString("ru-RU", { hour: "2-digit", minute: "2-digit" });
const dateLabel = daysAgo === 0
? "Сегодня"
: daysAgo === 1
? "Вчера"
: date.toLocaleDateString("ru-RU", {
day: "numeric",
month: "long",
...(date.getFullYear() === current.getFullYear() ? {} : { year: "numeric" }),
});
const elapsedMs = Math.max(0, current.getTime() - date.getTime());
const units = elapsedMs < 60 * 60 * 1000
? [Math.max(1, Math.floor(elapsedMs / 60_000)), "minute"]
: elapsedMs < 24 * 60 * 60 * 1000
? [Math.floor(elapsedMs / 3_600_000), "hour"]
: [Math.floor(elapsedMs / 86_400_000), "day"];
const relative = elapsedMs < 60_000
? "только что"
: new Intl.RelativeTimeFormat("ru-RU", { numeric: "always" }).format(-units[0], units[1]);
const full = date.toLocaleString("ru-RU", {
day: "numeric",
month: "long",
year: "numeric",
hour: "2-digit",
minute: "2-digit",
});
return { label: `${dateLabel}, ${time}`, tooltip: `${full} (${relative})` };
}