Update time filters: NOW=1h, TODAY=24h, RECENT=3 days, PAST=all

This commit is contained in:
Your Name 2025-12-11 14:37:43 -05:00
parent fbaee6ab17
commit eb81f038bf
1 changed files with 16 additions and 13 deletions

View File

@ -40,17 +40,18 @@ export function matchesSubFilter(post, subFilter) {
return sub === subFilter.toLowerCase();
}
// time filter local règles :
// Live/NOW = 10 minutes
// Today/TODAY = 24 heures
// Recently/RECENT = 4 heures
// Past/PAST = plus vieux que 24 h
// time filter local règles demandées :
// NOW = dernière 1h
// TODAY = dernière 24h
// RECENT = dernier 3 jours
// PAST = ALL (pas de filtre de temps)
export function matchesTimeFilter(createdAt, timeFilter) {
if (!timeFilter) return true;
if (!createdAt) return true;
let d;
if (typeof createdAt === "string") {
// backend renvoie souvent "YYYY-MM-DD HH:MM:SS"
if (createdAt.includes(" ")) {
d = new Date(createdAt.replace(" ", "T") + "Z");
} else {
@ -61,20 +62,21 @@ export function matchesTimeFilter(createdAt, timeFilter) {
}
if (Number.isNaN(d.getTime())) return true;
// PAST = ALL => aucun filtre temps
if (timeFilter === "PAST") return true;
const now = new Date();
const diffMs = now.getTime() - d.getTime();
const diffMin = diffMs / 60000;
const diffHours = diffMs / 3600000;
const diffDays = diffMs / 86400000;
switch (timeFilter) {
case "NOW": // Live = 10 minutes
return diffMin <= 10;
case "NOW": // 1h
return diffHours <= 1;
case "TODAY": // 24h
return diffHours <= 24;
case "RECENT": // 4h
return diffHours <= 4;
case "PAST": // plus vieux que 24h
return diffHours > 24;
case "RECENT": // 3 jours
return diffDays <= 3;
default:
return true;
}
@ -84,7 +86,8 @@ export function matchesTimeFilter(createdAt, timeFilter) {
export function isInViewRadius(post, center, radiusKm) {
if (!center || !radiusKm) return true;
const [lngC, latC] = center;
const coords = post.coords || [post.lon ?? post.lng, post.lat ?? post.latitude];
const coords =
post.coords || [post.lon ?? post.lng, post.lat ?? post.latitude];
const [lngP, latP] = coords;
if (
typeof lngP !== "number" ||