Compute analytics timeframe dynamically
Some checks failed
linter / quality (push) Has been cancelled
tests / ci (push) Has been cancelled
tests / ui (push) Has been cancelled

This commit is contained in:
Codex Agent
2026-01-12 11:12:50 +01:00
parent 03bf178d61
commit dce24bb86a
3 changed files with 41 additions and 3 deletions

View File

@@ -5,3 +5,24 @@ export function resolveMaxCount(values: number[]): number {
return Math.max(...values, 1);
}
export function resolveTimelineHours(timestamps: string[], fallbackHours = 12): number {
if (!Array.isArray(timestamps) || timestamps.length < 2) {
return fallbackHours;
}
const times = timestamps
.map((value) => new Date(value).getTime())
.filter((value) => Number.isFinite(value));
if (times.length < 2) {
return fallbackHours;
}
const min = Math.min(...times);
const max = Math.max(...times);
const diff = Math.max(0, max - min);
const hours = diff / (1000 * 60 * 60);
return Math.max(1, Math.round(hours));
}