Files
zpan/server/domain/admin-stats-time.ts
T
saltbo 60f8f64481 refactor(analytics): enforce offline result boundaries
Build versioned UTC hourly rollups, validate analytics facts, and keep dashboard requests result-only with explicit coverage semantics.

Move derived metrics to the server and simplify the admin dashboard around one reconcilable UTC range without export.
2026-07-18 01:58:34 -04:00

16 lines
536 B
TypeScript

export function statsDayKey(date: Date): string {
return date.toISOString().slice(0, 10)
}
export function utcDateStart(date: string): Date {
const value = new Date(`${date}T00:00:00.000Z`)
if (Number.isNaN(value.getTime()) || statsDayKey(value) !== date) throw new Error(`Invalid UTC date: ${date}`)
return value
}
export function addCalendarDays(date: string, days: number): string {
const value = new Date(`${date}T00:00:00.000Z`)
value.setUTCDate(value.getUTCDate() + days)
return value.toISOString().slice(0, 10)
}