feat: label stale evidence data

This commit is contained in:
ik
2026-09-20 20:21:39 +07:00
parent 1dfe1e8ba4
commit 5a8174b11e
6 changed files with 25 additions and 9 deletions
+1 -1
View File
@@ -34,7 +34,7 @@ export type MediaAsset = { id: string; entity_type: "fish" | "waterbody" | "tack
export const spotPath = (item: Pick<Activity, "waterbody_slug" | "x" | "y">) => `/spots/${item.waterbody_slug}-${item.x}x${item.y}`;
export { activityLevel, ago, kg, plural } from "./presentation";
export { activityLevel, ago, freshnessStatus, kg, plural } from "./presentation";
const base = process.env.API_INTERNAL_URL || import.meta.env.API_INTERNAL_URL || "http://localhost:8000";
+7
View File
@@ -20,3 +20,10 @@ export function ago(value: string) {
const minutes = Math.max(0, Math.round((Date.now() - new Date(value).getTime()) / 60000));
return minutes < 60 ? `${minutes} мин назад` : `${Math.floor(minutes / 60)} ч назад`;
}
export function freshnessStatus(value: string | null | undefined, now = Date.now()): "fresh" | "stale" | "unknown" {
if (!value) return "unknown";
const timestamp = new Date(value).getTime();
if (!Number.isFinite(timestamp)) return "unknown";
return now - timestamp > 48 * 60 * 60 * 1000 ? "stale" : "fresh";
}